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>
This commit is contained in:
brian m. carlson 2020-07-29 23:14:23 +00:00 коммит произвёл Junio C Hamano
Родитель eff45daab8
Коммит ceaa4b3ad7
2 изменённых файлов: 22 добавлений и 1 удалений

Просмотреть файл

@ -928,6 +928,17 @@ test_expect_success 'test_oid can look up data for SHA-256' '
test "$hexsz" -eq 64 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' ' test_expect_success 'test_bool_env' '
( (
sane_unset envvar && sane_unset envvar &&

Просмотреть файл

@ -1468,7 +1468,17 @@ test_oid_cache () {
# Look up a per-hash value based on a key ($1). The value must have been loaded # 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. # by test_oid_init or test_oid_cache.
test_oid () { 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 # If the variable is unset, we must be missing an entry for this
# key-hash pair, so exit with an error. # key-hash pair, so exit with an error.