Skip to content

Commit

Permalink
Merge branch 'bc/hash-independent-tests'
Browse files Browse the repository at this point in the history
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
  ...
  • Loading branch information
gitster committed May 30, 2018
2 parents d89f124 + eea253b commit 9472b13
Show file tree
Hide file tree
Showing 71 changed files with 338 additions and 267 deletions.
4 changes: 2 additions & 2 deletions t/diff-lib.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
:

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.
Expand All @@ -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.
Expand Down
12 changes: 8 additions & 4 deletions t/lib-diff-alternative.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@
Expand Down Expand Up @@ -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 @@
Expand Down
24 changes: 12 additions & 12 deletions t/t0000-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
'

Expand Down Expand Up @@ -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
Expand All @@ -900,15 +900,15 @@ 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
'

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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -964,15 +964,15 @@ 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
'

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
'

Expand Down Expand Up @@ -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
Expand All @@ -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" |
Expand Down
2 changes: 1 addition & 1 deletion t/t0090-cache-tree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion t/t1000-read-tree-m-3way.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion t/t1001-read-tree-m-2way.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion t/t1002-read-tree-m-u-2way.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions t/t1006-cat-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
'

Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions t/t1007-hash-object.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
"
}
Expand Down Expand Up @@ -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)
'

Expand Down Expand Up @@ -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)
'

Expand All @@ -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)"
'

Expand Down
2 changes: 1 addition & 1 deletion t/t1012-read-tree-df.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion t/t1400-update-ref.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions t/t1407-worktree-ref-store.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
4 changes: 2 additions & 2 deletions t/t1450-fsck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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' '
Expand All @@ -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
'

Expand Down
6 changes: 3 additions & 3 deletions t/t1501-work-tree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
(
Expand All @@ -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
(
Expand Down
6 changes: 6 additions & 0 deletions t/t1512-rev-parse-disambiguation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
(
Expand Down
2 changes: 1 addition & 1 deletion t/t1601-index-bogus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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' '
Expand Down
2 changes: 1 addition & 1 deletion t/t1700-split-index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
2 changes: 1 addition & 1 deletion t/t2011-checkout-invalid-head.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 --
'

Expand Down
Loading

0 comments on commit 9472b13

Please sign in to comment.