diff --git a/test/Makefile b/test/Makefile index eaa944fb..0b33660b 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,15 +1,16 @@ -.PHONY: all check clean +.PHONY: all check clean $(wildcard TEST-??-*) -check: +$(wildcard TEST-??-*): @[ "$$EUID" == "0" ] || { echo "'check' must be run as root! Please use 'sudo'."; exit 1; } - @{ ret=0; \ - for i in TEST-[0-9]*; do \ - [ -d $$i ] || continue ; \ - [ -f $$i/Makefile ] || continue ; \ - if [ -n "$$TESTS" ]; then t=$${i##TEST-}; t=$${t%%-*}; [ "$${TESTS#*$$t*}" != "$$TESTS" ] || continue; fi; \ - if [ -n "$$SKIP" ]; then t=$${i##TEST-}; t=$${t%%-*}; [ "$${SKIP#*$$t*}" != "$$SKIP" ] && continue; fi; \ - $(MAKE) -C $$i all ; ret=$$((ret + $$?)); \ - done; exit $$ret; } + @{ \ + [ -d $@ ] || exit 0; \ + [ -f $@/Makefile ] || exit 0; \ + if [ -n "$$TESTS" ]; then t=$${$@##TEST-}; t=$${t%%-*}; [ "$${TESTS#*$$t*}" != "$$TESTS" ] || exit 0; fi; \ + if [ -n "$$SKIP" ]; then t=$${$@##TEST-}; t=$${t%%-*}; [ "$${SKIP#*$$t*}" != "$$SKIP" ] && exit 0; fi; \ + $(MAKE) -C $@ all ; \ + } + +check: $(wildcard TEST-??-*) clean: @for i in TEST-[0-9]*; do \ diff --git a/test/test-functions b/test/test-functions index 2b8a4d26..57611ff5 100644 --- a/test/test-functions +++ b/test/test-functions @@ -4,14 +4,14 @@ export PATH [[ -e .testdir ]] && . .testdir if [[ -z "$TESTDIR" ]] || [[ ! -d "$TESTDIR" ]]; then - TESTDIR=$(mktemp -d -p "/var/tmp" -t dracut-test.XXXXXX) + TESTDIR=$(mktemp -d -p "/var/tmp" -t dracut-test.XXXXXX) fi echo "TESTDIR=\"$TESTDIR\"" > .testdir export TESTDIR command -v test_check &>/dev/null || test_check() { - : -} + : + } # terminal sequence to set color to a 'success' color (currently: green) function SETCOLOR_SUCCESS() { echo -en '\033[0;32m'; } @@ -22,6 +22,11 @@ function SETCOLOR_WARNING() { echo -en '\033[0;33m'; } # terminal sequence to reset to the default color. function SETCOLOR_NORMAL() { echo -en '\033[0;39m'; } +COLOR_SUCCESS='\033[0;32m' +COLOR_FAILURE='\033[0;31m' +COLOR_WARNING='\033[0;33m' +COLOR_NORMAL='\033[0;39m' + check_root() { if (( $EUID != 0 )); then SETCOLOR_FAILURE; echo "Tests must be run as root! Please use 'sudo'."; SETCOLOR_NORMAL @@ -49,45 +54,44 @@ while (($# > 0)); do exit $?;; --all) check_root - echo -n "TEST: $TEST_DESCRIPTION "; if ! test_check 2&>test.log ; then - SETCOLOR_WARNING - echo "[SKIPPED]" - SETCOLOR_NORMAL + echo -e "TEST: $TEST_DESCRIPTION " $COLOR_WARNING "[SKIPPED]" $COLOR_NORMAL exit 0; + else + echo "TEST: $TEST_DESCRIPTION [STARTED]"; fi if [ "$V" != "1" ]; then - ( - test_setup && test_run - ret=$? - test_cleanup - rm -fr -- "$TESTDIR" - rm -f -- .testdir - exit $ret - ) test.log 2>&1 + ( + test_setup && test_run + ret=$? + test_cleanup + rm -fr -- "$TESTDIR" + rm -f -- .testdir + exit $ret + ) test.log 2>&1 else - set -o pipefail - ( - test_setup && test_run - ret=$? - test_cleanup - rm -fr -- "$TESTDIR" - rm -f -- .testdir - exit $ret - ) &1 | tee test.log + set -o pipefail + ( + test_setup && test_run + ret=$? + test_cleanup + rm -fr -- "$TESTDIR" + rm -f -- .testdir + exit $ret + ) &1 | tee test.log fi ret=$? set +o pipefail if [ $ret -eq 0 ]; then - rm -- test.log - SETCOLOR_SUCCESS - echo "[OK]" - SETCOLOR_NORMAL + rm -- test.log + echo -e "TEST: $TEST_DESCRIPTION " $COLOR_SUCCESS "[OK]" $COLOR_NORMAL else - SETCOLOR_FAILURE - echo "[FAILED]" - SETCOLOR_NORMAL - echo "see $(pwd)/test.log" + echo -e "TEST: $TEST_DESCRIPTION " $COLOR_FAILURE "[FAILED]" $COLOR_NORMAL + if [ "$V" == "2" ]; then + cat $(pwd)/test.log + else + echo "see $(pwd)/test.log" + fi fi exit $ret;; *) break ;;