Skip to content

Commit ceaa4b3

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Reviewed-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent eff45da commit ceaa4b3

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

t/t0000-basic.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,17 @@ test_expect_success 'test_oid can look up data for SHA-256' '
928928
test "$hexsz" -eq 64
929929
'
930930

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+
931942
test_expect_success 'test_bool_env' '
932943
(
933944
sane_unset envvar &&

t/test-lib-functions.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,17 @@ test_oid_cache () {
14681468
# Look up a per-hash value based on a key ($1). The value must have been loaded
14691469
# by test_oid_init or test_oid_cache.
14701470
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" &&
14721482

14731483
# If the variable is unset, we must be missing an entry for this
14741484
# key-hash pair, so exit with an error.

0 commit comments

Comments
 (0)