Merge branch 'ab/lib-subtest'

Updates to the tests in t0000 to test the test framework.

* ab/lib-subtest:
  test-lib tests: get rid of copy/pasted mock test code
  test-lib tests: assert 1 exit code, not non-zero
  test-lib tests: refactor common part of check_sub_test_lib_test*()
  test-lib tests: avoid subshell for "test_cmp" for readability
  test-lib tests: don't provide a description for the sub-tests
  test-lib tests: split up "write and run" into two functions
  test-lib tests: move "run_sub_test" to a new lib-subtest.sh
This commit is contained in:
Junio C Hamano 2021-10-13 15:15:57 -07:00
commit cf006037bf
2 changed files with 213 additions and 330 deletions

95
t/lib-subtest.sh Normal file
View File

@ -0,0 +1,95 @@
write_sub_test_lib_test () {
name="$1" # stdin is the body of the test code
mkdir "$name" &&
write_script "$name/$name.sh" "$TEST_SHELL_PATH" <<-EOF &&
test_description='A test of test-lib.sh itself'
# Point to the t/test-lib.sh, which isn't in ../ as usual
. "\$TEST_DIRECTORY"/test-lib.sh
EOF
cat >>"$name/$name.sh"
}
_run_sub_test_lib_test_common () {
cmp_op="$1" want_code="$2" name="$3" # stdin is the body of the test code
shift 3
# intercept pseudo-options at the front of the argument list that we
# will not pass to child script
skip=
while test $# -gt 0
do
case "$1" in
--skip=*)
skip=${1#--*=}
shift
;;
*)
break
;;
esac
done
(
cd "$name" &&
# Pretend we're not running under a test harness, whether we
# are or not. The test-lib output depends on the setting of
# this variable, so we need a stable setting under which to run
# the sub-test.
sane_unset HARNESS_ACTIVE &&
export TEST_DIRECTORY &&
# The child test re-sources GIT-BUILD-OPTIONS and may thus
# override the test output directory. We thus pass it as an
# explicit override to the child.
TEST_OUTPUT_DIRECTORY_OVERRIDE=$(pwd) &&
export TEST_OUTPUT_DIRECTORY_OVERRIDE &&
GIT_SKIP_TESTS=$skip &&
export GIT_SKIP_TESTS &&
sane_unset GIT_TEST_FAIL_PREREQS &&
./"$name.sh" "$@" >out 2>err;
ret=$? &&
test "$ret" "$cmp_op" "$want_code"
)
}
write_and_run_sub_test_lib_test () {
name="$1" descr="$2" # stdin is the body of the test code
write_sub_test_lib_test "$@" || return 1
_run_sub_test_lib_test_common -eq 0 "$@"
}
write_and_run_sub_test_lib_test_err () {
name="$1" descr="$2" # stdin is the body of the test code
write_sub_test_lib_test "$@" || return 1
_run_sub_test_lib_test_common -eq 1 "$@"
}
run_sub_test_lib_test () {
_run_sub_test_lib_test_common -eq 0 "$@"
}
run_sub_test_lib_test_err () {
_run_sub_test_lib_test_common -eq 1 "$@"
}
_check_sub_test_lib_test_common () {
name="$1" &&
sed -e 's/^> //' -e 's/Z$//' >"$name"/expect.out &&
test_cmp "$name"/expect.out "$name"/out
}
check_sub_test_lib_test () {
name="$1" # stdin is the expected output from the test
_check_sub_test_lib_test_common "$name" &&
test_must_be_empty "$name"/err
}
check_sub_test_lib_test_err () {
name="$1" # stdin is the expected output from the test
_check_sub_test_lib_test_common "$name" &&
# expected error output is in descriptor 3
sed -e 's/^> //' -e 's/Z$//' <&3 >"$name"/expect.err &&
test_cmp "$name"/expect.err "$name"/err
}

View File

