Skip to content

Commit c7309f6

Browse files
pks-tgitster
authored andcommitted
t1006: don't strip timestamps from expected results
In t1006 we have a bunch of tests that verify the output format of the git-cat-file(1) command. But while part of the output for some tests would include commit timestamps, we don't verify those but instead strip them before comparing expected with actual results. This is done by the function `maybe_remove_timestamp`, which goes all the way back to the ancient commit b335d3f (Add tests for git cat-file, 2008-04-23). Our tests had been in a different shape back then. Most importantly we didn't yet have the infrastructure to create objects with deterministic timestamps. Nowadays we do though, and thus there is no reason anymore to strip the timestamps. Refactor the tests to not strip the timestamp anymore. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fe86abd commit c7309f6

File tree

1 file changed

+26
-42
lines changed

1 file changed

+26
-42
lines changed

t/t1006-cat-file.sh

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -109,26 +109,12 @@ strlen () {
109109
echo_without_newline "$1" | wc -c | sed -e 's/^ *//'
110110
}
111111

112-
maybe_remove_timestamp () {
113-
if test -z "$2"; then
114-
echo_without_newline "$1"
115-
else
116-
echo_without_newline "$(printf '%s\n' "$1" | remove_timestamp)"
117-
fi
118-
}
119-
120-
remove_timestamp () {
121-
sed -e 's/ [0-9][0-9]* [-+][0-9][0-9][0-9][0-9]$//'
122-
}
123-
124-
125112
run_tests () {
126113
type=$1
127114
sha1=$2
128115
size=$3
129116
content=$4
130117
pretty_content=$5
131-
no_ts=$6
132118

133119
batch_output="$sha1 $type $size
134120
$content"
@@ -163,21 +149,21 @@ $content"
163149

164150
test -z "$content" ||
165151
test_expect_success "Content of $type is correct" '
166-
maybe_remove_timestamp "$content" $no_ts >expect &&
167-
maybe_remove_timestamp "$(git cat-file $type $sha1)" $no_ts >actual &&
152+
echo_without_newline "$content" >expect &&
153+
git cat-file $type $sha1 >actual &&
168154
test_cmp expect actual
169155
'
170156

171157
test_expect_success "Pretty content of $type is correct" '
172-
maybe_remove_timestamp "$pretty_content" $no_ts >expect &&
173-
maybe_remove_timestamp "$(git cat-file -p $sha1)" $no_ts >actual &&
158+
echo_without_newline "$pretty_content" >expect &&
159+
git cat-file -p $sha1 >actual &&
174160
test_cmp expect actual
175161
'
176162

177163
test -z "$content" ||
178164
test_expect_success "--batch output of $type is correct" '
179-
maybe_remove_timestamp "$batch_output" $no_ts >expect &&
180-
maybe_remove_timestamp "$(echo $sha1 | git cat-file --batch)" $no_ts >actual &&
165+
echo "$batch_output" >expect &&
166+
echo $sha1 | git cat-file --batch >actual &&
181167
test_cmp expect actual
182168
'
183169

@@ -191,9 +177,8 @@ $content"
191177
do
192178
test -z "$content" ||
193179
test_expect_success "--batch-command $opt output of $type content is correct" '
194-
maybe_remove_timestamp "$batch_output" $no_ts >expect &&
195-
maybe_remove_timestamp "$(test_write_lines "contents $sha1" |
196-
git cat-file --batch-command $opt)" $no_ts >actual &&
180+
echo "$batch_output" >expect &&
181+
test_write_lines "contents $sha1" | git cat-file --batch-command $opt >actual &&
197182
test_cmp expect actual
198183
'
199184

@@ -228,21 +213,19 @@ $content"
228213
test_expect_success "--batch without type ($type)" '
229214
{
230215
echo "$size" &&
231-
maybe_remove_timestamp "$content" $no_ts
216+
echo "$content"
232217
} >expect &&
233-
echo $sha1 | git cat-file --batch="%(objectsize)" >actual.full &&
234-
maybe_remove_timestamp "$(cat actual.full)" $no_ts >actual &&
218+
echo $sha1 | git cat-file --batch="%(objectsize)" >actual &&
235219
test_cmp expect actual
236220
'
237221

