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
0445e6f0a1 (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>
This commit is contained in:
Ævar Arnfjörð Bjarmason
2021-09-22 13:19:52 +02:00
committed by Junio C Hamano
parent e07b817cfc
commit 56722a0635

View File

@ -11,8 +11,8 @@ write_sub_test_lib_test () {
} }
_run_sub_test_lib_test_common () { _run_sub_test_lib_test_common () {
neg="$1" name="$2" # stdin is the body of the test code cmp_op="$1" want_code="$2" name="$3" # stdin is the body of the test code
shift 2 shift 3
# intercept pseudo-options at the front of the argument list that we # intercept pseudo-options at the front of the argument list that we
# will not pass to child script # will not pass to child script
@ -48,33 +48,30 @@ _run_sub_test_lib_test_common () {
GIT_SKIP_TESTS=$skip && GIT_SKIP_TESTS=$skip &&
export GIT_SKIP_TESTS && export GIT_SKIP_TESTS &&
sane_unset GIT_TEST_FAIL_PREREQS && sane_unset GIT_TEST_FAIL_PREREQS &&
if test -z "$neg" ./"$name.sh" "$@" >out 2>err;
then ret=$? &&
./"$name.sh" "$@" >out 2>err test "$ret" "$cmp_op" "$want_code"
else
! ./"$name.sh" "$@" >out 2>err
fi
) )
} }
write_and_run_sub_test_lib_test () { write_and_run_sub_test_lib_test () {
name="$1" descr="$2" # stdin is the body of the test code name="$1" descr="$2" # stdin is the body of the test code
write_sub_test_lib_test "$@" || return 1 write_sub_test_lib_test "$@" || return 1
_run_sub_test_lib_test_common '' "$@" _run_sub_test_lib_test_common -eq 0 "$@"
} }
write_and_run_sub_test_lib_test_err () { write_and_run_sub_test_lib_test_err () {
name="$1" descr="$2" # stdin is the body of the test code name="$1" descr="$2" # stdin is the body of the test code
write_sub_test_lib_test "$@" || return 1 write_sub_test_lib_test "$@" || return 1
_run_sub_test_lib_test_common '!' "$@" _run_sub_test_lib_test_common -eq 1 "$@"
} }
run_sub_test_lib_test () { run_sub_test_lib_test () {
_run_sub_test_lib_test_common '' "$@" _run_sub_test_lib_test_common -eq 0 "$@"
} }
run_sub_test_lib_test_err () { run_sub_test_lib_test_err () {
_run_sub_test_lib_test_common '!' "$@" _run_sub_test_lib_test_common -eq 1 "$@"
} }
_check_sub_test_lib_test_common () { _check_sub_test_lib_test_common () {