Skip to content

Commit ca8d148

Browse files
committed
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 <[email protected]>
1 parent b1d04bf commit ca8d148

9 files changed

+65
-53
lines changed

t/t0040-parse-options.sh

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ EOF
5050

5151
test_expect_success 'test help' '
5252
test_must_fail test-parse-options -h > output 2> output.err &&
53-
test ! -s output.err &&
53+
test_must_be_empty output.err &&
5454
test_i18ncmp expect output
5555
'
5656

@@ -75,7 +75,7 @@ check() {
7575
shift &&
7676
sed "s/^$what .*/$what $expect/" <expect.template >expect &&
7777
test-parse-options $* >output 2>output.err &&
78-
test ! -s output.err &&
78+
test_must_be_empty output.err &&
7979
test_cmp expect output
8080
}
8181

@@ -86,7 +86,7 @@ check_i18n() {
8686
shift &&
8787
sed "s/^$what .*/$what $expect/" <expect.template >expect &&
8888
test-parse-options $* >output 2>output.err &&
89-
test ! -s output.err &&
89+
test_must_be_empty output.err &&
9090
test_i18ncmp expect output
9191
}
9292

@@ -99,7 +99,7 @@ check_unknown() {
9999
esac &&
100100
cat expect.err >>expect &&
101101
test_must_fail test-parse-options $* >output 2>output.err &&
102-
test ! -s output &&
102+
test_must_be_empty output &&
103103
test_cmp expect output.err
104104
}
105105

@@ -112,7 +112,7 @@ check_unknown_i18n() {
112112
esac &&
113113
cat expect.err >>expect &&
114114
test_must_fail test-parse-options $* >output 2>output.err &&
115-
test ! -s output &&
115+
test_must_be_empty output &&
116116
test_i18ncmp expect output.err
117117
}
118118

@@ -149,7 +149,7 @@ test_expect_success 'short options' '
149149
test-parse-options -s123 -b -i 1729 -b -vv -n -F my.file \
150150
> output 2> output.err &&
151151
test_cmp expect output &&
152-
test ! -s output.err
152+
test_must_be_empty output.err
153153
'
154154

155155
cat > expect << EOF
@@ -168,7 +168,7 @@ test_expect_success 'long options' '
168168
test-parse-options --boolean --integer 1729 --boolean --string2=321 \
169169
--verbose --verbose --no-dry-run --abbrev=10 --file fi.le\
170170
--obsolete > output 2> output.err &&
171-
test ! -s output.err &&
171+
test_must_be_empty output.err &&
172172
test_cmp expect output
173173
'
174174

@@ -199,7 +199,7 @@ EOF
199199
test_expect_success 'intermingled arguments' '
200200
test-parse-options a1 --string 123 b1 --boolean -j 13 -- --boolean \
201201
> output 2> output.err &&
202-
test ! -s output.err &&
202+
test_must_be_empty output.err &&
203203
test_cmp expect output
204204
'
205205

@@ -217,13 +217,13 @@ EOF
217217

218218
test_expect_success 'unambiguously abbreviated option' '
219219
test-parse-options --int 2 --boolean --no-bo > output 2> output.err &&
220-
test ! -s output.err &&
220+
test_must_be_empty output.err &&
221221
test_cmp expect output
222222
'
223223

224224
test_expect_success 'unambiguously abbreviated option with "="' '
225225
test-parse-options --int=2 > output 2> output.err &&
226-
test ! -s output.err &&
226+
test_must_be_empty output.err &&
227227
test_cmp expect output
228228
'
229229

@@ -246,7 +246,7 @@ EOF
246246

247247
test_expect_success 'non ambiguous option (after two options it abbreviates)' '
248248
test-parse-options --st 123 > output 2> output.err &&
249-
test ! -s output.err &&
249+
test_must_be_empty output.err &&
250250
test_cmp expect output
251251
'
252252

@@ -256,7 +256,7 @@ EOF
256256

257257
test_expect_success 'detect possible typos' '
258258
test_must_fail test-parse-options -boolean > output 2> output.err &&
259-
test ! -s output &&
259+
test_must_be_empty output &&
260260
test_cmp typo.err output.err
261261
'
262262

@@ -266,7 +266,7 @@ EOF
266266

267267
test_expect_success 'detect possible typos' '
268268
test_must_fail test-parse-options -ambiguous > output 2> output.err &&
269-
test ! -s output &&
269+
test_must_be_empty output &&
270270
test_cmp typo.err output.err
271271
'
272272

