This is the next in the series of improvements to make tests hash-independent. A range-diff is below. Changes from v4: * Add local statements to the &&-chain. * Fix a typo in the local statement. * Add a helpful comment about why test_detect_hash is hard-coded to SHA-1. Changes from v3: * Update t/README to specify new helpers. * Escape "$" in double quotes. * Add documentation comments to test helpers. * Use local instead of underscores in variable names. * Use expr instead of egrep to match hash algorithm names. * Improve clarity of unset variable check in test_oid. * Wrap test_oid_init in a test_expect_success. * Improved && chain handling in test functions. * Add test_detect_hash in test_oid_init. * Clean up extra blank line. * Add patch from Derrick Stolee for t5318, modified slightly. Changes from v2: * Fix a typo in "zero_2". * Provide better matching of expected output. * Add and use test_oid_init instead of filename-based test_oid_cache. * Add test_set_hash. * Provide better error checking in newly added test functions. * Move t0000 constants into the test, removing the separate file. * Switch to using a differently named temporary file in t0027. Changes from v1: * Adopt pure shell approach for helper. * Add tests for the helpers. * Explicitly refer to SHA-256 now that we know it will be NewHash. * Updated t0000 to remove SHA1 prerequisite. * Change name of helper from test_translate to test_oid. * Add helper to cache information in the shell. * Simplified lookup of HEAD in t0002. * Switched to using existing helper function in t0027. * Simplified handling of IDs in t0064. Derrick Stolee (1): t5318: use test_oid for HASH_LEN brian m. carlson (11): t: add test functions to translate hash-related values t0000: use hash translation table t0000: update tests for SHA-256 t0002: abstract away SHA-1 specific constants t0027: make hash size independent t0064: make hash size independent t1006: make hash size independent t1400: switch hard-coded object ID to variable t1405: make hash size independent t1406: make hash-size independent t1407: make hash size independent t/README | 22 ++++ t/oid-info/README | 19 +++ t/oid-info/hash-info | 8 ++ t/oid-info/oid | 29 +++++ t/t0000-basic.sh | 213 ++++++++++++++++++++++----------- t/t0002-gitfile.sh | 27 +++-- t/t0027-auto-crlf.sh | 3 +- t/t0064-sha1-array.sh | 49 ++++---- t/t1006-cat-file.sh | 6 +- t/t1400-update-ref.sh | 2 +- t/t1405-main-ref-store.sh | 4 +- t/t1406-submodule-ref-store.sh | 6 +- t/t1407-worktree-ref-store.sh | 4 +- t/t5318-commit-graph.sh | 5 +- t/test-lib-functions.sh | 69 +++++++++++ 15 files changed, 352 insertions(+), 114 deletions(-) create mode 100644 t/oid-info/README create mode 100644 t/oid-info/hash-info create mode 100644 t/oid-info/oid Range-diff against v4: 1: fd13b542e7 ! 1: 831a0df666 t: add test functions to translate hash-related values @@ -222,6 +222,8 @@ + +# 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' +} + @@ -241,9 +243,9 @@ +# rawsz sha1:20 +# rawsz sha256:32 +test_oid_cache () { -+ local tag reset k v ++ local tag rest k v && + -+ test -n "$test_hash_algo" || test_detect_hash && ++ { test -n "$test_hash_algo" || test_detect_hash; } && + while read tag rest + do + case $tag in @@ -271,7 +273,7 @@ +# 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 var="test_oid_${test_hash_algo}_$1" && + + # If the variable is unset, we must be missing an entry for this + # key-hash pair, so exit with an error. 2: 335c75e1ec = 2: 75eb36456b t0000: use hash translation table 3: 257b458ad9 = 3: d1cebc5dba t0000: update tests for SHA-256 4: 69080d3bfc = 4: a75f4a049e t0002: abstract away SHA-1 specific constants 5: a4297d7ae8 = 5: ab8598048e t0027: make hash size independent 6: 7cf1221274 = 6: ed540a08e8 t0064: make hash size independent 7: 7e5c857c25 = 7: e221995a27 t1006: make hash size independent 8: 9271787d4b = 8: 3a168746ff t1400: switch hard-coded object ID to variable 9: 43bd41156a = 9: 3e55ccdd15 t1405: make hash size independent 10: 875bbd7fc5 = 10: df7d4eb112 t1406: make hash-size independent 11: a9c2d31089 = 11: b1a04c1986 t1407: make hash size independent 12: 10452cc352 = 12: 63d21a1eca t5318: use test_oid for HASH_LEN