@ -19,6 +19,7 @@ modification *should* take notice and update the test vectors here.
'
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-subtest.sh
try_local_xy () {
local x="local" y="alsolocal" &&
@ -66,95 +67,8 @@ test_expect_success 'success is reported like this' '
:
'
_run_sub_test_lib_test_common () {
neg="$1" name="$2" descr="$3" # stdin is the body of the test code
shift 3
# intercept pseudo-options at the front of the argument list that we
# will not pass to child script
skip=
while test $# -gt 0
do
case "$1" in
--skip=*)
skip=${1#--*=}
shift
;;
*)
break
;;
esac
done
mkdir "$name" &&
(
# Pretend we're not running under a test harness, whether we
# are or not. The test-lib output depends on the setting of
# this variable, so we need a stable setting under which to run
# the sub-test.
sane_unset HARNESS_ACTIVE &&
cd "$name" &&
write_script "$name.sh" "$TEST_SHELL_PATH" <<-EOF &&
test_description='$descr (run in sub test-lib)
This is run in a sub test-lib so that we do not get incorrect
passing metrics
'
# Point to the t/test-lib.sh, which isn't in ../ as usual
. "\$TEST_DIRECTORY"/test-lib.sh
EOF
cat >>"$name.sh" &&
export TEST_DIRECTORY &&
# The child test re-sources GIT-BUILD-OPTIONS and may thus
# override the test output directory. We thus pass it as an
# explicit override to the child.
TEST_OUTPUT_DIRECTORY_OVERRIDE=$(pwd) &&
export TEST_OUTPUT_DIRECTORY_OVERRIDE &&
GIT_SKIP_TESTS=$skip &&
export GIT_SKIP_TESTS &&
sane_unset GIT_TEST_FAIL_PREREQS &&
if test -z "$neg"
then
./"$name.sh" "$@" >out 2>err
else
! ./"$name.sh" "$@" >out 2>err
fi
)
}
run_sub_test_lib_test () {
_run_sub_test_lib_test_common '' "$@"
}
run_sub_test_lib_test_err () {
_run_sub_test_lib_test_common '!' "$@"
}
check_sub_test_lib_test () {
name="$1" # stdin is the expected output from the test
(
cd "$name" &&
test_must_be_empty err &&
sed -e 's/^> //' -e 's/Z$//' >expect &&
test_cmp expect out
)
}
check_sub_test_lib_test_err () {
name="$1" # stdin is the expected output from the test
# expected error output is in descriptor 3
(
cd "$name" &&
sed -e 's/^> //' -e 's/Z$//' >expect.out &&
test_cmp expect.out out &&
sed -e 's/^> //' -e 's/Z$//' <&3 >expect.err &&
test_cmp expect.err err
)
}
test_expect_success 'pretend we have a fully passing test suite' '
run_sub_test_lib_test full-pass "3 passing tests" <<-\EOF &&
test_expect_success 'subtest: 3 passing tests' '
write_and_run_sub_test_lib_test full-pass <<-\EOF &&
for i in 1 2 3
do
test_expect_success "passing test #$i" "true"
@ -170,9 +84,8 @@ test_expect_success 'pretend we have a fully passing test suite' '
EOF
'
test_expect_success 'pretend we have a partially passing test suite' '
run_sub_test_lib_test_err \
partial-pass "2/3 tests passing" <<-\EOF &&
test_expect_success 'subtest: 2/3 tests passing' '
write_and_run_sub_test_lib_test_err partial-pass <<-\EOF &&
test_expect_success "passing test #1" "true"
test_expect_success "failing test #2" "false"
test_expect_success "passing test #3" "true"
@ -188,8 +101,8 @@ test_expect_success 'pretend we have a partially passing test suite' '
EOF
'
test_expect_success 'pretend we have a known breakage' '
run_sub_test_lib_test failing-todo "A failing TODO test" <<-\EOF &&
test_expect_success 'subtest: a failing TODO test' '
write_and_run_sub_test_lib_test failing-todo <<-\EOF &&
test_expect_success "passing test" "true"
test_expect_failure "pretend we have a known breakage" "false"
test_done
@ -203,8 +116,8 @@ test_expect_success 'pretend we have a known breakage' '
EOF
'
test_expect_success 'pretend we have fixed a known breakage' '
run_sub_test_lib_test passing-todo "A passing TODO test" <<-\EOF &&
test_expect_success 'subtest: a passing TODO test' '
write_and_run_sub_test_lib_test passing-todo <<-\EOF &&
test_expect_failure "pretend we have fixed a known breakage" "true"
test_done
EOF
@ -215,9 +128,8 @@ test_expect_success 'pretend we have fixed a known breakage' '
EOF
'
test_expect_success 'pretend we have fixed one of two known breakages (run in sub test-lib)' '
run_sub_test_lib_test partially-passing-todos \
"2 TODO tests, one passing" <<-\EOF &&
test_expect_success 'subtest: 2 TODO tests, one passin' '
write_and_run_sub_test_lib_test partially-passing-todos <<-\EOF &&
test_expect_failure "pretend we have a known breakage" "false"
test_expect_success "pretend we have a passing test" "true"
test_expect_failure "pretend we have fixed another known breakage" "true"
@ -234,9 +146,8 @@ test_expect_success 'pretend we have fixed one of two known breakages (run in su
EOF
'
test_expect_success 'pretend we have a pass, fail, and known breakage' '
run_sub_test_lib_test_err \
mixed-results1 "mixed results #1" <<-\EOF &&
test_expect_success 'subtest: mixed results: pass, failure and a TODO test' '
write_and_run_sub_test_lib_test_err mixed-results1 <<-\EOF &&
test_expect_success "passing test" "true"
test_expect_success "failing test" "false"
test_expect_failure "pretend we have a known breakage" "false"
@ -253,9 +164,8 @@ test_expect_success 'pretend we have a pass, fail, and known breakage' '
EOF
'
test_expect_success 'pretend we have a mix of all possible results' '
run_sub_test_lib_test_err \
mixed-results2 "mixed results #2" <<-\EOF &&
test_expect_success 'subtest: mixed results: a mixture of all possible results' '
write_and_run_sub_test_lib_test_err mixed-results2 <<-\EOF &&
test_expect_success "passing test" "true"
test_expect_success "passing test" "true"
test_expect_success "passing test" "true"
@ -289,9 +199,8 @@ test_expect_success 'pretend we have a mix of all possible results' '
EOF
'
test_expect_success 'test --verbose' '
run_sub_test_lib_test_err \
t1234-verbose "test verbose" --verbose <<-\EOF &&
test_expect_success 'subtest: --verbose option' '
write_and_run_sub_test_lib_test_err t1234-verbose --verbose <<-\EOF &&
test_expect_success "passing test" true
test_expect_success "test with output" "echo foo"
test_expect_success "failing test" false
@ -316,19 +225,14 @@ test_expect_success 'test --verbose' '
EOF
'
test_expect_success 'test --verbose-only' '
test_expect_success 'subtest: --verbose-only option' '
run_sub_test_lib_test_err \
t2345-verbose-only-2 "test verbose-only=2" \
--verbose-only=2 <<-\EOF &&
test_expect_success "passing test" true
test_expect_success "test with output" "echo foo"
test_expect_success "failing test" false
test_done
EOF
check_sub_test_lib_test t2345-verbose-only-2 <<-\EOF
t1234-verbose \
--verbose-only=2 &&
check_sub_test_lib_test t1234-verbose <<-\EOF
> ok 1 - passing test
> Z
> expecting success of 2345.2 '\''test with output'\'': echo foo
> expecting success of 1234.2 '\''test with output'\'': echo foo
> foo
> ok 2 - test with output
> Z
@ -339,18 +243,11 @@ test_expect_success 'test --verbose-only' '
EOF
'
test_expect_success 'GIT_SKIP_TESTS' '
test_expect_success 'subtest: skip one with GIT_SKIP_TESTS' '
(
run_sub_test_lib_test git-skip-tests-basic \
"GIT_SKIP_TESTS" \
--skip="git.2" <<-\EOF &&
for i in 1 2 3
do
test_expect_success "passing test #$i" "true"
done
test_done
EOF
check_sub_test_lib_test git-skip-tests-basic <<-\EOF
run_sub_test_lib_test full-pass \
--skip="full.2" &&
check_sub_test_lib_test full-pass <<-\EOF
> ok 1 - passing test #1
> ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
> ok 3 - passing test #3
@ -360,10 +257,9 @@ test_expect_success 'GIT_SKIP_TESTS' '
)
'
test_expect_success 'GIT_SKIP_TESTS several tests' '
test_expect_success 'subtest: skip several with GIT_SKIP_TESTS' '
(
run_sub_test_lib_test git-skip-tests-several \
"GIT_SKIP_TESTS several tests" \
write_and_run_sub_test_lib_test git-skip-tests-several \
--skip="git.2 git.5" <<-\EOF &&
for i in 1 2 3 4 5 6
do
@ -384,18 +280,11 @@ test_expect_success 'GIT_SKIP_TESTS several tests' '
)
'
test_expect_success 'GIT_SKIP_TESTS sh pattern' '
test_expect_success 'subtest: sh pattern skipping with GIT_SKIP_TESTS' '
(
run_sub_test_lib_test git-skip-tests-sh-pattern \
"GIT_SKIP_TESTS sh pattern" \
--skip="git.[2-5]" <<-\EOF &&
for i in 1 2 3 4 5 6
do
test_expect_success "passing test #$i" "true"
done
test_done
EOF
check_sub_test_lib_test git-skip-tests-sh-pattern <<-\EOF
run_sub_test_lib_test git-skip-tests-several \
--skip="git.[2-5]" &&
check_sub_test_lib_test git-skip-tests-several <<-\EOF
> ok 1 - passing test #1
> ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
> ok 3 # skip passing test #3 (GIT_SKIP_TESTS)
@ -408,35 +297,23 @@ test_expect_success 'GIT_SKIP_TESTS sh pattern' '
)
'
test_expect_success 'GIT_SKIP_TESTS entire suite' '
test_expect_success 'subtest: skip entire test suite with GIT_SKIP_TESTS' '
(
run_sub_test_lib_test git-skip-tests-entire-suite \
"GIT_SKIP_TESTS entire suite" \
--skip="git" <<-\EOF &&
for i in 1 2 3
do
test_expect_success "passing test #$i" "true"
done
test_done
EOF
check_sub_test_lib_test git-skip-tests-entire-suite <<-\EOF
GIT_SKIP_TESTS="git" && export GIT_SKIP_TESTS &&
run_sub_test_lib_test git-skip-tests-several \
--skip="git" &&
check_sub_test_lib_test git-skip-tests-several <<-\EOF
> 1..0 # SKIP skip all tests in git
EOF
)
'
test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' '
test_expect_success 'subtest: GIT_SKIP_TESTS does not skip unmatched suite' '
(
run_sub_test_lib_test git-skip-tests-unmatched-suite \
"GIT_SKIP_TESTS does not skip unmatched suite" \
--skip="notgit" <<-\EOF &&
for i in 1 2 3
do
test_expect_success "passing test #$i" "true"
done
test_done
EOF
check_sub_test_lib_test git-skip-tests-unmatched-suite <<-\EOF
GIT_SKIP_TESTS="notgit" && export GIT_SKIP_TESTS &&
run_sub_test_lib_test full-pass \
--skip="notfull" &&
check_sub_test_lib_test full-pass <<-\EOF
> ok 1 - passing test #1
> ok 2 - passing test #2
> ok 3 - passing test #3
@ -446,16 +323,9 @@ test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' '
)
'
test_expect_success '--run basic' '
run_sub_test_lib_test run-basic \
"--run basic" --run="1,3,5" <<-\EOF &&
for i in 1 2 3 4 5 6
do
test_expect_success "passing test #$i" "true"
done
test_done
EOF
check_sub_test_lib_test run-basic <<-\EOF
test_expect_success 'subtest: --run basic' '
run_sub_test_lib_test git-skip-tests-several --run="1,3,5" &&
check_sub_test_lib_test git-skip-tests-several <<-\EOF
> ok 1 - passing test #1
> ok 2 # skip passing test #2 (--run)
> ok 3 - passing test #3
@ -467,16 +337,10 @@ test_expect_success '--run basic' '
EOF
'
test_expect_success '--run with a range' '
run_sub_test_lib_test run-range \
"--run with a range" --run="1-3" <<-\EOF &&
for i in 1 2 3 4 5 6
do
test_expect_success "passing test #$i" "true"
done
test_done
EOF
check_sub_test_lib_test run-range <<-\EOF
test_expect_success 'subtest: --run with a range' '
run_sub_test_lib_test git-skip-tests-several \
--run="1-3" &&
check_sub_test_lib_test git-skip-tests-several <<-\EOF
> ok 1 - passing test #1
> ok 2 - passing test #2
> ok 3 - passing test #3
@ -488,16 +352,10 @@ test_expect_success '--run with a range' '
EOF
'
test_expect_success '--run with two ranges' '
run_sub_test_lib_test run-two-ranges \
"--run with two ranges" --run="1-2,5-6" <<-\EOF &&
for i in 1 2 3 4 5 6
do
test_expect_success "passing test #$i" "true"
done
test_done
EOF
check_sub_test_lib_test run-two-ranges <<-\EOF
test_expect_success 'subtest: --run with two ranges' '
run_sub_test_lib_test git-skip-tests-several \
--run="1-2,5-6" &&
check_sub_test_lib_test git-skip-tests-several <<-\EOF
> ok 1 - passing test #1
> ok 2 - passing test #2
> ok 3 # skip passing test #3 (--run)
@ -509,16 +367,10 @@ test_expect_success '--run with two ranges' '
EOF
'
test_expect_success '--run with a left open range' '
run_sub_test_lib_test run-left-open-range \
"--run with a left open range" --run="-3" <<-\EOF &&
for i in 1 2 3 4 5 6
do
test_expect_success "passing test #$i" "true"
done
test_done
EOF
check_sub_test_lib_test run-left-open-range <<-\EOF
test_expect_success 'subtest: --run with a left open range' '
run_sub_test_lib_test git-skip-tests-several \
--run="-3" &&
check_sub_test_lib_test git-skip-tests-several <<-\EOF
> ok 1 - passing test #1
> ok 2 - passing test #2
> ok 3 - passing test #3
@ -530,16 +382,10 @@ test_expect_success '--run with a left open range' '
EOF
'
test_expect_success '--run with a right open range' '
run_sub_test_lib_test run-right-open-range \
"--run with a right open range" --run="4-" <<-\EOF &&
for i in 1 2 3 4 5 6
do
test_expect_success "passing test #$i" "true"
done
test_done
EOF
check_sub_test_lib_test run-right-open-range <<-\EOF
test_expect_success 'subtest: --run with a right open range' '
run_sub_test_lib_test git-skip-tests-several \
--run="4-" &&
check_sub_test_lib_test git-skip-tests-several <<-\EOF
> ok 1 # skip passing test #1 (--run)
> ok 2 # skip passing test #2 (--run)
> ok 3 # skip passing test #3 (--run)
@ -551,16 +397,10 @@ test_expect_success '--run with a right open range' '
EOF
'
test_expect_success '--run with basic negation' '
run_sub_test_lib_test run-basic-neg \
"--run with basic negation" --run="!3" <<-\EOF &&
for i in 1 2 3 4 5 6
do
test_expect_success "passing test #$i" "true"
done
test_done
EOF
check_sub_test_lib_test run-basic-neg <<-\EOF
test_expect_success 'subtest: --run with basic negation' '
run_sub_test_lib_test git-skip-tests-several \
--run="!3" &&
check_sub_test_lib_test git-skip-tests-several <<-\EOF
> ok 1 - passing test #1
> ok 2 - passing test #2
> ok 3 # skip passing test #3 (--run)
@ -572,16 +412,10 @@ test_expect_success '--run with basic negation' '
EOF
'
test_expect_success '--run with two negations' '
run_sub_test_lib_test run-two-neg \
"--run with two negations" --run="!3,!6" <<-\EOF &&
for i in 1 2 3 4 5 6
do
test_expect_success "passing test #$i" "true"
done
test_done
EOF
check_sub_test_lib_test run-two-neg <<-\EOF
test_expect_success 'subtest: --run with two negations' '
run_sub_test_lib_test git-skip-tests-several \
--run="!3,!6" &&
check_sub_test_lib_test git-skip-tests-several <<-\EOF
> ok 1 - passing test #1
> ok 2 - passing test #2
> ok 3 # skip passing test #3 (--run)
@ -593,16 +427,10 @@ test_expect_success '--run with two negations' '
EOF
'
test_expect_success '--run a range and negation' '
run_sub_test_lib_test run-range-and-neg \
"--run a range and negation" --run="-4,!2" <<-\EOF &&
for i in 1 2 3 4 5 6
do
test_expect_success "passing test #$i" "true"
done
test_done
EOF
check_sub_test_lib_test run-range-and-neg <<-\EOF
test_expect_success 'subtest: --run a range and negation' '
run_sub_test_lib_test git-skip-tests-several \
--run="-4,!2" &&
check_sub_test_lib_test git-skip-tests-several <<-\EOF
> ok 1 - passing test #1
> ok 2 # skip passing test #2 (--run)
> ok 3 - passing test #3
@ -614,16 +442,10 @@ test_expect_success '--run a range and negation' '
EOF
'
test_expect_success '--run range negation' '
run_sub_test_lib_test run-range-neg \
"--run range negation" --run="!1-3" <<-\EOF &&
for i in 1 2 3 4 5 6
do
test_expect_success "passing test #$i" "true"
done
test_done
EOF
check_sub_test_lib_test run-range-neg <<-\EOF
test_expect_success 'subtest: --run range negation' '
run_sub_test_lib_test git-skip-tests-several \
--run="!1-3" &&
check_sub_test_lib_test git-skip-tests-several <<-\EOF
> ok 1 # skip passing test #1 (--run)
> ok 2 # skip passing test #2 (--run)
> ok 3 # skip passing test #3 (--run)
@ -635,17 +457,10 @@ test_expect_success '--run range negation' '
EOF
'
test_expect_success '--run include, exclude and include' '
run_sub_test_lib_test run-inc-neg-inc \
"--run include, exclude and include" \
--run="1-5,!1-3,2" <<-\EOF &&
for i in 1 2 3 4 5 6
do
test_expect_success "passing test #$i" "true"
done
test_done
EOF
check_sub_test_lib_test run-inc-neg-inc <<-\EOF
test_expect_success 'subtest: --run include, exclude and include' '
run_sub_test_lib_test git-skip-tests-several \
--run="1-5,!1-3,2" &&
check_sub_test_lib_test git-skip-tests-several <<-\EOF
> ok 1 # skip passing test #1 (--run)
> ok 2 - passing test #2
> ok 3 # skip passing test #3 (--run)
@ -657,17 +472,10 @@ test_expect_success '--run include, exclude and include' '
EOF
'
test_expect_success '--run include, exclude and include, comma separated' '
run_sub_test_lib_test run-inc-neg-inc-comma \
"--run include, exclude and include, comma separated" \
--run=1-5,!1-3,2 <<-\EOF &&
for i in 1 2 3 4 5 6
do
test_expect_success "passing test #$i" "true"
done
test_done
EOF
check_sub_test_lib_test run-inc-neg-inc-comma <<-\EOF
test_expect_success 'subtest: --run include, exclude and include, comma separated' '
run_sub_test_lib_test git-skip-tests-several \
--run=1-5,!1-3,2 &&
check_sub_test_lib_test git-skip-tests-several <<-\EOF
> ok 1 # skip passing test #1 (--run)
> ok 2 - passing test #2
> ok 3 # skip passing test #3 (--run)
@ -679,17 +487,10 @@ test_expect_success '--run include, exclude and include, comma separated' '
EOF
'
test_expect_success '--run exclude and include' '
run_sub_test_lib_test run-neg-inc \
"--run exclude and include" \
--run="!3-,5" <<-\EOF &&
for i in 1 2 3 4 5 6
do
test_expect_success "passing test #$i" "true"
done
test_done
EOF
check_sub_test_lib_test run-neg-inc <<-\EOF
test_expect_success 'subtest: --run exclude and include' '
run_sub_test_lib_test git-skip-tests-several \
--run="!3-,5" &&
check_sub_test_lib_test git-skip-tests-several <<-\EOF
> ok 1 - passing test #1
> ok 2 - passing test #2
> ok 3 # skip passing test #3 (--run)
@ -701,17 +502,10 @@ test_expect_success '--run exclude and include' '
EOF
'
test_expect_success '--run empty selectors' '
run_sub_test_lib_test run-empty-sel \
"--run empty selectors" \
--run="1,,3,,,5" <<-\EOF &&
for i in 1 2 3 4 5 6
do
test_expect_success "passing test #$i" "true"
done
test_done
EOF
check_sub_test_lib_test run-empty-sel <<-\EOF
test_expect_success 'subtest: --run empty selectors' '
run_sub_test_lib_test git-skip-tests-several \
--run="1,,3,,,5" &&
check_sub_test_lib_test git-skip-tests-several <<-\EOF
> ok 1 - passing test #1
> ok 2 # skip passing test #2 (--run)
> ok 3 - passing test #3
@ -723,9 +517,8 @@ test_expect_success '--run empty selectors' '
EOF
'
test_expect_success '--run substring selector' '
run_sub_test_lib_test run-substring-selector \
"--run empty selectors" \
test_expect_success 'subtest: --run substring selector' '
write_and_run_sub_test_lib_test run-substring-selector \
--run="relevant" <<-\EOF &&
test_expect_success "relevant test" "true"
for i in 1 2 3 4 5 6
@ -747,9 +540,8 @@ test_expect_success '--run substring selector' '
EOF
'
test_expect_success '--run keyword selection' '
run_sub_test_lib_test_err run-inv-range-start \
"--run invalid range start" \
test_expect_success 'subtest: --run keyword selection' '
write_and_run_sub_test_lib_test_err run-inv-range-start \
--run="a-5" <<-\EOF &&
test_expect_success "passing test #1" "true"
test_done
@ -762,14 +554,10 @@ test_expect_success '--run keyword selection' '
EOF_ERR
'
test_expect_success '--run invalid range end' '
run_sub_test_lib_test_err run-inv-range-end \
"--run invalid range end" \
--run="1-z" <<-\EOF &&
test_expect_success "passing test #1" "true"
test_done
EOF
check_sub_test_lib_test_err run-inv-range-end \
test_expect_success 'subtest: --run invalid range end' '
run_sub_test_lib_test_err run-inv-range-start \
--run="1-z" &&
check_sub_test_lib_test_err run-inv-range-start \
<<-\EOF_OUT 3<<-EOF_ERR
> FATAL: Unexpected exit with code 1
EOF_OUT
@ -777,8 +565,8 @@ test_expect_success '--run invalid range end' '
EOF_ERR
'
test_expect_success 'tests respect prerequisites' '
run_sub_test_lib_test prereqs "tests respect prereqs" <<-\EOF &&
test_expect_success 'subtest: tests respect prerequisites' '
write_and_run_sub_test_lib_test prereqs <<-\EOF &&
test_set_prereq HAVEIT
test_expect_success HAVEIT "prereq is satisfied" "true"
@ -807,8 +595,8 @@ test_expect_success 'tests respect prerequisites' '
EOF
'
test_expect_success 'tests respect lazy prerequisites' '
run_sub_test_lib_test lazy-prereqs "respect lazy prereqs" <<-\EOF &&
test_expect_success 'subtest: tests respect lazy prerequisites' '
write_and_run_sub_test_lib_test lazy-prereqs <<-\EOF &&
test_lazy_prereq LAZY_TRUE true
test_expect_success LAZY_TRUE "lazy prereq is satisifed" "true"
@ -831,8 +619,8 @@ test_expect_success 'tests respect lazy prerequisites' '
EOF
'
test_expect_success 'nested lazy prerequisites' '
run_sub_test_lib_test nested-lazy "nested lazy prereqs" <<-\EOF &&
test_expect_success 'subtest: nested lazy prerequisites' '
write_and_run_sub_test_lib_test nested-lazy <<-\EOF &&
test_lazy_prereq NESTED_INNER "
>inner &&
@ -857,9 +645,9 @@ test_expect_success 'nested lazy prerequisites' '
EOF
'
test_expect_success 'lazy prereqs do not turn off tracing' '
run_sub_test_lib_test lazy-prereq-and-tracing \
"lazy prereqs and -x" -v -x <<-\EOF &&
test_expect_success 'subtest: lazy prereqs do not turn off tracing' '
write_and_run_sub_test_lib_test lazy-prereq-and-tracing \
-v -x <<-\EOF &&
test_lazy_prereq LAZY true
test_expect_success lazy "test_have_prereq LAZY && echo trace"
@ -870,8 +658,8 @@ test_expect_success 'lazy prereqs do not turn off tracing' '
grep "echo trace" lazy-prereq-and-tracing/err
'
test_expect_success 'tests clean up after themselves' '
run_sub_test_lib_test cleanup "test with cleanup" <<-\EOF &&
test_expect_success 'subtest: tests clean up after themselves' '
write_and_run_sub_test_lib_test cleanup <<-\EOF &&
clean=no
test_expect_success "do cleanup" "
test_when_finished clean=yes
@ -890,9 +678,9 @@ test_expect_success 'tests clean up after themselves' '
EOF
'
test_expect_success 'tests clean up even on failures' '
run_sub_test_lib_test_err \
failing-cleanup "Failing tests with cleanup commands" <<-\EOF &&
test_expect_success 'subtest: tests clean up even on failures' '
write_and_run_sub_test_lib_test_err \
failing-cleanup <<-\EOF &&
test_expect_success "tests clean up even after a failure" "
touch clean-after-failure &&
test_when_finished rm clean-after-failure &&
@ -919,9 +707,9 @@ test_expect_success 'tests clean up even on failures' '
EOF
'
test_expect_success 'test_atexit is run' '
run_sub_test_lib_test_err \
atexit-cleanup "Run atexit commands" -i <<-\EOF &&
test_expect_success 'subtest: test_atexit is run' '
write_and_run_sub_test_lib_test_err \
atexit-cleanup -i <<-\EOF &&
test_expect_success "tests clean up even after a failure" "
> ../../clean-atexit &&
test_atexit rm ../../clean-atexit &&