]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/test-lib-functions.sh
Merge branch 'jc/add-i-use-builtin-experimental'
[thirdparty/git.git] / t / test-lib-functions.sh
index b791933ffd2eadb6a00a9ba2fc5344b457d6f040..f9904066feed6d609d8d568dbd16080957ed7aa3 100644 (file)
@@ -820,7 +820,7 @@ test_must_fail_acceptable () {
        fi
 
        case "$1" in
-       git|__git*|test-tool|test-svn-fe|test_terminal)
+       git|__git*|test-tool|test_terminal)
                return 0
                ;;
        *)
@@ -952,7 +952,13 @@ test_expect_code () {
 # - not all diff versions understand "-u"
 
 test_cmp() {
-       eval "$GIT_TEST_CMP" '"$@"'
+       test $# -eq 2 || BUG "test_cmp requires two arguments"
+       if ! eval "$GIT_TEST_CMP" '"$@"'
+       then
+               test "x$1" = x- || test -e "$1" || BUG "test_cmp '$1' missing"
+               test "x$2" = x- || test -e "$2" || BUG "test_cmp '$2' missing"
+               return 1
+       fi
 }
 
 # Check that the given config key has the expected value.
@@ -981,7 +987,13 @@ test_cmp_config() {
 # test_cmp_bin - helper to compare binary files
 
 test_cmp_bin() {
-       cmp "$@"
+       test $# -eq 2 || BUG "test_cmp_bin requires two arguments"
+       if ! cmp "$@"
+       then
+               test "x$1" = x- || test -e "$1" || BUG "test_cmp_bin '$1' missing"
+               test "x$2" = x- || test -e "$2" || BUG "test_cmp_bin '$2' missing"
+               return 1
+       fi
 }
 
 # Use this instead of test_cmp to compare files that contain expected and
@@ -1464,9 +1476,7 @@ test_set_hash () {
 
 # Detect the hash algorithm in use.
 test_detect_hash () {
-       # Currently we only support SHA-1, but in the future this function will
-       # actually detect the algorithm in use.
-       test_hash_algo='sha1'
+       test_hash_algo="${GIT_TEST_DEFAULT_HASH:-sha1}"
 }
 
 # Load common hash metadata and common placeholder object IDs for use with
@@ -1515,7 +1525,17 @@ test_oid_cache () {
 # Look up a per-hash value based on a key ($1).  The value must have been loaded
 # by test_oid_init or test_oid_cache.
 test_oid () {
-       local var="test_oid_${test_hash_algo}_$1" &&
+       local algo="${test_hash_algo}" &&
+
+       case "$1" in
+       --hash=*)
+               algo="${1#--hash=}" &&
+               shift;;
+       *)
+               ;;
+       esac &&
+
+       local var="test_oid_${algo}_$1" &&
 
        # If the variable is unset, we must be missing an entry for this
        # key-hash pair, so exit with an error.