#!/bin/bash function installData() { local DIR=$1 shift 1 mkdir -p ${DIR} for file in $*; do cp data/${file} ${DIR} done } if [ "x${MENUTEST}" == "x" ]; then echo 'To run the test set $MENUTEST to your menu-spec implementation.' exit 1 fi if [ "x${MENUTESTDIR}" == "x" ]; then MENUTESTDIR=/tmp/menutestdir echo Using ${MENUTESTDIR} as test directory, override with '$MENUTESTDIR.' else echo Using ${MENUTESTDIR} as test directory. fi export MENUTESTDIR if [ "x${TESTS}" == "x" ]; then TESTS=`ls tests` fi FAILED= SUCCEEDED= for TEST in ${TESTS}; do echo rm -rf ${MENUTESTDIR} 2> /dev/null mkdir ${MENUTESTDIR} RESULT=tests/${TEST}/result if [ ! -e ${RESULT} ]; then echo '!!! Result file ('${RESULT}') for '${TEST}' missing' else ( echo ">>> Running test ${TEST}" # Some predefined values XDG_CONFIG_HOME=${MENUTESTDIR}/xdg_config_home XDG_DATA_HOME=${MENUTESTDIR}/xdg_data_home XDG_CONFIG_DIR=${MENUTESTDIR}/xdg_config_dir XDG_DATA_DIR=${MENUTESTDIR}/xdg_data_dir XDG_CONFIG_DIRS=$XDG_CONFIG_DIR XDG_DATA_DIRS=$XDG_DATA_DIR export XDG_CONFIG_HOME export XDG_DATA_HOME export XDG_CONFIG_DIR export XDG_DATA_DIR export XDG_CONFIG_DIRS export XDG_DATA_DIRS . tests/${TEST}/test $MENUTEST > ${MENUTESTDIR}/result1 2> ${MENUTESTDIR}/log ./expand ${RESULT} > ${MENUTESTDIR}/result2 ) if diff -q ${MENUTESTDIR}/result1 ${MENUTESTDIR}/result2 > /dev/null; then echo '>>> OK' SUCCEEDED="${SUCCEEDED} ${TEST}" else sort ${MENUTESTDIR}/result1 > ${MENUTESTDIR}/result1.sorted sort ${MENUTESTDIR}/result2 > ${MENUTESTDIR}/result2.sorted if diff -u ${MENUTESTDIR}/result1.sorted ${MENUTESTDIR}/result2.sorted > ${MENUTESTDIR}/result.diff; then echo '>>> OK (different order)' SUCCEEDED="${SUCCEEDED} ${TEST}" else echo '>>> Failed' cat ${MENUTESTDIR}/result.diff cat ${MENUTESTDIR}/log FAILED="${FAILED} ${TEST}" fi fi fi done echo "OK tests: ${SUCCEEDED}" if ! test -z "${FAILED}" ; then echo "Failed tests: ${FAILED}" exit 1 fi echo `echo ${SUCCEEDED} | wc -w`' tests passed, '`echo ${FAILED} | wc -w`' tests failed' if test -z "${FAILED}" ; then exit 0 else exit 1 fi