From: Junio C Hamano Date: Wed, 10 Oct 2018 03:37:16 +0000 (+0900) Subject: Merge branch 'bc/hash-independent-tests' X-Git-Tag: v2.20.0-rc0~198 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/d555663f16fb1bc28ebc44a4e78ff4e277c3b69e?ds=inline;hp=-c Merge branch 'bc/hash-independent-tests' Various tests have been updated to make it easier to swap the hash function used for object identification. * bc/hash-independent-tests: t5318: use test_oid for HASH_LEN t1407: make hash size independent t1406: make hash-size independent t1405: make hash size independent t1400: switch hard-coded object ID to variable t1006: make hash size independent t0064: make hash size independent t0002: abstract away SHA-1 specific constants t0000: update tests for SHA-256 t0000: use hash translation table t: add test functions to translate hash-related values --- d555663f16fb1bc28ebc44a4e78ff4e277c3b69e diff --combined t/README index 3ea6c85460,eed574dd9b..5e48a043ce --- a/t/README +++ b/t/README @@@ -319,14 -319,6 +319,14 @@@ GIT_TEST_OE_DELTA_SIZE= exercises th path where deltas larger than this limit require extra memory allocation for bookkeeping. +GIT_TEST_VALIDATE_INDEX_CACHE_ENTRIES= checks that cache-tree +records are valid when the index is written out or after a merge. This +is mostly to catch missing invalidation. Default is true. + +GIT_TEST_COMMIT_GRAPH=, when true, forces the commit-graph to +be written after every 'git commit' command, and overrides the +'core.commitGraph' setting to true. + Naming Tests ------------ @@@ -814,6 -806,28 +814,28 @@@ library for your script to use the symbolic link in the file system and a part that does; then only the latter part need be protected by a SYMLINKS prerequisite (see below). + - test_oid_init + + This function loads facts and useful object IDs related to the hash + algorithm(s) in use from the files in t/oid-info. + + - test_oid_cache + + This function reads per-hash algorithm information from standard + input (usually a heredoc) in the format described in + t/oid-info/README. This is useful for test-specific values, such as + object IDs, which must vary based on the hash algorithm. + + Certain fixed values, such as hash sizes and common placeholder + object IDs, can be loaded with test_oid_init (described above). + + - test_oid + + This function looks up a value for the hash algorithm in use, based + on the key given. The value must have been loaded using + test_oid_init or test_oid_cache. Providing an unknown key is an + error. + Prerequisites ------------- diff --combined t/t1400-update-ref.sh index 02493f14ba,6072650686..663f17c5fe --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@@ -346,7 -346,7 +346,7 @@@ test_expect_success "verifying $m's lo git update-ref $m $D cat >.git/logs/$m < 1117150320 -0500 + $Z $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500 $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500 @@@ -807,37 -807,6 +807,37 @@@ test_expect_success 'stdin delete symre test_cmp expect actual ' +test_expect_success 'stdin update symref works flag --no-deref' ' + git symbolic-ref TESTSYMREFONE $b && + git symbolic-ref TESTSYMREFTWO $b && + cat >stdin <<-EOF && + update TESTSYMREFONE $a $b + update TESTSYMREFTWO $a $b + EOF + git update-ref --no-deref --stdin expect && + git rev-parse $a $a >actual && + test_cmp expect actual && + git rev-parse $m~1 >expect && + git rev-parse $b >actual && + test_cmp expect actual +' + +test_expect_success 'stdin delete symref works flag --no-deref' ' + git symbolic-ref TESTSYMREFONE $b && + git symbolic-ref TESTSYMREFTWO $b && + cat >stdin <<-EOF && + delete TESTSYMREFONE $b + delete TESTSYMREFTWO $b + EOF + git update-ref --no-deref --stdin expect && + git rev-parse $b >actual && + test_cmp expect actual +' + test_expect_success 'stdin delete ref works with right old value' ' echo "delete $b $m~1" >stdin && git update-ref --stdin /dev/null + then + error 'bug in the test script: bad hash algorithm' + fi && + eval "test_oid_${k}_$tag=\"\$v\"" + done + } + + # 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" && + + # If the variable is unset, we must be missing an entry for this + # key-hash pair, so exit with an error. + if eval "test -z \"\${$var+set}\"" + then + error "bug in the test script: undefined key '$1'" >&2 + fi && + eval "printf '%s' \"\${$var}\"" + }