@@ -285,7 +285,7 @@ EOF
285285

286286
test_expect_success 'keep some options as arguments' '
287287
test-parse-options --quux > output 2> output.err &&
288-
test ! -s output.err &&
288+
test_must_be_empty output.err &&
289289
test_cmp expect output
290290
'
291291

@@ -305,7 +305,7 @@ EOF
305305
test_expect_success 'OPT_DATE() and OPT_SET_PTR() work' '
306306
test-parse-options -t "1970-01-01 00:00:01 +0000" --default-string \
307307
foo -q > output 2> output.err &&
308-
test ! -s output.err &&
308+
test_must_be_empty output.err &&
309309
test_cmp expect output
310310
'
311311

@@ -324,7 +324,7 @@ EOF
324324

325325
test_expect_success 'OPT_CALLBACK() and OPT_BIT() work' '
326326
test-parse-options --length=four -b -4 > output 2> output.err &&
327-
test ! -s output.err &&
327+
test_must_be_empty output.err &&
328328
test_cmp expect output
329329
'
330330

@@ -352,13 +352,13 @@ EOF
352352

353353
test_expect_success 'OPT_BIT() and OPT_SET_INT() work' '
354354
test-parse-options --set23 -bbbbb --no-or4 > output 2> output.err &&
355-
test ! -s output.err &&
355+
test_must_be_empty output.err &&
356356
test_cmp expect output
357357
'
358358

359359
test_expect_success 'OPT_NEGBIT() and OPT_SET_INT() work' '
360360
test-parse-options --set23 -bbbbb --neg-or4 > output 2> output.err &&
361-
test ! -s output.err &&
361+
test_must_be_empty output.err &&
362362
test_cmp expect output
363363
'
364364

@@ -376,19 +376,19 @@ EOF
376376

377377
test_expect_success 'OPT_BIT() works' '
378378
test-parse-options -bb --or4 > output 2> output.err &&
379-
test ! -s output.err &&
379+
test_must_be_empty output.err &&
380380
test_cmp expect output
381381
'
382382

383383
test_expect_success 'OPT_NEGBIT() works' '
384384
test-parse-options -bb --no-neg-or4 > output 2> output.err &&
385-
test ! -s output.err &&
385+
test_must_be_empty output.err &&
386386
test_cmp expect output
387387
'
388388

389389
test_expect_success 'OPT_COUNTUP() with PARSE_OPT_NODASH works' '
390390
test-parse-options + + + + + + > output 2> output.err &&
391-
test ! -s output.err &&
391+
test_must_be_empty output.err &&
392392
test_cmp expect output
393393
'
394394

@@ -406,7 +406,7 @@ EOF
406406

407407
test_expect_success 'OPT_NUMBER_CALLBACK() works' '
408408
test-parse-options -12345 > output 2> output.err &&
409-
test ! -s output.err &&
409+
test_must_be_empty output.err &&
410410
test_cmp expect output
411411
'
412412

@@ -424,7 +424,7 @@ EOF
424424

425425
test_expect_success 'negation of OPT_NONEG flags is not ambiguous' '
426426
test-parse-options --no-ambig >output 2>output.err &&
427-
test ! -s output.err &&
427+
test_must_be_empty output.err &&
428428
test_cmp expect output
429429
'
430430

t/t3400-rebase.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ test_expect_success 'default to @{upstream} when upstream arg is missing' '
179179
test_expect_success 'rebase -q is quiet' '
180180
git checkout -b quiet topic &&
181181
git rebase -q master >output.out 2>&1 &&
182-
test ! -s output.out
182+
test_must_be_empty output.out
183183
'
184184

185185
test_expect_success 'Rebase a commit that sprinkles CRs in' '

t/t3903-stash.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,17 @@ test_expect_success 'apply -q is quiet' '
200200
echo foo > file &&
201201
git stash &&
202202
git stash apply -q > output.out 2>&1 &&
203-
test ! -s output.out
203+
test_must_be_empty output.out
204204
'
205205

206206
test_expect_success 'save -q is quiet' '
207207
git stash save --quiet > output.out 2>&1 &&
208-
test ! -s output.out
208+
test_must_be_empty output.out
209209
'
210210

211211
test_expect_success 'pop -q is quiet' '
212212
git stash pop -q > output.out 2>&1 &&
213-
test ! -s output.out
213+
test_must_be_empty output.out
214214
'
215215

