Skip to content

Commit 56722a0

Browse files
avargitster
authored andcommitted
test-lib tests: assert 1 exit code, not non-zero
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 0445e6f (test-lib: '--run' to run only specific tests, 2014-04-30). Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e07b817 commit 56722a0

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

t/lib-subtest.sh

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ write_sub_test_lib_test () {
1111
}
1212

1313
_run_sub_test_lib_test_common () {
14-
neg="$1" name="$2" # stdin is the body of the test code
15-
shift 2
14+
cmp_op="$1" want_code="$2" name="$3" # stdin is the body of the test code
15+
shift 3
1616

1717
# intercept pseudo-options at the front of the argument list that we
1818
# will not pass to child script
@@ -48,33 +48,30 @@ _run_sub_test_lib_test_common () {
4848
GIT_SKIP_TESTS=$skip &&
4949
export GIT_SKIP_TESTS &&
5050
sane_unset GIT_TEST_FAIL_PREREQS &&
51-
if test -z "$neg"
52-
then
53-
./"$name.sh" "$@" >out 2>err
54-
else
55-
! ./"$name.sh" "$@" >out 2>err
56-
fi
51+
./"$name.sh" "$@" >out 2>err;
52+
ret=$? &&
53+
test "$ret" "$cmp_op" "$want_code"
5754
)
5855
}
5956

6057
write_and_run_sub_test_lib_test () {
6158
name="$1" descr="$2" # stdin is the body of the test code
6259
write_sub_test_lib_test "$@" || return 1
63-
_run_sub_test_lib_test_common '' "$@"
60+
_run_sub_test_lib_test_common -eq 0 "$@"
6461
}
6562

6663
write_and_run_sub_test_lib_test_err () {
6764
name="$1" descr="$2" # stdin is the body of the test code
6865
write_sub_test_lib_test "$@" || return 1
69-
_run_sub_test_lib_test_common '!' "$@"
66+
_run_sub_test_lib_test_common -eq 1 "$@"
7067
}
7168

7269
run_sub_test_lib_test () {
73-
_run_sub_test_lib_test_common '' "$@"
70+
_run_sub_test_lib_test_common -eq 0 "$@"
7471
}
7572

7673
run_sub_test_lib_test_err () {
77-
_run_sub_test_lib_test_common '!' "$@"
74+
_run_sub_test_lib_test_common -eq 1 "$@"
7875
}
7976

8077
_check_sub_test_lib_test_common () {

0 commit comments

Comments
 (0)