diff options
Diffstat (limited to 'Test')
-rw-r--r-- | Test/C03traps.ztst | 2 | ||||
-rw-r--r-- | Test/D02glob.ztst | 12 | ||||
-rw-r--r-- | Test/E03posix.ztst | 2 | ||||
-rw-r--r-- | Test/P01privileged.ztst | 23 | ||||
-rw-r--r-- | Test/README | 7 | ||||
-rw-r--r-- | Test/V14system.ztst | 2 | ||||
-rw-r--r-- | Test/X03zlebindkey.ztst | 1 | ||||
-rwxr-xr-x | Test/ztst.zsh | 65 |
8 files changed, 76 insertions, 38 deletions
diff --git a/Test/C03traps.ztst b/Test/C03traps.ztst index 6f84e5db2..f120809a7 100644 --- a/Test/C03traps.ztst +++ b/Test/C03traps.ztst @@ -901,7 +901,7 @@ F:Must be tested with a top-level script rather than source or function fn trap1 trap2 echo out2 ' --f:(workers/44007) function execution continues after 'exit' in trap +0:'exit' in trap causes calling function to return >out1 >fn1 >trap1 diff --git a/Test/D02glob.ztst b/Test/D02glob.ztst index 72891a2a7..850a535e5 100644 --- a/Test/D02glob.ztst +++ b/Test/D02glob.ztst @@ -748,13 +748,21 @@ touch glob.tmp/secret-d$1/dir/file chmod $1 glob.tmp/secret-d$1 done - print -raC 2 -- glob.tmp/secret-*/* glob.tmp/secret-*/file + if (( EUID == 0 )); then + ZTST_skip='Not testing unreadable directories (root reads anything)' + else + print -raC 2 -- glob.tmp/secret-*/* glob.tmp/secret-*/file + fi 0:names inside unreadable directories can be globbed if searchable >glob.tmp/secret-d444/dir glob.tmp/secret-d444/file >glob.tmp/secret-s444/dir glob.tmp/secret-s444/file >glob.tmp/secret-d111/file glob.tmp/secret-s111/file - print -rC 2 -- glob.tmp/secret-*/dir/* + if (( EUID == 0 )); then + ZTST_skip='Not testing unreadable directories (root reads anything)' + else + print -rC 2 -- glob.tmp/secret-*/dir/* + fi 0:glob files in readable directories inside unreadable directories >glob.tmp/secret-d111/dir/file glob.tmp/secret-s111/dir/file diff --git a/Test/E03posix.ztst b/Test/E03posix.ztst index caab97ab6..6ac4d1732 100644 --- a/Test/E03posix.ztst +++ b/Test/E03posix.ztst @@ -153,7 +153,7 @@ F:This may also need to apply to multibyte whitespace F:POSIX has neither math functions nor floating point >42 - ARGV0=sh $ZTST_testdir/../Src/zsh -c 'EUID=10; echo "$EUID"' + ARGV0=sh $ZTST_testdir/../Src/zsh -c 'EUID=1; EUID=10; echo $EUID' -f:EUID is not a special variable >10 diff --git a/Test/P01privileged.ztst b/Test/P01privileged.ztst index 7c4a1be35..5d45c1a4c 100644 --- a/Test/P01privileged.ztst +++ b/Test/P01privileged.ztst @@ -26,23 +26,23 @@ %prep - # Mind your empty lines here. The logic in this %prep section is somewhat - # complex compared to most others; to avoid lots of nested/duplicated - # conditions we need to make sure that this all gets executed as a single - # function from which we can return early + # If ZTST_unimplemented is set to non-null in a chunk then all the + # remaining chunks (and all of %test and %clean sections) will be skipped. [[ $EUID == 0 || -n $ZSH_TEST_UNPRIVILEGED_UID$ZSH_TEST_UNPRIVILEGED_GID ]] || { ZTST_unimplemented='PRIVILEGED tests require super-user privileges (or env var)' - return 1 + return 0 } + (( $+commands[perl] )) || { # @todo Eliminate this dependency with a C wrapper? ZTST_unimplemented='PRIVILEGED tests require Perl' - return 1 + return 0 } + grep -qE '#define HAVE_SETRES?UID' $ZTST_testdir/../config.h || { ZTST_unimplemented='PRIVILEGED tests require setreuid()/setresuid()' - return 1 + return 0 } - # + ruid= euid= rgid= egid= # if [[ -n $ZSH_TEST_UNPRIVILEGED_UID ]]; then @@ -76,13 +76,14 @@ # [[ -n $ruid && -n $euid ]] || { ZTST_unimplemented='PRIVILEGED tests require unprivileged UID:EUID' - return 1 + return 0 } + [[ -n $rgid || -n $egid ]] || { ZTST_unimplemented='PRIVILEGED tests require unprivileged GID:EGID' - return 1 + return 0 } - # + print -ru$ZTST_fd \ "Using unprivileged UID $ruid, EUID $euid, GID $rgid, EGID $egid" # diff --git a/Test/README b/Test/README index 726d68e72..670434ac3 100644 --- a/Test/README +++ b/Test/README @@ -20,6 +20,13 @@ more information about the tests being performed with ZTST_verbose=1 make check (`test' is equivalent to `check') or change 1 to 2 for even more detail. +A test file is usually aborted on the first error. To continue to the +end, run with + ZTST_continue=1 make check +This can usefully be combined with ZTST_verbose. The test is always +aborted on a syntax error as in that case it is not obvoius how to +continue. + Individual or groups of tests can be performed with make TESTNUM=C02 check or diff --git a/Test/V14system.ztst b/Test/V14system.ztst index 100daab08..ffdb730a4 100644 --- a/Test/V14system.ztst +++ b/Test/V14system.ztst @@ -5,10 +5,10 @@ if zmodload -s zsh/system && zmodload -s zsh/zselect; then tst_dir=V14.tmp mkdir -p -- $tst_dir + : > $tst_dir/file # File on which to acquire flock. else ZTST_unimplemented='the zsh/system and zsh/zselect modules are not available' fi - : > $tst_dir/file # File on which to acquire flock. %test diff --git a/Test/X03zlebindkey.ztst b/Test/X03zlebindkey.ztst index 3e299a337..43692a85b 100644 --- a/Test/X03zlebindkey.ztst +++ b/Test/X03zlebindkey.ztst @@ -3,6 +3,7 @@ # into bindings. The latter is particularly tricky with multibyte sequences. %prep + unset -m LC_\* ZSH_TEST_LANG= langs=(en_{US,GB}.{UTF-,utf}8 en.UTF-8 $(locale -a 2>/dev/null | egrep 'utf8|UTF-8')) diff --git a/Test/ztst.zsh b/Test/ztst.zsh index 89fe69b5b..aca275c1c 100755 --- a/Test/ztst.zsh +++ b/Test/ztst.zsh @@ -17,6 +17,9 @@ # Defined in such a way that any value from the environment is used. : ${ZTST_verbose:=0} +# If non-zero, continue the tests even after a test fails. +: ${ZTST_continue:=0} + # We require all options to be reset, not just emulation options. # Unfortunately, due to the crud which may be in /etc/zshenv this might # still not be good enough. Maybe we should trick it somehow. @@ -30,6 +33,9 @@ emulate -R zsh [[ -n $LC_NUMERIC ]] && LC_NUMERIC=C [[ -n $LC_MESSAGES ]] && LC_MESSAGES=C [[ -n $LANG ]] && LANG=C +# Test file may (or may not) set LANG to other locales. In either case, +# LANG must be passed to child zsh. +export LANG # Don't propagate variables that are set by default in the shell. typeset +x WORDCHARS @@ -143,6 +149,10 @@ ZTST_testfailed() { $ZTST_failmsg" fi ZTST_testfailed=1 + # if called from within ZTST_Test() this will increment ZTST_Test's local + # ZTST_failures. Otherwise global ZTST_failures will be incremented + # (but currently its value is not used). + (( ++ZTST_failures )) return 1 } ZTST_testxpassed() { @@ -156,6 +166,7 @@ ZTST_testxpassed() { $ZTST_failmsg" fi ZTST_testfailed=1 + (( ++ZTST_failures )) return 1 } @@ -291,16 +302,18 @@ ZTST_execchunk() { } # Functions for preparation and cleaning. -# When cleaning up (non-zero string argument), we ignore status. -ZTST_prepclean() { - # Execute indented code chunks. - while ZTST_getchunk; do - ZTST_execchunk >/dev/null || [[ -n $1 ]] || { - [[ -n "$ZTST_unimplemented" ]] || +ZTST_prep ZTST_clean () { + # Execute indented code chunks. If ZTST_unimplemented is set + # in any chunk then we will skip the remaining chunks. + # We ignore return status of chunks when cleaning up. + while [[ -z "$ZTST_unimplemented" ]] && ZTST_getchunk; do + ZTST_execchunk >/dev/null || [[ $0 = ZTST_clean ]] || { ZTST_testfailed "non-zero status from preparation code: -$ZTST_code" && return 0 +$ZTST_code" + return 1 } done + return 0 } # diff wrapper @@ -373,12 +386,12 @@ ZTST_diff() { return "$diff_ret" } - + ZTST_test() { local last match mbegin mend found substlines local diff_out diff_err local ZTST_skip - integer expected_to_fail + integer expected_to_fail ZTST_failures while true; do rm -f $ZTST_in $ZTST_out $ZTST_err @@ -492,7 +505,7 @@ $ZTST_curline" $ZTST_code${$(<$ZTST_terr):+ Error output: $(<$ZTST_terr)}" - return 1 + if (( ZTST_continue ));then continue; else return 1; fi fi ZTST_verbose 2 "ZTST_test: test produced standard output: @@ -515,7 +528,7 @@ $(<$ZTST_terr)" $ZTST_code${$(<$ZTST_terr):+ Error output: $(<$ZTST_terr)}" - return 1 + if (( ZTST_continue ));then continue; else return 1; fi fi if [[ $ZTST_flags = *q* && -s $ZTST_err ]]; then substlines="$(<$ZTST_err)" @@ -529,21 +542,27 @@ $(<$ZTST_terr)}" fi ZTST_testfailed "error output differs from expected as shown above for: $ZTST_code" - return 1 + if (( ZTST_continue ));then continue; else return 1; fi fi if (( expected_to_fail )); then ZTST_testxpassed - return 1 + if (( ZTST_continue ));then continue; else return 1; fi fi fi ZTST_verbose 1 "Test successful." [[ -n $last ]] && break done - ZTST_verbose 2 "ZTST_test: all tests successful" + if (( ZTST_failures )); then + ZTST_verbose 1 "ZTST_test: $ZTST_failures test(s) failed" + else + ZTST_verbose 2 "ZTST_test: all tests successful" + fi # reset message to keep ZTST_testfailed output correct ZTST_message='' + + return ZTST_failures } @@ -563,27 +582,29 @@ while [[ -z "$ZTST_unimplemented" ]] && ZTST_getsect $ZTST_skipok; do (prep) if (( ${ZTST_sects[prep]} + ${ZTST_sects[test]} + \ ${ZTST_sects[clean]} )); then ZTST_testfailed "\`prep' section must come first" - exit 1 + break # skip %test and %clean sections, but run ZTST_cleanup fi - ZTST_prepclean + ZTST_prep || ZTST_skipok=1 ZTST_sects[prep]=1 ;; (test) if (( ${ZTST_sects[test]} + ${ZTST_sects[clean]} )); then ZTST_testfailed "bad placement of \`test' section" - exit 1 + break # skip %clean section, but run ZTST_cleanup fi - # careful here: we can't execute ZTST_test before || or && - # because that affects the behaviour of traps in the tests. - ZTST_test - (( $? )) && ZTST_skipok=1 + if [[ -z "$ZTST_skipok" ]]; then # if no error in %prep + # careful here: we can't execute ZTST_test before || or && + # because that affects the behaviour of traps in the tests. + ZTST_test + (( $? )) && ZTST_skipok=1 + fi ZTST_sects[test]=1 ;; (clean) if (( ${ZTST_sects[test]} == 0 || ${ZTST_sects[clean]} )); then ZTST_testfailed "bad use of \`clean' section" else - ZTST_prepclean 1 + ZTST_clean ZTST_sects[clean]=1 fi ZTST_skipok= |