216216
test_expect_success 'pop -q --index works and is quiet' '
@@ -219,13 +219,13 @@ test_expect_success 'pop -q --index works and is quiet' '
219219
git stash save --quiet &&
220220
git stash pop -q --index > output.out 2>&1 &&
221221
test foo = "$(git show :file)" &&
222-
test ! -s output.out
222+
test_must_be_empty output.out
223223
'
224224

225225
test_expect_success 'drop -q is quiet' '
226226
git stash &&
227227
git stash drop -q > output.out 2>&1 &&
228-
test ! -s output.out
228+
test_must_be_empty output.out
229229
'
230230

231231
test_expect_success 'stash -k' '

t/t5521-pull-options.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,66 +15,66 @@ test_expect_success 'git pull -q' '
1515
mkdir clonedq &&
1616
(cd clonedq && git init &&
1717
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)
2020
'
2121

2222
test_expect_success 'git pull -q --rebase' '
2323
mkdir clonedqrb &&
2424
(cd clonedqrb && git init &&
2525
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 &&
2828
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)
3131
'
3232

3333
test_expect_success 'git pull' '
3434
mkdir cloned &&
3535
(cd cloned && git init &&
3636
git pull "../parent" >out 2>err &&
3737
test -s err &&
38-
test ! -s out)
38+
test_must_be_empty out)
3939
'
4040

4141
test_expect_success 'git pull --rebase' '
4242
mkdir clonedrb &&
4343
(cd clonedrb && git init &&
4444
git pull --rebase "../parent" >out 2>err &&
4545
test -s err &&
46-
test ! -s out)
46+
test_must_be_empty out)
4747
'
4848

4949
test_expect_success 'git pull -v' '
5050
mkdir clonedv &&
5151
(cd clonedv && git init &&
5252
git pull -v "../parent" >out 2>err &&
5353
test -s err &&
54-
test ! -s out)
54+
test_must_be_empty out)
5555
'
5656

5757
test_expect_success 'git pull -v --rebase' '
5858
mkdir clonedvrb &&
5959
(cd clonedvrb && git init &&
6060
git pull -v --rebase "../parent" >out 2>err &&
6161
test -s err &&
62-
test ! -s out)
62+
test_must_be_empty out)
6363
'
6464

6565
test_expect_success 'git pull -v -q' '
6666
mkdir clonedvq &&
6767
(cd clonedvq && git init &&
6868
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)
7171
'
7272

7373
test_expect_success 'git pull -q -v' '
7474
mkdir clonedqv &&
7575
(cd clonedqv && git init &&
7676
git pull -q -v "../parent" >out 2>err &&
77-
test ! -s out &&
77+
test_must_be_empty out &&
7878
test -s err)
7979
'
8080

t/t5702-clone-options.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test_expect_success 'clone -o' '
2222
test_expect_success 'redirected clone' '
2323
2424
git clone "file://$(pwd)/parent" clone-redirected >out 2>err &&
25-
test ! -s err
25+
test_must_be_empty err
2626
2727
'
2828
test_expect_success 'redirected clone -v' '

t/t7102-reset.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ test_expect_success 'disambiguation (1)' '
457457
test_must_fail git diff --quiet -- secondfile &&
458458
test -z "$(git diff --cached --name-only)" &&
459459
test -f secondfile &&
460-
test ! -s secondfile
460+
test_must_be_empty secondfile
461461
462462
'
463463

t/t7400-submodule-basic.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ test_expect_success 'submodule add' '
7878
(
7979
cd addtest &&
8080
git submodule add -q "$submodurl" submod >actual &&
81-
test ! -s actual &&
81+
test_must_be_empty actual &&
8282
echo "gitdir: ../.git/modules/submod" >expect &&
8383
test_cmp expect submod/.git &&
8484
(
@@ -308,7 +308,7 @@ test_expect_success 'update should work when path is an empty dir' '
308308
309309
mkdir init &&
310310
git submodule update -q >update.out &&
311-
test ! -s update.out &&
311+
test_must_be_empty update.out &&
312312
313313
inspect init &&
314314
test_cmp expect head-sha1
@@ -696,7 +696,7 @@ test_expect_success 'submodule add --name allows to replace a submodule with ano
696696
rm -rf repo &&
697697
git rm repo &&
698698
git submodule add -q --name repo_new "$submodurl/bare.git" repo >actual &&
699-
test ! -s actual &&
699+
test_must_be_empty actual &&
700700
echo "gitdir: ../.git/modules/submod" >expect &&
701701
test_cmp expect submod/.git &&
702702
(

0 commit comments

Comments
 (0)