test: test_must_be_empty helper
There are quite a lot places where an output file is expected to be empty, and we fail the test when it is not. The output from running the test script with -i -v can be helped if we showed the unexpected contents at that point. We could of course do >expected.empty && test_cmp expected.empty actual but this is commmon enough to be done with a dedicated helper. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jun 9, 2013 at 11:29 UTC
ca8d148daf3014577222c2562ca2c8170a866aa4
9 files changed
+65
-53
t/t0040-parse-options.sh
+23
-23
@@ -50,7 +50,7 @@ EOF
50
51
test_expect_success 'test help' '
52
test_must_fail test-parse-options -h > output 2> output.err &&
53
- test ! -s output.err &&
53
+ test_must_be_empty output.err &&
54
test_i18ncmp expect output
55
'
56
@@ -75,7 +75,7 @@ check() {
75
shift &&
76
sed "s/^$what .*/$what $expect/" <expect.template >expect &&
77
test-parse-options $* >output 2>output.err &&
78
- test ! -s output.err &&
78
+ test_must_be_empty output.err &&
79
test_cmp expect output
80
}
81
@@ -86,7 +86,7 @@ check_i18n() {
86
shift &&
87
sed "s/^$what .*/$what $expect/" <expect.template >expect &&
88
test-parse-options $* >output 2>output.err &&
89
- test ! -s output.err &&
89
+ test_must_be_empty output.err &&
90
test_i18ncmp expect output
91
}
92
@@ -99,7 +99,7 @@ check_unknown() {
99
esac &&
100
cat expect.err >>expect &&
101
test_must_fail test-parse-options $* >output 2>output.err &&
102
- test ! -s output &&
102
+ test_must_be_empty output &&
103
test_cmp expect output.err
104
}
105
@@ -112,7 +112,7 @@ check_unknown_i18n() {
112
esac &&
113
cat expect.err >>expect &&
114
test_must_fail test-parse-options $* >output 2>output.err &&
115
- test ! -s output &&
115
+ test_must_be_empty output &&
116
test_i18ncmp expect output.err
117
}
118
@@ -149,7 +149,7 @@ test_expect_success 'short options' '
149
test-parse-options -s123 -b -i 1729 -b -vv -n -F my.file \
150
> output 2> output.err &&
151
test_cmp expect output &&
152
- test ! -s output.err
152
+ test_must_be_empty output.err
153
'
154
155
cat > expect << EOF
@@ -168,7 +168,7 @@ test_expect_success 'long options' '
168
test-parse-options --boolean --integer 1729 --boolean --string2=321 \
169
--verbose --verbose --no-dry-run --abbrev=10 --file fi.le\
170
--obsolete > output 2> output.err &&
171
- test ! -s output.err &&
171
+ test_must_be_empty output.err &&
172
test_cmp expect output
173
'
174
@@ -199,7 +199,7 @@ EOF
199
test_expect_success 'intermingled arguments' '
200
test-parse-options a1 --string 123 b1 --boolean -j 13 -- --boolean \
201
> output 2> output.err &&
202
- test ! -s output.err &&
202
+ test_must_be_empty output.err &&
203
test_cmp expect output
204
'
205
@@ -217,13 +217,13 @@ EOF
217
218
test_expect_success 'unambiguously abbreviated option' '
219
test-parse-options --int 2 --boolean --no-bo > output 2> output.err &&
220
- test ! -s output.err &&
220
+ test_must_be_empty output.err &&
221
test_cmp expect output
222
'
223
224
test_expect_success 'unambiguously abbreviated option with "="' '
225
test-parse-options --int=2 > output 2> output.err &&
226
- test ! -s output.err &&
226
+ test_must_be_empty output.err &&
227
test_cmp expect output
228
'
229
@@ -246,7 +246,7 @@ EOF
246
247
test_expect_success 'non ambiguous option (after two options it abbreviates)' '
248
test-parse-options --st 123 > output 2> output.err &&
249
- test ! -s output.err &&
249
+ test_must_be_empty output.err &&
250
test_cmp expect output
251
'
252
@@ -256,7 +256,7 @@ EOF
256
257
test_expect_success 'detect possible typos' '
258
test_must_fail test-parse-options -boolean > output 2> output.err &&
259
- test ! -s output &&
259
+ test_must_be_empty output &&
260
test_cmp typo.err output.err
261
'
262
@@ -266,7 +266,7 @@ EOF
266
267
test_expect_success 'detect possible typos' '
268
test_must_fail test-parse-options -ambiguous > output 2> output.err &&
269
- test ! -s output &&
269
+ test_must_be_empty output &&
270
test_cmp typo.err output.err
271
'
272
@@ -285,7 +285,7 @@ EOF
285
286
test_expect_success 'keep some options as arguments' '
287
test-parse-options --quux > output 2> output.err &&
288
- test ! -s output.err &&
288
+ test_must_be_empty output.err &&
289
test_cmp expect output
290
'
291
@@ -305,7 +305,7 @@ EOF
305
test_expect_success 'OPT_DATE() and OPT_SET_PTR() work' '
306
test-parse-options -t "1970-01-01 00:00:01 +0000" --default-string \
307
foo -q > output 2> output.err &&
308
- test ! -s output.err &&
308
+ test_must_be_empty output.err &&
309
test_cmp expect output
310
'
311
@@ -324,7 +324,7 @@ EOF
324
325
test_expect_success 'OPT_CALLBACK() and OPT_BIT() work' '
326
test-parse-options --length=four -b -4 > output 2> output.err &&
327
- test ! -s output.err &&
327
+ test_must_be_empty output.err &&
328
test_cmp expect output
329
'
330
@@ -352,13 +352,13 @@ EOF
352
353
test_expect_success 'OPT_BIT() and OPT_SET_INT() work' '
354
test-parse-options --set23 -bbbbb --no-or4 > output 2> output.err &&
355
- test ! -s output.err &&
355
+ test_must_be_empty output.err &&
356
test_cmp expect output
357
'
358
359
test_expect_success 'OPT_NEGBIT() and OPT_SET_INT() work' '
360
test-parse-options --set23 -bbbbb --neg-or4 > output 2> output.err &&
361
- test ! -s output.err &&
361
+ test_must_be_empty output.err &&
362
test_cmp expect output
363
'
364
@@ -376,19 +376,19 @@ EOF
376
377
test_expect_success 'OPT_BIT() works' '
378
test-parse-options -bb --or4 > output 2> output.err &&
379
- test ! -s output.err &&
379
+ test_must_be_empty output.err &&
380
test_cmp expect output
381
'
382
383
test_expect_success 'OPT_NEGBIT() works' '
384
test-parse-options -bb --no-neg-or4 > output 2> output.err &&
385
- test ! -s output.err &&
385
+ test_must_be_empty output.err &&
386
test_cmp expect output
387
'
388
389
test_expect_success 'OPT_COUNTUP() with PARSE_OPT_NODASH works' '
390
test-parse-options + + + + + + > output 2> output.err &&
391
- test ! -s output.err &&
391
+ test_must_be_empty output.err &&
392
test_cmp expect output
393
'
394
@@ -406,7 +406,7 @@ EOF
406
407
test_expect_success 'OPT_NUMBER_CALLBACK() works' '
408
test-parse-options -12345 > output 2> output.err &&
409
- test ! -s output.err &&
409
+ test_must_be_empty output.err &&
410
test_cmp expect output
411
'
412
@@ -424,7 +424,7 @@ EOF
424
425
test_expect_success 'negation of OPT_NONEG flags is not ambiguous' '
426
test-parse-options --no-ambig >output 2>output.err &&
427
- test ! -s output.err &&
427
+ test_must_be_empty output.err &&
428
test_cmp expect output
429
'
430
t/t3400-rebase.sh
+1
-1
@@ -179,7 +179,7 @@ test_expect_success 'default to @{upstream} when upstream arg is missing' '
179
test_expect_success 'rebase -q is quiet' '
180
git checkout -b quiet topic &&
181
git rebase -q master >output.out 2>&1 &&
182
- test ! -s output.out
182
+ test_must_be_empty output.out
183
'
184
185
test_expect_success 'Rebase a commit that sprinkles CRs in' '
t/t3903-stash.sh
+5
-5
@@ -200,17 +200,17 @@ test_expect_success 'apply -q is quiet' '
200
echo foo > file &&
201
git stash &&
202
git stash apply -q > output.out 2>&1 &&
203
- test ! -s output.out
203
+ test_must_be_empty output.out
204
'
205
206
test_expect_success 'save -q is quiet' '
207
git stash save --quiet > output.out 2>&1 &&
208
- test ! -s output.out
208
+ test_must_be_empty output.out
209
'
210
211
test_expect_success 'pop -q is quiet' '
212
git stash pop -q > output.out 2>&1 &&
213
- test ! -s output.out
213
+ test_must_be_empty output.out
214
'
215
216
test_expect_success 'pop -q --index works and is quiet' '
@@ -219,13 +219,13 @@ test_expect_success 'pop -q --index works and is quiet' '
219
git stash save --quiet &&
220
git stash pop -q --index > output.out 2>&1 &&
221
test foo = "$(git show :file)" &&
222
- test ! -s output.out
222
+ test_must_be_empty output.out
223
'
224
225
test_expect_success 'drop -q is quiet' '
226
git stash &&
227
git stash drop -q > output.out 2>&1 &&
228
- test ! -s output.out
228
+ test_must_be_empty output.out
229
'
230
231
test_expect_success 'stash -k' '
t/t5521-pull-options.sh
+13
-13
@@ -15,19 +15,19 @@ test_expect_success 'git pull -q' '
15
mkdir clonedq &&
16
(cd clonedq && git init &&
17
git pull -q "../parent" >out 2>err &&
18
- test ! -s err &&
19
- test ! -s out)
18
+ test_must_be_empty err &&
19
+ test_must_be_empty out)
20
'
21
22
test_expect_success 'git pull -q --rebase' '
23
mkdir clonedqrb &&
24
(cd clonedqrb && git init &&
25
git pull -q --rebase "../parent" >out 2>err &&
26
- test ! -s err &&
27
- test ! -s out &&
26
+ test_must_be_empty err &&
27
+ test_must_be_empty out &&
28
git pull -q --rebase "../parent" >out 2>err &&
29
- test ! -s err &&
30
- test ! -s out)
29
+ test_must_be_empty err &&
30
+ test_must_be_empty out)
31
'
32
33
test_expect_success 'git pull' '
@@ -35,7 +35,7 @@ test_expect_success 'git pull' '
35
(cd cloned && git init &&
36
git pull "../parent" >out 2>err &&
37
test -s err &&
38
- test ! -s out)
38
+ test_must_be_empty out)
39
'
40
41
test_expect_success 'git pull --rebase' '
@@ -43,7 +43,7 @@ test_expect_success 'git pull --rebase' '
43
(cd clonedrb && git init &&
44
git pull --rebase "../parent" >out 2>err &&
45
test -s err &&
46
- test ! -s out)
46
+ test_must_be_empty out)
47
'
48
49
test_expect_success 'git pull -v' '
@@ -51,7 +51,7 @@ test_expect_success 'git pull -v' '
51
(cd clonedv && git init &&
52
git pull -v "../parent" >out 2>err &&
53
test -s err &&
54
- test ! -s out)
54
+ test_must_be_empty out)
55
'
56
57
test_expect_success 'git pull -v --rebase' '
@@ -59,22 +59,22 @@ test_expect_success 'git pull -v --rebase' '
59
(cd clonedvrb && git init &&
60
git pull -v --rebase "../parent" >out 2>err &&
61
test -s err &&
62
- test ! -s out)
62
+ test_must_be_empty out)
63
'
64
65
test_expect_success 'git pull -v -q' '
66
mkdir clonedvq &&
67
(cd clonedvq && git init &&
68
git pull -v -q "../parent" >out 2>err &&
69
- test ! -s out &&
70
- test ! -s err)
69
+ test_must_be_empty out &&
70
+ test_must_be_empty err)
71
'
72
73
test_expect_success 'git pull -q -v' '
74
mkdir clonedqv &&
75
(cd clonedqv && git init &&
76
git pull -q -v "../parent" >out 2>err &&
77
- test ! -s out &&
77
+ test_must_be_empty out &&
78
test -s err)
79
'
80
t/t5702-clone-options.sh
+1
-1
@@ -22,7 +22,7 @@ test_expect_success 'clone -o' '
22
test_expect_success 'redirected clone' '
23
24
git clone "file://$(pwd)/parent" clone-redirected >out 2>err &&
25
- test ! -s err
25
+ test_must_be_empty err
26
27
'
28
test_expect_success 'redirected clone -v' '
t/t7102-reset.sh
+1
-1
@@ -457,7 +457,7 @@ test_expect_success 'disambiguation (1)' '
457
test_must_fail git diff --quiet -- secondfile &&
458
test -z "$(git diff --cached --name-only)" &&
459
test -f secondfile &&
460
- test ! -s secondfile
460
+ test_must_be_empty secondfile
461
462
'
463
t/t7400-submodule-basic.sh
+3
-3
@@ -78,7 +78,7 @@ test_expect_success 'submodule add' '
78
(
79
cd addtest &&
80
git submodule add -q "$submodurl" submod >actual &&
81
- test ! -s actual &&
81
+ test_must_be_empty actual &&
82
echo "gitdir: ../.git/modules/submod" >expect &&
83
test_cmp expect submod/.git &&
84
(
@@ -308,7 +308,7 @@ test_expect_success 'update should work when path is an empty dir' '
308
309
mkdir init &&
310
git submodule update -q >update.out &&
311
- test ! -s update.out &&
311
+ test_must_be_empty update.out &&
312
313
inspect init &&
314
test_cmp expect head-sha1
@@ -696,7 +696,7 @@ test_expect_success 'submodule add --name allows to replace a submodule with ano
696
rm -rf repo &&
697
git rm repo &&
698
git submodule add -q --name repo_new "$submodurl/bare.git" repo >actual &&
699
- test ! -s actual &&
699
+ test_must_be_empty actual &&
700
echo "gitdir: ../.git/modules/submod" >expect &&
701
test_cmp expect submod/.git &&
702
(
t/t9402-git-cvsserver-refs.sh
+6
-6
@@ -330,7 +330,7 @@ test_expect_success 'validate result of edits [cvswork2]' '
330
331
test_expect_success 'validate basic diffs saved during above cvswork2 edits' '
332
test $(grep Index: cvsEdit1.diff | wc -l) = 1 &&
333
- test ! -s cvsEdit2-empty.diff &&
333
+ test_must_be_empty cvsEdit2-empty.diff &&
334
test $(grep Index: cvsEdit2-N.diff | wc -l) = 1 &&
335
test $(grep Index: cvsEdit3.diff | wc -l) = 3 &&
336
rm -rf diffSandbox &&
@@ -456,20 +456,20 @@ test_expect_success 'cvs up -r $(git rev-parse v1)' '
456
457
test_expect_success 'cvs diff -r v1 -u' '
458
( cd cvswork && cvs -f diff -r v1 -u ) >cvsDiff.out 2>cvs.log &&
459
- test ! -s cvsDiff.out &&
460
- test ! -s cvs.log
459
+ test_must_be_empty cvsDiff.out &&
460
+ test_must_be_empty cvs.log
461
'
462
463
test_expect_success 'cvs diff -N -r v2 -u' '
464
( cd cvswork && ! cvs -f diff -N -r v2 -u ) >cvsDiff.out 2>cvs.log &&
465
- test ! -s cvs.log &&
465
+ test_must_be_empty cvs.log &&
466
test -s cvsDiff.out &&
467
check_diff cvsDiff.out v2 v1 >check_diff.out 2>&1
468
'
469
470
test_expect_success 'cvs diff -N -r v2 -r v1.2' '
471
( cd cvswork && ! cvs -f diff -N -r v2 -r v1.2 -u ) >cvsDiff.out 2>cvs.log &&
472
- test ! -s cvs.log &&
472
+ test_must_be_empty cvs.log &&
473
test -s cvsDiff.out &&
474
check_diff cvsDiff.out v2 v1.2 >check_diff.out 2>&1
475
'
@@ -488,7 +488,7 @@ test_expect_success 'apply early [cvswork3] diff to b3' '
488
489
test_expect_success 'check [cvswork3] diff' '
490
( cd cvswork3 && ! cvs -f diff -N -u ) >"$WORKDIR/cvsDiff.out" 2>cvs.log &&
491
- test ! -s cvs.log &&
491
+ test_must_be_empty cvs.log &&
492
test -s cvsDiff.out &&
493
test $(grep Index: cvsDiff.out | wc -l) = 3 &&
494
test_cmp cvsDiff.out cvswork3edit.diff &&
t/test-lib-functions.sh
+12
@@ -606,6 +606,18 @@ test_cmp() {
606
$GIT_TEST_CMP "$@"
607
}
608
609
+# Check if the file expected to be empty is indeed empty, and barfs
610
+# otherwise.
611
+
612
+test_must_be_empty () {
613
+ if test -s "$1"
614
+ then
615
+ echo "'$1' is not empty, it contains:"
616
+ cat "$1"
617
+ return 1
618
+ fi
619
+}
620
+
621
# Tests that its two parameters refer to the same revision
622
test_cmp_rev () {
623
git rev-parse --verify "$1" >expect.rev &&