1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-16 12:21:18 +02:00

50013: skip %test if a chunk in %prep fails

Only %test is skipped if a chunk in %prep returns nonzero. Both %test
and %clean are skipped if ZTST_unimplemented is set in a chunk of %prep.
ZTST_cleanup is run in both cases.
This commit is contained in:
Jun-ichi Takimoto 2022-04-12 16:56:18 +09:00
parent 3622551e02
commit 06e5ec914f
3 changed files with 34 additions and 26 deletions

View file

@ -1,5 +1,8 @@
2022-04-12 Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>
* 50013: Test/P01privileged.ztst, Test/ztst.zsh: skip %test if
a chunk in %prep returns nonzero
* 49996 (Peter) + 50012: Test/README, Test/ztst.zsh: add
ZTST_continue to continue tests after a failure

View file

@ -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"
#

View file

@ -299,16 +299,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
@ -577,27 +579,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=