]> asedeno.scripts.mit.edu Git - git.git/blobdiff - t/test-lib.sh
Merge branch 'jn/maint-amend-missing-name' into maint
[git.git] / t / test-lib.sh
index acce3d06a8cba094d6eac88516dc316c8084e736..9bfa14be7f1c3935013d04318eeaecc68b4ef88c 100644 (file)
@@ -366,8 +366,9 @@ test_debug () {
 }
 
 test_run_ () {
-       test_cleanup='eval_ret=$?'
+       test_cleanup=:
        eval >&3 2>&4 "$1"
+       eval_ret=$?
        eval >&3 2>&4 "$test_cleanup"
        return 0
 }
@@ -529,6 +530,22 @@ test_must_fail () {
        test $? -gt 0 -a $? -le 129 -o $? -gt 192
 }
 
+# Similar to test_must_fail, but tolerates success, too.  This is
+# meant to be used in contexts like:
+#
+#      test_expect_success 'some command works without configuration' '
+#              test_might_fail git config --unset all.configuration &&
+#              do something
+#      '
+#
+# Writing "git config --unset all.configuration || :" would be wrong,
+# because we want to notice if it fails due to segv.
+
+test_might_fail () {
+       "$@"
+       test $? -ge 0 -a $? -le 129 -o $? -gt 192
+}
+
 # test_cmp is a helper function to compare actual and expected output.
 # You can use it like:
 #
@@ -567,8 +584,8 @@ test_cmp() {
 # the test to pass.
 
 test_when_finished () {
-       test_cleanup="eval_ret=\$?; { $*
-               } && (exit \"\$eval_ret\"); $test_cleanup"
+       test_cleanup="{ $*
+               } && (exit \"\$eval_ret\"); eval_ret=\$?; $test_cleanup"
 }
 
 # Most tests can use the created repository, but some may need to create more.