test-lib tests: refactor common part of check_sub_test_lib_test*()

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 <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Sep 22, 2021 at 13:19 UTC e07b817cfca9d15e6930dc09344846fb5246d4d7
1 file changed +9 -5
t/lib-subtest.sh
+9 -5
@@ -77,18 +77,22 @@ run_sub_test_lib_test_err () {
77 _run_sub_test_lib_test_common '!' "$@"
78 }
79
80 +_check_sub_test_lib_test_common () {
81 + name="$1" &&
82 + sed -e 's/^> //' -e 's/Z$//' >"$name"/expect.out &&
83 + test_cmp "$name"/expect.out "$name"/out
84 +}
85 +
86 check_sub_test_lib_test () {
87 name="$1" # stdin is the expected output from the test
82 - test_must_be_empty "$name"/err &&
83 - sed -e 's/^> //' -e 's/Z$//' >"$name"/expect &&
84 - test_cmp "$name/"expect "$name"/out
88 + _check_sub_test_lib_test_common "$name" &&
89 + test_must_be_empty "$name"/err
90 }
91
92 check_sub_test_lib_test_err () {
93 name="$1" # stdin is the expected output from the test
94 + _check_sub_test_lib_test_common "$name" &&
95 # expected error output is in descriptor 3
90 - sed -e 's/^> //' -e 's/Z$//' >"$name"/expect.out &&
91 - test_cmp "$name"/expect.out "$name"/out &&
96 sed -e 's/^> //' -e 's/Z$//' <&3 >"$name"/expect.err &&
97 test_cmp "$name"/expect.err "$name"/err
98 }