Skip to content
Snippets Groups Projects
Commit 9472b132 authored by Junio C Hamano's avatar Junio C Hamano
Browse files

Merge branch 'bc/hash-independent-tests'

Many tests hardcode the raw object names, which would change once
we migrate away from SHA-1.  While some of them must test against
exact object names, most of them do not have to use hardcoded
constants in the test.  The latter kind of tests have been updated
to test the moral equivalent of the original without hardcoding the
actual object names.

* bc/hash-independent-tests: (28 commits)
  t5300: abstract away SHA-1-specific constants
  t4208: abstract away SHA-1-specific constants
  t4045: abstract away SHA-1-specific constants
  t4042: abstract away SHA-1-specific constants
  t4205: sort log output in a hash-independent way
  t/lib-diff-alternative: abstract away SHA-1-specific constants
  t4030: abstract away SHA-1-specific constants
  t4029: abstract away SHA-1-specific constants
  t4029: fix test indentation
  t4022: abstract away SHA-1-specific constants
  t4020: abstract away SHA-1-specific constants
  t4014: abstract away SHA-1-specific constants
  t4008: abstract away SHA-1-specific constants
  t4007: abstract away SHA-1-specific constants
  t3905: abstract away SHA-1-specific constants
  t3702: abstract away SHA-1-specific constants
  t3103: abstract away SHA-1-specific constants
  t2203: abstract away SHA-1-specific constants
  t: skip pack tests if not using SHA-1
  t4044: skip test if not using SHA-1
  ...
parents d89f1248 eea253bf
No related branches found
No related tags found
No related merge requests found
Showing
with 63 additions and 53 deletions
:
 
