]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/test-lib-functions.sh
t7800: don't use test_config in a subshell
[thirdparty/git.git] / t / test-lib-functions.sh
index 8f8858a5f0a4f7a705960cef5b5558064a86ea28..0e80f377cec63a74ea357dc881e62b1d66e33d7f 100644 (file)
@@ -201,7 +201,14 @@ test_chmod () {
 
 # Unset a configuration variable, but don't fail if it doesn't exist.
 test_unconfig () {
-       git config --unset-all "$@"
+       config_dir=
+       if test "$1" = -C
+       then
+               shift
+               config_dir=$1
+               shift
+       fi
+       git ${config_dir:+-C "$config_dir"} config --unset-all "$@"
        config_status=$?
        case "$config_status" in
        5) # ok, nothing to unset
@@ -213,8 +220,15 @@ test_unconfig () {
 
 # Set git config, automatically unsetting it after the test is over.
 test_config () {
-       test_when_finished "test_unconfig '$1'" &&
-       git config "$@"
+       config_dir=
+       if test "$1" = -C
+       then
+               shift
+               config_dir=$1
+               shift
+       fi
+       test_when_finished "test_unconfig ${config_dir:+-C '$config_dir'} '$1'" &&
+       git ${config_dir:+-C "$config_dir"} config "$@"
 }
 
 test_config_global () {
@@ -348,11 +362,18 @@ test_declared_prereq () {
        return 1
 }
 
+test_verify_prereq () {
+       test -z "$test_prereq" ||
+       expr >/dev/null "$test_prereq" : '[A-Z0-9_,!]*$' ||
+       error "bug in the test script: '$test_prereq' does not look like a prereq"
+}
+
 test_expect_failure () {
        test_start_
        test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
        test "$#" = 2 ||
        error "bug in the test script: not 2 or 3 parameters to test-expect-failure"
+       test_verify_prereq
        export test_prereq
        if ! test_skip "$@"
        then
@@ -372,6 +393,7 @@ test_expect_success () {
        test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
        test "$#" = 2 ||
        error "bug in the test script: not 2 or 3 parameters to test-expect-success"
+       test_verify_prereq
        export test_prereq
        if ! test_skip "$@"
        then
@@ -400,6 +422,7 @@ test_external () {
        error >&5 "bug in the test script: not 3 or 4 parameters to test_external"
        descr="$1"
        shift
+       test_verify_prereq
        export test_prereq
        if ! test_skip "$descr" "$@"
        then