This refactors the testing of test-lib.sh itself in t0000 into a
lib-subtest.sh, fixing duplicate setup, bugs and various shell nits
along the way.
This was waiting on my now-merged 2019256717d (Merge branch
'ab/test-lib-updates', 2021-06-14).
There's a conflict here with Felipe's proposed
http://lore.kernel.org/git/20210609170520.67014-1-felipe.contreras@gmail.com,
but it's just a matter of moving the fix around and solving a trivial
conflict. I thought it was better to submit this now anyway, while
this code is fresh in people's minds.
I'm hoping Felipe will take some variant of my
http://lore.kernel.org/git/8735tk22if.fsf@evledraar.gmail.com and
perhaps review this series & base his patch on top of these changes,
but alternatively they can go in independently with Junio solving the
conflict.
Ævar Arnfjörð Bjarmason (8):
test-lib tests: move "run_sub_test" to a new lib-subtest.sh
test-lib tests: split up "write and run" into two functions
test-lib tests: stop using a subshell in write_sub_test_lib_test()
test-lib tests: don't provide a description for the sub-tests
test-lib tests: get rid of copy/pasted mock test code
test-lib tests: avoid subshell for "test_cmp" for readability
test-lib tests: refactor common part of check_sub_test_lib_test*()
test-lib tests: assert 1 exit code, not non-zero
t/lib-subtest.sh | 105 ++++++++++++
t/t0000-basic.sh | 419 +++++++++++++----------------------------------
2 files changed, 219 insertions(+), 305 deletions(-)
create mode 100644 t/lib-subtest.sh
--
2.32.0.rc3.434.gd8aed1f08a7
Now that we've split up the write_sub_test_lib_test*() and
run_sub_test_lib_test*() functions let's fix those tests in
t0000-basic.sh that were verbosely copy/pasting earlier tests.
I'm (ab)using writing a tag object under a ref-name that's
content-addressable from the content of the test script. If we can
update-ref that it's unique, if not we've got a duplicate. The tag
object stores the name of the earlier test for reporting the error.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 34 ++++++-
t/t0000-basic.sh | 224 ++++++++++++-----------------------------------
2 files changed, 88 insertions(+), 170 deletions(-)
@@ -1,3 +1,34 @@+_assert_unique_sub_test(){+name=$1&&++# Alert about the copy/paste programming+hash=$(githash-object-w"$name")&&+cat>tag.sig<<-EOF&&+object$hash+typeblob+tag$hash+tagger.<>0+0000++duplicatescriptdetected!++Thistestscriptwasalreadywrittenas:++$name++Youcanjustre-useitstestcodewithyourown+run_sub_test_lib_test*()+EOF++tag=$(gitmktag<tag.sig)&&+if!gitupdate-refrefs/tags/blob-$hash$tag$(test_oidzero)2>/dev/null+then+msg=$(gitfor-each-refrefs/tags/blob-$hash\+--format='%(contents)'refs/tags/blob-$hash)+error"on write of $name: $msg"+return1+fi+}+ write_sub_test_lib_test(){name="$1"# stdin is the body of the test codemkdir"$name"&&
@@ -7,7 +38,8 @@ write_sub_test_lib_test () {# Point to the t/test-lib.sh, which isn't in ../ as usual."\$TEST_DIRECTORY"/test-lib.shEOF-cat>>"$name/$name.sh"+cat>>"$name/$name.sh"&&+_assert_unique_sub_test"$name/$name.sh"} _run_sub_test_lib_test_common(){
@@ -226,18 +226,13 @@ test_expect_success 'subtest: --verbose option' '' test_expect_success'subtest: --verbose-only option''-write_and_run_sub_test_lib_test_err\-t2345-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_testt2345-verbose-only-2<<-\EOF+run_sub_test_lib_test_err\+t1234-verbose\+--verbose-only=2&&+check_sub_test_lib_testt1234-verbose<<-\EOF>ok1-passingtest>Z->expectingsuccessof2345.2'\''test with output'\'':echofoo+>expectingsuccessof1234.2'\''test with output'\'':echofoo>foo>ok2-testwithoutput>Z
@@ -250,16 +245,9 @@ test_expect_success 'subtest: --verbose-only option' ' test_expect_success'subtest: skip one with GIT_SKIP_TESTS''(-GIT_SKIP_TESTS="git.2"&&exportGIT_SKIP_TESTS&&-write_and_run_sub_test_lib_testgit-skip-tests-basic\-<<-\EOF&&-foriin123-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testgit-skip-tests-basic<<-\EOF+GIT_SKIP_TESTS="full.2"&&exportGIT_SKIP_TESTS&&+run_sub_test_lib_testfull-pass&&+check_sub_test_lib_testfull-pass<<-\EOF>ok1-passingtest#1>ok2# skip passing test #2 (GIT_SKIP_TESTS)>ok3-passingtest#3
@@ -296,15 +284,8 @@ test_expect_success 'subtest: skip several with GIT_SKIP_TESTS' ' test_expect_success'subtest: sh pattern skipping with GIT_SKIP_TESTS''(GIT_SKIP_TESTS="git.[2-5]"&&exportGIT_SKIP_TESTS&&-write_and_run_sub_test_lib_testgit-skip-tests-sh-pattern\-<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testgit-skip-tests-sh-pattern<<-\EOF+run_sub_test_lib_testgit-skip-tests-several&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2# skip passing test #2 (GIT_SKIP_TESTS)>ok3# skip passing test #3 (GIT_SKIP_TESTS)
@@ -320,15 +301,8 @@ test_expect_success 'subtest: sh pattern skipping with GIT_SKIP_TESTS' ' test_expect_success'subtest: skip entire test suite with GIT_SKIP_TESTS''(GIT_SKIP_TESTS="git"&&exportGIT_SKIP_TESTS&&-write_and_run_sub_test_lib_testgit-skip-tests-entire-suite\-<<-\EOF&&-foriin123-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testgit-skip-tests-entire-suite<<-\EOF+run_sub_test_lib_testgit-skip-tests-several&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>1..0# SKIP skip all tests in gitEOF)
@@ -337,15 +311,8 @@ test_expect_success 'subtest: skip entire test suite with GIT_SKIP_TESTS' ' test_expect_success'subtest: GIT_SKIP_TESTS does not skip unmatched suite''(GIT_SKIP_TESTS="notgit"&&exportGIT_SKIP_TESTS&&-write_and_run_sub_test_lib_testgit-skip-tests-unmatched-suite\-<<-\EOF&&-foriin123-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testgit-skip-tests-unmatched-suite<<-\EOF+run_sub_test_lib_testfull-pass&&+check_sub_test_lib_testfull-pass<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3-passingtest#3
@@ -356,14 +323,8 @@ test_expect_success 'subtest: GIT_SKIP_TESTS does not skip unmatched suite' '' test_expect_success'subtest: --run basic''-write_and_run_sub_test_lib_testrun-basic--run="1,3,5"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-basic<<-\EOF+run_sub_test_lib_testgit-skip-tests-several--run="1,3,5"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2# skip passing test #2 (--run)>ok3-passingtest#3
@@ -376,15 +337,9 @@ test_expect_success 'subtest: --run basic' '' test_expect_success'subtest: --run with a range''-write_and_run_sub_test_lib_testrun-range\---run="1-3"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-range<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="1-3"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3-passingtest#3
@@ -397,15 +352,9 @@ test_expect_success 'subtest: --run with a range' '' test_expect_success'subtest: --run with two ranges''-write_and_run_sub_test_lib_testrun-two-ranges\---run="1-2,5-6"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-two-ranges<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="1-2,5-6"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -418,15 +367,9 @@ test_expect_success 'subtest: --run with two ranges' '' test_expect_success'subtest: --run with a left open range''-write_and_run_sub_test_lib_testrun-left-open-range\---run="-3"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-left-open-range<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="-3"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3-passingtest#3
@@ -439,15 +382,9 @@ test_expect_success 'subtest: --run with a left open range' '' test_expect_success'subtest: --run with a right open range''-write_and_run_sub_test_lib_testrun-right-open-range\---run="4-"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-right-open-range<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="4-"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1# skip passing test #1 (--run)>ok2# skip passing test #2 (--run)>ok3# skip passing test #3 (--run)
@@ -460,15 +397,9 @@ test_expect_success 'subtest: --run with a right open range' '' test_expect_success'subtest: --run with basic negation''-write_and_run_sub_test_lib_testrun-basic-neg\---run="!3"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-basic-neg<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="!3"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -481,15 +412,9 @@ test_expect_success 'subtest: --run with basic negation' '' test_expect_success'subtest: --run with two negations''-write_and_run_sub_test_lib_testrun-two-neg\---run="!3,!6"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-two-neg<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="!3,!6"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -502,15 +427,9 @@ test_expect_success 'subtest: --run with two negations' '' test_expect_success'subtest: --run a range and negation''-write_and_run_sub_test_lib_testrun-range-and-neg\---run="-4,!2"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-range-and-neg<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="-4,!2"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2# skip passing test #2 (--run)>ok3-passingtest#3
@@ -523,15 +442,9 @@ test_expect_success 'subtest: --run a range and negation' '' test_expect_success'subtest: --run range negation''-write_and_run_sub_test_lib_testrun-range-neg\---run="!1-3"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-range-neg<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="!1-3"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1# skip passing test #1 (--run)>ok2# skip passing test #2 (--run)>ok3# skip passing test #3 (--run)
@@ -544,15 +457,9 @@ test_expect_success 'subtest: --run range negation' '' test_expect_success'subtest: --run include, exclude and include''-write_and_run_sub_test_lib_testrun-inc-neg-inc\---run="1-5,!1-3,2"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-inc-neg-inc<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="1-5,!1-3,2"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1# skip passing test #1 (--run)>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -565,15 +472,9 @@ test_expect_success 'subtest: --run include, exclude and include' '' test_expect_success'subtest: --run include, exclude and include, comma separated''-write_and_run_sub_test_lib_testrun-inc-neg-inc-comma\---run=1-5,!1-3,2<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-inc-neg-inc-comma<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run=1-5,!1-3,2&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1# skip passing test #1 (--run)>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -586,15 +487,9 @@ test_expect_success 'subtest: --run include, exclude and include, comma separate' test_expect_success'subtest: --run exclude and include''-write_and_run_sub_test_lib_testrun-neg-inc\---run="!3-,5"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-neg-inc<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="!3-,5"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -607,15 +502,9 @@ test_expect_success 'subtest: --run exclude and include' '' test_expect_success'subtest: --run empty selectors''-write_and_run_sub_test_lib_testrun-empty-sel\---run="1,,3,,,5"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-empty-sel<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="1,,3,,,5"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2# skip passing test #2 (--run)>ok3-passingtest#3
@@ -665,12 +554,9 @@ test_expect_success 'subtest: --run keyword selection' '' test_expect_success'subtest: --run invalid range end''-write_and_run_sub_test_lib_test_errrun-inv-range-end\---run="1-z"<<-\EOF&&-test_expect_success"passing test #1""true"-test_done-EOF-check_sub_test_lib_test_errrun-inv-range-end\+run_sub_test_lib_test_errrun-inv-range-start\+--run="1-z"&&+check_sub_test_lib_test_errrun-inv-range-start\<<-\EOF_OUT 3<<-EOF_ERR>FATAL:Unexpectedexitwithcode1EOF_OUT
Improve the testing for test-lib.sh itself to assert that we have a
exit code of 1, not any non-zero. Improves code added in
0445e6f0a12 (test-lib: '--run' to run only specific tests,
2014-04-30).
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
@@ -43,8 +43,8 @@ write_sub_test_lib_test () {} _run_sub_test_lib_test_common(){-neg="$1"name="$2"# stdin is the body of the test code-shift2+cmp_op="$1"want_code="$2"name="$3"# stdin is the body of the test code+shift3(cd"$name"&&
@@ -58,33 +58,30 @@ _run_sub_test_lib_test_common () {TEST_OUTPUT_DIRECTORY=$(pwd)&&exportTEST_OUTPUT_DIRECTORY&&sane_unsetGIT_TEST_FAIL_PREREQS&&-iftest-z"$neg"-then-./"$name.sh""$@">out2>err-else-!./"$name.sh""$@">out2>err-fi+./"$name.sh""$@">out2>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 codewrite_sub_test_lib_test"$@"||return1-_run_sub_test_lib_test_common''"$@"+_run_sub_test_lib_test_common-eq0"$@"} write_and_run_sub_test_lib_test_err(){name="$1"descr="$2"# stdin is the body of the test codewrite_sub_test_lib_test"$@"||return1-_run_sub_test_lib_test_common'!'"$@"+_run_sub_test_lib_test_common-eq1"$@"} run_sub_test_lib_test(){-_run_sub_test_lib_test_common''"$@"+_run_sub_test_lib_test_common-eq0"$@"} run_sub_test_lib_test_err(){-_run_sub_test_lib_test_common'!'"$@"+_run_sub_test_lib_test_common-eq1"$@"} _check_sub_test_lib_test_common(){
Change the $test_description provided for the generated subtests to be
constant, since the only purpose of having it is that test-lib.sh will
barf if it isn't supplied.
The other purpose of having it was to effectively split up the test
description between the argument to test_expect_success and the
argument to "write_and_run_sub_test_lib_test". Let's only use one of
the two.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 12 ++--
t/t0000-basic.sh | 147 +++++++++++++++++++++--------------------------
2 files changed, 71 insertions(+), 88 deletions(-)
@@ -1,12 +1,8 @@ write_sub_test_lib_test(){-name="$1"descr="$2"# stdin is the body of the test code+name="$1"# stdin is the body of the test codemkdir"$name"&&write_script"$name/$name.sh""$TEST_SHELL_PATH"<<-EOF&&-test_description='$descr(runinsubtest-lib)--Thisisruninasubtest-libsothatwedonotgetincorrect-passingmetrics-'+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
@@ -15,8 +11,8 @@ write_sub_test_lib_test () {} _run_sub_test_lib_test_common(){-neg="$1"name="$2"descr="$3"# stdin is the body of the test code-shift3+neg="$1"name="$2"# stdin is the body of the test code+shift2(cd"$name"&&
@@ -67,8 +67,8 @@ test_expect_success 'success is reported like this' ':'-test_expect_success'pretend we have a fully passing test suite''-write_and_run_sub_test_lib_testfull-pass"3 passing tests"<<-\EOF&&+test_expect_success'subtest: 3 passing tests''+write_and_run_sub_test_lib_testfull-pass<<-\EOF&&foriin123dotest_expect_success"passing test #$i""true"
@@ -84,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''-write_and_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_errpartial-pass<<-\EOF&&test_expect_success"passing test #1""true"test_expect_success"failing test #2""false"test_expect_success"passing test #3""true"
@@ -102,8 +101,8 @@ test_expect_success 'pretend we have a partially passing test suite' 'EOF'-test_expect_success'pretend we have a known breakage''-write_and_run_sub_test_lib_testfailing-todo"A failing TODO test"<<-\EOF&&+test_expect_success'subtest: a failing TODO test''+write_and_run_sub_test_lib_testfailing-todo<<-\EOF&&test_expect_success"passing test""true"test_expect_failure"pretend we have a known breakage""false"test_done
@@ -117,8 +116,8 @@ test_expect_success 'pretend we have a known breakage' 'EOF'-test_expect_success'pretend we have fixed a known breakage''-write_and_run_sub_test_lib_testpassing-todo"A passing TODO test"<<-\EOF&&+test_expect_success'subtest: a passing TODO test''+write_and_run_sub_test_lib_testpassing-todo<<-\EOF&&test_expect_failure"pretend we have fixed a known breakage""true"test_doneEOF
@@ -129,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)''-write_and_run_sub_test_lib_testpartially-passing-todos\-"2 TODO tests, one passing"<<-\EOF&&+test_expect_success'subtest: 2 TODO tests, one passin''+write_and_run_sub_test_lib_testpartially-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"
@@ -148,9 +146,8 @@ test_expect_success 'pretend we have fixed one of two known breakages (run in suEOF'-test_expect_success'pretend we have a pass, fail, and known breakage''-write_and_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_errmixed-results1<<-\EOF&&test_expect_success"passing test""true"test_expect_success"failing test""false"test_expect_failure"pretend we have a known breakage""false"
@@ -167,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''-write_and_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_errmixed-results2<<-\EOF&&test_expect_success"passing test""true"test_expect_success"passing test""true"test_expect_success"passing test""true"
@@ -203,9 +199,8 @@ test_expect_success 'pretend we have a mix of all possible results' 'EOF'-test_expect_success'test --verbose''-write_and_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_errt1234-verbose--verbose<<-\EOF&&test_expect_success"passing test"truetest_expect_success"test with output""echo foo"test_expect_success"failing test"false
@@ -253,11 +248,11 @@ test_expect_success 'test --verbose-only' 'EOF'-test_expect_success'GIT_SKIP_TESTS''+test_expect_success'subtest: skip one with GIT_SKIP_TESTS''(GIT_SKIP_TESTS="git.2"&&exportGIT_SKIP_TESTS&&write_and_run_sub_test_lib_testgit-skip-tests-basic\-"GIT_SKIP_TESTS"<<-\EOF&&+<<-\EOF&&foriin123dotest_expect_success"passing test #$i""true"
@@ -274,11 +269,11 @@ test_expect_success 'GIT_SKIP_TESTS' ')'-test_expect_success'GIT_SKIP_TESTS several tests''+test_expect_success'subtest: skip several with GIT_SKIP_TESTS''(GIT_SKIP_TESTS="git.2 git.5"&&exportGIT_SKIP_TESTS&&write_and_run_sub_test_lib_testgit-skip-tests-several\-"GIT_SKIP_TESTS several tests"<<-\EOF&&+<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -298,11 +293,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''(GIT_SKIP_TESTS="git.[2-5]"&&exportGIT_SKIP_TESTS&&write_and_run_sub_test_lib_testgit-skip-tests-sh-pattern\-"GIT_SKIP_TESTS sh pattern"<<-\EOF&&+<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -322,11 +317,11 @@ 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''(GIT_SKIP_TESTS="git"&&exportGIT_SKIP_TESTS&&write_and_run_sub_test_lib_testgit-skip-tests-entire-suite\-"GIT_SKIP_TESTS entire suite"<<-\EOF&&+<<-\EOF&&foriin123dotest_expect_success"passing test #$i""true"
@@ -339,11 +334,11 @@ test_expect_success 'GIT_SKIP_TESTS entire suite' ')'-test_expect_success'GIT_SKIP_TESTS does not skip unmatched suite''+test_expect_success'subtest: GIT_SKIP_TESTS does not skip unmatched suite''(GIT_SKIP_TESTS="notgit"&&exportGIT_SKIP_TESTS&&write_and_run_sub_test_lib_testgit-skip-tests-unmatched-suite\-"GIT_SKIP_TESTS does not skip unmatched suite"<<-\EOF&&+<<-\EOF&&foriin123dotest_expect_success"passing test #$i""true"
@@ -360,9 +355,8 @@ test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' ')'-test_expect_success'--run basic''-write_and_run_sub_test_lib_testrun-basic\-"--run basic"--run="1,3,5"<<-\EOF&&+test_expect_success'subtest: --run basic''+write_and_run_sub_test_lib_testrun-basic--run="1,3,5"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -381,9 +375,9 @@ test_expect_success '--run basic' 'EOF'-test_expect_success'--run with a range''+test_expect_success'subtest: --run with a range''write_and_run_sub_test_lib_testrun-range\-"--run with a range"--run="1-3"<<-\EOF&&+--run="1-3"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -402,9 +396,9 @@ test_expect_success '--run with a range' 'EOF'-test_expect_success'--run with two ranges''+test_expect_success'subtest: --run with two ranges''write_and_run_sub_test_lib_testrun-two-ranges\-"--run with two ranges"--run="1-2,5-6"<<-\EOF&&+--run="1-2,5-6"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -423,9 +417,9 @@ test_expect_success '--run with two ranges' 'EOF'-test_expect_success'--run with a left open range''+test_expect_success'subtest: --run with a left open range''write_and_run_sub_test_lib_testrun-left-open-range\-"--run with a left open range"--run="-3"<<-\EOF&&+--run="-3"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -444,9 +438,9 @@ test_expect_success '--run with a left open range' 'EOF'-test_expect_success'--run with a right open range''+test_expect_success'subtest: --run with a right open range''write_and_run_sub_test_lib_testrun-right-open-range\-"--run with a right open range"--run="4-"<<-\EOF&&+--run="4-"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -465,9 +459,9 @@ test_expect_success '--run with a right open range' 'EOF'-test_expect_success'--run with basic negation''+test_expect_success'subtest: --run with basic negation''write_and_run_sub_test_lib_testrun-basic-neg\-"--run with basic negation"--run="!3"<<-\EOF&&+--run="!3"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -486,9 +480,9 @@ test_expect_success '--run with basic negation' 'EOF'-test_expect_success'--run with two negations''+test_expect_success'subtest: --run with two negations''write_and_run_sub_test_lib_testrun-two-neg\-"--run with two negations"--run="!3,!6"<<-\EOF&&+--run="!3,!6"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -507,9 +501,9 @@ test_expect_success '--run with two negations' 'EOF'-test_expect_success'--run a range and negation''+test_expect_success'subtest: --run a range and negation''write_and_run_sub_test_lib_testrun-range-and-neg\-"--run a range and negation"--run="-4,!2"<<-\EOF&&+--run="-4,!2"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -528,9 +522,9 @@ test_expect_success '--run a range and negation' 'EOF'-test_expect_success'--run range negation''+test_expect_success'subtest: --run range negation''write_and_run_sub_test_lib_testrun-range-neg\-"--run range negation"--run="!1-3"<<-\EOF&&+--run="!1-3"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -549,9 +543,8 @@ test_expect_success '--run range negation' 'EOF'-test_expect_success'--run include, exclude and include''+test_expect_success'subtest: --run include, exclude and include''write_and_run_sub_test_lib_testrun-inc-neg-inc\-"--run include, exclude and include"\--run="1-5,!1-3,2"<<-\EOF&&foriin123456do
@@ -571,9 +564,8 @@ test_expect_success '--run include, exclude and include' 'EOF'-test_expect_success'--run include, exclude and include, comma separated''+test_expect_success'subtest: --run include, exclude and include, comma separated''write_and_run_sub_test_lib_testrun-inc-neg-inc-comma\-"--run include, exclude and include, comma separated"\--run=1-5,!1-3,2<<-\EOF&&foriin123456do
@@ -593,9 +585,8 @@ test_expect_success '--run include, exclude and include, comma separated' 'EOF'-test_expect_success'--run exclude and include''+test_expect_success'subtest: --run exclude and include''write_and_run_sub_test_lib_testrun-neg-inc\-"--run exclude and include"\--run="!3-,5"<<-\EOF&&foriin123456do
@@ -771,9 +758,9 @@ test_expect_success 'nested lazy prerequisites' 'EOF'-test_expect_success'lazy prereqs do not turn off tracing''+test_expect_success'subtest: lazy prereqs do not turn off tracing''write_and_run_sub_test_lib_testlazy-prereq-and-tracing\-"lazy prereqs and -x"-v-x<<-\EOF&&+-v-x<<-\EOF&&test_lazy_prereqLAZYtruetest_expect_successlazy"test_have_prereq LAZY && echo trace"
@@ -784,8 +771,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''-write_and_run_sub_test_lib_testcleanup"test with cleanup"<<-\EOF&&+test_expect_success'subtest: tests clean up after themselves''+write_and_run_sub_test_lib_testcleanup<<-\EOF&&clean=notest_expect_success"do cleanup""test_when_finishedclean=yes
@@ -804,9 +791,9 @@ test_expect_success 'tests clean up after themselves' 'EOF'-test_expect_success'tests clean up even on failures''+test_expect_success'subtest: tests clean up even on failures''write_and_run_sub_test_lib_test_err\-failing-cleanup"Failing tests with cleanup commands"<<-\EOF&&+failing-cleanup<<-\EOF&&test_expect_success"tests clean up even after a failure""touchclean-after-failure&&test_when_finishedrmclean-after-failure&&
@@ -833,9 +820,9 @@ test_expect_success 'tests clean up even on failures' 'EOF'-test_expect_success'test_atexit is run''+test_expect_success'subtest: test_atexit is run''write_and_run_sub_test_lib_test_err\-atexit-cleanup"Run atexit commands"-i<<-\EOF&&+atexit-cleanup-i<<-\EOF&&test_expect_success"tests clean up even after a failure"">../../clean-atexit&&test_atexitrm../../clean-atexit&&
Move the "check_sub_test_lib_test()" and its sister functions to a new
lib-subtest.sh.
In the future (not in this series) I'd like to test test-lib's output
in a more targeted and smaller test, and I'll need these functions to
do that.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 64 ++++++++++++++++++++++++++++++++++++++++++++++
t/t0000-basic.sh | 66 +-----------------------------------------------
2 files changed, 65 insertions(+), 65 deletions(-)
create mode 100644 t/lib-subtest.sh
@@ -0,0 +1,64 @@+_run_sub_test_lib_test_common(){+neg="$1"name="$2"descr="$3"# stdin is the body of the test code+shift3+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_unsetHARNESS_ACTIVE&&+cd"$name"&&+write_script"$name.sh""$TEST_SHELL_PATH"<<-EOF&&+test_description='$descr(runinsubtest-lib)++Thisisruninasubtest-libsothatwedonotgetincorrect+passingmetrics+'++# Point to the t/test-lib.sh, which isn't in ../ as usual+."\$TEST_DIRECTORY"/test-lib.sh+EOF+cat>>"$name.sh"&&+exportTEST_DIRECTORY&&+TEST_OUTPUT_DIRECTORY=$(pwd)&&+exportTEST_OUTPUT_DIRECTORY&&+sane_unsetGIT_TEST_FAIL_PREREQS&&+iftest-z"$neg"+then+./"$name.sh""$@">out2>err+else+!./"$name.sh""$@">out2>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_emptyerr&&+sed-e's/^> //'-e's/Z$//'>expect&&+test_cmpexpectout+)+}++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_cmpexpect.outout&&+sed-e's/^> //'-e's/Z$//'<&3>expect.err&&+test_cmpexpect.errerr+)+}
@@ -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(){localx="local"y="alsolocal"&&
@@ -66,71 +67,6 @@ 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-shift3-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_unsetHARNESS_ACTIVE&&-cd"$name"&&-write_script"$name.sh""$TEST_SHELL_PATH"<<-EOF&&-test_description='$descr(runinsubtest-lib)--Thisisruninasubtest-libsothatwedonotgetincorrect-passingmetrics-'--# Point to the t/test-lib.sh, which isn't in ../ as usual-."\$TEST_DIRECTORY"/test-lib.sh-EOF-cat>>"$name.sh"&&-exportTEST_DIRECTORY&&-TEST_OUTPUT_DIRECTORY=$(pwd)&&-exportTEST_OUTPUT_DIRECTORY&&-sane_unsetGIT_TEST_FAIL_PREREQS&&-iftest-z"$neg"-then-./"$name.sh""$@">out2>err-else-!./"$name.sh""$@">out2>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_emptyerr&&-sed-e's/^> //'-e's/Z$//'>expect&&-test_cmpexpectout-)-}--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_cmpexpect.outout&&-sed-e's/^> //'-e's/Z$//'<&3>expect.err&&-test_cmpexpect.errerr-)-}- test_expect_success'pretend we have a fully passing test suite''run_sub_test_lib_testfull-pass"3 passing tests"<<-\EOF&&foriin123
Now that this function doesn't handle running the test anymore we can
do away with the sub-shell, which was used to scope an "unset" and
"export" shell variables.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
@@ -1,20 +1,17 @@ write_sub_test_lib_test(){name="$1"descr="$2"# stdin is the body of the test codemkdir"$name"&&-(-cd"$name"&&-write_script"$name.sh""$TEST_SHELL_PATH"<<-EOF&&-test_description='$descr(runinsubtest-lib)+write_script"$name/$name.sh""$TEST_SHELL_PATH"<<-EOF&&+test_description='$descr(runinsubtest-lib)-Thisisruninasubtest-libsothatwedonotgetincorrect-passingmetrics-'+Thisisruninasubtest-libsothatwedonotgetincorrect+passingmetrics+'-# Point to the t/test-lib.sh, which isn't in ../ as usual-."\$TEST_DIRECTORY"/test-lib.sh-EOF-cat>>"$name.sh"-)+# 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(){
The use of a sub-shell for running the test_cmp of stdout/stderr for
the test author was introduced in this form in 565b6fa87bb (tests:
refactor mechanics of testing in a sub test-lib, 2012-12-16), but from
looking at the history that seemed to have diligently copied my
original ad-hoc implementation in 7b905119703 (t/t0000-basic.sh: Run
the passing TODO test inside its own test-lib, 2010-08-19).
There's no reason to use a subshell here, we try to avoid it in
general. It also improves readability, if the test fails we print out
the relative path in the trash directory that needs to be looked
at.
Before that was mostly obscured, since the "write_sub_test_lib_test"
will pick the directory for you from the test name.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)
@@ -89,22 +89,16 @@ run_sub_test_lib_test_err () { check_sub_test_lib_test(){name="$1"# stdin is the expected output from the test-(-cd"$name"&&-test_must_be_emptyerr&&-sed-e's/^> //'-e's/Z$//'>expect&&-test_cmpexpectout-)+test_must_be_empty"$name"/err&&+sed-e's/^> //'-e's/Z$//'>"$name"/expect&&+test_cmp"$name/"expect"$name"/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_cmpexpect.outout&&-sed-e's/^> //'-e's/Z$//'<&3>expect.err&&-test_cmpexpect.errerr-)+sed-e's/^> //'-e's/Z$//'>"$name"/expect.out&&+test_cmp"$name"/expect.out"$name"/out&&+sed-e's/^> //'-e's/Z$//'<&3>"$name"/expect.err&&+test_cmp"$name"/expect.err"$name"/err}
Refactor the two check_sub_test_lib_test*() functions to avoid
duplicating the same comparison they did of stdout. This duplication
was initially added when check_sub_test_lib_test_err() was added in
0445e6f0a12 (test-lib: '--run' to run only specific tests,
2014-04-30).
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
@@ -87,18 +87,22 @@ run_sub_test_lib_test_err () {_run_sub_test_lib_test_common'!'"$@"}+_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-test_must_be_empty"$name"/err&&-sed-e's/^> //'-e's/Z$//'>"$name"/expect&&-test_cmp"$name/"expect"$name"/out+_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$//'>"$name"/expect.out&&-test_cmp"$name"/expect.out"$name"/out&&sed-e's/^> //'-e's/Z$//'<&3>"$name"/expect.err&&test_cmp"$name"/expect.err"$name"/err}
Refactor the function to write and run tests of the test-lib.sh output
into two functions.
When this was added back in 565b6fa87bb (tests: refactor mechanics of
testing in a sub test-lib, 2012-12-16) there was no reason to do this,
but since we started supporting test arguments in
517cd55fd51 (test-lib: self-test that --verbose works, 2013-06-23)
we've started to write out duplicate tests simply to test different
arguments, now we'll be able to re-use them.
This change doesn't consolidate any of those tests yet, it just makes
it possible to do so. All the changes in t0000-basic.sh are a simple
search-replacement.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 39 +++++++++++++++++++------
t/t0000-basic.sh | 74 ++++++++++++++++++++++++------------------------
2 files changed, 67 insertions(+), 46 deletions(-)
@@ -1,13 +1,7 @@-_run_sub_test_lib_test_common(){-neg="$1"name="$2"descr="$3"# stdin is the body of the test code-shift3+write_sub_test_lib_test(){+name="$1"descr="$2"# stdin is the body of the test codemkdir"$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_unsetHARNESS_ACTIVE&&cd"$name"&&write_script"$name.sh""$TEST_SHELL_PATH"<<-EOF&&test_description='$descr(runinsubtest-lib)
@@ -19,7 +13,22 @@ _run_sub_test_lib_test_common () {# Point to the t/test-lib.sh, which isn't in ../ as usual."\$TEST_DIRECTORY"/test-lib.shEOF-cat>>"$name.sh"&&+cat>>"$name.sh"+)+}++_run_sub_test_lib_test_common(){+neg="$1"name="$2"descr="$3"# stdin is the body of the test code+shift3+(+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_unsetHARNESS_ACTIVE&&+exportTEST_DIRECTORY&&TEST_OUTPUT_DIRECTORY=$(pwd)&&exportTEST_OUTPUT_DIRECTORY&&
@@ -33,6 +42,18 @@ _run_sub_test_lib_test_common () {)}+write_and_run_sub_test_lib_test(){+name="$1"descr="$2"# stdin is the body of the test code+write_sub_test_lib_test"$@"||return1+_run_sub_test_lib_test_common''"$@"+}++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"$@"||return1+_run_sub_test_lib_test_common'!'"$@"+}+ run_sub_test_lib_test(){_run_sub_test_lib_test_common''"$@"}
@@ -68,7 +68,7 @@ test_expect_success 'success is reported like this' '' test_expect_success'pretend we have a fully passing test suite''-run_sub_test_lib_testfull-pass"3 passing tests"<<-\EOF&&+write_and_run_sub_test_lib_testfull-pass"3 passing tests"<<-\EOF&&foriin123dotest_expect_success"passing test #$i""true"
@@ -85,7 +85,7 @@ test_expect_success 'pretend we have a fully passing test suite' '' test_expect_success'pretend we have a partially passing test suite''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\partial-pass"2/3 tests passing"<<-\EOF&&test_expect_success"passing test #1""true"test_expect_success"failing test #2""false"
@@ -103,7 +103,7 @@ test_expect_success 'pretend we have a partially passing test suite' '' test_expect_success'pretend we have a known breakage''-run_sub_test_lib_testfailing-todo"A failing TODO test"<<-\EOF&&+write_and_run_sub_test_lib_testfailing-todo"A failing TODO test"<<-\EOF&&test_expect_success"passing test""true"test_expect_failure"pretend we have a known breakage""false"test_done
@@ -118,7 +118,7 @@ test_expect_success 'pretend we have a known breakage' '' test_expect_success'pretend we have fixed a known breakage''-run_sub_test_lib_testpassing-todo"A passing TODO test"<<-\EOF&&+write_and_run_sub_test_lib_testpassing-todo"A passing TODO test"<<-\EOF&&test_expect_failure"pretend we have fixed a known breakage""true"test_doneEOF
@@ -130,7 +130,7 @@ test_expect_success 'pretend we have fixed a known breakage' '' test_expect_success'pretend we have fixed one of two known breakages (run in sub test-lib)''-run_sub_test_lib_testpartially-passing-todos\+write_and_run_sub_test_lib_testpartially-passing-todos\"2 TODO tests, one passing"<<-\EOF&&test_expect_failure"pretend we have a known breakage""false"test_expect_success"pretend we have a passing test""true"
@@ -149,7 +149,7 @@ test_expect_success 'pretend we have fixed one of two known breakages (run in su' test_expect_success'pretend we have a pass, fail, and known breakage''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\mixed-results1"mixed results #1"<<-\EOF&&test_expect_success"passing test""true"test_expect_success"failing test""false"
@@ -168,7 +168,7 @@ test_expect_success 'pretend we have a pass, fail, and known breakage' '' test_expect_success'pretend we have a mix of all possible results''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\mixed-results2"mixed results #2"<<-\EOF&&test_expect_success"passing test""true"test_expect_success"passing test""true"
@@ -204,7 +204,7 @@ test_expect_success 'pretend we have a mix of all possible results' '' test_expect_success'test --verbose''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\t1234-verbose"test verbose"--verbose<<-\EOF&&test_expect_success"passing test"truetest_expect_success"test with output""echo foo"
@@ -277,7 +277,7 @@ test_expect_success 'GIT_SKIP_TESTS' ' test_expect_success'GIT_SKIP_TESTS several tests''(GIT_SKIP_TESTS="git.2 git.5"&&exportGIT_SKIP_TESTS&&-run_sub_test_lib_testgit-skip-tests-several\+write_and_run_sub_test_lib_testgit-skip-tests-several\"GIT_SKIP_TESTS several tests"<<-\EOF&&foriin123456do
@@ -301,7 +301,7 @@ test_expect_success 'GIT_SKIP_TESTS several tests' ' test_expect_success'GIT_SKIP_TESTS sh pattern''(GIT_SKIP_TESTS="git.[2-5]"&&exportGIT_SKIP_TESTS&&-run_sub_test_lib_testgit-skip-tests-sh-pattern\+write_and_run_sub_test_lib_testgit-skip-tests-sh-pattern\"GIT_SKIP_TESTS sh pattern"<<-\EOF&&foriin123456do
@@ -342,7 +342,7 @@ test_expect_success 'GIT_SKIP_TESTS entire suite' ' test_expect_success'GIT_SKIP_TESTS does not skip unmatched suite''(GIT_SKIP_TESTS="notgit"&&exportGIT_SKIP_TESTS&&-run_sub_test_lib_testgit-skip-tests-unmatched-suite\+write_and_run_sub_test_lib_testgit-skip-tests-unmatched-suite\"GIT_SKIP_TESTS does not skip unmatched suite"<<-\EOF&&foriin123do
@@ -361,7 +361,7 @@ test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' '' test_expect_success'--run basic''-run_sub_test_lib_testrun-basic\+write_and_run_sub_test_lib_testrun-basic\"--run basic"--run="1,3,5"<<-\EOF&&foriin123456do
@@ -382,7 +382,7 @@ test_expect_success '--run basic' '' test_expect_success'--run with a range''-run_sub_test_lib_testrun-range\+write_and_run_sub_test_lib_testrun-range\"--run with a range"--run="1-3"<<-\EOF&&foriin123456do
@@ -403,7 +403,7 @@ test_expect_success '--run with a range' '' test_expect_success'--run with two ranges''-run_sub_test_lib_testrun-two-ranges\+write_and_run_sub_test_lib_testrun-two-ranges\"--run with two ranges"--run="1-2,5-6"<<-\EOF&&foriin123456do
@@ -424,7 +424,7 @@ test_expect_success '--run with two ranges' '' test_expect_success'--run with a left open range''-run_sub_test_lib_testrun-left-open-range\+write_and_run_sub_test_lib_testrun-left-open-range\"--run with a left open range"--run="-3"<<-\EOF&&foriin123456do
@@ -445,7 +445,7 @@ test_expect_success '--run with a left open range' '' test_expect_success'--run with a right open range''-run_sub_test_lib_testrun-right-open-range\+write_and_run_sub_test_lib_testrun-right-open-range\"--run with a right open range"--run="4-"<<-\EOF&&foriin123456do
@@ -466,7 +466,7 @@ test_expect_success '--run with a right open range' '' test_expect_success'--run with basic negation''-run_sub_test_lib_testrun-basic-neg\+write_and_run_sub_test_lib_testrun-basic-neg\"--run with basic negation"--run="!3"<<-\EOF&&foriin123456do
@@ -487,7 +487,7 @@ test_expect_success '--run with basic negation' '' test_expect_success'--run with two negations''-run_sub_test_lib_testrun-two-neg\+write_and_run_sub_test_lib_testrun-two-neg\"--run with two negations"--run="!3,!6"<<-\EOF&&foriin123456do
@@ -508,7 +508,7 @@ test_expect_success '--run with two negations' '' test_expect_success'--run a range and negation''-run_sub_test_lib_testrun-range-and-neg\+write_and_run_sub_test_lib_testrun-range-and-neg\"--run a range and negation"--run="-4,!2"<<-\EOF&&foriin123456do
@@ -529,7 +529,7 @@ test_expect_success '--run a range and negation' '' test_expect_success'--run range negation''-run_sub_test_lib_testrun-range-neg\+write_and_run_sub_test_lib_testrun-range-neg\"--run range negation"--run="!1-3"<<-\EOF&&foriin123456do
@@ -550,7 +550,7 @@ test_expect_success '--run range negation' '' test_expect_success'--run include, exclude and include''-run_sub_test_lib_testrun-inc-neg-inc\+write_and_run_sub_test_lib_testrun-inc-neg-inc\"--run include, exclude and include"\--run="1-5,!1-3,2"<<-\EOF&&foriin123456
@@ -572,7 +572,7 @@ test_expect_success '--run include, exclude and include' '' test_expect_success'--run include, exclude and include, comma separated''-run_sub_test_lib_testrun-inc-neg-inc-comma\+write_and_run_sub_test_lib_testrun-inc-neg-inc-comma\"--run include, exclude and include, comma separated"\--run=1-5,!1-3,2<<-\EOF&&foriin123456
@@ -594,7 +594,7 @@ test_expect_success '--run include, exclude and include, comma separated' '' test_expect_success'--run exclude and include''-run_sub_test_lib_testrun-neg-inc\+write_and_run_sub_test_lib_testrun-neg-inc\"--run exclude and include"\--run="!3-,5"<<-\EOF&&foriin123456
@@ -772,7 +772,7 @@ test_expect_success 'nested lazy prerequisites' '' test_expect_success'lazy prereqs do not turn off tracing''-run_sub_test_lib_testlazy-prereq-and-tracing\+write_and_run_sub_test_lib_testlazy-prereq-and-tracing\"lazy prereqs and -x"-v-x<<-\EOF&&test_lazy_prereqLAZYtrue
@@ -785,7 +785,7 @@ test_expect_success 'lazy prereqs do not turn off tracing' '' test_expect_success'tests clean up after themselves''-run_sub_test_lib_testcleanup"test with cleanup"<<-\EOF&&+write_and_run_sub_test_lib_testcleanup"test with cleanup"<<-\EOF&&clean=notest_expect_success"do cleanup""test_when_finishedclean=yes
@@ -805,7 +805,7 @@ test_expect_success 'tests clean up after themselves' '' test_expect_success'tests clean up even on failures''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\failing-cleanup"Failing tests with cleanup commands"<<-\EOF&&test_expect_success"tests clean up even after a failure""touchclean-after-failure&&
@@ -834,7 +834,7 @@ test_expect_success 'tests clean up even on failures' '' test_expect_success'test_atexit is run''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\atexit-cleanup"Run atexit commands"-i<<-\EOF&&test_expect_success"tests clean up even after a failure"">../../clean-atexit&&
From: Felipe Contreras <hidden> Date: 2021-06-15 18:05:54
Ævar Arnfjörð Bjarmason wrote:
There's a conflict here with Felipe's proposed
http://lore.kernel.org/git/20210609170520.67014-1-felipe.contreras@gmail.com,
but it's just a matter of moving the fix around and solving a trivial
conflict. I thought it was better to submit this now anyway, while
this code is fresh in people's minds.
I'm hoping Felipe will take some variant of my
http://lore.kernel.org/git/8735tk22if.fsf@evledraar.gmail.com and
perhaps review this series & base his patch on top of these changes,
but alternatively they can go in independently with Junio solving the
conflict.
I have no problem rebasing my patch on top of your series, but my
current v2 doesn't touch _run_sub_test_lib_test_common at all, and I'm
not sure your proposal of TEST_NO_RESULTS_OUTPUT is the way to go, so
perhaps there's no need to rebase at all.
Unless there's something on this series that would help
TEST_OUTPUT_DIRECTORY, which at a quick glance doesn't seem to be the
case.
Cheers.
--
Felipe Contreras
This refactors the testing of test-lib.sh itself in t0000 into a
lib-subtest.sh, fixing duplicate setup, bugs and various shell nits
along the way.
The v1[1] of this recently started conflicting with the cooking
jk/t0000-subtests-fix and ps/t0000-output-directory-fix, and got
ejected from "seen". This v2 is rebased on top of those two, so it
merges cleanly with "seen".
1. https://lore.kernel.org/git/cover-0.8-00000000000-20210614T104351Z-avarab@gmail.com/
Ævar Arnfjörð Bjarmason (8):
test-lib tests: move "run_sub_test" to a new lib-subtest.sh
test-lib tests: split up "write and run" into two functions
test-lib tests: stop using a subshell in write_sub_test_lib_test()
test-lib tests: don't provide a description for the sub-tests
test-lib tests: get rid of copy/pasted mock test code
test-lib tests: avoid subshell for "test_cmp" for readability
test-lib tests: refactor common part of check_sub_test_lib_test*()
test-lib tests: assert 1 exit code, not non-zero
t/lib-subtest.sh | 128 ++++++++++++++
t/t0000-basic.sh | 448 +++++++++++++----------------------------------
2 files changed, 246 insertions(+), 330 deletions(-)
create mode 100644 t/lib-subtest.sh
Range-diff against v1:
1: 3c0a78530d2 ! 1: 7a06ea3a7b7 test-lib tests: move "run_sub_test" to a new lib-subtest.sh
@@ t/lib-subtest.sh (new)
+_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
@@ t/lib-subtest.sh (new)
+ EOF
+ cat >>"$name.sh" &&
+ export TEST_DIRECTORY &&
-+ TEST_OUTPUT_DIRECTORY=$(pwd) &&
-+ export TEST_OUTPUT_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
@@ t/t0000-basic.sh: 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
@@ t/t0000-basic.sh: test_expect_success 'success is reported like this' '
- EOF
- cat >>"$name.sh" &&
- export TEST_DIRECTORY &&
-- TEST_OUTPUT_DIRECTORY=$(pwd) &&
-- export TEST_OUTPUT_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
2: 9e2715d2e20 ! 2: 28117b84abf test-lib tests: split up "write and run" into two functions
@@ Commit message
## t/lib-subtest.sh ##
@@
--_run_sub_test_lib_test_common () {
-- neg="$1" name="$2" descr="$3" # stdin is the body of the test code
-- shift 3
+write_sub_test_lib_test () {
+ name="$1" descr="$2" # stdin is the body of the test code
- 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)
-@@ t/lib-subtest.sh: _run_sub_test_lib_test_common () {
- # Point to the t/test-lib.sh, which isn't in ../ as usual
- . "\$TEST_DIRECTORY"/test-lib.sh
- EOF
-- cat >>"$name.sh" &&
++ mkdir "$name" &&
++ (
++ 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"
+ )
+}
+
-+_run_sub_test_lib_test_common () {
-+ neg="$1" name="$2" descr="$3" # stdin is the body of the test code
-+ shift 3
-+ (
+ _run_sub_test_lib_test_common () {
+ neg="$1" name="$2" descr="$3" # stdin is the body of the test code
+ shift 3
+@@ t/lib-subtest.sh: _run_sub_test_lib_test_common () {
+ esac
+ done
+
+- mkdir "$name" &&
+ (
+ 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 &&
-+
+ # 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 &&
- TEST_OUTPUT_DIRECTORY=$(pwd) &&
- export TEST_OUTPUT_DIRECTORY &&
+ # The child test re-sources GIT-BUILD-OPTIONS and may thus
+ # override the test output directory. We thus pass it as an
@@ t/lib-subtest.sh: _run_sub_test_lib_test_common () {
)
}
@@ t/lib-subtest.sh: _run_sub_test_lib_test_common () {
run_sub_test_lib_test () {
_run_sub_test_lib_test_common '' "$@"
}
+@@ t/lib-subtest.sh: check_sub_test_lib_test_err () {
+ test_cmp expect.err err
+ )
+ }
++
## t/t0000-basic.sh ##
@@ t/t0000-basic.sh: test_expect_success 'success is reported like this' '
@@ t/t0000-basic.sh: test_expect_success 'test --verbose' '
--verbose-only=2 <<-\EOF &&
test_expect_success "passing test" true
@@ t/t0000-basic.sh: test_expect_success 'test --verbose-only' '
+
test_expect_success 'GIT_SKIP_TESTS' '
(
- GIT_SKIP_TESTS="git.2" && export GIT_SKIP_TESTS &&
- run_sub_test_lib_test git-skip-tests-basic \
+ write_and_run_sub_test_lib_test git-skip-tests-basic \
- "GIT_SKIP_TESTS" <<-\EOF &&
+ "GIT_SKIP_TESTS" \
+ --skip="git.2" <<-\EOF &&
for i in 1 2 3
- do
@@ t/t0000-basic.sh: test_expect_success 'GIT_SKIP_TESTS' '
+
test_expect_success 'GIT_SKIP_TESTS several tests' '
(
- GIT_SKIP_TESTS="git.2 git.5" && export GIT_SKIP_TESTS &&
- run_sub_test_lib_test git-skip-tests-several \
+ write_and_run_sub_test_lib_test git-skip-tests-several \
- "GIT_SKIP_TESTS several tests" <<-\EOF &&
+ "GIT_SKIP_TESTS several tests" \
+ --skip="git.2 git.5" <<-\EOF &&
for i in 1 2 3 4 5 6
- do
@@ t/t0000-basic.sh: test_expect_success 'GIT_SKIP_TESTS several tests' '
+
test_expect_success 'GIT_SKIP_TESTS sh pattern' '
(
- GIT_SKIP_TESTS="git.[2-5]" && export GIT_SKIP_TESTS &&
- run_sub_test_lib_test git-skip-tests-sh-pattern \
+ write_and_run_sub_test_lib_test git-skip-tests-sh-pattern \
- "GIT_SKIP_TESTS sh pattern" <<-\EOF &&
+ "GIT_SKIP_TESTS sh pattern" \
+ --skip="git.[2-5]" <<-\EOF &&
for i in 1 2 3 4 5 6
- do
@@ t/t0000-basic.sh: test_expect_success 'GIT_SKIP_TESTS sh pattern' '
+
test_expect_success 'GIT_SKIP_TESTS entire suite' '
(
- GIT_SKIP_TESTS="git" && export GIT_SKIP_TESTS &&
- run_sub_test_lib_test git-skip-tests-entire-suite \
+ write_and_run_sub_test_lib_test git-skip-tests-entire-suite \
- "GIT_SKIP_TESTS entire suite" <<-\EOF &&
+ "GIT_SKIP_TESTS entire suite" \
+ --skip="git" <<-\EOF &&
for i in 1 2 3
- do
@@ t/t0000-basic.sh: test_expect_success 'GIT_SKIP_TESTS entire suite' '
+
test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' '
(
- GIT_SKIP_TESTS="notgit" && export GIT_SKIP_TESTS &&
- run_sub_test_lib_test git-skip-tests-unmatched-suite \
+ write_and_run_sub_test_lib_test git-skip-tests-unmatched-suite \
- "GIT_SKIP_TESTS does not skip unmatched suite" <<-\EOF &&
+ "GIT_SKIP_TESTS does not skip unmatched suite" \
+ --skip="notgit" <<-\EOF &&
for i in 1 2 3
- do
@@ t/t0000-basic.sh: test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' '
'
3: cd6c740c912 = 3: 7d5ed335a36 test-lib tests: stop using a subshell in write_sub_test_lib_test()
4: 0578470d899 ! 4: 2a0dd64da90 test-lib tests: don't provide a description for the sub-tests
@@ t/lib-subtest.sh: write_sub_test_lib_test () {
- shift 3
+ neg="$1" name="$2" # stdin is the body of the test code
+ shift 2
- (
- cd "$name" &&
+ # intercept pseudo-options at the front of the argument list that we
+ # will not pass to child script
## t/t0000-basic.sh ##
@@ t/t0000-basic.sh: test_expect_success 'success is reported like this' '
@@ t/t0000-basic.sh: test_expect_success 'test --verbose-only' '
-test_expect_success 'GIT_SKIP_TESTS' '
+test_expect_success 'subtest: skip one with GIT_SKIP_TESTS' '
(
- GIT_SKIP_TESTS="git.2" && export GIT_SKIP_TESTS &&
write_and_run_sub_test_lib_test git-skip-tests-basic \
-- "GIT_SKIP_TESTS" <<-\EOF &&
-+ <<-\EOF &&
+- "GIT_SKIP_TESTS" \
+ --skip="git.2" <<-\EOF &&
for i in 1 2 3
do
- test_expect_success "passing test #$i" "true"
@@ t/t0000-basic.sh: test_expect_success 'GIT_SKIP_TESTS' '
)
'
@@ t/t0000-basic.sh: test_expect_success 'GIT_SKIP_TESTS' '
-test_expect_success 'GIT_SKIP_TESTS several tests' '
+test_expect_success 'subtest: skip several with GIT_SKIP_TESTS' '
(
- GIT_SKIP_TESTS="git.2 git.5" && export GIT_SKIP_TESTS &&
write_and_run_sub_test_lib_test git-skip-tests-several \
-- "GIT_SKIP_TESTS several tests" <<-\EOF &&
-+ <<-\EOF &&
+- "GIT_SKIP_TESTS several tests" \
+ --skip="git.2 git.5" <<-\EOF &&
for i in 1 2 3 4 5 6
do
- test_expect_success "passing test #$i" "true"
@@ t/t0000-basic.sh: test_expect_success 'GIT_SKIP_TESTS several tests' '
)
'
@@ t/t0000-basic.sh: 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' '
(
- GIT_SKIP_TESTS="git.[2-5]" && export GIT_SKIP_TESTS &&
write_and_run_sub_test_lib_test git-skip-tests-sh-pattern \
-- "GIT_SKIP_TESTS sh pattern" <<-\EOF &&
-+ <<-\EOF &&
+- "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"
@@ t/t0000-basic.sh: test_expect_success 'GIT_SKIP_TESTS sh pattern' '
)
'
@@ t/t0000-basic.sh: 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' '
(
- GIT_SKIP_TESTS="git" && export GIT_SKIP_TESTS &&
write_and_run_sub_test_lib_test git-skip-tests-entire-suite \
-- "GIT_SKIP_TESTS entire suite" <<-\EOF &&
-+ <<-\EOF &&
+- "GIT_SKIP_TESTS entire suite" \
+ --skip="git" <<-\EOF &&
for i in 1 2 3
do
- test_expect_success "passing test #$i" "true"
@@ t/t0000-basic.sh: test_expect_success 'GIT_SKIP_TESTS entire suite' '
)
'
@@ t/t0000-basic.sh: test_expect_success 'GIT_SKIP_TESTS entire suite' '
-test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' '
+test_expect_success 'subtest: GIT_SKIP_TESTS does not skip unmatched suite' '
(
- GIT_SKIP_TESTS="notgit" && export GIT_SKIP_TESTS &&
write_and_run_sub_test_lib_test git-skip-tests-unmatched-suite \
-- "GIT_SKIP_TESTS does not skip unmatched suite" <<-\EOF &&
-+ <<-\EOF &&
+- "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"
@@ t/t0000-basic.sh: test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' '
)
'
5: 1909616d9ca ! 5: f60190dec6a test-lib tests: get rid of copy/pasted mock test code
@@ t/t0000-basic.sh: test_expect_success 'subtest: --verbose-only option' '
test_expect_success 'subtest: skip one with GIT_SKIP_TESTS' '
(
-- GIT_SKIP_TESTS="git.2" && export GIT_SKIP_TESTS &&
- write_and_run_sub_test_lib_test git-skip-tests-basic \
-- <<-\EOF &&
+- --skip="git.2" <<-\EOF &&
- for i in 1 2 3
- do
- test_expect_success "passing test #$i" "true"
@@ t/t0000-basic.sh: test_expect_success 'subtest: --verbose-only option' '
- test_done
- EOF
- check_sub_test_lib_test git-skip-tests-basic <<-\EOF
-+ GIT_SKIP_TESTS="full.2" && export GIT_SKIP_TESTS &&
-+ run_sub_test_lib_test full-pass &&
++ 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
@@ t/t0000-basic.sh: test_expect_success 'subtest: skip several with GIT_SKIP_TESTS' '
+
test_expect_success 'subtest: sh pattern skipping with GIT_SKIP_TESTS' '
(
- GIT_SKIP_TESTS="git.[2-5]" && export GIT_SKIP_TESTS &&
- write_and_run_sub_test_lib_test git-skip-tests-sh-pattern \
-- <<-\EOF &&
+- --skip="git.[2-5]" <<-\EOF &&
- for i in 1 2 3 4 5 6
- do
- test_expect_success "passing test #$i" "true"
@@ t/t0000-basic.sh: test_expect_success 'subtest: skip several with GIT_SKIP_TESTS
- test_done
- EOF
- check_sub_test_lib_test git-skip-tests-sh-pattern <<-\EOF
-+ run_sub_test_lib_test git-skip-tests-several &&
++ 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)
@@ t/t0000-basic.sh: test_expect_success 'subtest: sh pattern skipping with GIT_SKIP_TESTS' '
+
test_expect_success 'subtest: skip entire test suite with GIT_SKIP_TESTS' '
(
- GIT_SKIP_TESTS="git" && export GIT_SKIP_TESTS &&
- write_and_run_sub_test_lib_test git-skip-tests-entire-suite \
-- <<-\EOF &&
+- --skip="git" <<-\EOF &&
- for i in 1 2 3
- do
- test_expect_success "passing test #$i" "true"
@@ t/t0000-basic.sh: test_expect_success 'subtest: sh pattern skipping with GIT_SKI
- test_done
- EOF
- check_sub_test_lib_test git-skip-tests-entire-suite <<-\EOF
-+ run_sub_test_lib_test git-skip-tests-several &&
++ 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
)
@@ t/t0000-basic.sh: test_expect_success 'subtest: skip entire test suite with GIT_SKIP_TESTS' '
+
test_expect_success 'subtest: GIT_SKIP_TESTS does not skip unmatched suite' '
(
- GIT_SKIP_TESTS="notgit" && export GIT_SKIP_TESTS &&
- write_and_run_sub_test_lib_test git-skip-tests-unmatched-suite \
-- <<-\EOF &&
+- --skip="notgit" <<-\EOF &&
- for i in 1 2 3
- do
- test_expect_success "passing test #$i" "true"
@@ t/t0000-basic.sh: test_expect_success 'subtest: skip entire test suite with GIT_
- test_done
- EOF
- check_sub_test_lib_test git-skip-tests-unmatched-suite <<-\EOF
-+ run_sub_test_lib_test full-pass &&
++ 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
6: 2f717e437e6 ! 6: 022ddbabf63 test-lib tests: avoid subshell for "test_cmp" for readability
@@ t/lib-subtest.sh: run_sub_test_lib_test_err () {
+ sed -e 's/^> //' -e 's/Z$//' <&3 >"$name"/expect.err &&
+ test_cmp "$name"/expect.err "$name"/err
}
+
7: 1f32eb60411 = 7: ae0226e164c test-lib tests: refactor common part of check_sub_test_lib_test*()
8: ddbc8db2802 ! 8: 676547e001e test-lib tests: assert 1 exit code, not non-zero
@@ t/lib-subtest.sh: write_sub_test_lib_test () {
- shift 2
+ cmp_op="$1" want_code="$2" name="$3" # stdin is the body of the test code
+ shift 3
- (
- cd "$name" &&
+ # intercept pseudo-options at the front of the argument list that we
+ # will not pass to child script
@@ t/lib-subtest.sh: _run_sub_test_lib_test_common () {
- TEST_OUTPUT_DIRECTORY=$(pwd) &&
- export TEST_OUTPUT_DIRECTORY &&
+ GIT_SKIP_TESTS=$skip &&
+ export GIT_SKIP_TESTS &&
sane_unset GIT_TEST_FAIL_PREREQS &&
- if test -z "$neg"
- then
--
2.32.0.955.ge7c5360f7e7
Move the "check_sub_test_lib_test()" and its sister functions to a new
lib-subtest.sh.
In the future (not in this series) I'd like to test test-lib's output
in a more targeted and smaller test, and I'll need these functions to
do that.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 86 ++++++++++++++++++++++++++++++++++++++++++++++
t/t0000-basic.sh | 88 +-----------------------------------------------
2 files changed, 87 insertions(+), 87 deletions(-)
create mode 100644 t/lib-subtest.sh
@@ -0,0 +1,86 @@+_run_sub_test_lib_test_common(){+neg="$1"name="$2"descr="$3"# stdin is the body of the test code+shift3++# intercept pseudo-options at the front of the argument list that we+# will not pass to child script+skip=+whiletest$#-gt0+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_unsetHARNESS_ACTIVE&&+cd"$name"&&+write_script"$name.sh""$TEST_SHELL_PATH"<<-EOF&&+test_description='$descr(runinsubtest-lib)++Thisisruninasubtest-libsothatwedonotgetincorrect+passingmetrics+'++# Point to the t/test-lib.sh, which isn't in ../ as usual+."\$TEST_DIRECTORY"/test-lib.sh+EOF+cat>>"$name.sh"&&+exportTEST_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)&&+exportTEST_OUTPUT_DIRECTORY_OVERRIDE&&+GIT_SKIP_TESTS=$skip&&+exportGIT_SKIP_TESTS&&+sane_unsetGIT_TEST_FAIL_PREREQS&&+iftest-z"$neg"+then+./"$name.sh""$@">out2>err+else+!./"$name.sh""$@">out2>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_emptyerr&&+sed-e's/^> //'-e's/Z$//'>expect&&+test_cmpexpectout+)+}++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_cmpexpect.outout&&+sed-e's/^> //'-e's/Z$//'<&3>expect.err&&+test_cmpexpect.errerr+)+}
@@ -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(){localx="local"y="alsolocal"&&
@@ -66,93 +67,6 @@ 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-shift3--# intercept pseudo-options at the front of the argument list that we-# will not pass to child script-skip=-whiletest$#-gt0-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_unsetHARNESS_ACTIVE&&-cd"$name"&&-write_script"$name.sh""$TEST_SHELL_PATH"<<-EOF&&-test_description='$descr(runinsubtest-lib)--Thisisruninasubtest-libsothatwedonotgetincorrect-passingmetrics-'--# Point to the t/test-lib.sh, which isn't in ../ as usual-."\$TEST_DIRECTORY"/test-lib.sh-EOF-cat>>"$name.sh"&&-exportTEST_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)&&-exportTEST_OUTPUT_DIRECTORY_OVERRIDE&&-GIT_SKIP_TESTS=$skip&&-exportGIT_SKIP_TESTS&&-sane_unsetGIT_TEST_FAIL_PREREQS&&-iftest-z"$neg"-then-./"$name.sh""$@">out2>err-else-!./"$name.sh""$@">out2>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_emptyerr&&-sed-e's/^> //'-e's/Z$//'>expect&&-test_cmpexpectout-)-}--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_cmpexpect.outout&&-sed-e's/^> //'-e's/Z$//'<&3>expect.err&&-test_cmpexpect.errerr-)-}- test_expect_success'pretend we have a fully passing test suite''run_sub_test_lib_testfull-pass"3 passing tests"<<-\EOF&&foriin123
Refactor the function to write and run tests of the test-lib.sh output
into two functions.
When this was added back in 565b6fa87bb (tests: refactor mechanics of
testing in a sub test-lib, 2012-12-16) there was no reason to do this,
but since we started supporting test arguments in
517cd55fd51 (test-lib: self-test that --verbose works, 2013-06-23)
we've started to write out duplicate tests simply to test different
arguments, now we'll be able to re-use them.
This change doesn't consolidate any of those tests yet, it just makes
it possible to do so. All the changes in t0000-basic.sh are a simple
search-replacement.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 46 ++++++++++++++++++++++--------
t/t0000-basic.sh | 74 ++++++++++++++++++++++++------------------------
2 files changed, 71 insertions(+), 49 deletions(-)
@@ -1,3 +1,22 @@+write_sub_test_lib_test(){+name="$1"descr="$2"# stdin is the body of the test code+mkdir"$name"&&+(+cd"$name"&&+write_script"$name.sh""$TEST_SHELL_PATH"<<-EOF&&+test_description='$descr(runinsubtest-lib)++Thisisruninasubtest-libsothatwedonotgetincorrect+passingmetrics+'++# Point to the t/test-lib.sh, which isn't in ../ as usual+."\$TEST_DIRECTORY"/test-lib.sh+EOF+cat>>"$name.sh"+)+}+ _run_sub_test_lib_test_common(){neg="$1"name="$2"descr="$3"# stdin is the body of the test codeshift3
@@ -18,25 +37,15 @@ _run_sub_test_lib_test_common () {esacdone-mkdir"$name"&&(+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_unsetHARNESS_ACTIVE&&-cd"$name"&&-write_script"$name.sh""$TEST_SHELL_PATH"<<-EOF&&-test_description='$descr(runinsubtest-lib)-Thisisruninasubtest-libsothatwedonotgetincorrect-passingmetrics-'--# Point to the t/test-lib.sh, which isn't in ../ as usual-."\$TEST_DIRECTORY"/test-lib.sh-EOF-cat>>"$name.sh"&&exportTEST_DIRECTORY&&# The child test re-sources GIT-BUILD-OPTIONS and may thus# override the test output directory. We thus pass it as an
@@ -55,6 +64,18 @@ _run_sub_test_lib_test_common () {)}+write_and_run_sub_test_lib_test(){+name="$1"descr="$2"# stdin is the body of the test code+write_sub_test_lib_test"$@"||return1+_run_sub_test_lib_test_common''"$@"+}++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"$@"||return1+_run_sub_test_lib_test_common'!'"$@"+}+ run_sub_test_lib_test(){_run_sub_test_lib_test_common''"$@"}
@@ -68,7 +68,7 @@ test_expect_success 'success is reported like this' '' test_expect_success'pretend we have a fully passing test suite''-run_sub_test_lib_testfull-pass"3 passing tests"<<-\EOF&&+write_and_run_sub_test_lib_testfull-pass"3 passing tests"<<-\EOF&&foriin123dotest_expect_success"passing test #$i""true"
@@ -85,7 +85,7 @@ test_expect_success 'pretend we have a fully passing test suite' '' test_expect_success'pretend we have a partially passing test suite''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\partial-pass"2/3 tests passing"<<-\EOF&&test_expect_success"passing test #1""true"test_expect_success"failing test #2""false"
@@ -103,7 +103,7 @@ test_expect_success 'pretend we have a partially passing test suite' '' test_expect_success'pretend we have a known breakage''-run_sub_test_lib_testfailing-todo"A failing TODO test"<<-\EOF&&+write_and_run_sub_test_lib_testfailing-todo"A failing TODO test"<<-\EOF&&test_expect_success"passing test""true"test_expect_failure"pretend we have a known breakage""false"test_done
@@ -118,7 +118,7 @@ test_expect_success 'pretend we have a known breakage' '' test_expect_success'pretend we have fixed a known breakage''-run_sub_test_lib_testpassing-todo"A passing TODO test"<<-\EOF&&+write_and_run_sub_test_lib_testpassing-todo"A passing TODO test"<<-\EOF&&test_expect_failure"pretend we have fixed a known breakage""true"test_doneEOF
@@ -130,7 +130,7 @@ test_expect_success 'pretend we have fixed a known breakage' '' test_expect_success'pretend we have fixed one of two known breakages (run in sub test-lib)''-run_sub_test_lib_testpartially-passing-todos\+write_and_run_sub_test_lib_testpartially-passing-todos\"2 TODO tests, one passing"<<-\EOF&&test_expect_failure"pretend we have a known breakage""false"test_expect_success"pretend we have a passing test""true"
@@ -149,7 +149,7 @@ test_expect_success 'pretend we have fixed one of two known breakages (run in su' test_expect_success'pretend we have a pass, fail, and known breakage''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\mixed-results1"mixed results #1"<<-\EOF&&test_expect_success"passing test""true"test_expect_success"failing test""false"
@@ -168,7 +168,7 @@ test_expect_success 'pretend we have a pass, fail, and known breakage' '' test_expect_success'pretend we have a mix of all possible results''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\mixed-results2"mixed results #2"<<-\EOF&&test_expect_success"passing test""true"test_expect_success"passing test""true"
@@ -204,7 +204,7 @@ test_expect_success 'pretend we have a mix of all possible results' '' test_expect_success'test --verbose''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\t1234-verbose"test verbose"--verbose<<-\EOF&&test_expect_success"passing test"truetest_expect_success"test with output""echo foo"
@@ -276,7 +276,7 @@ test_expect_success 'GIT_SKIP_TESTS' ' test_expect_success'GIT_SKIP_TESTS several tests''(-run_sub_test_lib_testgit-skip-tests-several\+write_and_run_sub_test_lib_testgit-skip-tests-several\"GIT_SKIP_TESTS several tests"\--skip="git.2 git.5"<<-\EOF&&foriin123456
@@ -300,7 +300,7 @@ test_expect_success 'GIT_SKIP_TESTS several tests' ' test_expect_success'GIT_SKIP_TESTS sh pattern''(-run_sub_test_lib_testgit-skip-tests-sh-pattern\+write_and_run_sub_test_lib_testgit-skip-tests-sh-pattern\"GIT_SKIP_TESTS sh pattern"\--skip="git.[2-5]"<<-\EOF&&foriin123456
@@ -341,7 +341,7 @@ test_expect_success 'GIT_SKIP_TESTS entire suite' ' test_expect_success'GIT_SKIP_TESTS does not skip unmatched suite''(-run_sub_test_lib_testgit-skip-tests-unmatched-suite\+write_and_run_sub_test_lib_testgit-skip-tests-unmatched-suite\"GIT_SKIP_TESTS does not skip unmatched suite"\--skip="notgit"<<-\EOF&&foriin123
@@ -361,7 +361,7 @@ test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' '' test_expect_success'--run basic''-run_sub_test_lib_testrun-basic\+write_and_run_sub_test_lib_testrun-basic\"--run basic"--run="1,3,5"<<-\EOF&&foriin123456do
@@ -382,7 +382,7 @@ test_expect_success '--run basic' '' test_expect_success'--run with a range''-run_sub_test_lib_testrun-range\+write_and_run_sub_test_lib_testrun-range\"--run with a range"--run="1-3"<<-\EOF&&foriin123456do
@@ -403,7 +403,7 @@ test_expect_success '--run with a range' '' test_expect_success'--run with two ranges''-run_sub_test_lib_testrun-two-ranges\+write_and_run_sub_test_lib_testrun-two-ranges\"--run with two ranges"--run="1-2,5-6"<<-\EOF&&foriin123456do
@@ -424,7 +424,7 @@ test_expect_success '--run with two ranges' '' test_expect_success'--run with a left open range''-run_sub_test_lib_testrun-left-open-range\+write_and_run_sub_test_lib_testrun-left-open-range\"--run with a left open range"--run="-3"<<-\EOF&&foriin123456do
@@ -445,7 +445,7 @@ test_expect_success '--run with a left open range' '' test_expect_success'--run with a right open range''-run_sub_test_lib_testrun-right-open-range\+write_and_run_sub_test_lib_testrun-right-open-range\"--run with a right open range"--run="4-"<<-\EOF&&foriin123456do
@@ -466,7 +466,7 @@ test_expect_success '--run with a right open range' '' test_expect_success'--run with basic negation''-run_sub_test_lib_testrun-basic-neg\+write_and_run_sub_test_lib_testrun-basic-neg\"--run with basic negation"--run="!3"<<-\EOF&&foriin123456do
@@ -487,7 +487,7 @@ test_expect_success '--run with basic negation' '' test_expect_success'--run with two negations''-run_sub_test_lib_testrun-two-neg\+write_and_run_sub_test_lib_testrun-two-neg\"--run with two negations"--run="!3,!6"<<-\EOF&&foriin123456do
@@ -508,7 +508,7 @@ test_expect_success '--run with two negations' '' test_expect_success'--run a range and negation''-run_sub_test_lib_testrun-range-and-neg\+write_and_run_sub_test_lib_testrun-range-and-neg\"--run a range and negation"--run="-4,!2"<<-\EOF&&foriin123456do
@@ -529,7 +529,7 @@ test_expect_success '--run a range and negation' '' test_expect_success'--run range negation''-run_sub_test_lib_testrun-range-neg\+write_and_run_sub_test_lib_testrun-range-neg\"--run range negation"--run="!1-3"<<-\EOF&&foriin123456do
@@ -550,7 +550,7 @@ test_expect_success '--run range negation' '' test_expect_success'--run include, exclude and include''-run_sub_test_lib_testrun-inc-neg-inc\+write_and_run_sub_test_lib_testrun-inc-neg-inc\"--run include, exclude and include"\--run="1-5,!1-3,2"<<-\EOF&&foriin123456
@@ -572,7 +572,7 @@ test_expect_success '--run include, exclude and include' '' test_expect_success'--run include, exclude and include, comma separated''-run_sub_test_lib_testrun-inc-neg-inc-comma\+write_and_run_sub_test_lib_testrun-inc-neg-inc-comma\"--run include, exclude and include, comma separated"\--run=1-5,!1-3,2<<-\EOF&&foriin123456
@@ -594,7 +594,7 @@ test_expect_success '--run include, exclude and include, comma separated' '' test_expect_success'--run exclude and include''-run_sub_test_lib_testrun-neg-inc\+write_and_run_sub_test_lib_testrun-neg-inc\"--run exclude and include"\--run="!3-,5"<<-\EOF&&foriin123456
@@ -772,7 +772,7 @@ test_expect_success 'nested lazy prerequisites' '' test_expect_success'lazy prereqs do not turn off tracing''-run_sub_test_lib_testlazy-prereq-and-tracing\+write_and_run_sub_test_lib_testlazy-prereq-and-tracing\"lazy prereqs and -x"-v-x<<-\EOF&&test_lazy_prereqLAZYtrue
@@ -785,7 +785,7 @@ test_expect_success 'lazy prereqs do not turn off tracing' '' test_expect_success'tests clean up after themselves''-run_sub_test_lib_testcleanup"test with cleanup"<<-\EOF&&+write_and_run_sub_test_lib_testcleanup"test with cleanup"<<-\EOF&&clean=notest_expect_success"do cleanup""test_when_finishedclean=yes
@@ -805,7 +805,7 @@ test_expect_success 'tests clean up after themselves' '' test_expect_success'tests clean up even on failures''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\failing-cleanup"Failing tests with cleanup commands"<<-\EOF&&test_expect_success"tests clean up even after a failure""touchclean-after-failure&&
@@ -834,7 +834,7 @@ test_expect_success 'tests clean up even on failures' '' test_expect_success'test_atexit is run''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\atexit-cleanup"Run atexit commands"-i<<-\EOF&&test_expect_success"tests clean up even after a failure"">../../clean-atexit&&
Now that we've split up the write_sub_test_lib_test*() and
run_sub_test_lib_test*() functions let's fix those tests in
t0000-basic.sh that were verbosely copy/pasting earlier tests.
I'm (ab)using writing a tag object under a ref-name that's
content-addressable from the content of the test script. If we can
update-ref that it's unique, if not we've got a duplicate. The tag
object stores the name of the earlier test for reporting the error.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 34 ++++++-
t/t0000-basic.sh | 228 +++++++++++++----------------------------------
2 files changed, 93 insertions(+), 169 deletions(-)
@@ -1,3 +1,34 @@+_assert_unique_sub_test(){+name=$1&&++# Alert about the copy/paste programming+hash=$(githash-object-w"$name")&&+cat>tag.sig<<-EOF&&+object$hash+typeblob+tag$hash+tagger.<>0+0000++duplicatescriptdetected!++Thistestscriptwasalreadywrittenas:++$name++Youcanjustre-useitstestcodewithyourown+run_sub_test_lib_test*()+EOF++tag=$(gitmktag<tag.sig)&&+if!gitupdate-refrefs/tags/blob-$hash$tag$(test_oidzero)2>/dev/null+then+msg=$(gitfor-each-refrefs/tags/blob-$hash\+--format='%(contents)'refs/tags/blob-$hash)+error"on write of $name: $msg"+return1+fi+}+ write_sub_test_lib_test(){name="$1"# stdin is the body of the test codemkdir"$name"&&
@@ -7,7 +38,8 @@ write_sub_test_lib_test () {# Point to the t/test-lib.sh, which isn't in ../ as usual."\$TEST_DIRECTORY"/test-lib.shEOF-cat>>"$name/$name.sh"+cat>>"$name/$name.sh"&&+_assert_unique_sub_test"$name/$name.sh"} _run_sub_test_lib_test_common(){
@@ -226,18 +226,13 @@ test_expect_success 'subtest: --verbose option' '' test_expect_success'subtest: --verbose-only option''-write_and_run_sub_test_lib_test_err\-t2345-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_testt2345-verbose-only-2<<-\EOF+run_sub_test_lib_test_err\+t1234-verbose\+--verbose-only=2&&+check_sub_test_lib_testt1234-verbose<<-\EOF>ok1-passingtest>Z->expectingsuccessof2345.2'\''test with output'\'':echofoo+>expectingsuccessof1234.2'\''test with output'\'':echofoo>foo>ok2-testwithoutput>Z
@@ -250,15 +245,9 @@ test_expect_success 'subtest: --verbose-only option' ' test_expect_success'subtest: skip one with GIT_SKIP_TESTS''(-write_and_run_sub_test_lib_testgit-skip-tests-basic\---skip="git.2"<<-\EOF&&-foriin123-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testgit-skip-tests-basic<<-\EOF+run_sub_test_lib_testfull-pass\+--skip="full.2"&&+check_sub_test_lib_testfull-pass<<-\EOF>ok1-passingtest#1>ok2# skip passing test #2 (GIT_SKIP_TESTS)>ok3-passingtest#3
@@ -293,15 +282,9 @@ test_expect_success 'subtest: skip several with GIT_SKIP_TESTS' ' test_expect_success'subtest: sh pattern skipping with GIT_SKIP_TESTS''(-write_and_run_sub_test_lib_testgit-skip-tests-sh-pattern\---skip="git.[2-5]"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testgit-skip-tests-sh-pattern<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--skip="git.[2-5]"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2# skip passing test #2 (GIT_SKIP_TESTS)>ok3# skip passing test #3 (GIT_SKIP_TESTS)
@@ -316,15 +299,10 @@ test_expect_success 'subtest: sh pattern skipping with GIT_SKIP_TESTS' ' test_expect_success'subtest: skip entire test suite with GIT_SKIP_TESTS''(-write_and_run_sub_test_lib_testgit-skip-tests-entire-suite\---skip="git"<<-\EOF&&-foriin123-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testgit-skip-tests-entire-suite<<-\EOF+GIT_SKIP_TESTS="git"&&exportGIT_SKIP_TESTS&&+run_sub_test_lib_testgit-skip-tests-several\+--skip="git"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>1..0# SKIP skip all tests in gitEOF)
@@ -332,15 +310,10 @@ test_expect_success 'subtest: skip entire test suite with GIT_SKIP_TESTS' ' test_expect_success'subtest: GIT_SKIP_TESTS does not skip unmatched suite''(-write_and_run_sub_test_lib_testgit-skip-tests-unmatched-suite\---skip="notgit"<<-\EOF&&-foriin123-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testgit-skip-tests-unmatched-suite<<-\EOF+GIT_SKIP_TESTS="notgit"&&exportGIT_SKIP_TESTS&&+run_sub_test_lib_testfull-pass\+--skip="notfull"&&+check_sub_test_lib_testfull-pass<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3-passingtest#3
@@ -351,14 +324,8 @@ test_expect_success 'subtest: GIT_SKIP_TESTS does not skip unmatched suite' '' test_expect_success'subtest: --run basic''-write_and_run_sub_test_lib_testrun-basic--run="1,3,5"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-basic<<-\EOF+run_sub_test_lib_testgit-skip-tests-several--run="1,3,5"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2# skip passing test #2 (--run)>ok3-passingtest#3
@@ -371,15 +338,9 @@ test_expect_success 'subtest: --run basic' '' test_expect_success'subtest: --run with a range''-write_and_run_sub_test_lib_testrun-range\---run="1-3"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-range<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="1-3"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3-passingtest#3
@@ -392,15 +353,9 @@ test_expect_success 'subtest: --run with a range' '' test_expect_success'subtest: --run with two ranges''-write_and_run_sub_test_lib_testrun-two-ranges\---run="1-2,5-6"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-two-ranges<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="1-2,5-6"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -413,15 +368,9 @@ test_expect_success 'subtest: --run with two ranges' '' test_expect_success'subtest: --run with a left open range''-write_and_run_sub_test_lib_testrun-left-open-range\---run="-3"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-left-open-range<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="-3"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3-passingtest#3
@@ -434,15 +383,9 @@ test_expect_success 'subtest: --run with a left open range' '' test_expect_success'subtest: --run with a right open range''-write_and_run_sub_test_lib_testrun-right-open-range\---run="4-"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-right-open-range<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="4-"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1# skip passing test #1 (--run)>ok2# skip passing test #2 (--run)>ok3# skip passing test #3 (--run)
@@ -455,15 +398,9 @@ test_expect_success 'subtest: --run with a right open range' '' test_expect_success'subtest: --run with basic negation''-write_and_run_sub_test_lib_testrun-basic-neg\---run="!3"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-basic-neg<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="!3"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -476,15 +413,9 @@ test_expect_success 'subtest: --run with basic negation' '' test_expect_success'subtest: --run with two negations''-write_and_run_sub_test_lib_testrun-two-neg\---run="!3,!6"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-two-neg<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="!3,!6"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -497,15 +428,9 @@ test_expect_success 'subtest: --run with two negations' '' test_expect_success'subtest: --run a range and negation''-write_and_run_sub_test_lib_testrun-range-and-neg\---run="-4,!2"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-range-and-neg<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="-4,!2"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2# skip passing test #2 (--run)>ok3-passingtest#3
@@ -518,15 +443,9 @@ test_expect_success 'subtest: --run a range and negation' '' test_expect_success'subtest: --run range negation''-write_and_run_sub_test_lib_testrun-range-neg\---run="!1-3"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-range-neg<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="!1-3"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1# skip passing test #1 (--run)>ok2# skip passing test #2 (--run)>ok3# skip passing test #3 (--run)
@@ -539,15 +458,9 @@ test_expect_success 'subtest: --run range negation' '' test_expect_success'subtest: --run include, exclude and include''-write_and_run_sub_test_lib_testrun-inc-neg-inc\---run="1-5,!1-3,2"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-inc-neg-inc<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="1-5,!1-3,2"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1# skip passing test #1 (--run)>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -560,15 +473,9 @@ test_expect_success 'subtest: --run include, exclude and include' '' test_expect_success'subtest: --run include, exclude and include, comma separated''-write_and_run_sub_test_lib_testrun-inc-neg-inc-comma\---run=1-5,!1-3,2<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-inc-neg-inc-comma<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run=1-5,!1-3,2&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1# skip passing test #1 (--run)>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -581,15 +488,9 @@ test_expect_success 'subtest: --run include, exclude and include, comma separate' test_expect_success'subtest: --run exclude and include''-write_and_run_sub_test_lib_testrun-neg-inc\---run="!3-,5"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-neg-inc<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="!3-,5"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -602,15 +503,9 @@ test_expect_success 'subtest: --run exclude and include' '' test_expect_success'subtest: --run empty selectors''-write_and_run_sub_test_lib_testrun-empty-sel\---run="1,,3,,,5"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-empty-sel<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="1,,3,,,5"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2# skip passing test #2 (--run)>ok3-passingtest#3
@@ -660,12 +555,9 @@ test_expect_success 'subtest: --run keyword selection' '' test_expect_success'subtest: --run invalid range end''-write_and_run_sub_test_lib_test_errrun-inv-range-end\---run="1-z"<<-\EOF&&-test_expect_success"passing test #1""true"-test_done-EOF-check_sub_test_lib_test_errrun-inv-range-end\+run_sub_test_lib_test_errrun-inv-range-start\+--run="1-z"&&+check_sub_test_lib_test_errrun-inv-range-start\<<-\EOF_OUT 3<<-EOF_ERR>FATAL:Unexpectedexitwithcode1EOF_OUT
Change the $test_description provided for the generated subtests to be
constant, since the only purpose of having it is that test-lib.sh will
barf if it isn't supplied.
The other purpose of having it was to effectively split up the test
description between the argument to test_expect_success and the
argument to "write_and_run_sub_test_lib_test". Let's only use one of
the two.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 12 ++--
t/t0000-basic.sh | 142 +++++++++++++++++++++--------------------------
2 files changed, 66 insertions(+), 88 deletions(-)
@@ -1,12 +1,8 @@ write_sub_test_lib_test(){-name="$1"descr="$2"# stdin is the body of the test code+name="$1"# stdin is the body of the test codemkdir"$name"&&write_script"$name/$name.sh""$TEST_SHELL_PATH"<<-EOF&&-test_description='$descr(runinsubtest-lib)--Thisisruninasubtest-libsothatwedonotgetincorrect-passingmetrics-'+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
@@ -15,8 +11,8 @@ write_sub_test_lib_test () {} _run_sub_test_lib_test_common(){-neg="$1"name="$2"descr="$3"# stdin is the body of the test code-shift3+neg="$1"name="$2"# stdin is the body of the test code+shift2# intercept pseudo-options at the front of the argument list that we# will not pass to child script
@@ -67,8 +67,8 @@ test_expect_success 'success is reported like this' ':'-test_expect_success'pretend we have a fully passing test suite''-write_and_run_sub_test_lib_testfull-pass"3 passing tests"<<-\EOF&&+test_expect_success'subtest: 3 passing tests''+write_and_run_sub_test_lib_testfull-pass<<-\EOF&&foriin123dotest_expect_success"passing test #$i""true"
@@ -84,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''-write_and_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_errpartial-pass<<-\EOF&&test_expect_success"passing test #1""true"test_expect_success"failing test #2""false"test_expect_success"passing test #3""true"
@@ -102,8 +101,8 @@ test_expect_success 'pretend we have a partially passing test suite' 'EOF'-test_expect_success'pretend we have a known breakage''-write_and_run_sub_test_lib_testfailing-todo"A failing TODO test"<<-\EOF&&+test_expect_success'subtest: a failing TODO test''+write_and_run_sub_test_lib_testfailing-todo<<-\EOF&&test_expect_success"passing test""true"test_expect_failure"pretend we have a known breakage""false"test_done
@@ -117,8 +116,8 @@ test_expect_success 'pretend we have a known breakage' 'EOF'-test_expect_success'pretend we have fixed a known breakage''-write_and_run_sub_test_lib_testpassing-todo"A passing TODO test"<<-\EOF&&+test_expect_success'subtest: a passing TODO test''+write_and_run_sub_test_lib_testpassing-todo<<-\EOF&&test_expect_failure"pretend we have fixed a known breakage""true"test_doneEOF
@@ -129,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)''-write_and_run_sub_test_lib_testpartially-passing-todos\-"2 TODO tests, one passing"<<-\EOF&&+test_expect_success'subtest: 2 TODO tests, one passin''+write_and_run_sub_test_lib_testpartially-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"
@@ -148,9 +146,8 @@ test_expect_success 'pretend we have fixed one of two known breakages (run in suEOF'-test_expect_success'pretend we have a pass, fail, and known breakage''-write_and_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_errmixed-results1<<-\EOF&&test_expect_success"passing test""true"test_expect_success"failing test""false"test_expect_failure"pretend we have a known breakage""false"
@@ -167,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''-write_and_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_errmixed-results2<<-\EOF&&test_expect_success"passing test""true"test_expect_success"passing test""true"test_expect_success"passing test""true"
@@ -203,9 +199,8 @@ test_expect_success 'pretend we have a mix of all possible results' 'EOF'-test_expect_success'test --verbose''-write_and_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_errt1234-verbose--verbose<<-\EOF&&test_expect_success"passing test"truetest_expect_success"test with output""echo foo"test_expect_success"failing test"false
@@ -253,10 +248,9 @@ test_expect_success 'test --verbose-only' 'EOF'-test_expect_success'GIT_SKIP_TESTS''+test_expect_success'subtest: skip one with GIT_SKIP_TESTS''(write_and_run_sub_test_lib_testgit-skip-tests-basic\-"GIT_SKIP_TESTS"\--skip="git.2"<<-\EOF&&foriin123do
@@ -274,10 +268,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''(write_and_run_sub_test_lib_testgit-skip-tests-several\-"GIT_SKIP_TESTS several tests"\--skip="git.2 git.5"<<-\EOF&&foriin123456do
@@ -298,10 +291,9 @@ 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''(write_and_run_sub_test_lib_testgit-skip-tests-sh-pattern\-"GIT_SKIP_TESTS sh pattern"\--skip="git.[2-5]"<<-\EOF&&foriin123456do
@@ -322,10 +314,9 @@ 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''(write_and_run_sub_test_lib_testgit-skip-tests-entire-suite\-"GIT_SKIP_TESTS entire suite"\--skip="git"<<-\EOF&&foriin123do
@@ -339,10 +330,9 @@ test_expect_success 'GIT_SKIP_TESTS entire suite' ')'-test_expect_success'GIT_SKIP_TESTS does not skip unmatched suite''+test_expect_success'subtest: GIT_SKIP_TESTS does not skip unmatched suite''(write_and_run_sub_test_lib_testgit-skip-tests-unmatched-suite\-"GIT_SKIP_TESTS does not skip unmatched suite"\--skip="notgit"<<-\EOF&&foriin123do
@@ -360,9 +350,8 @@ test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' ')'-test_expect_success'--run basic''-write_and_run_sub_test_lib_testrun-basic\-"--run basic"--run="1,3,5"<<-\EOF&&+test_expect_success'subtest: --run basic''+write_and_run_sub_test_lib_testrun-basic--run="1,3,5"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -381,9 +370,9 @@ test_expect_success '--run basic' 'EOF'-test_expect_success'--run with a range''+test_expect_success'subtest: --run with a range''write_and_run_sub_test_lib_testrun-range\-"--run with a range"--run="1-3"<<-\EOF&&+--run="1-3"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -402,9 +391,9 @@ test_expect_success '--run with a range' 'EOF'-test_expect_success'--run with two ranges''+test_expect_success'subtest: --run with two ranges''write_and_run_sub_test_lib_testrun-two-ranges\-"--run with two ranges"--run="1-2,5-6"<<-\EOF&&+--run="1-2,5-6"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -423,9 +412,9 @@ test_expect_success '--run with two ranges' 'EOF'-test_expect_success'--run with a left open range''+test_expect_success'subtest: --run with a left open range''write_and_run_sub_test_lib_testrun-left-open-range\-"--run with a left open range"--run="-3"<<-\EOF&&+--run="-3"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -444,9 +433,9 @@ test_expect_success '--run with a left open range' 'EOF'-test_expect_success'--run with a right open range''+test_expect_success'subtest: --run with a right open range''write_and_run_sub_test_lib_testrun-right-open-range\-"--run with a right open range"--run="4-"<<-\EOF&&+--run="4-"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -465,9 +454,9 @@ test_expect_success '--run with a right open range' 'EOF'-test_expect_success'--run with basic negation''+test_expect_success'subtest: --run with basic negation''write_and_run_sub_test_lib_testrun-basic-neg\-"--run with basic negation"--run="!3"<<-\EOF&&+--run="!3"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -486,9 +475,9 @@ test_expect_success '--run with basic negation' 'EOF'-test_expect_success'--run with two negations''+test_expect_success'subtest: --run with two negations''write_and_run_sub_test_lib_testrun-two-neg\-"--run with two negations"--run="!3,!6"<<-\EOF&&+--run="!3,!6"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -507,9 +496,9 @@ test_expect_success '--run with two negations' 'EOF'-test_expect_success'--run a range and negation''+test_expect_success'subtest: --run a range and negation''write_and_run_sub_test_lib_testrun-range-and-neg\-"--run a range and negation"--run="-4,!2"<<-\EOF&&+--run="-4,!2"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -528,9 +517,9 @@ test_expect_success '--run a range and negation' 'EOF'-test_expect_success'--run range negation''+test_expect_success'subtest: --run range negation''write_and_run_sub_test_lib_testrun-range-neg\-"--run range negation"--run="!1-3"<<-\EOF&&+--run="!1-3"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -549,9 +538,8 @@ test_expect_success '--run range negation' 'EOF'-test_expect_success'--run include, exclude and include''+test_expect_success'subtest: --run include, exclude and include''write_and_run_sub_test_lib_testrun-inc-neg-inc\-"--run include, exclude and include"\--run="1-5,!1-3,2"<<-\EOF&&foriin123456do
@@ -571,9 +559,8 @@ test_expect_success '--run include, exclude and include' 'EOF'-test_expect_success'--run include, exclude and include, comma separated''+test_expect_success'subtest: --run include, exclude and include, comma separated''write_and_run_sub_test_lib_testrun-inc-neg-inc-comma\-"--run include, exclude and include, comma separated"\--run=1-5,!1-3,2<<-\EOF&&foriin123456do
@@ -593,9 +580,8 @@ test_expect_success '--run include, exclude and include, comma separated' 'EOF'-test_expect_success'--run exclude and include''+test_expect_success'subtest: --run exclude and include''write_and_run_sub_test_lib_testrun-neg-inc\-"--run exclude and include"\--run="!3-,5"<<-\EOF&&foriin123456do
@@ -771,9 +753,9 @@ test_expect_success 'nested lazy prerequisites' 'EOF'-test_expect_success'lazy prereqs do not turn off tracing''+test_expect_success'subtest: lazy prereqs do not turn off tracing''write_and_run_sub_test_lib_testlazy-prereq-and-tracing\-"lazy prereqs and -x"-v-x<<-\EOF&&+-v-x<<-\EOF&&test_lazy_prereqLAZYtruetest_expect_successlazy"test_have_prereq LAZY && echo trace"
@@ -784,8 +766,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''-write_and_run_sub_test_lib_testcleanup"test with cleanup"<<-\EOF&&+test_expect_success'subtest: tests clean up after themselves''+write_and_run_sub_test_lib_testcleanup<<-\EOF&&clean=notest_expect_success"do cleanup""test_when_finishedclean=yes
@@ -804,9 +786,9 @@ test_expect_success 'tests clean up after themselves' 'EOF'-test_expect_success'tests clean up even on failures''+test_expect_success'subtest: tests clean up even on failures''write_and_run_sub_test_lib_test_err\-failing-cleanup"Failing tests with cleanup commands"<<-\EOF&&+failing-cleanup<<-\EOF&&test_expect_success"tests clean up even after a failure""touchclean-after-failure&&test_when_finishedrmclean-after-failure&&
@@ -833,9 +815,9 @@ test_expect_success 'tests clean up even on failures' 'EOF'-test_expect_success'test_atexit is run''+test_expect_success'subtest: test_atexit is run''write_and_run_sub_test_lib_test_err\-atexit-cleanup"Run atexit commands"-i<<-\EOF&&+atexit-cleanup-i<<-\EOF&&test_expect_success"tests clean up even after a failure"">../../clean-atexit&&test_atexitrm../../clean-atexit&&
Now that this function doesn't handle running the test anymore we can
do away with the sub-shell, which was used to scope an "unset" and
"export" shell variables.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
@@ -1,20 +1,17 @@ write_sub_test_lib_test(){name="$1"descr="$2"# stdin is the body of the test codemkdir"$name"&&-(-cd"$name"&&-write_script"$name.sh""$TEST_SHELL_PATH"<<-EOF&&-test_description='$descr(runinsubtest-lib)+write_script"$name/$name.sh""$TEST_SHELL_PATH"<<-EOF&&+test_description='$descr(runinsubtest-lib)-Thisisruninasubtest-libsothatwedonotgetincorrect-passingmetrics-'+Thisisruninasubtest-libsothatwedonotgetincorrect+passingmetrics+'-# Point to the t/test-lib.sh, which isn't in ../ as usual-."\$TEST_DIRECTORY"/test-lib.sh-EOF-cat>>"$name.sh"-)+# 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(){
The use of a sub-shell for running the test_cmp of stdout/stderr for
the test author was introduced in this form in 565b6fa87bb (tests:
refactor mechanics of testing in a sub test-lib, 2012-12-16), but from
looking at the history that seemed to have diligently copied my
original ad-hoc implementation in 7b905119703 (t/t0000-basic.sh: Run
the passing TODO test inside its own test-lib, 2010-08-19).
There's no reason to use a subshell here, we try to avoid it in
general. It also improves readability, if the test fails we print out
the relative path in the trash directory that needs to be looked
at.
Before that was mostly obscured, since the "write_sub_test_lib_test"
will pick the directory for you from the test name.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)
@@ -111,23 +111,17 @@ run_sub_test_lib_test_err () { check_sub_test_lib_test(){name="$1"# stdin is the expected output from the test-(-cd"$name"&&-test_must_be_emptyerr&&-sed-e's/^> //'-e's/Z$//'>expect&&-test_cmpexpectout-)+test_must_be_empty"$name"/err&&+sed-e's/^> //'-e's/Z$//'>"$name"/expect&&+test_cmp"$name/"expect"$name"/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_cmpexpect.outout&&-sed-e's/^> //'-e's/Z$//'<&3>expect.err&&-test_cmpexpect.errerr-)+sed-e's/^> //'-e's/Z$//'>"$name"/expect.out&&+test_cmp"$name"/expect.out"$name"/out&&+sed-e's/^> //'-e's/Z$//'<&3>"$name"/expect.err&&+test_cmp"$name"/expect.err"$name"/err}
Refactor the two check_sub_test_lib_test*() functions to avoid
duplicating the same comparison they did of stdout. This duplication
was initially added when check_sub_test_lib_test_err() was added in
0445e6f0a12 (test-lib: '--run' to run only specific tests,
2014-04-30).
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
@@ -109,18 +109,22 @@ run_sub_test_lib_test_err () {_run_sub_test_lib_test_common'!'"$@"}+_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-test_must_be_empty"$name"/err&&-sed-e's/^> //'-e's/Z$//'>"$name"/expect&&-test_cmp"$name/"expect"$name"/out+_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$//'>"$name"/expect.out&&-test_cmp"$name"/expect.out"$name"/out&&sed-e's/^> //'-e's/Z$//'<&3>"$name"/expect.err&&test_cmp"$name"/expect.err"$name"/err}
Improve the testing for test-lib.sh itself to assert that we have a
exit code of 1, not any non-zero. Improves code added in
0445e6f0a12 (test-lib: '--run' to run only specific tests,
2014-04-30).
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
@@ -43,8 +43,8 @@ write_sub_test_lib_test () {} _run_sub_test_lib_test_common(){-neg="$1"name="$2"# stdin is the body of the test code-shift2+cmp_op="$1"want_code="$2"name="$3"# stdin is the body of the test code+shift3# intercept pseudo-options at the front of the argument list that we# will not pass to child script
@@ -80,33 +80,30 @@ _run_sub_test_lib_test_common () {GIT_SKIP_TESTS=$skip&&exportGIT_SKIP_TESTS&&sane_unsetGIT_TEST_FAIL_PREREQS&&-iftest-z"$neg"-then-./"$name.sh""$@">out2>err-else-!./"$name.sh""$@">out2>err-fi+./"$name.sh""$@">out2>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 codewrite_sub_test_lib_test"$@"||return1-_run_sub_test_lib_test_common''"$@"+_run_sub_test_lib_test_common-eq0"$@"} write_and_run_sub_test_lib_test_err(){name="$1"descr="$2"# stdin is the body of the test codewrite_sub_test_lib_test"$@"||return1-_run_sub_test_lib_test_common'!'"$@"+_run_sub_test_lib_test_common-eq1"$@"} run_sub_test_lib_test(){-_run_sub_test_lib_test_common''"$@"+_run_sub_test_lib_test_common-eq0"$@"} run_sub_test_lib_test_err(){-_run_sub_test_lib_test_common'!'"$@"+_run_sub_test_lib_test_common-eq1"$@"} _check_sub_test_lib_test_common(){
This series has been looking for reviewer attention for a while. It
splits up the testing of test-lib.sh itself from t0000-basic.sh into a
lib-subtest.sh library, a subsequent series of mine makes use of that
library.
The diffstat is nicely negative since a lot of the test code is
something we could delete as redundant, the tests are also made
stricter as a result (e.g. now checking 1 exit code, not any
non-zero).
For v2, see:
https://lore.kernel.org/git/cover-0.8-00000000000-20210721T225504Z-avarab@gmail.com/
The ony tricky part of this series is the "clever" way of (ab)using
the object store and tags to detect copy/pasted tests. For this v3
I've split that up into its own commit, see [56]/9 for the removal of
the copy/pasting and the assertion, respectively.
This series also depended on ps/t0000-output-directory-fix and
jk/t0000-subtests-fix, since both made it mo "master" it's been
rebased on "master". The range-diff that's not the split-up around
[56]/9 is due to that rebasing.
Ævar Arnfjörð Bjarmason (9):
test-lib tests: move "run_sub_test" to a new lib-subtest.sh
test-lib tests: split up "write and run" into two functions
test-lib tests: stop using a subshell in write_sub_test_lib_test()
test-lib tests: don't provide a description for the sub-tests
test-lib tests: get rid of copy/pasted mock test code
test-lib tests: assert no copy/pasted mock test code
test-lib tests: avoid subshell for "test_cmp" for readability
test-lib tests: refactor common part of check_sub_test_lib_test*()
test-lib tests: assert 1 exit code, not non-zero
t/lib-subtest.sh | 127 ++++++++++++++
t/t0000-basic.sh | 448 +++++++++++++----------------------------------
2 files changed, 245 insertions(+), 330 deletions(-)
create mode 100644 t/lib-subtest.sh
Range-diff against v2:
1: 7a06ea3a7b = 1: 3f34420a3e test-lib tests: move "run_sub_test" to a new lib-subtest.sh
2: 28117b84ab ! 2: c9c16016da test-lib tests: split up "write and run" into two functions
@@ t/lib-subtest.sh: _run_sub_test_lib_test_common () {
run_sub_test_lib_test () {
_run_sub_test_lib_test_common '' "$@"
}
-@@ t/lib-subtest.sh: check_sub_test_lib_test_err () {
- test_cmp expect.err err
- )
- }
-+
## t/t0000-basic.sh ##
@@ t/t0000-basic.sh: test_expect_success 'success is reported like this' '
3: 7d5ed335a3 = 3: 76f57eadcd test-lib tests: stop using a subshell in write_sub_test_lib_test()
4: 2a0dd64da9 = 4: cde015c7dd test-lib tests: don't provide a description for the sub-tests
5: f60190dec6 ! 5: 7d1e6b9a3e test-lib tests: get rid of copy/pasted mock test code
@@ Commit message
run_sub_test_lib_test*() functions let's fix those tests in
t0000-basic.sh that were verbosely copy/pasting earlier tests.
- I'm (ab)using writing a tag object under a ref-name that's
- content-addressable from the content of the test script. If we can
- update-ref that it's unique, if not we've got a duplicate. The tag
- object stores the name of the earlier test for reporting the error.
+ In a subsequent commit we'll add an assertion to check whether we
+ caught all of the copy/pasting.
Signed-off-by: Ævar Arnfjörð Bjarmason [off-list ref]
- ## t/lib-subtest.sh ##
-@@
-+_assert_unique_sub_test () {
-+ name=$1 &&
-+
-+ # Alert about the copy/paste programming
-+ hash=$(git hash-object -w "$name") &&
-+ cat >tag.sig <<-EOF &&
-+ object $hash
-+ type blob
-+ tag $hash
-+ tagger . <> 0 +0000
-+
-+ duplicate script detected!
-+
-+ This test script was already written as:
-+
-+ $name
-+
-+ You can just re-use its test code with your own
-+ run_sub_test_lib_test*()
-+ EOF
-+
-+ tag=$(git mktag <tag.sig) &&
-+ if ! git update-ref refs/tags/blob-$hash $tag $(test_oid zero) 2>/dev/null
-+ then
-+ msg=$(git for-each-ref refs/tags/blob-$hash \
-+ --format='%(contents)' refs/tags/blob-$hash)
-+ error "on write of $name: $msg"
-+ return 1
-+ fi
-+}
-+
- write_sub_test_lib_test () {
- name="$1" # stdin is the body of the test code
- mkdir "$name" &&
-@@ t/lib-subtest.sh: write_sub_test_lib_test () {
- # Point to the t/test-lib.sh, which isn't in ../ as usual
- . "\$TEST_DIRECTORY"/test-lib.sh
- EOF
-- cat >>"$name/$name.sh"
-+ cat >>"$name/$name.sh" &&
-+ _assert_unique_sub_test "$name/$name.sh"
- }
-
- _run_sub_test_lib_test_common () {
-
## t/t0000-basic.sh ##
@@ t/t0000-basic.sh: test_expect_success 'subtest: --verbose option' '
'
-: ---------- > 6: bc79b29f3c test-lib tests: assert no copy/pasted mock test code
6: 022ddbabf6 ! 7: 48176f3e60 test-lib tests: avoid subshell for "test_cmp" for readability
@@ t/lib-subtest.sh: run_sub_test_lib_test_err () {
+ sed -e 's/^> //' -e 's/Z$//' <&3 >"$name"/expect.err &&
+ test_cmp "$name"/expect.err "$name"/err
}
-
7: ae0226e164 = 8: fda7c4fbe3 test-lib tests: refactor common part of check_sub_test_lib_test*()
8: 676547e001 = 9: dd0af5bd6c test-lib tests: assert 1 exit code, not non-zero
--
2.33.0.rc0.635.g0ab9d6d3b5a
Move the "check_sub_test_lib_test()" and its sister functions to a new
lib-subtest.sh.
In the future (not in this series) I'd like to test test-lib's output
in a more targeted and smaller test, and I'll need these functions to
do that.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 86 ++++++++++++++++++++++++++++++++++++++++++++++
t/t0000-basic.sh | 88 +-----------------------------------------------
2 files changed, 87 insertions(+), 87 deletions(-)
create mode 100644 t/lib-subtest.sh
@@ -0,0 +1,86 @@+_run_sub_test_lib_test_common(){+neg="$1"name="$2"descr="$3"# stdin is the body of the test code+shift3++# intercept pseudo-options at the front of the argument list that we+# will not pass to child script+skip=+whiletest$#-gt0+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_unsetHARNESS_ACTIVE&&+cd"$name"&&+write_script"$name.sh""$TEST_SHELL_PATH"<<-EOF&&+test_description='$descr(runinsubtest-lib)++Thisisruninasubtest-libsothatwedonotgetincorrect+passingmetrics+'++# Point to the t/test-lib.sh, which isn't in ../ as usual+."\$TEST_DIRECTORY"/test-lib.sh+EOF+cat>>"$name.sh"&&+exportTEST_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)&&+exportTEST_OUTPUT_DIRECTORY_OVERRIDE&&+GIT_SKIP_TESTS=$skip&&+exportGIT_SKIP_TESTS&&+sane_unsetGIT_TEST_FAIL_PREREQS&&+iftest-z"$neg"+then+./"$name.sh""$@">out2>err+else+!./"$name.sh""$@">out2>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_emptyerr&&+sed-e's/^> //'-e's/Z$//'>expect&&+test_cmpexpectout+)+}++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_cmpexpect.outout&&+sed-e's/^> //'-e's/Z$//'<&3>expect.err&&+test_cmpexpect.errerr+)+}
@@ -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(){localx="local"y="alsolocal"&&
@@ -66,93 +67,6 @@ 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-shift3--# intercept pseudo-options at the front of the argument list that we-# will not pass to child script-skip=-whiletest$#-gt0-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_unsetHARNESS_ACTIVE&&-cd"$name"&&-write_script"$name.sh""$TEST_SHELL_PATH"<<-EOF&&-test_description='$descr(runinsubtest-lib)--Thisisruninasubtest-libsothatwedonotgetincorrect-passingmetrics-'--# Point to the t/test-lib.sh, which isn't in ../ as usual-."\$TEST_DIRECTORY"/test-lib.sh-EOF-cat>>"$name.sh"&&-exportTEST_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)&&-exportTEST_OUTPUT_DIRECTORY_OVERRIDE&&-GIT_SKIP_TESTS=$skip&&-exportGIT_SKIP_TESTS&&-sane_unsetGIT_TEST_FAIL_PREREQS&&-iftest-z"$neg"-then-./"$name.sh""$@">out2>err-else-!./"$name.sh""$@">out2>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_emptyerr&&-sed-e's/^> //'-e's/Z$//'>expect&&-test_cmpexpectout-)-}--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_cmpexpect.outout&&-sed-e's/^> //'-e's/Z$//'<&3>expect.err&&-test_cmpexpect.errerr-)-}- test_expect_success'pretend we have a fully passing test suite''run_sub_test_lib_testfull-pass"3 passing tests"<<-\EOF&&foriin123
Refactor the function to write and run tests of the test-lib.sh output
into two functions.
When this was added back in 565b6fa87bb (tests: refactor mechanics of
testing in a sub test-lib, 2012-12-16) there was no reason to do this,
but since we started supporting test arguments in
517cd55fd51 (test-lib: self-test that --verbose works, 2013-06-23)
we've started to write out duplicate tests simply to test different
arguments, now we'll be able to re-use them.
This change doesn't consolidate any of those tests yet, it just makes
it possible to do so. All the changes in t0000-basic.sh are a simple
search-replacement.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 45 +++++++++++++++++++++--------
t/t0000-basic.sh | 74 ++++++++++++++++++++++++------------------------
2 files changed, 70 insertions(+), 49 deletions(-)
@@ -1,3 +1,22 @@+write_sub_test_lib_test(){+name="$1"descr="$2"# stdin is the body of the test code+mkdir"$name"&&+(+cd"$name"&&+write_script"$name.sh""$TEST_SHELL_PATH"<<-EOF&&+test_description='$descr(runinsubtest-lib)++Thisisruninasubtest-libsothatwedonotgetincorrect+passingmetrics+'++# Point to the t/test-lib.sh, which isn't in ../ as usual+."\$TEST_DIRECTORY"/test-lib.sh+EOF+cat>>"$name.sh"+)+}+ _run_sub_test_lib_test_common(){neg="$1"name="$2"descr="$3"# stdin is the body of the test codeshift3
@@ -18,25 +37,15 @@ _run_sub_test_lib_test_common () {esacdone-mkdir"$name"&&(+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_unsetHARNESS_ACTIVE&&-cd"$name"&&-write_script"$name.sh""$TEST_SHELL_PATH"<<-EOF&&-test_description='$descr(runinsubtest-lib)-Thisisruninasubtest-libsothatwedonotgetincorrect-passingmetrics-'--# Point to the t/test-lib.sh, which isn't in ../ as usual-."\$TEST_DIRECTORY"/test-lib.sh-EOF-cat>>"$name.sh"&&exportTEST_DIRECTORY&&# The child test re-sources GIT-BUILD-OPTIONS and may thus# override the test output directory. We thus pass it as an
@@ -55,6 +64,18 @@ _run_sub_test_lib_test_common () {)}+write_and_run_sub_test_lib_test(){+name="$1"descr="$2"# stdin is the body of the test code+write_sub_test_lib_test"$@"||return1+_run_sub_test_lib_test_common''"$@"+}++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"$@"||return1+_run_sub_test_lib_test_common'!'"$@"+}+ run_sub_test_lib_test(){_run_sub_test_lib_test_common''"$@"}
@@ -68,7 +68,7 @@ test_expect_success 'success is reported like this' '' test_expect_success'pretend we have a fully passing test suite''-run_sub_test_lib_testfull-pass"3 passing tests"<<-\EOF&&+write_and_run_sub_test_lib_testfull-pass"3 passing tests"<<-\EOF&&foriin123dotest_expect_success"passing test #$i""true"
@@ -85,7 +85,7 @@ test_expect_success 'pretend we have a fully passing test suite' '' test_expect_success'pretend we have a partially passing test suite''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\partial-pass"2/3 tests passing"<<-\EOF&&test_expect_success"passing test #1""true"test_expect_success"failing test #2""false"
@@ -103,7 +103,7 @@ test_expect_success 'pretend we have a partially passing test suite' '' test_expect_success'pretend we have a known breakage''-run_sub_test_lib_testfailing-todo"A failing TODO test"<<-\EOF&&+write_and_run_sub_test_lib_testfailing-todo"A failing TODO test"<<-\EOF&&test_expect_success"passing test""true"test_expect_failure"pretend we have a known breakage""false"test_done
@@ -118,7 +118,7 @@ test_expect_success 'pretend we have a known breakage' '' test_expect_success'pretend we have fixed a known breakage''-run_sub_test_lib_testpassing-todo"A passing TODO test"<<-\EOF&&+write_and_run_sub_test_lib_testpassing-todo"A passing TODO test"<<-\EOF&&test_expect_failure"pretend we have fixed a known breakage""true"test_doneEOF
@@ -130,7 +130,7 @@ test_expect_success 'pretend we have fixed a known breakage' '' test_expect_success'pretend we have fixed one of two known breakages (run in sub test-lib)''-run_sub_test_lib_testpartially-passing-todos\+write_and_run_sub_test_lib_testpartially-passing-todos\"2 TODO tests, one passing"<<-\EOF&&test_expect_failure"pretend we have a known breakage""false"test_expect_success"pretend we have a passing test""true"
@@ -149,7 +149,7 @@ test_expect_success 'pretend we have fixed one of two known breakages (run in su' test_expect_success'pretend we have a pass, fail, and known breakage''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\mixed-results1"mixed results #1"<<-\EOF&&test_expect_success"passing test""true"test_expect_success"failing test""false"
@@ -168,7 +168,7 @@ test_expect_success 'pretend we have a pass, fail, and known breakage' '' test_expect_success'pretend we have a mix of all possible results''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\mixed-results2"mixed results #2"<<-\EOF&&test_expect_success"passing test""true"test_expect_success"passing test""true"
@@ -204,7 +204,7 @@ test_expect_success 'pretend we have a mix of all possible results' '' test_expect_success'test --verbose''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\t1234-verbose"test verbose"--verbose<<-\EOF&&test_expect_success"passing test"truetest_expect_success"test with output""echo foo"
@@ -276,7 +276,7 @@ test_expect_success 'GIT_SKIP_TESTS' ' test_expect_success'GIT_SKIP_TESTS several tests''(-run_sub_test_lib_testgit-skip-tests-several\+write_and_run_sub_test_lib_testgit-skip-tests-several\"GIT_SKIP_TESTS several tests"\--skip="git.2 git.5"<<-\EOF&&foriin123456
@@ -300,7 +300,7 @@ test_expect_success 'GIT_SKIP_TESTS several tests' ' test_expect_success'GIT_SKIP_TESTS sh pattern''(-run_sub_test_lib_testgit-skip-tests-sh-pattern\+write_and_run_sub_test_lib_testgit-skip-tests-sh-pattern\"GIT_SKIP_TESTS sh pattern"\--skip="git.[2-5]"<<-\EOF&&foriin123456
@@ -341,7 +341,7 @@ test_expect_success 'GIT_SKIP_TESTS entire suite' ' test_expect_success'GIT_SKIP_TESTS does not skip unmatched suite''(-run_sub_test_lib_testgit-skip-tests-unmatched-suite\+write_and_run_sub_test_lib_testgit-skip-tests-unmatched-suite\"GIT_SKIP_TESTS does not skip unmatched suite"\--skip="notgit"<<-\EOF&&foriin123
@@ -361,7 +361,7 @@ test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' '' test_expect_success'--run basic''-run_sub_test_lib_testrun-basic\+write_and_run_sub_test_lib_testrun-basic\"--run basic"--run="1,3,5"<<-\EOF&&foriin123456do
@@ -382,7 +382,7 @@ test_expect_success '--run basic' '' test_expect_success'--run with a range''-run_sub_test_lib_testrun-range\+write_and_run_sub_test_lib_testrun-range\"--run with a range"--run="1-3"<<-\EOF&&foriin123456do
@@ -403,7 +403,7 @@ test_expect_success '--run with a range' '' test_expect_success'--run with two ranges''-run_sub_test_lib_testrun-two-ranges\+write_and_run_sub_test_lib_testrun-two-ranges\"--run with two ranges"--run="1-2,5-6"<<-\EOF&&foriin123456do
@@ -424,7 +424,7 @@ test_expect_success '--run with two ranges' '' test_expect_success'--run with a left open range''-run_sub_test_lib_testrun-left-open-range\+write_and_run_sub_test_lib_testrun-left-open-range\"--run with a left open range"--run="-3"<<-\EOF&&foriin123456do
@@ -445,7 +445,7 @@ test_expect_success '--run with a left open range' '' test_expect_success'--run with a right open range''-run_sub_test_lib_testrun-right-open-range\+write_and_run_sub_test_lib_testrun-right-open-range\"--run with a right open range"--run="4-"<<-\EOF&&foriin123456do
@@ -466,7 +466,7 @@ test_expect_success '--run with a right open range' '' test_expect_success'--run with basic negation''-run_sub_test_lib_testrun-basic-neg\+write_and_run_sub_test_lib_testrun-basic-neg\"--run with basic negation"--run="!3"<<-\EOF&&foriin123456do
@@ -487,7 +487,7 @@ test_expect_success '--run with basic negation' '' test_expect_success'--run with two negations''-run_sub_test_lib_testrun-two-neg\+write_and_run_sub_test_lib_testrun-two-neg\"--run with two negations"--run="!3,!6"<<-\EOF&&foriin123456do
@@ -508,7 +508,7 @@ test_expect_success '--run with two negations' '' test_expect_success'--run a range and negation''-run_sub_test_lib_testrun-range-and-neg\+write_and_run_sub_test_lib_testrun-range-and-neg\"--run a range and negation"--run="-4,!2"<<-\EOF&&foriin123456do
@@ -529,7 +529,7 @@ test_expect_success '--run a range and negation' '' test_expect_success'--run range negation''-run_sub_test_lib_testrun-range-neg\+write_and_run_sub_test_lib_testrun-range-neg\"--run range negation"--run="!1-3"<<-\EOF&&foriin123456do
@@ -550,7 +550,7 @@ test_expect_success '--run range negation' '' test_expect_success'--run include, exclude and include''-run_sub_test_lib_testrun-inc-neg-inc\+write_and_run_sub_test_lib_testrun-inc-neg-inc\"--run include, exclude and include"\--run="1-5,!1-3,2"<<-\EOF&&foriin123456
@@ -572,7 +572,7 @@ test_expect_success '--run include, exclude and include' '' test_expect_success'--run include, exclude and include, comma separated''-run_sub_test_lib_testrun-inc-neg-inc-comma\+write_and_run_sub_test_lib_testrun-inc-neg-inc-comma\"--run include, exclude and include, comma separated"\--run=1-5,!1-3,2<<-\EOF&&foriin123456
@@ -594,7 +594,7 @@ test_expect_success '--run include, exclude and include, comma separated' '' test_expect_success'--run exclude and include''-run_sub_test_lib_testrun-neg-inc\+write_and_run_sub_test_lib_testrun-neg-inc\"--run exclude and include"\--run="!3-,5"<<-\EOF&&foriin123456
@@ -772,7 +772,7 @@ test_expect_success 'nested lazy prerequisites' '' test_expect_success'lazy prereqs do not turn off tracing''-run_sub_test_lib_testlazy-prereq-and-tracing\+write_and_run_sub_test_lib_testlazy-prereq-and-tracing\"lazy prereqs and -x"-v-x<<-\EOF&&test_lazy_prereqLAZYtrue
@@ -785,7 +785,7 @@ test_expect_success 'lazy prereqs do not turn off tracing' '' test_expect_success'tests clean up after themselves''-run_sub_test_lib_testcleanup"test with cleanup"<<-\EOF&&+write_and_run_sub_test_lib_testcleanup"test with cleanup"<<-\EOF&&clean=notest_expect_success"do cleanup""test_when_finishedclean=yes
@@ -805,7 +805,7 @@ test_expect_success 'tests clean up after themselves' '' test_expect_success'tests clean up even on failures''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\failing-cleanup"Failing tests with cleanup commands"<<-\EOF&&test_expect_success"tests clean up even after a failure""touchclean-after-failure&&
@@ -834,7 +834,7 @@ test_expect_success 'tests clean up even on failures' '' test_expect_success'test_atexit is run''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\atexit-cleanup"Run atexit commands"-i<<-\EOF&&test_expect_success"tests clean up even after a failure"">../../clean-atexit&&
Now that this function doesn't handle running the test anymore we can
do away with the sub-shell, which was used to scope an "unset" and
"export" shell variables.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
@@ -1,20 +1,17 @@ write_sub_test_lib_test(){name="$1"descr="$2"# stdin is the body of the test codemkdir"$name"&&-(-cd"$name"&&-write_script"$name.sh""$TEST_SHELL_PATH"<<-EOF&&-test_description='$descr(runinsubtest-lib)+write_script"$name/$name.sh""$TEST_SHELL_PATH"<<-EOF&&+test_description='$descr(runinsubtest-lib)-Thisisruninasubtest-libsothatwedonotgetincorrect-passingmetrics-'+Thisisruninasubtest-libsothatwedonotgetincorrect+passingmetrics+'-# Point to the t/test-lib.sh, which isn't in ../ as usual-."\$TEST_DIRECTORY"/test-lib.sh-EOF-cat>>"$name.sh"-)+# 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(){
Now that we've split up the write_sub_test_lib_test*() and
run_sub_test_lib_test*() functions let's fix those tests in
t0000-basic.sh that were verbosely copy/pasting earlier tests.
In a subsequent commit we'll add an assertion to check whether we
caught all of the copy/pasting.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/t0000-basic.sh | 228 +++++++++++++----------------------------------
1 file changed, 60 insertions(+), 168 deletions(-)
@@ -226,18 +226,13 @@ test_expect_success 'subtest: --verbose option' '' test_expect_success'subtest: --verbose-only option''-write_and_run_sub_test_lib_test_err\-t2345-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_testt2345-verbose-only-2<<-\EOF+run_sub_test_lib_test_err\+t1234-verbose\+--verbose-only=2&&+check_sub_test_lib_testt1234-verbose<<-\EOF>ok1-passingtest>Z->expectingsuccessof2345.2'\''test with output'\'':echofoo+>expectingsuccessof1234.2'\''test with output'\'':echofoo>foo>ok2-testwithoutput>Z
@@ -250,15 +245,9 @@ test_expect_success 'subtest: --verbose-only option' ' test_expect_success'subtest: skip one with GIT_SKIP_TESTS''(-write_and_run_sub_test_lib_testgit-skip-tests-basic\---skip="git.2"<<-\EOF&&-foriin123-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testgit-skip-tests-basic<<-\EOF+run_sub_test_lib_testfull-pass\+--skip="full.2"&&+check_sub_test_lib_testfull-pass<<-\EOF>ok1-passingtest#1>ok2# skip passing test #2 (GIT_SKIP_TESTS)>ok3-passingtest#3
@@ -293,15 +282,9 @@ test_expect_success 'subtest: skip several with GIT_SKIP_TESTS' ' test_expect_success'subtest: sh pattern skipping with GIT_SKIP_TESTS''(-write_and_run_sub_test_lib_testgit-skip-tests-sh-pattern\---skip="git.[2-5]"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testgit-skip-tests-sh-pattern<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--skip="git.[2-5]"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2# skip passing test #2 (GIT_SKIP_TESTS)>ok3# skip passing test #3 (GIT_SKIP_TESTS)
@@ -316,15 +299,10 @@ test_expect_success 'subtest: sh pattern skipping with GIT_SKIP_TESTS' ' test_expect_success'subtest: skip entire test suite with GIT_SKIP_TESTS''(-write_and_run_sub_test_lib_testgit-skip-tests-entire-suite\---skip="git"<<-\EOF&&-foriin123-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testgit-skip-tests-entire-suite<<-\EOF+GIT_SKIP_TESTS="git"&&exportGIT_SKIP_TESTS&&+run_sub_test_lib_testgit-skip-tests-several\+--skip="git"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>1..0# SKIP skip all tests in gitEOF)
@@ -332,15 +310,10 @@ test_expect_success 'subtest: skip entire test suite with GIT_SKIP_TESTS' ' test_expect_success'subtest: GIT_SKIP_TESTS does not skip unmatched suite''(-write_and_run_sub_test_lib_testgit-skip-tests-unmatched-suite\---skip="notgit"<<-\EOF&&-foriin123-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testgit-skip-tests-unmatched-suite<<-\EOF+GIT_SKIP_TESTS="notgit"&&exportGIT_SKIP_TESTS&&+run_sub_test_lib_testfull-pass\+--skip="notfull"&&+check_sub_test_lib_testfull-pass<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3-passingtest#3
@@ -351,14 +324,8 @@ test_expect_success 'subtest: GIT_SKIP_TESTS does not skip unmatched suite' '' test_expect_success'subtest: --run basic''-write_and_run_sub_test_lib_testrun-basic--run="1,3,5"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-basic<<-\EOF+run_sub_test_lib_testgit-skip-tests-several--run="1,3,5"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2# skip passing test #2 (--run)>ok3-passingtest#3
@@ -371,15 +338,9 @@ test_expect_success 'subtest: --run basic' '' test_expect_success'subtest: --run with a range''-write_and_run_sub_test_lib_testrun-range\---run="1-3"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-range<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="1-3"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3-passingtest#3
@@ -392,15 +353,9 @@ test_expect_success 'subtest: --run with a range' '' test_expect_success'subtest: --run with two ranges''-write_and_run_sub_test_lib_testrun-two-ranges\---run="1-2,5-6"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-two-ranges<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="1-2,5-6"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -413,15 +368,9 @@ test_expect_success 'subtest: --run with two ranges' '' test_expect_success'subtest: --run with a left open range''-write_and_run_sub_test_lib_testrun-left-open-range\---run="-3"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-left-open-range<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="-3"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3-passingtest#3
@@ -434,15 +383,9 @@ test_expect_success 'subtest: --run with a left open range' '' test_expect_success'subtest: --run with a right open range''-write_and_run_sub_test_lib_testrun-right-open-range\---run="4-"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-right-open-range<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="4-"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1# skip passing test #1 (--run)>ok2# skip passing test #2 (--run)>ok3# skip passing test #3 (--run)
@@ -455,15 +398,9 @@ test_expect_success 'subtest: --run with a right open range' '' test_expect_success'subtest: --run with basic negation''-write_and_run_sub_test_lib_testrun-basic-neg\---run="!3"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-basic-neg<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="!3"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -476,15 +413,9 @@ test_expect_success 'subtest: --run with basic negation' '' test_expect_success'subtest: --run with two negations''-write_and_run_sub_test_lib_testrun-two-neg\---run="!3,!6"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-two-neg<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="!3,!6"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -497,15 +428,9 @@ test_expect_success 'subtest: --run with two negations' '' test_expect_success'subtest: --run a range and negation''-write_and_run_sub_test_lib_testrun-range-and-neg\---run="-4,!2"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-range-and-neg<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="-4,!2"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2# skip passing test #2 (--run)>ok3-passingtest#3
@@ -518,15 +443,9 @@ test_expect_success 'subtest: --run a range and negation' '' test_expect_success'subtest: --run range negation''-write_and_run_sub_test_lib_testrun-range-neg\---run="!1-3"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-range-neg<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="!1-3"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1# skip passing test #1 (--run)>ok2# skip passing test #2 (--run)>ok3# skip passing test #3 (--run)
@@ -539,15 +458,9 @@ test_expect_success 'subtest: --run range negation' '' test_expect_success'subtest: --run include, exclude and include''-write_and_run_sub_test_lib_testrun-inc-neg-inc\---run="1-5,!1-3,2"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-inc-neg-inc<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="1-5,!1-3,2"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1# skip passing test #1 (--run)>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -560,15 +473,9 @@ test_expect_success 'subtest: --run include, exclude and include' '' test_expect_success'subtest: --run include, exclude and include, comma separated''-write_and_run_sub_test_lib_testrun-inc-neg-inc-comma\---run=1-5,!1-3,2<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-inc-neg-inc-comma<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run=1-5,!1-3,2&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1# skip passing test #1 (--run)>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -581,15 +488,9 @@ test_expect_success 'subtest: --run include, exclude and include, comma separate' test_expect_success'subtest: --run exclude and include''-write_and_run_sub_test_lib_testrun-neg-inc\---run="!3-,5"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-neg-inc<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="!3-,5"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -602,15 +503,9 @@ test_expect_success 'subtest: --run exclude and include' '' test_expect_success'subtest: --run empty selectors''-write_and_run_sub_test_lib_testrun-empty-sel\---run="1,,3,,,5"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-empty-sel<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="1,,3,,,5"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2# skip passing test #2 (--run)>ok3-passingtest#3
@@ -660,12 +555,9 @@ test_expect_success 'subtest: --run keyword selection' '' test_expect_success'subtest: --run invalid range end''-write_and_run_sub_test_lib_test_errrun-inv-range-end\---run="1-z"<<-\EOF&&-test_expect_success"passing test #1""true"-test_done-EOF-check_sub_test_lib_test_errrun-inv-range-end\+run_sub_test_lib_test_errrun-inv-range-start\+--run="1-z"&&+check_sub_test_lib_test_errrun-inv-range-start\<<-\EOF_OUT 3<<-EOF_ERR>FATAL:Unexpectedexitwithcode1EOF_OUT
Change the $test_description provided for the generated subtests to be
constant, since the only purpose of having it is that test-lib.sh will
barf if it isn't supplied.
The other purpose of having it was to effectively split up the test
description between the argument to test_expect_success and the
argument to "write_and_run_sub_test_lib_test". Let's only use one of
the two.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 12 ++--
t/t0000-basic.sh | 142 +++++++++++++++++++++--------------------------
2 files changed, 66 insertions(+), 88 deletions(-)
@@ -1,12 +1,8 @@ write_sub_test_lib_test(){-name="$1"descr="$2"# stdin is the body of the test code+name="$1"# stdin is the body of the test codemkdir"$name"&&write_script"$name/$name.sh""$TEST_SHELL_PATH"<<-EOF&&-test_description='$descr(runinsubtest-lib)--Thisisruninasubtest-libsothatwedonotgetincorrect-passingmetrics-'+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
@@ -15,8 +11,8 @@ write_sub_test_lib_test () {} _run_sub_test_lib_test_common(){-neg="$1"name="$2"descr="$3"# stdin is the body of the test code-shift3+neg="$1"name="$2"# stdin is the body of the test code+shift2# intercept pseudo-options at the front of the argument list that we# will not pass to child script
@@ -67,8 +67,8 @@ test_expect_success 'success is reported like this' ':'-test_expect_success'pretend we have a fully passing test suite''-write_and_run_sub_test_lib_testfull-pass"3 passing tests"<<-\EOF&&+test_expect_success'subtest: 3 passing tests''+write_and_run_sub_test_lib_testfull-pass<<-\EOF&&foriin123dotest_expect_success"passing test #$i""true"
@@ -84,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''-write_and_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_errpartial-pass<<-\EOF&&test_expect_success"passing test #1""true"test_expect_success"failing test #2""false"test_expect_success"passing test #3""true"
@@ -102,8 +101,8 @@ test_expect_success 'pretend we have a partially passing test suite' 'EOF'-test_expect_success'pretend we have a known breakage''-write_and_run_sub_test_lib_testfailing-todo"A failing TODO test"<<-\EOF&&+test_expect_success'subtest: a failing TODO test''+write_and_run_sub_test_lib_testfailing-todo<<-\EOF&&test_expect_success"passing test""true"test_expect_failure"pretend we have a known breakage""false"test_done
@@ -117,8 +116,8 @@ test_expect_success 'pretend we have a known breakage' 'EOF'-test_expect_success'pretend we have fixed a known breakage''-write_and_run_sub_test_lib_testpassing-todo"A passing TODO test"<<-\EOF&&+test_expect_success'subtest: a passing TODO test''+write_and_run_sub_test_lib_testpassing-todo<<-\EOF&&test_expect_failure"pretend we have fixed a known breakage""true"test_doneEOF
@@ -129,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)''-write_and_run_sub_test_lib_testpartially-passing-todos\-"2 TODO tests, one passing"<<-\EOF&&+test_expect_success'subtest: 2 TODO tests, one passin''+write_and_run_sub_test_lib_testpartially-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"
@@ -148,9 +146,8 @@ test_expect_success 'pretend we have fixed one of two known breakages (run in suEOF'-test_expect_success'pretend we have a pass, fail, and known breakage''-write_and_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_errmixed-results1<<-\EOF&&test_expect_success"passing test""true"test_expect_success"failing test""false"test_expect_failure"pretend we have a known breakage""false"
@@ -167,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''-write_and_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_errmixed-results2<<-\EOF&&test_expect_success"passing test""true"test_expect_success"passing test""true"test_expect_success"passing test""true"
@@ -203,9 +199,8 @@ test_expect_success 'pretend we have a mix of all possible results' 'EOF'-test_expect_success'test --verbose''-write_and_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_errt1234-verbose--verbose<<-\EOF&&test_expect_success"passing test"truetest_expect_success"test with output""echo foo"test_expect_success"failing test"false
@@ -253,10 +248,9 @@ test_expect_success 'test --verbose-only' 'EOF'-test_expect_success'GIT_SKIP_TESTS''+test_expect_success'subtest: skip one with GIT_SKIP_TESTS''(write_and_run_sub_test_lib_testgit-skip-tests-basic\-"GIT_SKIP_TESTS"\--skip="git.2"<<-\EOF&&foriin123do
@@ -274,10 +268,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''(write_and_run_sub_test_lib_testgit-skip-tests-several\-"GIT_SKIP_TESTS several tests"\--skip="git.2 git.5"<<-\EOF&&foriin123456do
@@ -298,10 +291,9 @@ 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''(write_and_run_sub_test_lib_testgit-skip-tests-sh-pattern\-"GIT_SKIP_TESTS sh pattern"\--skip="git.[2-5]"<<-\EOF&&foriin123456do
@@ -322,10 +314,9 @@ 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''(write_and_run_sub_test_lib_testgit-skip-tests-entire-suite\-"GIT_SKIP_TESTS entire suite"\--skip="git"<<-\EOF&&foriin123do
@@ -339,10 +330,9 @@ test_expect_success 'GIT_SKIP_TESTS entire suite' ')'-test_expect_success'GIT_SKIP_TESTS does not skip unmatched suite''+test_expect_success'subtest: GIT_SKIP_TESTS does not skip unmatched suite''(write_and_run_sub_test_lib_testgit-skip-tests-unmatched-suite\-"GIT_SKIP_TESTS does not skip unmatched suite"\--skip="notgit"<<-\EOF&&foriin123do
@@ -360,9 +350,8 @@ test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' ')'-test_expect_success'--run basic''-write_and_run_sub_test_lib_testrun-basic\-"--run basic"--run="1,3,5"<<-\EOF&&+test_expect_success'subtest: --run basic''+write_and_run_sub_test_lib_testrun-basic--run="1,3,5"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -381,9 +370,9 @@ test_expect_success '--run basic' 'EOF'-test_expect_success'--run with a range''+test_expect_success'subtest: --run with a range''write_and_run_sub_test_lib_testrun-range\-"--run with a range"--run="1-3"<<-\EOF&&+--run="1-3"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -402,9 +391,9 @@ test_expect_success '--run with a range' 'EOF'-test_expect_success'--run with two ranges''+test_expect_success'subtest: --run with two ranges''write_and_run_sub_test_lib_testrun-two-ranges\-"--run with two ranges"--run="1-2,5-6"<<-\EOF&&+--run="1-2,5-6"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -423,9 +412,9 @@ test_expect_success '--run with two ranges' 'EOF'-test_expect_success'--run with a left open range''+test_expect_success'subtest: --run with a left open range''write_and_run_sub_test_lib_testrun-left-open-range\-"--run with a left open range"--run="-3"<<-\EOF&&+--run="-3"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -444,9 +433,9 @@ test_expect_success '--run with a left open range' 'EOF'-test_expect_success'--run with a right open range''+test_expect_success'subtest: --run with a right open range''write_and_run_sub_test_lib_testrun-right-open-range\-"--run with a right open range"--run="4-"<<-\EOF&&+--run="4-"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -465,9 +454,9 @@ test_expect_success '--run with a right open range' 'EOF'-test_expect_success'--run with basic negation''+test_expect_success'subtest: --run with basic negation''write_and_run_sub_test_lib_testrun-basic-neg\-"--run with basic negation"--run="!3"<<-\EOF&&+--run="!3"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -486,9 +475,9 @@ test_expect_success '--run with basic negation' 'EOF'-test_expect_success'--run with two negations''+test_expect_success'subtest: --run with two negations''write_and_run_sub_test_lib_testrun-two-neg\-"--run with two negations"--run="!3,!6"<<-\EOF&&+--run="!3,!6"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -507,9 +496,9 @@ test_expect_success '--run with two negations' 'EOF'-test_expect_success'--run a range and negation''+test_expect_success'subtest: --run a range and negation''write_and_run_sub_test_lib_testrun-range-and-neg\-"--run a range and negation"--run="-4,!2"<<-\EOF&&+--run="-4,!2"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -528,9 +517,9 @@ test_expect_success '--run a range and negation' 'EOF'-test_expect_success'--run range negation''+test_expect_success'subtest: --run range negation''write_and_run_sub_test_lib_testrun-range-neg\-"--run range negation"--run="!1-3"<<-\EOF&&+--run="!1-3"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -549,9 +538,8 @@ test_expect_success '--run range negation' 'EOF'-test_expect_success'--run include, exclude and include''+test_expect_success'subtest: --run include, exclude and include''write_and_run_sub_test_lib_testrun-inc-neg-inc\-"--run include, exclude and include"\--run="1-5,!1-3,2"<<-\EOF&&foriin123456do
@@ -571,9 +559,8 @@ test_expect_success '--run include, exclude and include' 'EOF'-test_expect_success'--run include, exclude and include, comma separated''+test_expect_success'subtest: --run include, exclude and include, comma separated''write_and_run_sub_test_lib_testrun-inc-neg-inc-comma\-"--run include, exclude and include, comma separated"\--run=1-5,!1-3,2<<-\EOF&&foriin123456do
@@ -593,9 +580,8 @@ test_expect_success '--run include, exclude and include, comma separated' 'EOF'-test_expect_success'--run exclude and include''+test_expect_success'subtest: --run exclude and include''write_and_run_sub_test_lib_testrun-neg-inc\-"--run exclude and include"\--run="!3-,5"<<-\EOF&&foriin123456do
@@ -771,9 +753,9 @@ test_expect_success 'nested lazy prerequisites' 'EOF'-test_expect_success'lazy prereqs do not turn off tracing''+test_expect_success'subtest: lazy prereqs do not turn off tracing''write_and_run_sub_test_lib_testlazy-prereq-and-tracing\-"lazy prereqs and -x"-v-x<<-\EOF&&+-v-x<<-\EOF&&test_lazy_prereqLAZYtruetest_expect_successlazy"test_have_prereq LAZY && echo trace"
@@ -784,8 +766,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''-write_and_run_sub_test_lib_testcleanup"test with cleanup"<<-\EOF&&+test_expect_success'subtest: tests clean up after themselves''+write_and_run_sub_test_lib_testcleanup<<-\EOF&&clean=notest_expect_success"do cleanup""test_when_finishedclean=yes
@@ -804,9 +786,9 @@ test_expect_success 'tests clean up after themselves' 'EOF'-test_expect_success'tests clean up even on failures''+test_expect_success'subtest: tests clean up even on failures''write_and_run_sub_test_lib_test_err\-failing-cleanup"Failing tests with cleanup commands"<<-\EOF&&+failing-cleanup<<-\EOF&&test_expect_success"tests clean up even after a failure""touchclean-after-failure&&test_when_finishedrmclean-after-failure&&
@@ -833,9 +815,9 @@ test_expect_success 'tests clean up even on failures' 'EOF'-test_expect_success'test_atexit is run''+test_expect_success'subtest: test_atexit is run''write_and_run_sub_test_lib_test_err\-atexit-cleanup"Run atexit commands"-i<<-\EOF&&+atexit-cleanup-i<<-\EOF&&test_expect_success"tests clean up even after a failure"">../../clean-atexit&&test_atexitrm../../clean-atexit&&
In the preceding commit we got rid of a bunch of copy/pasted test code
from t0000-basic.sh in favor of re-using earlier already set up tests.
Since copy/pasting the tests is likely to be something done by mistake
in the future, let's add an assertion that detects whether this has
happened.
Now that we don't provide a unique test_description="" to these tests
we can rely on the content written out being the same in this
case. Let's use the object store to hash it, and attempt to create a
"blob-<CONTENT_OID>" tag. If another test has already written out the
same content we'll fail, and the tag envelope will provide an error
message pointing us in the right direction..
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 34 +++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
@@ -1,3 +1,34 @@+_assert_unique_sub_test(){+name=$1&&++# Alert about the copy/paste programming+hash=$(githash-object-w"$name")&&+cat>tag.sig<<-EOF&&+object$hash+typeblob+tag$hash+tagger.<>0+0000++duplicatescriptdetected!++Thistestscriptwasalreadywrittenas:++$name++Youcanjustre-useitstestcodewithyourown+run_sub_test_lib_test*()+EOF++tag=$(gitmktag<tag.sig)&&+if!gitupdate-refrefs/tags/blob-$hash$tag$(test_oidzero)2>/dev/null+then+msg=$(gitfor-each-refrefs/tags/blob-$hash\+--format='%(contents)'refs/tags/blob-$hash)+error"on write of $name: $msg"+return1+fi+}+ write_sub_test_lib_test(){name="$1"# stdin is the body of the test codemkdir"$name"&&
@@ -7,7 +38,8 @@ write_sub_test_lib_test () {# Point to the t/test-lib.sh, which isn't in ../ as usual."\$TEST_DIRECTORY"/test-lib.shEOF-cat>>"$name/$name.sh"+cat>>"$name/$name.sh"&&+_assert_unique_sub_test"$name/$name.sh"} _run_sub_test_lib_test_common(){
The use of a sub-shell for running the test_cmp of stdout/stderr for
the test author was introduced in this form in 565b6fa87bb (tests:
refactor mechanics of testing in a sub test-lib, 2012-12-16), but from
looking at the history that seemed to have diligently copied my
original ad-hoc implementation in 7b905119703 (t/t0000-basic.sh: Run
the passing TODO test inside its own test-lib, 2010-08-19).
There's no reason to use a subshell here, we try to avoid it in
general. It also improves readability, if the test fails we print out
the relative path in the trash directory that needs to be looked
at.
Before that was mostly obscured, since the "write_sub_test_lib_test"
will pick the directory for you from the test name.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)
@@ -111,22 +111,16 @@ run_sub_test_lib_test_err () { check_sub_test_lib_test(){name="$1"# stdin is the expected output from the test-(-cd"$name"&&-test_must_be_emptyerr&&-sed-e's/^> //'-e's/Z$//'>expect&&-test_cmpexpectout-)+test_must_be_empty"$name"/err&&+sed-e's/^> //'-e's/Z$//'>"$name"/expect&&+test_cmp"$name/"expect"$name"/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_cmpexpect.outout&&-sed-e's/^> //'-e's/Z$//'<&3>expect.err&&-test_cmpexpect.errerr-)+sed-e's/^> //'-e's/Z$//'>"$name"/expect.out&&+test_cmp"$name"/expect.out"$name"/out&&+sed-e's/^> //'-e's/Z$//'<&3>"$name"/expect.err&&+test_cmp"$name"/expect.err"$name"/err}
Refactor the two check_sub_test_lib_test*() functions to avoid
duplicating the same comparison they did of stdout. This duplication
was initially added when check_sub_test_lib_test_err() was added in
0445e6f0a12 (test-lib: '--run' to run only specific tests,
2014-04-30).
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
@@ -109,18 +109,22 @@ run_sub_test_lib_test_err () {_run_sub_test_lib_test_common'!'"$@"}+_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-test_must_be_empty"$name"/err&&-sed-e's/^> //'-e's/Z$//'>"$name"/expect&&-test_cmp"$name/"expect"$name"/out+_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$//'>"$name"/expect.out&&-test_cmp"$name"/expect.out"$name"/out&&sed-e's/^> //'-e's/Z$//'<&3>"$name"/expect.err&&test_cmp"$name"/expect.err"$name"/err}
Improve the testing for test-lib.sh itself to assert that we have a
exit code of 1, not any non-zero. Improves code added in
0445e6f0a12 (test-lib: '--run' to run only specific tests,
2014-04-30).
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
@@ -43,8 +43,8 @@ write_sub_test_lib_test () {} _run_sub_test_lib_test_common(){-neg="$1"name="$2"# stdin is the body of the test code-shift2+cmp_op="$1"want_code="$2"name="$3"# stdin is the body of the test code+shift3# intercept pseudo-options at the front of the argument list that we# will not pass to child script
@@ -80,33 +80,30 @@ _run_sub_test_lib_test_common () {GIT_SKIP_TESTS=$skip&&exportGIT_SKIP_TESTS&&sane_unsetGIT_TEST_FAIL_PREREQS&&-iftest-z"$neg"-then-./"$name.sh""$@">out2>err-else-!./"$name.sh""$@">out2>err-fi+./"$name.sh""$@">out2>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 codewrite_sub_test_lib_test"$@"||return1-_run_sub_test_lib_test_common''"$@"+_run_sub_test_lib_test_common-eq0"$@"} write_and_run_sub_test_lib_test_err(){name="$1"descr="$2"# stdin is the body of the test codewrite_sub_test_lib_test"$@"||return1-_run_sub_test_lib_test_common'!'"$@"+_run_sub_test_lib_test_common-eq1"$@"} run_sub_test_lib_test(){-_run_sub_test_lib_test_common''"$@"+_run_sub_test_lib_test_common-eq0"$@"} run_sub_test_lib_test_err(){-_run_sub_test_lib_test_common'!'"$@"+_run_sub_test_lib_test_common-eq1"$@"} _check_sub_test_lib_test_common(){
From: Carlo Arenas <hidden> Date: 2021-09-22 08:33:26
On Thu, Aug 5, 2021 at 5:37 AM Ævar Arnfjörð Bjarmason [off-list ref] wrote:
The only tricky part of this series is the "clever" way of (ab)using
the object store and tags to detect copy/pasted tests. For this v3
I've split that up into its own commit, see [56]/9 for the removal of
the copy/pasting and the assertion, respectively.
I think this series would be better without that assertion (commit).
While it is cool, it seems misplaced as it makes sense running ONLY
when subtests had been added, and therefore probably as part of some
"lint" job (ex: "as part of the static analysis CI job"), instead of
every time this is called.
FWIW, it is not only the conceptual misplacement that is a problem,
but as coded a bug in git, could make these tests fail for a totally
unrelated reason and therefore be confusing.
Other than that and my comment about probably avoiding the in series
rewriting of a function which might have been me not understanding the
commit message, got my "Reviewed-by" for what it is worth.
Carlo
A re-roll of v3[1] of this cleanup/refactoring of t0000-basic.sh
series which addresses Carlo's comments on it, thanks for the review
Carlo!
I.e. the old 3/9 is squashed into a 2/7, and the assertion of
non-duplicate tests is now ejected. I left a note in 7/7 that we may
want it in the future, but for now let's punt on it.
1. https://lore.kernel.org/git/cover-v3-0.9-0000000000-20210805T103237Z-avarab@gmail.com/
2. https://lore.kernel.org/git/CAPUEspg3pT1F5YMwGuwvmiyMGoYLUB0neHeunXnLxwc_G9zN-A@mail.gmail.com/
Ævar Arnfjörð Bjarmason (7):
test-lib tests: move "run_sub_test" to a new lib-subtest.sh
test-lib tests: split up "write and run" into two functions
test-lib tests: don't provide a description for the sub-tests
test-lib tests: avoid subshell for "test_cmp" for readability
test-lib tests: refactor common part of check_sub_test_lib_test*()
test-lib tests: assert 1 exit code, not non-zero
test-lib tests: get rid of copy/pasted mock test code
t/lib-subtest.sh | 95 ++++++++++
t/t0000-basic.sh | 448 +++++++++++++----------------------------------
2 files changed, 213 insertions(+), 330 deletions(-)
create mode 100644 t/lib-subtest.sh
Range-diff against v3:
1: 3f34420a3e1 = 1: f915bc2ee77 test-lib tests: move "run_sub_test" to a new lib-subtest.sh
2: c9c16016da6 ! 2: 5b5038867df test-lib tests: split up "write and run" into two functions
@@ Commit message
it possible to do so. All the changes in t0000-basic.sh are a simple
search-replacement.
+ Since the _run_sub_test_lib_test_common() function doesn't handle
+ running the test anymore we can do away with the sub-shell, which was
+ used to scope an "unset" and "export" shell variables.
+
Signed-off-by: Ævar Arnfjörð Bjarmason [off-list ref]
## t/lib-subtest.sh ##
@@ t/lib-subtest.sh
+write_sub_test_lib_test () {
+ name="$1" descr="$2" # stdin is the body of the test code
+ mkdir "$name" &&
-+ (
-+ cd "$name" &&
-+ write_script "$name.sh" "$TEST_SHELL_PATH" <<-EOF &&
-+ test_description='$descr (run in sub test-lib)
++ write_script "$name/$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
-+ '
++ 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"
-+ )
++ # 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 () {
@@ t/lib-subtest.sh: _run_sub_test_lib_test_common () {
- 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
3: 76f57eadcdd < -: ----------- test-lib tests: stop using a subshell in write_sub_test_lib_test()
4: cde015c7dd0 = 3: 78177ce1729 test-lib tests: don't provide a description for the sub-tests
7: 48176f3e60c = 4: a581bff6e62 test-lib tests: avoid subshell for "test_cmp" for readability
8: fda7c4fbe34 = 5: 5e95484fb61 test-lib tests: refactor common part of check_sub_test_lib_test*()
9: dd0af5bd6ce = 6: 1e0a49c1a70 test-lib tests: assert 1 exit code, not non-zero
5: 7d1e6b9a3e4 ! 7: 68f8fabaa1e test-lib tests: get rid of copy/pasted mock test code
@@ Commit message
run_sub_test_lib_test*() functions let's fix those tests in
t0000-basic.sh that were verbosely copy/pasting earlier tests.
- In a subsequent commit we'll add an assertion to check whether we
- caught all of the copy/pasting.
+ That we caught all of them was asserted with a follow-up change that's
+ not part of this series[1], we might add such a duplication check at
+ some later time, but for now let's just one-off remove the duplicate
+ boilerplate.
+
+ 1. https://lore.kernel.org/git/patch-v3-6.9-bc79b29f3c-20210805T103237Z-avarab@gmail.com/
Signed-off-by: Ævar Arnfjörð Bjarmason [off-list ref]
6: bc79b29f3cd < -: ----------- test-lib tests: assert no copy/pasted mock test code
--
2.33.0.1225.g9f062250122
Move the "check_sub_test_lib_test()" and its sister functions to a new
lib-subtest.sh.
In the future (not in this series) I'd like to test test-lib's output
in a more targeted and smaller test, and I'll need these functions to
do that.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 86 ++++++++++++++++++++++++++++++++++++++++++++++
t/t0000-basic.sh | 88 +-----------------------------------------------
2 files changed, 87 insertions(+), 87 deletions(-)
create mode 100644 t/lib-subtest.sh
@@ -0,0 +1,86 @@+_run_sub_test_lib_test_common(){+neg="$1"name="$2"descr="$3"# stdin is the body of the test code+shift3++# intercept pseudo-options at the front of the argument list that we+# will not pass to child script+skip=+whiletest$#-gt0+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_unsetHARNESS_ACTIVE&&+cd"$name"&&+write_script"$name.sh""$TEST_SHELL_PATH"<<-EOF&&+test_description='$descr(runinsubtest-lib)++Thisisruninasubtest-libsothatwedonotgetincorrect+passingmetrics+'++# Point to the t/test-lib.sh, which isn't in ../ as usual+."\$TEST_DIRECTORY"/test-lib.sh+EOF+cat>>"$name.sh"&&+exportTEST_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)&&+exportTEST_OUTPUT_DIRECTORY_OVERRIDE&&+GIT_SKIP_TESTS=$skip&&+exportGIT_SKIP_TESTS&&+sane_unsetGIT_TEST_FAIL_PREREQS&&+iftest-z"$neg"+then+./"$name.sh""$@">out2>err+else+!./"$name.sh""$@">out2>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_emptyerr&&+sed-e's/^> //'-e's/Z$//'>expect&&+test_cmpexpectout+)+}++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_cmpexpect.outout&&+sed-e's/^> //'-e's/Z$//'<&3>expect.err&&+test_cmpexpect.errerr+)+}
@@ -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(){localx="local"y="alsolocal"&&
@@ -66,93 +67,6 @@ 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-shift3--# intercept pseudo-options at the front of the argument list that we-# will not pass to child script-skip=-whiletest$#-gt0-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_unsetHARNESS_ACTIVE&&-cd"$name"&&-write_script"$name.sh""$TEST_SHELL_PATH"<<-EOF&&-test_description='$descr(runinsubtest-lib)--Thisisruninasubtest-libsothatwedonotgetincorrect-passingmetrics-'--# Point to the t/test-lib.sh, which isn't in ../ as usual-."\$TEST_DIRECTORY"/test-lib.sh-EOF-cat>>"$name.sh"&&-exportTEST_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)&&-exportTEST_OUTPUT_DIRECTORY_OVERRIDE&&-GIT_SKIP_TESTS=$skip&&-exportGIT_SKIP_TESTS&&-sane_unsetGIT_TEST_FAIL_PREREQS&&-iftest-z"$neg"-then-./"$name.sh""$@">out2>err-else-!./"$name.sh""$@">out2>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_emptyerr&&-sed-e's/^> //'-e's/Z$//'>expect&&-test_cmpexpectout-)-}--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_cmpexpect.outout&&-sed-e's/^> //'-e's/Z$//'<&3>expect.err&&-test_cmpexpect.errerr-)-}- test_expect_success'pretend we have a fully passing test suite''run_sub_test_lib_testfull-pass"3 passing tests"<<-\EOF&&foriin123
Refactor the function to write and run tests of the test-lib.sh output
into two functions.
When this was added back in 565b6fa87bb (tests: refactor mechanics of
testing in a sub test-lib, 2012-12-16) there was no reason to do this,
but since we started supporting test arguments in
517cd55fd51 (test-lib: self-test that --verbose works, 2013-06-23)
we've started to write out duplicate tests simply to test different
arguments, now we'll be able to re-use them.
This change doesn't consolidate any of those tests yet, it just makes
it possible to do so. All the changes in t0000-basic.sh are a simple
search-replacement.
Since the _run_sub_test_lib_test_common() function doesn't handle
running the test anymore we can do away with the sub-shell, which was
used to scope an "unset" and "export" shell variables.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 42 +++++++++++++++++++--------
t/t0000-basic.sh | 74 ++++++++++++++++++++++++------------------------
2 files changed, 67 insertions(+), 49 deletions(-)
@@ -1,3 +1,19 @@+write_sub_test_lib_test(){+name="$1"descr="$2"# stdin is the body of the test code+mkdir"$name"&&+write_script"$name/$name.sh""$TEST_SHELL_PATH"<<-EOF&&+test_description='$descr(runinsubtest-lib)++Thisisruninasubtest-libsothatwedonotgetincorrect+passingmetrics+'++# 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(){neg="$1"name="$2"descr="$3"# stdin is the body of the test codeshift3
@@ -18,25 +34,15 @@ _run_sub_test_lib_test_common () {esacdone-mkdir"$name"&&(+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_unsetHARNESS_ACTIVE&&-cd"$name"&&-write_script"$name.sh""$TEST_SHELL_PATH"<<-EOF&&-test_description='$descr(runinsubtest-lib)--Thisisruninasubtest-libsothatwedonotgetincorrect-passingmetrics-'-# Point to the t/test-lib.sh, which isn't in ../ as usual-."\$TEST_DIRECTORY"/test-lib.sh-EOF-cat>>"$name.sh"&&exportTEST_DIRECTORY&&# The child test re-sources GIT-BUILD-OPTIONS and may thus# override the test output directory. We thus pass it as an
@@ -55,6 +61,18 @@ _run_sub_test_lib_test_common () {)}+write_and_run_sub_test_lib_test(){+name="$1"descr="$2"# stdin is the body of the test code+write_sub_test_lib_test"$@"||return1+_run_sub_test_lib_test_common''"$@"+}++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"$@"||return1+_run_sub_test_lib_test_common'!'"$@"+}+ run_sub_test_lib_test(){_run_sub_test_lib_test_common''"$@"}
@@ -68,7 +68,7 @@ test_expect_success 'success is reported like this' '' test_expect_success'pretend we have a fully passing test suite''-run_sub_test_lib_testfull-pass"3 passing tests"<<-\EOF&&+write_and_run_sub_test_lib_testfull-pass"3 passing tests"<<-\EOF&&foriin123dotest_expect_success"passing test #$i""true"
@@ -85,7 +85,7 @@ test_expect_success 'pretend we have a fully passing test suite' '' test_expect_success'pretend we have a partially passing test suite''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\partial-pass"2/3 tests passing"<<-\EOF&&test_expect_success"passing test #1""true"test_expect_success"failing test #2""false"
@@ -103,7 +103,7 @@ test_expect_success 'pretend we have a partially passing test suite' '' test_expect_success'pretend we have a known breakage''-run_sub_test_lib_testfailing-todo"A failing TODO test"<<-\EOF&&+write_and_run_sub_test_lib_testfailing-todo"A failing TODO test"<<-\EOF&&test_expect_success"passing test""true"test_expect_failure"pretend we have a known breakage""false"test_done
@@ -118,7 +118,7 @@ test_expect_success 'pretend we have a known breakage' '' test_expect_success'pretend we have fixed a known breakage''-run_sub_test_lib_testpassing-todo"A passing TODO test"<<-\EOF&&+write_and_run_sub_test_lib_testpassing-todo"A passing TODO test"<<-\EOF&&test_expect_failure"pretend we have fixed a known breakage""true"test_doneEOF
@@ -130,7 +130,7 @@ test_expect_success 'pretend we have fixed a known breakage' '' test_expect_success'pretend we have fixed one of two known breakages (run in sub test-lib)''-run_sub_test_lib_testpartially-passing-todos\+write_and_run_sub_test_lib_testpartially-passing-todos\"2 TODO tests, one passing"<<-\EOF&&test_expect_failure"pretend we have a known breakage""false"test_expect_success"pretend we have a passing test""true"
@@ -149,7 +149,7 @@ test_expect_success 'pretend we have fixed one of two known breakages (run in su' test_expect_success'pretend we have a pass, fail, and known breakage''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\mixed-results1"mixed results #1"<<-\EOF&&test_expect_success"passing test""true"test_expect_success"failing test""false"
@@ -168,7 +168,7 @@ test_expect_success 'pretend we have a pass, fail, and known breakage' '' test_expect_success'pretend we have a mix of all possible results''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\mixed-results2"mixed results #2"<<-\EOF&&test_expect_success"passing test""true"test_expect_success"passing test""true"
@@ -204,7 +204,7 @@ test_expect_success 'pretend we have a mix of all possible results' '' test_expect_success'test --verbose''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\t1234-verbose"test verbose"--verbose<<-\EOF&&test_expect_success"passing test"truetest_expect_success"test with output""echo foo"
@@ -276,7 +276,7 @@ test_expect_success 'GIT_SKIP_TESTS' ' test_expect_success'GIT_SKIP_TESTS several tests''(-run_sub_test_lib_testgit-skip-tests-several\+write_and_run_sub_test_lib_testgit-skip-tests-several\"GIT_SKIP_TESTS several tests"\--skip="git.2 git.5"<<-\EOF&&foriin123456
@@ -300,7 +300,7 @@ test_expect_success 'GIT_SKIP_TESTS several tests' ' test_expect_success'GIT_SKIP_TESTS sh pattern''(-run_sub_test_lib_testgit-skip-tests-sh-pattern\+write_and_run_sub_test_lib_testgit-skip-tests-sh-pattern\"GIT_SKIP_TESTS sh pattern"\--skip="git.[2-5]"<<-\EOF&&foriin123456
@@ -341,7 +341,7 @@ test_expect_success 'GIT_SKIP_TESTS entire suite' ' test_expect_success'GIT_SKIP_TESTS does not skip unmatched suite''(-run_sub_test_lib_testgit-skip-tests-unmatched-suite\+write_and_run_sub_test_lib_testgit-skip-tests-unmatched-suite\"GIT_SKIP_TESTS does not skip unmatched suite"\--skip="notgit"<<-\EOF&&foriin123
@@ -361,7 +361,7 @@ test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' '' test_expect_success'--run basic''-run_sub_test_lib_testrun-basic\+write_and_run_sub_test_lib_testrun-basic\"--run basic"--run="1,3,5"<<-\EOF&&foriin123456do
@@ -382,7 +382,7 @@ test_expect_success '--run basic' '' test_expect_success'--run with a range''-run_sub_test_lib_testrun-range\+write_and_run_sub_test_lib_testrun-range\"--run with a range"--run="1-3"<<-\EOF&&foriin123456do
@@ -403,7 +403,7 @@ test_expect_success '--run with a range' '' test_expect_success'--run with two ranges''-run_sub_test_lib_testrun-two-ranges\+write_and_run_sub_test_lib_testrun-two-ranges\"--run with two ranges"--run="1-2,5-6"<<-\EOF&&foriin123456do
@@ -424,7 +424,7 @@ test_expect_success '--run with two ranges' '' test_expect_success'--run with a left open range''-run_sub_test_lib_testrun-left-open-range\+write_and_run_sub_test_lib_testrun-left-open-range\"--run with a left open range"--run="-3"<<-\EOF&&foriin123456do
@@ -445,7 +445,7 @@ test_expect_success '--run with a left open range' '' test_expect_success'--run with a right open range''-run_sub_test_lib_testrun-right-open-range\+write_and_run_sub_test_lib_testrun-right-open-range\"--run with a right open range"--run="4-"<<-\EOF&&foriin123456do
@@ -466,7 +466,7 @@ test_expect_success '--run with a right open range' '' test_expect_success'--run with basic negation''-run_sub_test_lib_testrun-basic-neg\+write_and_run_sub_test_lib_testrun-basic-neg\"--run with basic negation"--run="!3"<<-\EOF&&foriin123456do
@@ -487,7 +487,7 @@ test_expect_success '--run with basic negation' '' test_expect_success'--run with two negations''-run_sub_test_lib_testrun-two-neg\+write_and_run_sub_test_lib_testrun-two-neg\"--run with two negations"--run="!3,!6"<<-\EOF&&foriin123456do
@@ -508,7 +508,7 @@ test_expect_success '--run with two negations' '' test_expect_success'--run a range and negation''-run_sub_test_lib_testrun-range-and-neg\+write_and_run_sub_test_lib_testrun-range-and-neg\"--run a range and negation"--run="-4,!2"<<-\EOF&&foriin123456do
@@ -529,7 +529,7 @@ test_expect_success '--run a range and negation' '' test_expect_success'--run range negation''-run_sub_test_lib_testrun-range-neg\+write_and_run_sub_test_lib_testrun-range-neg\"--run range negation"--run="!1-3"<<-\EOF&&foriin123456do
@@ -550,7 +550,7 @@ test_expect_success '--run range negation' '' test_expect_success'--run include, exclude and include''-run_sub_test_lib_testrun-inc-neg-inc\+write_and_run_sub_test_lib_testrun-inc-neg-inc\"--run include, exclude and include"\--run="1-5,!1-3,2"<<-\EOF&&foriin123456
@@ -572,7 +572,7 @@ test_expect_success '--run include, exclude and include' '' test_expect_success'--run include, exclude and include, comma separated''-run_sub_test_lib_testrun-inc-neg-inc-comma\+write_and_run_sub_test_lib_testrun-inc-neg-inc-comma\"--run include, exclude and include, comma separated"\--run=1-5,!1-3,2<<-\EOF&&foriin123456
@@ -594,7 +594,7 @@ test_expect_success '--run include, exclude and include, comma separated' '' test_expect_success'--run exclude and include''-run_sub_test_lib_testrun-neg-inc\+write_and_run_sub_test_lib_testrun-neg-inc\"--run exclude and include"\--run="!3-,5"<<-\EOF&&foriin123456
@@ -772,7 +772,7 @@ test_expect_success 'nested lazy prerequisites' '' test_expect_success'lazy prereqs do not turn off tracing''-run_sub_test_lib_testlazy-prereq-and-tracing\+write_and_run_sub_test_lib_testlazy-prereq-and-tracing\"lazy prereqs and -x"-v-x<<-\EOF&&test_lazy_prereqLAZYtrue
@@ -785,7 +785,7 @@ test_expect_success 'lazy prereqs do not turn off tracing' '' test_expect_success'tests clean up after themselves''-run_sub_test_lib_testcleanup"test with cleanup"<<-\EOF&&+write_and_run_sub_test_lib_testcleanup"test with cleanup"<<-\EOF&&clean=notest_expect_success"do cleanup""test_when_finishedclean=yes
@@ -805,7 +805,7 @@ test_expect_success 'tests clean up after themselves' '' test_expect_success'tests clean up even on failures''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\failing-cleanup"Failing tests with cleanup commands"<<-\EOF&&test_expect_success"tests clean up even after a failure""touchclean-after-failure&&
@@ -834,7 +834,7 @@ test_expect_success 'tests clean up even on failures' '' test_expect_success'test_atexit is run''-run_sub_test_lib_test_err\+write_and_run_sub_test_lib_test_err\atexit-cleanup"Run atexit commands"-i<<-\EOF&&test_expect_success"tests clean up even after a failure"">../../clean-atexit&&
Change the $test_description provided for the generated subtests to be
constant, since the only purpose of having it is that test-lib.sh will
barf if it isn't supplied.
The other purpose of having it was to effectively split up the test
description between the argument to test_expect_success and the
argument to "write_and_run_sub_test_lib_test". Let's only use one of
the two.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 12 ++--
t/t0000-basic.sh | 142 +++++++++++++++++++++--------------------------
2 files changed, 66 insertions(+), 88 deletions(-)
@@ -1,12 +1,8 @@ write_sub_test_lib_test(){-name="$1"descr="$2"# stdin is the body of the test code+name="$1"# stdin is the body of the test codemkdir"$name"&&write_script"$name/$name.sh""$TEST_SHELL_PATH"<<-EOF&&-test_description='$descr(runinsubtest-lib)--Thisisruninasubtest-libsothatwedonotgetincorrect-passingmetrics-'+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
@@ -15,8 +11,8 @@ write_sub_test_lib_test () {} _run_sub_test_lib_test_common(){-neg="$1"name="$2"descr="$3"# stdin is the body of the test code-shift3+neg="$1"name="$2"# stdin is the body of the test code+shift2# intercept pseudo-options at the front of the argument list that we# will not pass to child script
@@ -67,8 +67,8 @@ test_expect_success 'success is reported like this' ':'-test_expect_success'pretend we have a fully passing test suite''-write_and_run_sub_test_lib_testfull-pass"3 passing tests"<<-\EOF&&+test_expect_success'subtest: 3 passing tests''+write_and_run_sub_test_lib_testfull-pass<<-\EOF&&foriin123dotest_expect_success"passing test #$i""true"
@@ -84,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''-write_and_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_errpartial-pass<<-\EOF&&test_expect_success"passing test #1""true"test_expect_success"failing test #2""false"test_expect_success"passing test #3""true"
@@ -102,8 +101,8 @@ test_expect_success 'pretend we have a partially passing test suite' 'EOF'-test_expect_success'pretend we have a known breakage''-write_and_run_sub_test_lib_testfailing-todo"A failing TODO test"<<-\EOF&&+test_expect_success'subtest: a failing TODO test''+write_and_run_sub_test_lib_testfailing-todo<<-\EOF&&test_expect_success"passing test""true"test_expect_failure"pretend we have a known breakage""false"test_done
@@ -117,8 +116,8 @@ test_expect_success 'pretend we have a known breakage' 'EOF'-test_expect_success'pretend we have fixed a known breakage''-write_and_run_sub_test_lib_testpassing-todo"A passing TODO test"<<-\EOF&&+test_expect_success'subtest: a passing TODO test''+write_and_run_sub_test_lib_testpassing-todo<<-\EOF&&test_expect_failure"pretend we have fixed a known breakage""true"test_doneEOF
@@ -129,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)''-write_and_run_sub_test_lib_testpartially-passing-todos\-"2 TODO tests, one passing"<<-\EOF&&+test_expect_success'subtest: 2 TODO tests, one passin''+write_and_run_sub_test_lib_testpartially-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"
@@ -148,9 +146,8 @@ test_expect_success 'pretend we have fixed one of two known breakages (run in suEOF'-test_expect_success'pretend we have a pass, fail, and known breakage''-write_and_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_errmixed-results1<<-\EOF&&test_expect_success"passing test""true"test_expect_success"failing test""false"test_expect_failure"pretend we have a known breakage""false"
@@ -167,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''-write_and_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_errmixed-results2<<-\EOF&&test_expect_success"passing test""true"test_expect_success"passing test""true"test_expect_success"passing test""true"
@@ -203,9 +199,8 @@ test_expect_success 'pretend we have a mix of all possible results' 'EOF'-test_expect_success'test --verbose''-write_and_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_errt1234-verbose--verbose<<-\EOF&&test_expect_success"passing test"truetest_expect_success"test with output""echo foo"test_expect_success"failing test"false
@@ -253,10 +248,9 @@ test_expect_success 'test --verbose-only' 'EOF'-test_expect_success'GIT_SKIP_TESTS''+test_expect_success'subtest: skip one with GIT_SKIP_TESTS''(write_and_run_sub_test_lib_testgit-skip-tests-basic\-"GIT_SKIP_TESTS"\--skip="git.2"<<-\EOF&&foriin123do
@@ -274,10 +268,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''(write_and_run_sub_test_lib_testgit-skip-tests-several\-"GIT_SKIP_TESTS several tests"\--skip="git.2 git.5"<<-\EOF&&foriin123456do
@@ -298,10 +291,9 @@ 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''(write_and_run_sub_test_lib_testgit-skip-tests-sh-pattern\-"GIT_SKIP_TESTS sh pattern"\--skip="git.[2-5]"<<-\EOF&&foriin123456do
@@ -322,10 +314,9 @@ 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''(write_and_run_sub_test_lib_testgit-skip-tests-entire-suite\-"GIT_SKIP_TESTS entire suite"\--skip="git"<<-\EOF&&foriin123do
@@ -339,10 +330,9 @@ test_expect_success 'GIT_SKIP_TESTS entire suite' ')'-test_expect_success'GIT_SKIP_TESTS does not skip unmatched suite''+test_expect_success'subtest: GIT_SKIP_TESTS does not skip unmatched suite''(write_and_run_sub_test_lib_testgit-skip-tests-unmatched-suite\-"GIT_SKIP_TESTS does not skip unmatched suite"\--skip="notgit"<<-\EOF&&foriin123do
@@ -360,9 +350,8 @@ test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' ')'-test_expect_success'--run basic''-write_and_run_sub_test_lib_testrun-basic\-"--run basic"--run="1,3,5"<<-\EOF&&+test_expect_success'subtest: --run basic''+write_and_run_sub_test_lib_testrun-basic--run="1,3,5"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -381,9 +370,9 @@ test_expect_success '--run basic' 'EOF'-test_expect_success'--run with a range''+test_expect_success'subtest: --run with a range''write_and_run_sub_test_lib_testrun-range\-"--run with a range"--run="1-3"<<-\EOF&&+--run="1-3"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -402,9 +391,9 @@ test_expect_success '--run with a range' 'EOF'-test_expect_success'--run with two ranges''+test_expect_success'subtest: --run with two ranges''write_and_run_sub_test_lib_testrun-two-ranges\-"--run with two ranges"--run="1-2,5-6"<<-\EOF&&+--run="1-2,5-6"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -423,9 +412,9 @@ test_expect_success '--run with two ranges' 'EOF'-test_expect_success'--run with a left open range''+test_expect_success'subtest: --run with a left open range''write_and_run_sub_test_lib_testrun-left-open-range\-"--run with a left open range"--run="-3"<<-\EOF&&+--run="-3"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -444,9 +433,9 @@ test_expect_success '--run with a left open range' 'EOF'-test_expect_success'--run with a right open range''+test_expect_success'subtest: --run with a right open range''write_and_run_sub_test_lib_testrun-right-open-range\-"--run with a right open range"--run="4-"<<-\EOF&&+--run="4-"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -465,9 +454,9 @@ test_expect_success '--run with a right open range' 'EOF'-test_expect_success'--run with basic negation''+test_expect_success'subtest: --run with basic negation''write_and_run_sub_test_lib_testrun-basic-neg\-"--run with basic negation"--run="!3"<<-\EOF&&+--run="!3"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -486,9 +475,9 @@ test_expect_success '--run with basic negation' 'EOF'-test_expect_success'--run with two negations''+test_expect_success'subtest: --run with two negations''write_and_run_sub_test_lib_testrun-two-neg\-"--run with two negations"--run="!3,!6"<<-\EOF&&+--run="!3,!6"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -507,9 +496,9 @@ test_expect_success '--run with two negations' 'EOF'-test_expect_success'--run a range and negation''+test_expect_success'subtest: --run a range and negation''write_and_run_sub_test_lib_testrun-range-and-neg\-"--run a range and negation"--run="-4,!2"<<-\EOF&&+--run="-4,!2"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -528,9 +517,9 @@ test_expect_success '--run a range and negation' 'EOF'-test_expect_success'--run range negation''+test_expect_success'subtest: --run range negation''write_and_run_sub_test_lib_testrun-range-neg\-"--run range negation"--run="!1-3"<<-\EOF&&+--run="!1-3"<<-\EOF&&foriin123456dotest_expect_success"passing test #$i""true"
@@ -549,9 +538,8 @@ test_expect_success '--run range negation' 'EOF'-test_expect_success'--run include, exclude and include''+test_expect_success'subtest: --run include, exclude and include''write_and_run_sub_test_lib_testrun-inc-neg-inc\-"--run include, exclude and include"\--run="1-5,!1-3,2"<<-\EOF&&foriin123456do
@@ -571,9 +559,8 @@ test_expect_success '--run include, exclude and include' 'EOF'-test_expect_success'--run include, exclude and include, comma separated''+test_expect_success'subtest: --run include, exclude and include, comma separated''write_and_run_sub_test_lib_testrun-inc-neg-inc-comma\-"--run include, exclude and include, comma separated"\--run=1-5,!1-3,2<<-\EOF&&foriin123456do
@@ -593,9 +580,8 @@ test_expect_success '--run include, exclude and include, comma separated' 'EOF'-test_expect_success'--run exclude and include''+test_expect_success'subtest: --run exclude and include''write_and_run_sub_test_lib_testrun-neg-inc\-"--run exclude and include"\--run="!3-,5"<<-\EOF&&foriin123456do
@@ -771,9 +753,9 @@ test_expect_success 'nested lazy prerequisites' 'EOF'-test_expect_success'lazy prereqs do not turn off tracing''+test_expect_success'subtest: lazy prereqs do not turn off tracing''write_and_run_sub_test_lib_testlazy-prereq-and-tracing\-"lazy prereqs and -x"-v-x<<-\EOF&&+-v-x<<-\EOF&&test_lazy_prereqLAZYtruetest_expect_successlazy"test_have_prereq LAZY && echo trace"
@@ -784,8 +766,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''-write_and_run_sub_test_lib_testcleanup"test with cleanup"<<-\EOF&&+test_expect_success'subtest: tests clean up after themselves''+write_and_run_sub_test_lib_testcleanup<<-\EOF&&clean=notest_expect_success"do cleanup""test_when_finishedclean=yes
@@ -804,9 +786,9 @@ test_expect_success 'tests clean up after themselves' 'EOF'-test_expect_success'tests clean up even on failures''+test_expect_success'subtest: tests clean up even on failures''write_and_run_sub_test_lib_test_err\-failing-cleanup"Failing tests with cleanup commands"<<-\EOF&&+failing-cleanup<<-\EOF&&test_expect_success"tests clean up even after a failure""touchclean-after-failure&&test_when_finishedrmclean-after-failure&&
@@ -833,9 +815,9 @@ test_expect_success 'tests clean up even on failures' 'EOF'-test_expect_success'test_atexit is run''+test_expect_success'subtest: test_atexit is run''write_and_run_sub_test_lib_test_err\-atexit-cleanup"Run atexit commands"-i<<-\EOF&&+atexit-cleanup-i<<-\EOF&&test_expect_success"tests clean up even after a failure"">../../clean-atexit&&test_atexitrm../../clean-atexit&&
The use of a sub-shell for running the test_cmp of stdout/stderr for
the test author was introduced in this form in 565b6fa87bb (tests:
refactor mechanics of testing in a sub test-lib, 2012-12-16), but from
looking at the history that seemed to have diligently copied my
original ad-hoc implementation in 7b905119703 (t/t0000-basic.sh: Run
the passing TODO test inside its own test-lib, 2010-08-19).
There's no reason to use a subshell here, we try to avoid it in
general. It also improves readability, if the test fails we print out
the relative path in the trash directory that needs to be looked
at.
Before that was mostly obscured, since the "write_sub_test_lib_test"
will pick the directory for you from the test name.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)
@@ -79,22 +79,16 @@ run_sub_test_lib_test_err () { check_sub_test_lib_test(){name="$1"# stdin is the expected output from the test-(-cd"$name"&&-test_must_be_emptyerr&&-sed-e's/^> //'-e's/Z$//'>expect&&-test_cmpexpectout-)+test_must_be_empty"$name"/err&&+sed-e's/^> //'-e's/Z$//'>"$name"/expect&&+test_cmp"$name/"expect"$name"/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_cmpexpect.outout&&-sed-e's/^> //'-e's/Z$//'<&3>expect.err&&-test_cmpexpect.errerr-)+sed-e's/^> //'-e's/Z$//'>"$name"/expect.out&&+test_cmp"$name"/expect.out"$name"/out&&+sed-e's/^> //'-e's/Z$//'<&3>"$name"/expect.err&&+test_cmp"$name"/expect.err"$name"/err}
Refactor the two check_sub_test_lib_test*() functions to avoid
duplicating the same comparison they did of stdout. This duplication
was initially added when check_sub_test_lib_test_err() was added in
0445e6f0a12 (test-lib: '--run' to run only specific tests,
2014-04-30).
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
@@ -77,18 +77,22 @@ run_sub_test_lib_test_err () {_run_sub_test_lib_test_common'!'"$@"}+_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-test_must_be_empty"$name"/err&&-sed-e's/^> //'-e's/Z$//'>"$name"/expect&&-test_cmp"$name/"expect"$name"/out+_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$//'>"$name"/expect.out&&-test_cmp"$name"/expect.out"$name"/out&&sed-e's/^> //'-e's/Z$//'<&3>"$name"/expect.err&&test_cmp"$name"/expect.err"$name"/err}
Improve the testing for test-lib.sh itself to assert that we have a
exit code of 1, not any non-zero. Improves code added in
0445e6f0a12 (test-lib: '--run' to run only specific tests,
2014-04-30).
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/lib-subtest.sh | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
@@ -11,8 +11,8 @@ write_sub_test_lib_test () {} _run_sub_test_lib_test_common(){-neg="$1"name="$2"# stdin is the body of the test code-shift2+cmp_op="$1"want_code="$2"name="$3"# stdin is the body of the test code+shift3# intercept pseudo-options at the front of the argument list that we# will not pass to child script
@@ -48,33 +48,30 @@ _run_sub_test_lib_test_common () {GIT_SKIP_TESTS=$skip&&exportGIT_SKIP_TESTS&&sane_unsetGIT_TEST_FAIL_PREREQS&&-iftest-z"$neg"-then-./"$name.sh""$@">out2>err-else-!./"$name.sh""$@">out2>err-fi+./"$name.sh""$@">out2>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 codewrite_sub_test_lib_test"$@"||return1-_run_sub_test_lib_test_common''"$@"+_run_sub_test_lib_test_common-eq0"$@"} write_and_run_sub_test_lib_test_err(){name="$1"descr="$2"# stdin is the body of the test codewrite_sub_test_lib_test"$@"||return1-_run_sub_test_lib_test_common'!'"$@"+_run_sub_test_lib_test_common-eq1"$@"} run_sub_test_lib_test(){-_run_sub_test_lib_test_common''"$@"+_run_sub_test_lib_test_common-eq0"$@"} run_sub_test_lib_test_err(){-_run_sub_test_lib_test_common'!'"$@"+_run_sub_test_lib_test_common-eq1"$@"} _check_sub_test_lib_test_common(){
Now that we've split up the write_sub_test_lib_test*() and
run_sub_test_lib_test*() functions let's fix those tests in
t0000-basic.sh that were verbosely copy/pasting earlier tests.
That we caught all of them was asserted with a follow-up change that's
not part of this series[1], we might add such a duplication check at
some later time, but for now let's just one-off remove the duplicate
boilerplate.
1. https://lore.kernel.org/git/patch-v3-6.9-bc79b29f3c-20210805T103237Z-avarab@gmail.com/
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/t0000-basic.sh | 228 +++++++++++++----------------------------------
1 file changed, 60 insertions(+), 168 deletions(-)
@@ -226,18 +226,13 @@ test_expect_success 'subtest: --verbose option' '' test_expect_success'subtest: --verbose-only option''-write_and_run_sub_test_lib_test_err\-t2345-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_testt2345-verbose-only-2<<-\EOF+run_sub_test_lib_test_err\+t1234-verbose\+--verbose-only=2&&+check_sub_test_lib_testt1234-verbose<<-\EOF>ok1-passingtest>Z->expectingsuccessof2345.2'\''test with output'\'':echofoo+>expectingsuccessof1234.2'\''test with output'\'':echofoo>foo>ok2-testwithoutput>Z
@@ -250,15 +245,9 @@ test_expect_success 'subtest: --verbose-only option' ' test_expect_success'subtest: skip one with GIT_SKIP_TESTS''(-write_and_run_sub_test_lib_testgit-skip-tests-basic\---skip="git.2"<<-\EOF&&-foriin123-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testgit-skip-tests-basic<<-\EOF+run_sub_test_lib_testfull-pass\+--skip="full.2"&&+check_sub_test_lib_testfull-pass<<-\EOF>ok1-passingtest#1>ok2# skip passing test #2 (GIT_SKIP_TESTS)>ok3-passingtest#3
@@ -293,15 +282,9 @@ test_expect_success 'subtest: skip several with GIT_SKIP_TESTS' ' test_expect_success'subtest: sh pattern skipping with GIT_SKIP_TESTS''(-write_and_run_sub_test_lib_testgit-skip-tests-sh-pattern\---skip="git.[2-5]"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testgit-skip-tests-sh-pattern<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--skip="git.[2-5]"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2# skip passing test #2 (GIT_SKIP_TESTS)>ok3# skip passing test #3 (GIT_SKIP_TESTS)
@@ -316,15 +299,10 @@ test_expect_success 'subtest: sh pattern skipping with GIT_SKIP_TESTS' ' test_expect_success'subtest: skip entire test suite with GIT_SKIP_TESTS''(-write_and_run_sub_test_lib_testgit-skip-tests-entire-suite\---skip="git"<<-\EOF&&-foriin123-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testgit-skip-tests-entire-suite<<-\EOF+GIT_SKIP_TESTS="git"&&exportGIT_SKIP_TESTS&&+run_sub_test_lib_testgit-skip-tests-several\+--skip="git"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>1..0# SKIP skip all tests in gitEOF)
@@ -332,15 +310,10 @@ test_expect_success 'subtest: skip entire test suite with GIT_SKIP_TESTS' ' test_expect_success'subtest: GIT_SKIP_TESTS does not skip unmatched suite''(-write_and_run_sub_test_lib_testgit-skip-tests-unmatched-suite\---skip="notgit"<<-\EOF&&-foriin123-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testgit-skip-tests-unmatched-suite<<-\EOF+GIT_SKIP_TESTS="notgit"&&exportGIT_SKIP_TESTS&&+run_sub_test_lib_testfull-pass\+--skip="notfull"&&+check_sub_test_lib_testfull-pass<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3-passingtest#3
@@ -351,14 +324,8 @@ test_expect_success 'subtest: GIT_SKIP_TESTS does not skip unmatched suite' '' test_expect_success'subtest: --run basic''-write_and_run_sub_test_lib_testrun-basic--run="1,3,5"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-basic<<-\EOF+run_sub_test_lib_testgit-skip-tests-several--run="1,3,5"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2# skip passing test #2 (--run)>ok3-passingtest#3
@@ -371,15 +338,9 @@ test_expect_success 'subtest: --run basic' '' test_expect_success'subtest: --run with a range''-write_and_run_sub_test_lib_testrun-range\---run="1-3"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-range<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="1-3"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3-passingtest#3
@@ -392,15 +353,9 @@ test_expect_success 'subtest: --run with a range' '' test_expect_success'subtest: --run with two ranges''-write_and_run_sub_test_lib_testrun-two-ranges\---run="1-2,5-6"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-two-ranges<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="1-2,5-6"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -413,15 +368,9 @@ test_expect_success 'subtest: --run with two ranges' '' test_expect_success'subtest: --run with a left open range''-write_and_run_sub_test_lib_testrun-left-open-range\---run="-3"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-left-open-range<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="-3"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3-passingtest#3
@@ -434,15 +383,9 @@ test_expect_success 'subtest: --run with a left open range' '' test_expect_success'subtest: --run with a right open range''-write_and_run_sub_test_lib_testrun-right-open-range\---run="4-"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-right-open-range<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="4-"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1# skip passing test #1 (--run)>ok2# skip passing test #2 (--run)>ok3# skip passing test #3 (--run)
@@ -455,15 +398,9 @@ test_expect_success 'subtest: --run with a right open range' '' test_expect_success'subtest: --run with basic negation''-write_and_run_sub_test_lib_testrun-basic-neg\---run="!3"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-basic-neg<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="!3"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -476,15 +413,9 @@ test_expect_success 'subtest: --run with basic negation' '' test_expect_success'subtest: --run with two negations''-write_and_run_sub_test_lib_testrun-two-neg\---run="!3,!6"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-two-neg<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="!3,!6"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -497,15 +428,9 @@ test_expect_success 'subtest: --run with two negations' '' test_expect_success'subtest: --run a range and negation''-write_and_run_sub_test_lib_testrun-range-and-neg\---run="-4,!2"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-range-and-neg<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="-4,!2"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2# skip passing test #2 (--run)>ok3-passingtest#3
@@ -518,15 +443,9 @@ test_expect_success 'subtest: --run a range and negation' '' test_expect_success'subtest: --run range negation''-write_and_run_sub_test_lib_testrun-range-neg\---run="!1-3"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-range-neg<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="!1-3"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1# skip passing test #1 (--run)>ok2# skip passing test #2 (--run)>ok3# skip passing test #3 (--run)
@@ -539,15 +458,9 @@ test_expect_success 'subtest: --run range negation' '' test_expect_success'subtest: --run include, exclude and include''-write_and_run_sub_test_lib_testrun-inc-neg-inc\---run="1-5,!1-3,2"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-inc-neg-inc<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="1-5,!1-3,2"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1# skip passing test #1 (--run)>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -560,15 +473,9 @@ test_expect_success 'subtest: --run include, exclude and include' '' test_expect_success'subtest: --run include, exclude and include, comma separated''-write_and_run_sub_test_lib_testrun-inc-neg-inc-comma\---run=1-5,!1-3,2<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-inc-neg-inc-comma<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run=1-5,!1-3,2&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1# skip passing test #1 (--run)>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -581,15 +488,9 @@ test_expect_success 'subtest: --run include, exclude and include, comma separate' test_expect_success'subtest: --run exclude and include''-write_and_run_sub_test_lib_testrun-neg-inc\---run="!3-,5"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-neg-inc<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="!3-,5"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2-passingtest#2>ok3# skip passing test #3 (--run)
@@ -602,15 +503,9 @@ test_expect_success 'subtest: --run exclude and include' '' test_expect_success'subtest: --run empty selectors''-write_and_run_sub_test_lib_testrun-empty-sel\---run="1,,3,,,5"<<-\EOF&&-foriin123456-do-test_expect_success"passing test #$i""true"-done-test_done-EOF-check_sub_test_lib_testrun-empty-sel<<-\EOF+run_sub_test_lib_testgit-skip-tests-several\+--run="1,,3,,,5"&&+check_sub_test_lib_testgit-skip-tests-several<<-\EOF>ok1-passingtest#1>ok2# skip passing test #2 (--run)>ok3-passingtest#3
@@ -660,12 +555,9 @@ test_expect_success 'subtest: --run keyword selection' '' test_expect_success'subtest: --run invalid range end''-write_and_run_sub_test_lib_test_errrun-inv-range-end\---run="1-z"<<-\EOF&&-test_expect_success"passing test #1""true"-test_done-EOF-check_sub_test_lib_test_errrun-inv-range-end\+run_sub_test_lib_test_errrun-inv-range-start\+--run="1-z"&&+check_sub_test_lib_test_errrun-inv-range-start\<<-\EOF_OUT 3<<-EOF_ERR>FATAL:Unexpectedexitwithcode1EOF_OUT