Skip to content

Commit 1c5e94f

Browse files
szedergitster
authored andcommitted
tests: use 'test_must_be_empty' instead of 'test_cmp <empty> <out>'
Using 'test_must_be_empty' is shorter and more idiomatic than >empty && test_cmp empty out as it saves the creation of an empty file. Furthermore, sometimes the expected empty file doesn't have such a descriptive name like 'empty', and its creation is far away from the place where it's finally used for comparison (e.g. in 't7600-merge.sh', where two expected empty files are created in the 'setup' test, but are used only about 500 lines later). These cases were found by instrumenting 'test_cmp' to error out the test script when it's used to compare empty files, and then converted manually. Note that even after this patch there still remain a lot of cases where we use 'test_cmp' to check empty files: - Sometimes the expected output is not hard-coded in the test, but 'test_cmp' is used to ensure that two similar git commands produce the same output, and that output happens to be empty, e.g. the test 'submodule update --merge - ignores --merge for new submodules' in 't7406-submodule-update.sh'. - Repetitive common tasks, including preparing the expected results and running 'test_cmp', are often extracted into a helper function, and some of this helper's callsites expect no output. - For the same reason as above, the whole 'test_expect_success' block is within a helper function, e.g. in 't3070-wildmatch.sh'. - Or 'test_cmp' is invoked in a loop, e.g. the test 'cvs update (-p)' in 't9400-git-cvsserver-server.sh'. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ec21ac8 commit 1c5e94f

Some content is hidden

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

46 files changed

+114
-226
lines changed

t/t0001-init.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,8 @@ test_expect_success 'reinit' '
167167
) &&
168168
test_i18ngrep "Initialized empty" again/out1 &&
169169
test_i18ngrep "Reinitialized existing" again/out2 &&
170-
>again/empty &&
171-
test_i18ncmp again/empty again/err1 &&
172-
test_i18ncmp again/empty again/err2
170+
test_must_be_empty again/err1 &&
171+
test_must_be_empty again/err2
173172
'
174173

175174
test_expect_success 'init with --template' '

t/t0003-attributes.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,8 @@ test_expect_success 'attribute test: --all option' '
208208
'
209209

210210
test_expect_success 'attribute test: --cached option' '
211-
: >empty &&
212211
git check-attr --cached --stdin --all <stdin-all | sort >actual &&
213-
test_cmp empty actual &&
212+
test_must_be_empty actual &&
214213
git add .gitattributes a/.gitattributes a/b/.gitattributes &&
215214
git check-attr --cached --stdin --all <stdin-all | sort >actual &&
216215
test_cmp specified-all actual

t/t0030-stripspace.sh

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -320,22 +320,20 @@ test_expect_success \
320320

321321
test_expect_success \
322322
'spaces with newline at end should be replaced with empty string' '
323-
printf "" >expect &&
324-
325323
echo | git stripspace >actual &&
326-
test_cmp expect actual &&
324+
test_must_be_empty actual &&
327325
328326
echo "$sss" | git stripspace >actual &&
329-
test_cmp expect actual &&
327+
test_must_be_empty actual &&
330328
331329
echo "$sss$sss" | git stripspace >actual &&
332-
test_cmp expect actual &&
330+
test_must_be_empty actual &&
333331
334332
echo "$sss$sss$sss" | git stripspace >actual &&
335-
test_cmp expect actual &&
333+
test_must_be_empty actual &&
336334
337335
echo "$sss$sss$sss$sss" | git stripspace >actual &&
338-
test_cmp expect actual
336+
test_must_be_empty actual
339337
'
340338

341339
test_expect_success \
@@ -349,19 +347,17 @@ test_expect_success \
349347

350348
test_expect_success \
351349
'spaces without newline at end should be replaced with empty string' '
352-
printf "" >expect &&
353-
354350
printf "" | git stripspace >actual &&
355-
test_cmp expect actual &&
351+
test_must_be_empty actual &&
356352
357353
printf "$sss$sss" | git stripspace >actual &&
358-
test_cmp expect actual &&
354+
test_must_be_empty actual &&
359355
360356
printf "$sss$sss$sss" | git stripspace >actual &&
361-
test_cmp expect actual &&
357+
test_must_be_empty actual &&
362358
363359
printf "$sss$sss$sss$sss" | git stripspace >actual &&
364-
test_cmp expect actual
360+
test_must_be_empty actual
365361
'
366362

367363
test_expect_success \

t/t0040-parse-options.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,9 @@ test_expect_success 'OPT_CALLBACK() and OPT_BIT() work' '
286286
test_cmp expect output
287287
'
288288

289-
>expect
290-
291289
test_expect_success 'OPT_CALLBACK() and callback errors work' '
292290
test_must_fail test-parse-options --no-length >output 2>output.err &&
293-
test_i18ncmp expect output &&
291+
test_must_be_empty output &&
294292
test_must_be_empty output.err
295293
'
296294

t/t0061-run-command.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ cat >hello-script <<-EOF
1111
#!$SHELL_PATH
1212
cat hello-script
1313
EOF
14-
>empty
1514

