summaryrefslogtreecommitdiff
path: root/t/lib-subtest.sh
diff options
context:
space:
mode:
Diffstat (limited to 't/lib-subtest.sh')
-rw-r--r--t/lib-subtest.sh42
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 '' "$@"
}