X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=test%2Ftest-lib.sh;h=7ae96c6999aaed84007b99e4e2a6c8a6beb754da;hb=b6f87c3085e25e5bf65a4f956af8846bc0681c52;hp=e7458c92f320d2b634ffed042e909c2324782f1a;hpb=e563b8cafd394f673f0a768d46c18dd5da7411a5;p=notmuch diff --git a/test/test-lib.sh b/test/test-lib.sh index e7458c92..7ae96c69 100644 --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -219,10 +219,21 @@ test_fixed=0 test_broken=0 test_success=0 +declare -a _exit_functions=() + +at_exit_function () { + _exit_functions=($1 ${_exit_functions[@]/$1}) +} + +rm_exit_function () { + _exit_functions=(${_exit_functions[@]/$1}) +} + _exit_common () { code=$? trap - EXIT set +ex + for _fn in ${_exit_functions[@]}; do $_fn; done rm -rf "$TEST_TMPDIR" } @@ -563,9 +574,8 @@ test_expect_equal () error "bug in the test script: test_expect_equal without test_begin_subtest" fi inside_subtest= - test "$#" = 3 && { prereq=$1; shift; } || prereq= test "$#" = 2 || - error "bug in the test script: not 2 or 3 parameters to test_expect_equal" + error "bug in the test script: not 2 parameters to test_expect_equal" output="$1" expected="$2" @@ -590,9 +600,8 @@ test_expect_equal_file () error "bug in the test script: test_expect_equal_file without test_begin_subtest" fi inside_subtest= - test "$#" = 3 && { prereq=$1; shift; } || prereq= test "$#" = 2 || - error "bug in the test script: not 2 or 3 parameters to test_expect_equal" + error "bug in the test script: not 2 parameters to test_expect_equal_file" file1="$1" file2="$2" @@ -633,9 +642,8 @@ test_sort_json () { } test_emacs_expect_t () { - test "$#" = 2 && { prereq=$1; shift; } || prereq= test "$#" = 1 || - error "bug in the test script: not 1 or 2 parameters to test_emacs_expect_t" + error "bug in the test script: not 1 parameter to test_emacs_expect_t" if [ -z "$inside_subtest" ]; then error "bug in the test script: test_emacs_expect_t without test_begin_subtest" fi @@ -750,12 +758,8 @@ notmuch_config_sanitize () # End of notmuch helper functions # Use test_set_prereq to tell that a particular prerequisite is available. -# The prerequisite can later be checked for in two ways: # -# - Explicitly using test_have_prereq. -# -# - Implicitly by specifying the prerequisite tag in the calls to -# test_expect_{success,failure,code}. +# The prerequisite can later be checked for by using test_have_prereq. # # The single parameter is the prerequisite tag (a simple word, in all # capital letters by convention). @@ -890,11 +894,6 @@ test_skip () { break esac done - if test -z "$to_skip" && test -n "$prereq" && - ! test_have_prereq "$prereq" - then - to_skip=t - fi case "$to_skip" in t) test_report_skip_ "$@" @@ -928,14 +927,17 @@ test_subtest_known_broken () { } test_expect_success () { - test "$#" = 3 && { prereq=$1; shift; } || prereq= - test "$#" = 2 || - error "bug in the test script: not 2 or 3 parameters to test-expect-success" - test_subtest_name="$1" - test_reset_state_ - if ! test_skip "$@" + exec 1>&6 2>&7 # Restore stdout and stderr + if [ -z "$inside_subtest" ]; then + error "bug in the test script: test_expect_success without test_begin_subtest" + fi + inside_subtest= + test "$#" = 1 || + error "bug in the test script: not 1 parameters to test_expect_success" + + if ! test_skip "$test_subtest_name" then - test_run_ "$2" + test_run_ "$1" run_ret="$?" # test_run_ may update missing external prerequisites test_check_missing_external_prereqs_ "$@" || @@ -943,20 +945,23 @@ test_expect_success () { then test_ok_ else - test_failure_ "$2" + test_failure_ "$1" fi fi } test_expect_code () { - test "$#" = 4 && { prereq=$1; shift; } || prereq= - test "$#" = 3 || - error "bug in the test script: not 3 or 4 parameters to test-expect-code" - test_subtest_name="$2" - test_reset_state_ - if ! test_skip "$@" + exec 1>&6 2>&7 # Restore stdout and stderr + if [ -z "$inside_subtest" ]; then + error "bug in the test script: test_expect_code without test_begin_subtest" + fi + inside_subtest= + test "$#" = 2 || + error "bug in the test script: not 2 parameters to test_expect_code" + + if ! test_skip "$test_subtest_name" then - test_run_ "$3" + test_run_ "$2" run_ret="$?" # test_run_ may update missing external prerequisites, test_check_missing_external_prereqs_ "$@" || @@ -964,7 +969,7 @@ test_expect_code () { then test_ok_ else - test_failure_ "exit code $eval_ret, expected $1" "$3" + test_failure_ "exit code $eval_ret, expected $1" "$2" fi fi } @@ -1127,7 +1132,7 @@ test_emacs () { test_python() { # Note: if there is need to print debug information from python program, # use stdout = os.fdopen(6, 'w') or stderr = os.fdopen(7, 'w') - PYTHONPATH="$TEST_DIRECTORY/../bindings/python${PYTHONPATH:+:$PYTHONPATH}" \ + PYTHONPATH="$NOTMUCH_SRCDIR/bindings/python${PYTHONPATH:+:$PYTHONPATH}" \ $NOTMUCH_PYTHON -B - > OUTPUT } @@ -1139,7 +1144,7 @@ test_C () { exec_file="test${test_count}" test_file="${exec_file}.c" cat > ${test_file} - ${TEST_CC} ${TEST_CFLAGS} -I${TEST_DIRECTORY} -I${TEST_DIRECTORY}/../lib -o ${exec_file} ${test_file} -L${TEST_DIRECTORY}/../lib/ -lnotmuch -ltalloc + ${TEST_CC} ${TEST_CFLAGS} -I${TEST_DIRECTORY} -I${NOTMUCH_SRCDIR}/lib -o ${exec_file} ${test_file} -L${TEST_DIRECTORY}/../lib/ -lnotmuch -ltalloc echo "== stdout ==" > OUTPUT.stdout echo "== stderr ==" > OUTPUT.stderr ./${exec_file} "$@" 1>>OUTPUT.stdout 2>>OUTPUT.stderr @@ -1197,6 +1202,22 @@ test_init_ () { . ./test-lib-common.sh || exit 1 +if [ "${NOTMUCH_GMIME_MAJOR}" = 3 ]; then + test_subtest_broken_gmime_3 () { + test_subtest_known_broken + } + test_subtest_broken_gmime_2 () { + true + } +else + test_subtest_broken_gmime_3 () { + true + } + test_subtest_broken_gmime_2 () { + test_subtest_known_broken + } +fi + emacs_generate_script