Skip to content

Commit 1080be2

Browse files
committed
Merge branch 'jk/test-must-fail-missing'
* jk/test-must-fail-missing: tests: make test_might_fail fail on missing commands tests: make test_might_fail more verbose tests: make test_must_fail fail on missing commands tests: make test_must_fail more verbose
2 parents 1d86cb8 + d0b8a61 commit 1080be2

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

t/test-lib.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,18 @@ test_path_is_missing () {
620620

621621
test_must_fail () {
622622
"$@"
623-
test $? -gt 0 -a $? -le 129 -o $? -gt 192
623+
exit_code=$?
624+
if test $exit_code = 0; then
625+
echo >&2 "test_must_fail: command succeeded: $*"
626+
return 1
627+
elif test $exit_code -gt 129 -a $exit_code -le 192; then
628+
echo >&2 "test_must_fail: died by signal: $*"
629+
return 1
630+
elif test $exit_code = 127; then
631+
echo >&2 "test_must_fail: command not found: $*"
632+
return 1
633+
fi
634+
return 0
624635
}
625636

626637
# Similar to test_must_fail, but tolerates success, too. This is
@@ -636,7 +647,15 @@ test_must_fail () {
636647

637648
test_might_fail () {
638649
"$@"
639-
test $? -ge 0 -a $? -le 129 -o $? -gt 192
650+
exit_code=$?
651+
if test $exit_code -gt 129 -a $exit_code -le 192; then
652+
echo >&2 "test_might_fail: died by signal: $*"
653+
return 1
654+
elif test $exit_code = 127; then
655+
echo >&2 "test_might_fail: command not found: $*"
656+
return 1
657+
fi
658+
return 0
640659
}
641660

642661
# test_cmp is a helper function to compare actual and expected output.

0 commit comments

Comments
 (0)