Skip to content

Commit 12fe490

Browse files
avargitster
authored andcommitted
test-lib tests: avoid subshell for "test_cmp" for readability
The use of a sub-shell for running the test_cmp of stdout/stderr for the test author was introduced in this form in 565b6fa (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 7b90511 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c3ff7be commit 12fe490

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

t/lib-subtest.sh

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,16 @@ run_sub_test_lib_test_err () {
7979

8080
check_sub_test_lib_test () {
8181
name="$1" # stdin is the expected output from the test
82-
(
83-
cd "$name" &&
84-
test_must_be_empty err &&
85-
sed -e 's/^> //' -e 's/Z$//' >expect &&
86-
test_cmp expect out
87-
)
82+
test_must_be_empty "$name"/err &&
83+
sed -e 's/^> //' -e 's/Z$//' >"$name"/expect &&
84+
test_cmp "$name/"expect "$name"/out
8885
}
8986

9087
check_sub_test_lib_test_err () {
9188
name="$1" # stdin is the expected output from the test
9289
# expected error output is in descriptor 3
93-
(
94-
cd "$name" &&
95-
sed -e 's/^> //' -e 's/Z$//' >expect.out &&
96-
test_cmp expect.out out &&
97-
sed -e 's/^> //' -e 's/Z$//' <&3 >expect.err &&
98-
test_cmp expect.err err
99-
)
90+
sed -e 's/^> //' -e 's/Z$//' >"$name"/expect.out &&
91+
test_cmp "$name"/expect.out "$name"/out &&
92+
sed -e 's/^> //' -e 's/Z$//' <&3 >"$name"/expect.err &&
93+
test_cmp "$name"/expect.err "$name"/err
10094
}

0 commit comments

Comments
 (0)