1615
test_expect_success 'start_command reports ENOENT' '
1716
test-tool run-command start-command-ENOENT ./does-not-exist
@@ -23,7 +22,7 @@ test_expect_success 'run_command can run a command' '
2322
test-tool run-command run-command ./hello.sh >actual 2>err &&
2423
2524
test_cmp hello-script actual &&
26-
test_cmp empty err
25+
test_must_be_empty err
2726
'
2827

2928
test_expect_success !MINGW 'run_command can run a script without a #! line' '
@@ -34,7 +33,7 @@ test_expect_success !MINGW 'run_command can run a script without a #! line' '
3433
test-tool run-command run-command ./hello >actual 2>err &&
3534
3635
test_cmp hello-script actual &&
37-
test_cmp empty err
36+
test_must_be_empty err
3837
'
3938

4039
test_expect_success 'run_command does not try to execute a directory' '
@@ -47,7 +46,7 @@ test_expect_success 'run_command does not try to execute a directory' '
4746
PATH=$PWD/bin1:$PWD/bin2:$PATH \
4847
test-tool run-command run-command greet >actual 2>err &&
4948
test_cmp bin2/greet actual &&
50-
test_cmp empty err
49+
test_must_be_empty err
5150
'
5251

5352
test_expect_success POSIXPERM 'run_command passes over non-executable file' '
@@ -64,7 +63,7 @@ test_expect_success POSIXPERM 'run_command passes over non-executable file' '
6463
PATH=$PWD/bin1:$PWD/bin2:$PATH \
6564
test-tool run-command run-command greet >actual 2>err &&
6665
test_cmp bin2/greet actual &&
67-
test_cmp empty err
66+
test_must_be_empty err
6867
'
6968

7069
test_expect_success POSIXPERM 'run_command reports EACCES' '

t/t1300-config.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,9 @@ test_expect_success 'working --list' '
346346
git config --list > output &&
347347
test_cmp expect output
348348
'
349-
cat > expect << EOF
350-
EOF
351-
352349
test_expect_success '--list without repo produces empty output' '
353350
git --git-dir=nonexistent config --list >output &&
354-
test_cmp expect output
351+
test_must_be_empty output
355352
'
356353

357354
cat > expect << EOF

t/t1410-reflog.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,8 @@ test_expect_success 'stale dirs do not cause d/f conflicts (reflogs off)' '
290290
# same as before, but we only create a reflog for "one" if
291291
# it already exists, which it does not
292292
git -c core.logallrefupdates=false branch one master &&
293-
: >expect &&
294293
git log -g --format="%gd %gs" one >actual &&
295-
test_cmp expect actual
294+
test_must_be_empty actual
296295
'
297296

298297
# Triggering the bug detected by this test requires a newline to fall

t/t1411-reflog-show.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,12 @@ test_expect_success '--date magic does not override explicit @{0} syntax' '
136136
test_cmp expect actual
137137
'
138138

139-
: >expect
140139
test_expect_success 'empty reflog file' '
141140
git branch empty &&
142141
git reflog expire --expire=all refs/heads/empty &&
143142
144143
git log -g empty >actual &&
145-
test_cmp expect actual
144+
test_must_be_empty actual
146145
'
147146

148147
# This guards against the alternative of showing the diffs vs. the

t/t1450-fsck.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ test_expect_success setup '
1616
git checkout HEAD^0 &&
1717
test_commit B fileB two &&
1818
git tag -d A B &&
19-
git reflog expire --expire=now --all &&
20-
>empty
19+
git reflog expire --expire=now --all
2120
'
2221

2322
test_expect_success 'loose objects borrowed from alternate are not missing' '
@@ -29,12 +28,12 @@ test_expect_success 'loose objects borrowed from alternate are not missing' '
2928
test_commit C fileC one &&
3029
git fsck --no-dangling >../actual 2>&1
3130
) &&
32-
test_cmp empty actual
31+
test_must_be_empty actual
3332
'
3433

3534
test_expect_success 'HEAD is part of refs, valid objects appear valid' '
3635
git fsck >actual 2>&1 &&
37-
test_cmp empty actual
36+
test_must_be_empty actual
3837
'
3938

4039
# Corruption tests follow. Make sure to remove all traces of the
@@ -346,12 +345,12 @@ test_expect_success 'tag with NUL in header' '
346345

347346
test_expect_success 'cleaned up' '
348347
git fsck >actual 2>&1 &&
349-
test_cmp empty actual
348+
test_must_be_empty actual
350349
'
351350

352351
test_expect_success 'rev-list --verify-objects' '
353352
git rev-list --verify-objects --all >/dev/null 2>out &&
354-
test_cmp empty out
353+
test_must_be_empty out
355354
'
356355

357356
test_expect_success 'rev-list --verify-objects with bad sha1' '

t/t1600-index.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ test_expect_success 'no warning with bogus GIT_INDEX_VERSION and existing index'
4141
GIT_INDEX_VERSION=1 &&
4242
export GIT_INDEX_VERSION &&
4343
git add a 2>actual.err &&
44-
>expect.err &&
45-
test_i18ncmp expect.err actual.err
44+
test_must_be_empty actual.err
4645
)
4746
'
4847

0 commit comments

Comments
 (0)