sanitize_diff_raw='/^:/s/ '"\($_x40\)"' '"\($_x40\)"' \([A-Z]\)[0-9]* / \1 \2 \3# /'
sanitize_diff_raw='/^:/s/ '"\($OID_REGEX\)"' '"\($OID_REGEX\)"' \([A-Z]\)[0-9]* / \1 \2 \3# /'
compare_diff_raw () {
# When heuristics are improved, the score numbers would change.
# Ignore them while comparing.
Loading
Loading
@@ -12,7 +12,7 @@ compare_diff_raw () {
test_cmp .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2
}
 
sanitize_diff_raw_z='/^:/s/ '"$_x40"' '"$_x40"' \([A-Z]\)[0-9]*$/ X X \1#/'
sanitize_diff_raw_z='/^:/s/ '"$OID_REGEX"' '"$OID_REGEX"' \([A-Z]\)[0-9]*$/ X X \1#/'
compare_diff_raw_z () {
# When heuristics are improved, the score numbers would change.
# Ignore them while comparing.
Loading
Loading
Loading
Loading
@@ -59,9 +59,11 @@ int main(int argc, char **argv)
}
EOF
 
cat >expect <<\EOF
file1=$(git rev-parse --short $(git hash-object file1))
file2=$(git rev-parse --short $(git hash-object file2))
cat >expect <<EOF
diff --git a/file1 b/file2
index 6faa5a3..e3af329 100644
index $file1..$file2 100644
--- a/file1
+++ b/file2
@@ -1,26 +1,25 @@
Loading
Loading
@@ -136,9 +138,11 @@ e
f
EOF
 
cat >expect <<\EOF
uniq1=$(git rev-parse --short $(git hash-object uniq1))
uniq2=$(git rev-parse --short $(git hash-object uniq2))
cat >expect <<EOF
diff --git a/uniq1 b/uniq2
index b414108..0fdf397 100644
index $uniq1..$uniq2 100644
--- a/uniq1
+++ b/uniq2
@@ -1,6 +1,6 @@
Loading
Loading
Loading
Loading
@@ -839,7 +839,7 @@ test_expect_success 'writing tree out with git write-tree' '
'
 
# we know the shape and contents of the tree and know the object ID for it.
test_expect_success 'validate object ID of a known tree' '
test_expect_success SHA1 'validate object ID of a known tree' '
test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a
'
 
Loading
Loading
@@ -882,7 +882,7 @@ test_expect_success 'showing stage with git ls-files --stage' '
git ls-files --stage >current
'
 
test_expect_success 'validate git ls-files output for a known tree' '
test_expect_success SHA1 'validate git ls-files output for a known tree' '
cat >expected <<-\EOF &&
100644 f87290f8eb2cbbea7857214459a0739927eab154 0 path0
120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0 path0sym
Loading
Loading
@@ -900,7 +900,7 @@ test_expect_success 'writing tree out with git write-tree' '
tree=$(git write-tree)
'
 
test_expect_success 'validate object ID for a known tree' '
test_expect_success SHA1 'validate object ID for a known tree' '
test "$tree" = 087704a96baf1c2d1c869a8b084481e121c88b5b
'
 
Loading
Loading
@@ -908,7 +908,7 @@ test_expect_success 'showing tree with git ls-tree' '
git ls-tree $tree >current
'
 
test_expect_success 'git ls-tree output for a known tree' '
test_expect_success SHA1 'git ls-tree output for a known tree' '
cat >expected <<-\EOF &&
100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
Loading
Loading
@@ -924,7 +924,7 @@ test_expect_success 'showing tree with git ls-tree -r' '
git ls-tree -r $tree >current
'
 
test_expect_success 'git ls-tree -r output for a known tree' '
test_expect_success SHA1 'git ls-tree -r output for a known tree' '
cat >expected <<-\EOF &&
100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
Loading
Loading
@@ -943,7 +943,7 @@ test_expect_success 'showing tree with git ls-tree -r -t' '
git ls-tree -r -t $tree >current
'
 
test_expect_success 'git ls-tree -r output for a known tree' '
test_expect_success SHA1 'git ls-tree -r output for a known tree' '
cat >expected <<-\EOF &&
100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
Loading
Loading
@@ -964,7 +964,7 @@ test_expect_success 'writing partial tree out with git write-tree --prefix' '
ptree=$(git write-tree --prefix=path3)
'
 
test_expect_success 'validate object ID for a known tree' '
test_expect_success SHA1 'validate object ID for a known tree' '
test "$ptree" = 21ae8269cacbe57ae09138dcc3a2887f904d02b3
'
 
Loading
Loading
@@ -972,7 +972,7 @@ test_expect_success 'writing partial tree out with git write-tree --prefix' '
ptree=$(git write-tree --prefix=path3/subp3)
'
 
test_expect_success 'validate object ID for a known tree' '
test_expect_success SHA1 'validate object ID for a known tree' '
test "$ptree" = 3c5e5399f3a333eddecce7a9b9465b63f65f51e2
'
 
Loading
Loading
@@ -1006,7 +1006,7 @@ test_expect_success 'git read-tree followed by write-tree should be idempotent'
test "$newtree" = "$tree"
'
 
test_expect_success 'validate git diff-files output for a know cache/work tree state' '
test_expect_success SHA1 'validate git diff-files output for a know cache/work tree state' '
cat >expected <<\EOF &&
:100644 100644 f87290f8eb2cbbea7857214459a0739927eab154 0000000000000000000000000000000000000000 M path0
:120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0000000000000000000000000000000000000000 M path0sym
Loading
Loading
@@ -1033,21 +1033,21 @@ test_expect_success 'no diff after checkout and git update-index --refresh' '
################################################################
P=087704a96baf1c2d1c869a8b084481e121c88b5b
 
test_expect_success 'git commit-tree records the correct tree in a commit' '
test_expect_success SHA1 'git commit-tree records the correct tree in a commit' '
commit0=$(echo NO | git commit-tree $P) &&
tree=$(git show --pretty=raw $commit0 |
sed -n -e "s/^tree //p" -e "/^author /q") &&
test "z$tree" = "z$P"
'
 
test_expect_success 'git commit-tree records the correct parent in a commit' '
test_expect_success SHA1 'git commit-tree records the correct parent in a commit' '
commit1=$(echo NO | git commit-tree $P -p $commit0) &&
parent=$(git show --pretty=raw $commit1 |
sed -n -e "s/^parent //p" -e "/^author /q") &&
test "z$commit0" = "z$parent"
'
 
test_expect_success 'git commit-tree omits duplicated parent in a commit' '
test_expect_success SHA1 'git commit-tree omits duplicated parent in a commit' '
commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
parent=$(git show --pretty=raw $commit2 |
sed -n -e "s/^parent //p" -e "/^author /q" |
Loading
Loading
Loading
Loading
@@ -9,7 +9,7 @@ cache-tree extension.
 
cmp_cache_tree () {
test-tool dump-cache-tree | sed -e '/#(ref)/d' >actual &&
sed "s/$_x40/SHA/" <actual >filtered &&
sed "s/$OID_REGEX/SHA/" <actual >filtered &&
test_cmp "$1" filtered
}
 
Loading
Loading
Loading
Loading
@@ -128,7 +128,7 @@ cat >expected <<\EOF
EOF
 
check_result () {
git ls-files --stage | sed -e 's/ '"$_x40"' / X /' >current &&
git ls-files --stage | sed -e 's/ '"$OID_REGEX"' / X /' >current &&
test_cmp expected current
}
 
Loading
Loading
Loading
Loading
@@ -30,7 +30,7 @@ read_tree_twoway () {
compare_change () {
sed -n >current \
-e '/^--- /d; /^+++ /d; /^@@ /d;' \
-e 's/^\([-+][0-7][0-7][0-7][0-7][0-7][0-7]\) '"$_x40"' /\1 X /p' \
-e 's/^\([-+][0-7][0-7][0-7][0-7][0-7][0-7]\) '"$OID_REGEX"' /\1 X /p' \
"$1"
test_cmp expected current
}
Loading
Loading
Loading
Loading
@@ -16,7 +16,7 @@ compare_change () {
-e '1{/^diff --git /d;}' \
-e '2{/^index /d;}' \
-e '/^--- /d; /^+++ /d; /^@@ /d;' \
-e 's/^\(.[0-7][0-7][0-7][0-7][0-7][0-7]\) '"$_x40"' /\1 X /' "$1"
-e 's/^\(.[0-7][0-7][0-7][0-7][0-7][0-7]\) '"$OID_REGEX"' /\1 X /' "$1"
test_cmp expected current
}
 
Loading
Loading
Loading
Loading
@@ -236,8 +236,8 @@ test_expect_success "--batch-check for an empty line" '
'
 
test_expect_success 'empty --batch-check notices missing object' '
echo "$_z40 missing" >expect &&
echo "$_z40" | git cat-file --batch-check="" >actual &&
echo "$ZERO_OID missing" >expect &&
echo "$ZERO_OID" | git cat-file --batch-check="" >actual &&
test_cmp expect actual
'
 
Loading
Loading
@@ -294,8 +294,8 @@ test_expect_success 'setup blobs which are likely to delta' '
 
test_expect_success 'confirm that neither loose blob is a delta' '
cat >expect <<-EOF &&
$_z40
$_z40
$ZERO_OID
$ZERO_OID
EOF
git cat-file --batch-check="%(deltabase)" <blobs >actual &&
test_cmp expect actual
Loading
Loading
Loading
Loading
@@ -9,13 +9,13 @@ echo_without_newline() {
}
 
test_blob_does_not_exist() {
test_expect_success 'blob does not exist in database' "
test_expect_success SHA1 'blob does not exist in database' "
test_must_fail git cat-file blob $1
"
}
 
test_blob_exists() {
test_expect_success 'blob exists in database' "
test_expect_success SHA1 'blob exists in database' "
git cat-file blob $1
"
}
Loading
Loading
@@ -73,19 +73,19 @@ test_expect_success "Can't use --path with --no-filters" '
 
push_repo
 
test_expect_success 'hash a file' '
test_expect_success SHA1 'hash a file' '
test $hello_sha1 = $(git hash-object hello)
'
 
test_blob_does_not_exist $hello_sha1
 
test_expect_success 'hash from stdin' '
test_expect_success SHA1 'hash from stdin' '
test $example_sha1 = $(git hash-object --stdin < example)
'
 
test_blob_does_not_exist $example_sha1
 
test_expect_success 'hash a file and write to database' '
test_expect_success SHA1 'hash a file and write to database' '
test $hello_sha1 = $(git hash-object -w hello)
'
 
Loading
Loading
@@ -161,7 +161,7 @@ pop_repo
for args in "-w --stdin" "--stdin -w"; do
push_repo
 
test_expect_success "hash from stdin and write to database ($args)" '
test_expect_success SHA1 "hash from stdin and write to database ($args)" '
test $example_sha1 = $(git hash-object $args < example)
'
 
Loading
Loading
@@ -176,14 +176,14 @@ example"
sha1s="$hello_sha1
$example_sha1"
 
test_expect_success "hash two files with names on stdin" '
test_expect_success SHA1 "hash two files with names on stdin" '
test "$sha1s" = "$(echo_without_newline "$filenames" | git hash-object --stdin-paths)"
'
 
for args in "-w --stdin-paths" "--stdin-paths -w"; do
push_repo
 
test_expect_success "hash two files with names on stdin and write to database ($args)" '
test_expect_success SHA1 "hash two files with names on stdin and write to database ($args)" '
test "$sha1s" = "$(echo_without_newline "$filenames" | git hash-object $args)"
'
 
Loading
Loading
Loading
Loading
@@ -32,7 +32,7 @@ settree () {
 
checkindex () {
git ls-files -s |
sed "s|^[0-7][0-7]* $_x40 \([0-3]\) |\1 |" >current &&
sed "s|^[0-7][0-7]* $OID_REGEX \([0-3]\) |\1 |" >current &&
cat >expect &&
test_cmp expect current
}
Loading
Loading
Loading
Loading
@@ -6,7 +6,7 @@
test_description='Test git update-ref and basic ref logging'
. ./test-lib.sh
 
Z=$_z40
Z=$ZERO_OID
 
m=refs/heads/master
n_dir=refs/heads/gu
Loading
Loading
Loading
Loading
@@ -50,13 +50,13 @@ test_expect_success 'create_symref(FOO, refs/heads/master)' '
'
 
test_expect_success 'for_each_reflog()' '
echo $_z40 > .git/logs/PSEUDO-MAIN &&
echo $ZERO_OID > .git/logs/PSEUDO-MAIN &&
mkdir -p .git/logs/refs/bisect &&
echo $_z40 > .git/logs/refs/bisect/random &&
echo $ZERO_OID > .git/logs/refs/bisect/random &&
 
echo $_z40 > .git/worktrees/wt/logs/PSEUDO-WT &&
echo $ZERO_OID > .git/worktrees/wt/logs/PSEUDO-WT &&
mkdir -p .git/worktrees/wt/logs/refs/bisect &&
echo $_z40 > .git/worktrees/wt/logs/refs/bisect/wt-random &&
echo $ZERO_OID > .git/worktrees/wt/logs/refs/bisect/wt-random &&
 
$RWT for-each-reflog | cut -c 42- | sort >actual &&
cat >expected <<-\EOF &&
Loading
Loading
Loading
Loading
@@ -713,7 +713,7 @@ test_expect_success 'fsck notices dangling objects' '
 
test_expect_success 'fsck $name notices bogus $name' '
test_must_fail git fsck bogus &&
test_must_fail git fsck $_z40
test_must_fail git fsck $ZERO_OID
'
 
test_expect_success 'bogus head does not fallback to all heads' '
Loading
Loading
@@ -723,7 +723,7 @@ test_expect_success 'bogus head does not fallback to all heads' '
blob=$(git rev-parse :foo) &&
test_when_finished "git rm --cached foo" &&
remove_object $blob &&
test_must_fail git fsck $_z40 >out 2>&1 &&
test_must_fail git fsck $ZERO_OID >out 2>&1 &&
! grep $blob out
'
 
Loading
Loading
Loading
Loading
@@ -238,10 +238,10 @@ test_expect_success '_gently() groks relative GIT_DIR & GIT_WORK_TREE' '
 
test_expect_success 'diff-index respects work tree under .git dir' '
cat >diff-index-cached.expected <<-EOF &&
:000000 100644 $_z40 $EMPTY_BLOB A sub/dir/tracked
:000000 100644 $ZERO_OID $EMPTY_BLOB A sub/dir/tracked
EOF
cat >diff-index.expected <<-EOF &&
:000000 100644 $_z40 $_z40 A sub/dir/tracked
:000000 100644 $ZERO_OID $ZERO_OID A sub/dir/tracked
EOF
 
(
Loading
Loading
@@ -257,7 +257,7 @@ test_expect_success 'diff-index respects work tree under .git dir' '
 
test_expect_success 'diff-files respects work tree under .git dir' '
cat >diff-files.expected <<-EOF &&
:100644 100644 $EMPTY_BLOB $_z40 M sub/dir/tracked
:100644 100644 $EMPTY_BLOB $ZERO_OID M sub/dir/tracked
EOF
 
(
Loading
Loading
Loading
Loading
@@ -22,6 +22,12 @@ one tagged as v1.0.0. They all have one regular file each.
 
. ./test-lib.sh
 
if ! test_have_prereq SHA1
then
skip_all='not using SHA-1 for objects'
test_done
fi
test_expect_success 'blob and tree' '
test_tick &&
(
Loading
Loading
Loading
Loading
@@ -4,7 +4,7 @@ test_description='test handling of bogus index entries'
. ./test-lib.sh
 
test_expect_success 'create tree with null sha1' '
tree=$(printf "160000 commit $_z40\\tbroken\\n" | git mktree)
tree=$(printf "160000 commit $ZERO_OID\\tbroken\\n" | git mktree)
'
 
test_expect_success 'read-tree refuses to read null sha1' '
Loading
Loading
Loading
Loading
@@ -426,7 +426,7 @@ test_expect_success 'writing split index with null sha1 does not write cache tre
git commit -m "commit" &&
{
git ls-tree HEAD &&
printf "160000 commit $_z40\\tbroken\\n"
printf "160000 commit $ZERO_OID\\tbroken\\n"
} >broken-tree &&
echo "add broken entry" >msg &&
 
Loading
Loading
Loading
Loading
@@ -15,7 +15,7 @@ test_expect_success 'checkout should not start branch from a tree' '
'
 
test_expect_success 'checkout master from invalid HEAD' '
echo $_z40 >.git/HEAD &&
echo $ZERO_OID >.git/HEAD &&
git checkout master --
'
 
Loading
Loading
Loading
Loading
@@ -477,7 +477,7 @@ post_checkout_hook () {
test_expect_success '"add" invokes post-checkout hook (branch)' '
post_checkout_hook &&
{
echo $_z40 $(git rev-parse HEAD) 1 &&
echo $ZERO_OID $(git rev-parse HEAD) 1 &&
echo $(pwd)/.git/worktrees/gumby &&
echo $(pwd)/gumby
} >hook.expect &&
Loading
Loading
@@ -488,7 +488,7 @@ test_expect_success '"add" invokes post-checkout hook (branch)' '
test_expect_success '"add" invokes post-checkout hook (detached)' '
post_checkout_hook &&
{
echo $_z40 $(git rev-parse HEAD) 1 &&
echo $ZERO_OID $(git rev-parse HEAD) 1 &&
echo $(pwd)/.git/worktrees/grumpy &&
echo $(pwd)/grumpy
} >hook.expect &&
Loading
Loading
@@ -506,7 +506,7 @@ test_expect_success '"add --no-checkout" suppresses post-checkout hook' '
test_expect_success '"add" in other worktree invokes post-checkout hook' '
post_checkout_hook &&
{
echo $_z40 $(git rev-parse HEAD) 1 &&
echo $ZERO_OID $(git rev-parse HEAD) 1 &&
echo $(pwd)/.git/worktrees/guppy &&
echo $(pwd)/guppy
} >hook.expect &&
Loading
Loading
@@ -518,7 +518,7 @@ test_expect_success '"add" in bare repo invokes post-checkout hook' '
rm -rf bare &&
git clone --bare . bare &&
{
echo $_z40 $(git --git-dir=bare rev-parse HEAD) 1 &&
echo $ZERO_OID $(git --git-dir=bare rev-parse HEAD) 1 &&
echo $(pwd)/bare/worktrees/goozy &&
echo $(pwd)/goozy
} >hook.expect &&
Loading
Loading
Loading
Loading
@@ -116,7 +116,7 @@ test_expect_success 'broken main worktree still at the top' '
git worktree add linked &&
cat >expected <<-EOF &&
worktree $(pwd)
HEAD $_z40
HEAD $ZERO_OID
 
EOF
cd linked &&
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment