diff options
author | Ævar Arnfjörð Bjarmason <avarab@gmail.com> | 2021-09-22 14:19:48 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-09-23 02:22:41 +0300 |
commit | 9f0a45208dbc488da790d0f2ef1491eb2aa858c2 (patch) | |
tree | 6f2e2d8124e4a0d2f5cebe85960016aa21db4e67 /t/lib-subtest.sh | |
parent | 866a3014de34d415300bdd488f2ccd7ae5fb2d65 (diff) |
test-lib tests: split up "write and run" into two functions
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 <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/lib-subtest.sh')
-rw-r--r-- | t/lib-subtest.sh | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/t/lib-subtest.sh b/t/lib-subtest.sh index 3cfe09911a..21fa570d0b 100644 --- a/t/lib-subtest.sh +++ b/t/lib-subtest.sh @@ -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 (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/$name.sh" +} + _run_sub_test_lib_test_common () { neg="$1" name="$2" descr="$3" # stdin is the body of the test code shift 3 @@ -18,25 +34,15 @@ _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 && - cd "$name" && - write_script "$name.sh" "$TEST_SHELL_PATH" <<-EOF && - test_description='$descr (run in sub test-lib) - - This is run in a sub test-lib so that we do not get incorrect - passing metrics - ' - # Point to the t/test-lib.sh, which isn't in ../ as usual - . "\$TEST_DIRECTORY"/test-lib.sh - EOF - cat >>"$name.sh" && export TEST_DIRECTORY && # The child test re-sources GIT-BUILD-OPTIONS and may thus # override the test output directory. We thus pass it as an @@ -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 "$@" || return 1 + _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 "$@" || return 1 + _run_sub_test_lib_test_common '!' "$@" +} + run_sub_test_lib_test () { _run_sub_test_lib_test_common '' "$@" } |