Skip to content

Commit ac223c4

Browse files
peffgitster
authored andcommitted
t0000: clear GIT_SKIP_TESTS before running sub-tests
In t0000, we run several fake "sub-test" suites to verify the behavior of the test suite. But because we don't clear the parent environment completely, the sub-tests can be fooled by variables meant for the parent. For example: GIT_SKIP_TESTS=t1234 ./t0000-basic.sh fails when a sub-test expects its fake t1234 to actually run. This particular pattern is unlikely in practice; we're running a single script, and there is no t1234 in the real test suite anyway (not yet, at least). A more real-world example is: GIT_SKIP_TESTS=t[^0]* make test to run only the t0* tests. The fix is conceptually simple: we should clear the GIT_SKIP_TESTS variable when running the sub-tests, because its contents (if any) will be meant for the main test suite. This is easy to do centrally in our sub-test helper. But there's a catch: some of our tests do set GIT_SKIP_TESTS intentionally to test the feature. We need to allow them to continue to set it, but clear it for all the other tests. And the sub-test helper can't tell if the GIT_SKIP_TESTS it sees is from a test or not. We can handle this by adding a new option to the helper to let callers specify the skip list. I considered adding a more general "--eval" option to let callers set up the env for the sub-test however they like. That would cover this case and possible future ones. But the quoting gets awkward for the callers (since we're now 2 layers deep in evals!), so I went with the simpler more specific solution. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent daab8a5 commit ac223c4

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

t/t0000-basic.sh

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ test_expect_success 'success is reported like this' '
6969
_run_sub_test_lib_test_common () {
7070
neg="$1" name="$2" descr="$3" # stdin is the body of the test code
7171
shift 3
72+
73+
# intercept pseudo-options at the front of the argument list that we
74+
# will not pass to child script
75+
skip=
76+
while test $# -gt 0
77+
do
78+
case "$1" in
79+
--skip=*)
80+
skip=${1#--*=}
81+
shift
82+
;;
83+
*)
84+
break
85+
;;
86+
esac
87+
done
88+
7289
mkdir "$name" &&
7390
(
7491
# Pretend we're not running under a test harness, whether we
@@ -91,6 +108,8 @@ _run_sub_test_lib_test_common () {
91108
export TEST_DIRECTORY &&
92109
TEST_OUTPUT_DIRECTORY=$(pwd) &&
93110
export TEST_OUTPUT_DIRECTORY &&
111+
GIT_SKIP_TESTS=$skip &&
112+
export GIT_SKIP_TESTS &&
94113
sane_unset GIT_TEST_FAIL_PREREQS &&
95114
if test -z "$neg"
96115
then
@@ -319,9 +338,9 @@ test_expect_success 'test --verbose-only' '
319338

320339
test_expect_success 'GIT_SKIP_TESTS' '
321340
(
322-
GIT_SKIP_TESTS="git.2" && export GIT_SKIP_TESTS &&
323341
run_sub_test_lib_test git-skip-tests-basic \
324-
"GIT_SKIP_TESTS" <<-\EOF &&
342+
"GIT_SKIP_TESTS" \
343+
--skip="git.2" <<-\EOF &&
325344
for i in 1 2 3
326345
do
327346
test_expect_success "passing test #$i" "true"
@@ -340,9 +359,9 @@ test_expect_success 'GIT_SKIP_TESTS' '
340359

341360
test_expect_success 'GIT_SKIP_TESTS several tests' '
342361
(
343-
GIT_SKIP_TESTS="git.2 git.5" && export GIT_SKIP_TESTS &&
344362
run_sub_test_lib_test git-skip-tests-several \
345-
"GIT_SKIP_TESTS several tests" <<-\EOF &&
363+
"GIT_SKIP_TESTS several tests" \
364+
--skip="git.2 git.5" <<-\EOF &&
346365
for i in 1 2 3 4 5 6
347366
do
348367
test_expect_success "passing test #$i" "true"
@@ -364,9 +383,9 @@ test_expect_success 'GIT_SKIP_TESTS several tests' '
364383

365384
test_expect_success 'GIT_SKIP_TESTS sh pattern' '
366385
(
367-
GIT_SKIP_TESTS="git.[2-5]" && export GIT_SKIP_TESTS &&
368386
run_sub_test_lib_test git-skip-tests-sh-pattern \
369-
"GIT_SKIP_TESTS sh pattern" <<-\EOF &&
387+
"GIT_SKIP_TESTS sh pattern" \
388+
--skip="git.[2-5]" <<-\EOF &&
370389
for i in 1 2 3 4 5 6
371390
do
372391
test_expect_success "passing test #$i" "true"
@@ -388,9 +407,9 @@ test_expect_success 'GIT_SKIP_TESTS sh pattern' '
388407

389408
test_expect_success 'GIT_SKIP_TESTS entire suite' '
390409
(
391-
GIT_SKIP_TESTS="git" && export GIT_SKIP_TESTS &&
392410
run_sub_test_lib_test git-skip-tests-entire-suite \
393-
"GIT_SKIP_TESTS entire suite" <<-\EOF &&
411+
"GIT_SKIP_TESTS entire suite" \
412+
--skip="git" <<-\EOF &&
394413
for i in 1 2 3
395414
do
396415
test_expect_success "passing test #$i" "true"
@@ -405,9 +424,9 @@ test_expect_success 'GIT_SKIP_TESTS entire suite' '
405424

406425
test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' '
407426
(
408-
GIT_SKIP_TESTS="notgit" && export GIT_SKIP_TESTS &&
409427
run_sub_test_lib_test git-skip-tests-unmatched-suite \
410-
"GIT_SKIP_TESTS does not skip unmatched suite" <<-\EOF &&
428+
"GIT_SKIP_TESTS does not skip unmatched suite" \
429+
--skip="notgit" <<-\EOF &&
411430
for i in 1 2 3
412431
do
413432
test_expect_success "passing test #$i" "true"

0 commit comments

Comments
 (0)