238222
test -z "$content" ||
239223
test_expect_success "--batch without size ($type)" '
240224
{
241225
echo "$type" &&
242-
maybe_remove_timestamp "$content" $no_ts
226+
echo "$content"
243227
} >expect &&
244-
echo $sha1 | git cat-file --batch="%(objecttype)" >actual.full &&
245-
maybe_remove_timestamp "$(cat actual.full)" $no_ts >actual &&
228+
echo $sha1 | git cat-file --batch="%(objecttype)" >actual &&
246229
test_cmp expect actual
247230
'
248231
}
@@ -284,20 +267,20 @@ test_expect_success '--batch-check without %(rest) considers whole line' '
284267

285268
tree_sha1=$(git write-tree)
286269
tree_size=$(($(test_oid rawsz) + 13))
287-
tree_pretty_content="100644 blob $hello_sha1 hello"
270+
tree_pretty_content="100644 blob $hello_sha1 hello${LF}"
288271

289272
run_tests 'tree' $tree_sha1 $tree_size "" "$tree_pretty_content"
290273

291274
commit_message="Initial commit"
292275
commit_sha1=$(echo_without_newline "$commit_message" | git commit-tree $tree_sha1)
293276
commit_size=$(($(test_oid hexsz) + 137))
294277
commit_content="tree $tree_sha1
295-
author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 0 +0000
296-
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 0 +0000
278+
author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE
279+
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
297280
298281
$commit_message"
299282

300-
run_tests 'commit' $commit_sha1 $commit_size "$commit_content" "$commit_content" 1
283+
run_tests 'commit' $commit_sha1 $commit_size "$commit_content" "$commit_content"
301284

302285
tag_header_without_timestamp="object $hello_sha1
303286
type blob
@@ -311,7 +294,7 @@ $tag_description"
311294
tag_sha1=$(echo_without_newline "$tag_content" | git hash-object -t tag --stdin -w)
312295
tag_size=$(strlen "$tag_content")
313296

314-
run_tests 'tag' $tag_sha1 $tag_size "$tag_content" "$tag_content" 1
297+
run_tests 'tag' $tag_sha1 $tag_size "$tag_content" "$tag_content"
315298

316299
test_expect_success \
317300
"Reach a blob from a tag pointing to it" \
@@ -400,13 +383,16 @@ deadbeef missing
400383
missing"
401384

402385
test_expect_success '--batch with multiple sha1s gives correct format' '
403-
test "$(maybe_remove_timestamp "$batch_output" 1)" = "$(maybe_remove_timestamp "$(echo_without_newline "$batch_input" | git cat-file --batch)" 1)"
386+
echo "$batch_output" >expect &&
387+
echo_without_newline "$batch_input" | git cat-file --batch >actual &&
388+
test_cmp expect actual
404389
'
405390

406391
test_expect_success '--batch, -z with multiple sha1s gives correct format' '
407392
echo_without_newline_nul "$batch_input" >in &&
408-
test "$(maybe_remove_timestamp "$batch_output" 1)" = \
409-
"$(maybe_remove_timestamp "$(git cat-file --batch -z <in)" 1)"
393+
echo "$batch_output" >expect &&
394+
git cat-file --batch -z <in >actual &&
395+
test_cmp expect actual
410396
'
411397

412398
batch_check_input="$hello_sha1
@@ -480,7 +466,7 @@ contents deadbeef
480466
flush"
481467

482468
test_expect_success '--batch-command with multiple command calls gives correct format' '
483-
remove_timestamp >expect <<-EOF &&
469+
cat >expect <<-EOF &&
484470
$hello_sha1 blob $hello_size
485471
$hello_content
486472
$commit_sha1 commit $commit_size
@@ -491,15 +477,13 @@ test_expect_success '--batch-command with multiple command calls gives correct f
491477
EOF
492478
493479
echo "$batch_command_multiple_contents" >in &&
494-
git cat-file --batch-command --buffer <in >actual_raw &&
480+
git cat-file --batch-command --buffer <in >actual &&
495481
496-
remove_timestamp <actual_raw >actual &&
497482
test_cmp expect actual &&
498483
499484
echo "$batch_command_multiple_contents" | tr "\n" "\0" >in &&
500-
git cat-file --batch-command --buffer -z <in >actual_raw &&
485+
git cat-file --batch-command --buffer -z <in >actual &&
501486
502-
remove_timestamp <actual_raw >actual &&
503487
test_cmp expect actual
504488
'
505489

0 commit comments

Comments
 (0)