Skip to content

Commit 9472b13

Browse files
committed
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 ...
2 parents d89f124 + eea253b commit 9472b13

File tree

71 files changed

+338
-267
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+338
-267
lines changed

t/diff-lib.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
:
22

3-
sanitize_diff_raw='/^:/s/ '"\($_x40\)"' '"\($_x40\)"' \([A-Z]\)[0-9]* / \1 \2 \3# /'
3+
sanitize_diff_raw='/^:/s/ '"\($OID_REGEX\)"' '"\($OID_REGEX\)"' \([A-Z]\)[0-9]* / \1 \2 \3# /'
44
compare_diff_raw () {
55
# When heuristics are improved, the score numbers would change.
66
# Ignore them while comparing.
@@ -12,7 +12,7 @@ compare_diff_raw () {
1212
test_cmp .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2
1313
}
1414

15-
sanitize_diff_raw_z='/^:/s/ '"$_x40"' '"$_x40"' \([A-Z]\)[0-9]*$/ X X \1#/'
15+
sanitize_diff_raw_z='/^:/s/ '"$OID_REGEX"' '"$OID_REGEX"' \([A-Z]\)[0-9]*$/ X X \1#/'
1616
compare_diff_raw_z () {
1717
# When heuristics are improved, the score numbers would change.
1818
# Ignore them while comparing.

t/lib-diff-alternative.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ int main(int argc, char **argv)
5959
}
6060
EOF
6161

62-
cat >expect <<\EOF
62+
file1=$(git rev-parse --short $(git hash-object file1))
63+
file2=$(git rev-parse --short $(git hash-object file2))
64+
cat >expect <<EOF
6365
diff --git a/file1 b/file2
64-
index 6faa5a3..e3af329 100644
66+
index $file1..$file2 100644
6567
--- a/file1
6668
+++ b/file2
6769
@@ -1,26 +1,25 @@
@@ -136,9 +138,11 @@ e
136138
f
137139
EOF
138140

139-
cat >expect <<\EOF
141+
uniq1=$(git rev-parse --short $(git hash-object uniq1))
142+
uniq2=$(git rev-parse --short $(git hash-object uniq2))
143+
cat >expect <<EOF
140144
diff --git a/uniq1 b/uniq2
141-
index b414108..0fdf397 100644
145+
index $uniq1..$uniq2 100644
142146
--- a/uniq1
143147
+++ b/uniq2
144148
@@ -1,6 +1,6 @@

t/t0000-basic.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ test_expect_success 'writing tree out with git write-tree' '
839839
'
840840

841841
# we know the shape and contents of the tree and know the object ID for it.
842-
test_expect_success 'validate object ID of a known tree' '
842+
test_expect_success SHA1 'validate object ID of a known tree' '
843843
test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a
844844
'
845845

@@ -882,7 +882,7 @@ test_expect_success 'showing stage with git ls-files --stage' '
882882
git ls-files --stage >current
883883
'
884884

885-
test_expect_success 'validate git ls-files output for a known tree' '
885+
test_expect_success SHA1 'validate git ls-files output for a known tree' '
886886
cat >expected <<-\EOF &&
887887
100644 f87290f8eb2cbbea7857214459a0739927eab154 0 path0
888888
120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0 path0sym
@@ -900,15 +900,15 @@ test_expect_success 'writing tree out with git write-tree' '
900900
tree=$(git write-tree)
901901
'
902902

903-
test_expect_success 'validate object ID for a known tree' '
903+
test_expect_success SHA1 'validate object ID for a known tree' '
904904
test "$tree" = 087704a96baf1c2d1c869a8b084481e121c88b5b
905905
'
906906

907907
test_expect_success 'showing tree with git ls-tree' '
908908
git ls-tree $tree >current
909909
'
910910

911-
test_expect_success 'git ls-tree output for a known tree' '
911+
test_expect_success SHA1 'git ls-tree output for a known tree' '
912912
cat >expected <<-\EOF &&
913913
100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
914914
120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
@@ -924,7 +924,7 @@ test_expect_success 'showing tree with git ls-tree -r' '
924924
git ls-tree -r $tree >current
925925
'
926926

927-
test_expect_success 'git ls-tree -r output for a known tree' '
927+
test_expect_success SHA1 'git ls-tree -r output for a known tree' '
928928
cat >expected <<-\EOF &&
929929
100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
930930
120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
@@ -943,7 +943,7 @@ test_expect_success 'showing tree with git ls-tree -r -t' '
943943
git ls-tree -r -t $tree >current
944944
'
945945

946-
test_expect_success 'git ls-tree -r output for a known tree' '
946+
test_expect_success SHA1 'git ls-tree -r output for a known tree' '
947947
cat >expected <<-\EOF &&
948948
100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
949949
120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
@@ -964,15 +964,15 @@ test_expect_success 'writing partial tree out with git write-tree --prefix' '
964964
ptree=$(git write-tree --prefix=path3)
965965
'
966966

967-
test_expect_success 'validate object ID for a known tree' '
967+
test_expect_success SHA1 'validate object ID for a known tree' '
968968
test "$ptree" = 21ae8269cacbe57ae09138dcc3a2887f904d02b3
969969
'
970970

971971
test_expect_success 'writing partial tree out with git write-tree --prefix' '
972972
ptree=$(git write-tree --prefix=path3/subp3)
973973
'
974974

975-
test_expect_success 'validate object ID for a known tree' '
975+
test_expect_success SHA1 'validate object ID for a known tree' '
976976
test "$ptree" = 3c5e5399f3a333eddecce7a9b9465b63f65f51e2
977977
'
978978

@@ -1006,7 +1006,7 @@ test_expect_success 'git read-tree followed by write-tree should be idempotent'
10061006
test "$newtree" = "$tree"
10071007
'
10081008

1009-
test_expect_success 'validate git diff-files output for a know cache/work tree state' '
1009+
test_expect_success SHA1 'validate git diff-files output for a know cache/work tree state' '
10101010
cat >expected <<\EOF &&
10111011
:100644 100644 f87290f8eb2cbbea7857214459a0739927eab154 0000000000000000000000000000000000000000 M path0
10121012
:120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0000000000000000000000000000000000000000 M path0sym
@@ -1033,21 +1033,21 @@ test_expect_success 'no diff after checkout and git update-index --refresh' '
10331033
################################################################
10341034
P=087704a96baf1c2d1c869a8b084481e121c88b5b
10351035

1036-
test_expect_success 'git commit-tree records the correct tree in a commit' '
1036+
test_expect_success SHA1 'git commit-tree records the correct tree in a commit' '
10371037
commit0=$(echo NO | git commit-tree $P) &&
10381038
tree=$(git show --pretty=raw $commit0 |
10391039
sed -n -e "s/^tree //p" -e "/^author /q") &&
10401040
test "z$tree" = "z$P"
10411041
'
10421042

1043-
test_expect_success 'git commit-tree records the correct parent in a commit' '
1043+
test_expect_success SHA1 'git commit-tree records the correct parent in a commit' '
10441044
commit1=$(echo NO | git commit-tree $P -p $commit0) &&
10451045
parent=$(git show --pretty=raw $commit1 |
10461046
sed -n -e "s/^parent //p" -e "/^author /q") &&
10471047
test "z$commit0" = "z$parent"
10481048
'
10491049

1050-
test_expect_success 'git commit-tree omits duplicated parent in a commit' '
1050+
test_expect_success SHA1 'git commit-tree omits duplicated parent in a commit' '
10511051
commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
10521052
parent=$(git show --pretty=raw $commit2 |
10531053
sed -n -e "s/^parent //p" -e "/^author /q" |

t/t0090-cache-tree.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cache-tree extension.
99

1010
cmp_cache_tree () {
1111
test-tool dump-cache-tree | sed -e '/#(ref)/d' >actual &&
12-
sed "s/$_x40/SHA/" <actual >filtered &&
12+
sed "s/$OID_REGEX/SHA/" <actual >filtered &&
1313
test_cmp "$1" filtered
1414
}
1515

t/t1000-read-tree-m-3way.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ cat >expected <<\EOF
128128
EOF
129129

130130
check_result () {
131-
git ls-files --stage | sed -e 's/ '"$_x40"' / X /' >current &&
131+
git ls-files --stage | sed -e 's/ '"$OID_REGEX"' / X /' >current &&
132132
test_cmp expected current
133133
}
134134

t/t1001-read-tree-m-2way.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ read_tree_twoway () {
3030
compare_change () {
3131
sed -n >current \
3232
-e '/^--- /d; /^+++ /d; /^@@ /d;' \
33-
-e 's/^\([-+][0-7][0-7][0-7][0-7][0-7][0-7]\) '"$_x40"' /\1 X /p' \
33+
-e 's/^\([-+][0-7][0-7][0-7][0-7][0-7][0-7]\) '"$OID_REGEX"' /\1 X /p' \
3434
"$1"
3535
test_cmp expected current
3636
}

t/t1002-read-tree-m-u-2way.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ compare_change () {
1616
-e '1{/^diff --git /d;}' \
1717
-e '2{/^index /d;}' \
1818
-e '/^--- /d; /^+++ /d; /^@@ /d;' \
19-
-e 's/^\(.[0-7][0-7][0-7][0-7][0-7][0-7]\) '"$_x40"' /\1 X /' "$1"
19+
-e 's/^\(.[0-7][0-7][0-7][0-7][0-7][0-7]\) '"$OID_REGEX"' /\1 X /' "$1"
2020
test_cmp expected current
2121
}
2222

t/t1006-cat-file.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ test_expect_success "--batch-check for an empty line" '
236236
'
237237

238238
test_expect_success 'empty --batch-check notices missing object' '
239-
echo "$_z40 missing" >expect &&
240-
echo "$_z40" | git cat-file --batch-check="" >actual &&
239+
echo "$ZERO_OID missing" >expect &&
240+
echo "$ZERO_OID" | git cat-file --batch-check="" >actual &&
241241
test_cmp expect actual
242242
'
243243

@@ -294,8 +294,8 @@ test_expect_success 'setup blobs which are likely to delta' '
294294

295295
test_expect_success 'confirm that neither loose blob is a delta' '
296296
cat >expect <<-EOF &&
297-
$_z40
298-
$_z40
297+
$ZERO_OID
298+
$ZERO_OID
299299
EOF
300300
git cat-file --batch-check="%(deltabase)" <blobs >actual &&
301301
test_cmp expect actual

t/t1007-hash-object.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ echo_without_newline() {
99
}
1010

1111
test_blob_does_not_exist() {
12-
test_expect_success 'blob does not exist in database' "
12+
test_expect_success SHA1 'blob does not exist in database' "
1313
test_must_fail git cat-file blob $1
1414
"
1515
}
1616

1717
test_blob_exists() {
18-
test_expect_success 'blob exists in database' "
18+
test_expect_success SHA1 'blob exists in database' "
1919
git cat-file blob $1
2020
"
2121
}
@@ -73,19 +73,19 @@ test_expect_success "Can't use --path with --no-filters" '
7373

7474
push_repo
7575

76-
test_expect_success 'hash a file' '
76+
test_expect_success SHA1 'hash a file' '
7777
test $hello_sha1 = $(git hash-object hello)
7878
'
7979

8080
test_blob_does_not_exist $hello_sha1
8181

82-
test_expect_success 'hash from stdin' '
82+
test_expect_success SHA1 'hash from stdin' '
8383
test $example_sha1 = $(git hash-object --stdin < example)
8484
'
8585

8686
test_blob_does_not_exist $example_sha1
8787

88-
test_expect_success 'hash a file and write to database' '
88+
test_expect_success SHA1 'hash a file and write to database' '
8989
test $hello_sha1 = $(git hash-object -w hello)
9090
'
9191

@@ -161,7 +161,7 @@ pop_repo
161161
for args in "-w --stdin" "--stdin -w"; do
162162
push_repo
163163

164-
test_expect_success "hash from stdin and write to database ($args)" '
164+
test_expect_success SHA1 "hash from stdin and write to database ($args)" '
165165
test $example_sha1 = $(git hash-object $args < example)
166166
'
167167

@@ -176,14 +176,14 @@ example"
176176
sha1s="$hello_sha1
177177
$example_sha1"
178178

179-
test_expect_success "hash two files with names on stdin" '
179+
test_expect_success SHA1 "hash two files with names on stdin" '
180180
test "$sha1s" = "$(echo_without_newline "$filenames" | git hash-object --stdin-paths)"
181181
'
182182

183183
for args in "-w --stdin-paths" "--stdin-paths -w"; do
184184
push_repo
185185

186-
test_expect_success "hash two files with names on stdin and write to database ($args)" '
186+
test_expect_success SHA1 "hash two files with names on stdin and write to database ($args)" '
187187
test "$sha1s" = "$(echo_without_newline "$filenames" | git hash-object $args)"
188188
'
189189

t/t1012-read-tree-df.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ settree () {
3232

3333
checkindex () {
3434
git ls-files -s |
35-
sed "s|^[0-7][0-7]* $_x40 \([0-3]\) |\1 |" >current &&
35+
sed "s|^[0-7][0-7]* $OID_REGEX \([0-3]\) |\1 |" >current &&
3636
cat >expect &&
3737
test_cmp expect current
3838
}

0 commit comments

Comments
 (0)