]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t: add test_oid option to select hash algorithm
authorbrian m. carlson <sandals@crustytoothpaste.net>
Wed, 29 Jul 2020 23:14:23 +0000 (23:14 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 30 Jul 2020 16:16:49 +0000 (09:16 -0700)
In some tests, we have data files which are written with a particular
hash algorithm. Instead of keeping two copies of the test files, we can
keep one, and translate the value on the fly.

In order to do so, we'll need to read both the source algorithm and the
current algorithm, so add an optional flag to the test_oid helper that
lets us look up a value for a specified hash algorithm. This should
not cause any conflicts with existing tests, since key arguments to
test_oid are allowed to contains only shell identifier characters.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Reviewed-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t0000-basic.sh
t/test-lib-functions.sh

index 2ff176cd5d954cb1c83f062adbdb28a7e14d2668..2599d026a220d545a0617a80687c2e301073e583 100755 (executable)
@@ -928,6 +928,17 @@ test_expect_success 'test_oid can look up data for SHA-256' '
        test "$hexsz" -eq 64
 '
 
+test_expect_success 'test_oid can look up data for a specified algorithm' '
+       rawsz="$(test_oid --hash=sha1 rawsz)" &&
+       hexsz="$(test_oid --hash=sha1 hexsz)" &&
+       test "$rawsz" -eq 20 &&
+       test "$hexsz" -eq 40 &&
+       rawsz="$(test_oid --hash=sha256 rawsz)" &&
+       hexsz="$(test_oid --hash=sha256 hexsz)" &&
+       test "$rawsz" -eq 32 &&
+       test "$hexsz" -eq 64
+'
+
 test_expect_success 'test_bool_env' '
        (
                sane_unset envvar &&
index 3103be8a32393f736481139dd70793ac4e4d97b7..2608e80f111e361da0c4f82b3f091f262115dc0a 100644 (file)
@@ -1468,7 +1468,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.