@matheusbsbs / matheus-bagliano / commits / ceaa4b3ad7
Fork 0

t: add test_oid option to select hash algorithm

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>

brian m. carlson committed Jul 29, 2020 at 23:14 UTC ceaa4b3ad7f1927fdfa8164e1bfecece4da48329
2 files changed +22 -1
t/t0000-basic.sh
+11
@@ -928,6 +928,17 @@ test_expect_success 'test_oid can look up data for SHA-256' '
928 test "$hexsz" -eq 64
929 '
930
931 +test_expect_success 'test_oid can look up data for a specified algorithm' '
932 + rawsz="$(test_oid --hash=sha1 rawsz)" &&
933 + hexsz="$(test_oid --hash=sha1 hexsz)" &&
934 + test "$rawsz" -eq 20 &&
935 + test "$hexsz" -eq 40 &&
936 + rawsz="$(test_oid --hash=sha256 rawsz)" &&
937 + hexsz="$(test_oid --hash=sha256 hexsz)" &&
938 + test "$rawsz" -eq 32 &&
939 + test "$hexsz" -eq 64
940 +'
941 +
942 test_expect_success 'test_bool_env' '
943 (
944 sane_unset envvar &&
t/test-lib-functions.sh
+11 -1
@@ -1468,7 +1468,17 @@ test_oid_cache () {
1468 # Look up a per-hash value based on a key ($1). The value must have been loaded
1469 # by test_oid_init or test_oid_cache.
1470 test_oid () {
1471 - local var="test_oid_${test_hash_algo}_$1" &&
1471 + local algo="${test_hash_algo}" &&
1472 +
1473 + case "$1" in
1474 + --hash=*)
1475 + algo="${1#--hash=}" &&
1476 + shift;;
1477 + *)
1478 + ;;
1479 + esac &&
1480 +
1481 + local var="test_oid_${algo}_$1" &&
1482
1483 # If the variable is unset, we must be missing an entry for this
1484 # key-hash pair, so exit with an error.