Skip to content

Commit ec10b01

Browse files
szedergitster
authored andcommitted
tests: use 'test_must_be_empty' instead of '! test -s'
Using 'test_must_be_empty' is preferable to '! test -s', because it gives a helpful error message if the given file is unexpectedly not empty, while the latter remains completely silent. Furthermore, it also catches cases when the given file unexpectedly does not exist at all. This patch was basically created by: sed -i -e 's/! test -s/test_must_be_empty/' t[0-9]*.sh with the following notable exceptions: - The '! test -s' check in '.gitmodules ignore=dirty suppresses submodules with untracked content' in 't7508-status.sh' is left as-is, because it's bogus and, therefore, it's subject of a dedicated patch. - The '! test -s' checks in 't9131-git-svn-empty-symlink.sh' and 't9135-git-svn-moved-branch-empty-file.sh' are immediately preceeded by a 'test -f' to ensure that the files exist in the first place. 'test_must_be_empty' ensures that as well, so those 'test -f' commands are removed as well. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d3c6751 commit ec10b01

25 files changed

+98
-99
lines changed

t/t0000-basic.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ check_sub_test_lib_test () {
116116
name="$1" # stdin is the expected output from the test
117117
(
118118
cd "$name" &&
119-
! test -s err &&
119+
test_must_be_empty err &&
120120
sed -e 's/^> //' -e 's/Z$//' >expect &&
121121
test_cmp expect out
122122
)

t/t0090-cache-tree.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ test_expect_success 'no phantom error when switching trees' '
239239
>newdir/one &&
240240
git add newdir/one &&
241241
git checkout 2>errors &&
242-
! test -s errors
242+
test_must_be_empty errors
243243
'
244244

245245
test_expect_success 'switching trees does not invalidate shared index' '

t/t0203-gettext-setlocale-sanity.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ test_expect_success 'git show a ISO-8859-1 commit under C locale' '
1111
. "$TEST_DIRECTORY"/t3901/8859-1.txt &&
1212
test_commit "iso-c-commit" iso-under-c &&
1313
git show >out 2>err &&
14-
! test -s err &&
14+
test_must_be_empty err &&
1515
grep -q "iso-c-commit" out
1616
'
1717

1818
test_expect_success GETTEXT_LOCALE 'git show a ISO-8859-1 commit under a UTF-8 locale' '
1919
. "$TEST_DIRECTORY"/t3901/8859-1.txt &&
2020
test_commit "iso-utf8-commit" iso-under-utf8 &&
2121
LANGUAGE=is LC_ALL="$is_IS_locale" git show >out 2>err &&
22-
! test -s err &&
22+
test_must_be_empty err &&
2323
grep -q "iso-utf8-commit" out
2424
'
2525

t/t1501-work-tree.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ test_expect_success 'setup: helper for testing rev-parse' '
4141
# rev-parse --show-prefix should output
4242
# a single newline when at the top of the work tree,
4343
# but we test for that separately.
44-
test -z "$4" && ! test -s actual.prefix ||
44+
test -z "$4" && test_must_be_empty actual.prefix ||
4545
test_cmp expected.prefix actual.prefix
4646
fi
4747
}

t/t1510-repo-setup.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,14 @@ test_expect_success '#0: nonbare repo, no explicit configuration' '
234234
try_repo 0 unset unset unset "" unset \
235235
.git "$here/0" "$here/0" "(null)" \
236236
.git "$here/0" "$here/0" sub/ 2>message &&
237-
! test -s message
237+
test_must_be_empty message
238238
'
239239

240240
test_expect_success '#1: GIT_WORK_TREE without explicit GIT_DIR is accepted' '
241241
try_repo 1 "$here" unset unset "" unset \
242242
"$here/1/.git" "$here" "$here" 1/ \
243243
"$here/1/.git" "$here" "$here" 1/sub/ 2>message &&
244-
! test -s message
244+
test_must_be_empty message
245245
'
246246

247247
test_expect_success '#2: worktree defaults to cwd with explicit GIT_DIR' '
@@ -268,7 +268,7 @@ test_expect_success '#4: core.worktree without GIT_DIR set is accepted' '
268268
try_case 4 unset unset \
269269
.git "$here/4/sub" "$here/4" "(null)" \
270270
"$here/4/.git" "$here/4/sub" "$here/4/sub" "(null)" 2>message &&
271-
! test -s message
271+
test_must_be_empty message
272272
'
273273

274274
test_expect_success '#5: core.worktree + GIT_WORK_TREE is accepted' '
@@ -279,7 +279,7 @@ test_expect_success '#5: core.worktree + GIT_WORK_TREE is accepted' '
279279
try_repo 5a .. unset "$here/5a" "" unset \
280280
"$here/5a/.git" "$here" "$here" 5a/ \
281281
"$here/5a/.git" "$here/5a" "$here/5a" sub/ &&
282-
! test -s message
282+
test_must_be_empty message
283283
'
284284

285285
test_expect_success '#6: setting GIT_DIR brings core.worktree to life' '
@@ -376,7 +376,7 @@ test_expect_success '#9: GIT_WORK_TREE accepted with gitfile' '
376376
try_repo 9 wt unset unset gitfile unset \
377377
"$here/9.git" "$here/9/wt" "$here/9" "(null)" \
378378
"$here/9.git" "$here/9/sub/wt" "$here/9/sub" "(null)" 2>message &&
379-
! test -s message
379+
test_must_be_empty message
380380
'
381381

382382
test_expect_success '#10: GIT_DIR can point to gitfile' '
@@ -402,15 +402,15 @@ test_expect_success '#12: core.worktree with gitfile is accepted' '
402402
try_repo 12 unset unset "$here/12" gitfile unset \
403403
"$here/12.git" "$here/12" "$here/12" "(null)" \
404404
"$here/12.git" "$here/12" "$here/12" sub/ 2>message &&
405-
! test -s message
405+
test_must_be_empty message
406406
'
407407

408408
test_expect_success '#13: core.worktree+GIT_WORK_TREE accepted (with gitfile)' '
409409
# or: you cannot intimidate away the lack of GIT_DIR setting
410410
try_repo 13 non-existent-too unset non-existent gitfile unset \
411411
"$here/13.git" "$here/13/non-existent-too" "$here/13" "(null)" \
412412
"$here/13.git" "$here/13/sub/non-existent-too" "$here/13/sub" "(null)" 2>message &&
413-
! test -s message
413+
test_must_be_empty message
414414
'
415415

416416
# case #14.
@@ -565,7 +565,7 @@ test_expect_success '#17: GIT_WORK_TREE without explicit GIT_DIR is accepted (ba
565565
try_repo 17c "$here/17c" unset unset "" true \
566566
.git "$here/17c" "$here/17c" "(null)" \
567567
"$here/17c/.git" "$here/17c" "$here/17c" sub/ 2>message &&
568-
! test -s message
568+
test_must_be_empty message
569569
'
570570

571571
test_expect_success '#18: bare .git named by GIT_DIR has no worktree' '
@@ -594,7 +594,7 @@ test_expect_success '#20a: core.worktree without GIT_DIR accepted (inside .git)'
594594
"$here/20a/.git" "$here/20a" "$here/20a" .git/wt/ &&
595595
try_case 20a/.git/wt/sub unset unset \
596596
"$here/20a/.git" "$here/20a" "$here/20a" .git/wt/sub/ &&
597-
! test -s message
597+
test_must_be_empty message
598598
'
599599

600600
test_expect_success '#20b/c: core.worktree and core.bare conflict' '
@@ -626,7 +626,7 @@ test_expect_success '#21: setup, core.worktree warns before overriding core.bare
626626
export GIT_WORK_TREE &&
627627
git status >/dev/null
628628
) 2>message &&
629-
! test -s message
629+
test_must_be_empty message
630630
631631
'
632632
run_wt_tests 21
@@ -742,7 +742,7 @@ test_expect_success '#25: GIT_WORK_TREE accepted if GIT_DIR unset (bare gitfile
742742
try_repo 25 "$here/25" unset unset gitfile true \
743743
"$here/25.git" "$here/25" "$here/25" "(null)" \
744744
"$here/25.git" "$here/25" "$here/25" "sub/" 2>message &&
745-
! test -s message
745+
test_must_be_empty message
746746
'
747747

748748
test_expect_success '#26: bare repo has no worktree (GIT_DIR -> gitfile case)' '
@@ -780,7 +780,7 @@ test_expect_success '#29: setup' '
780780
export GIT_WORK_TREE &&
781781
git status
782782
) 2>message &&
783-
! test -s message
783+
test_must_be_empty message
784784
'
785785
run_wt_tests 29 gitfile
786786

t/t2013-checkout-submodule.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,23 @@ test_expect_success '"checkout <submodule>" honors diff.ignoreSubmodules' '
4444
git config diff.ignoreSubmodules dirty &&
4545
echo x> submodule/untracked &&
4646
git checkout HEAD >actual 2>&1 &&
47-
! test -s actual
47+
test_must_be_empty actual
4848
'
4949

5050
test_expect_success '"checkout <submodule>" honors submodule.*.ignore from .gitmodules' '
5151
git config diff.ignoreSubmodules none &&
5252
git config -f .gitmodules submodule.submodule.path submodule &&
5353
git config -f .gitmodules submodule.submodule.ignore untracked &&
5454
git checkout HEAD >actual 2>&1 &&
55-
! test -s actual
55+
test_must_be_empty actual
5656
'
5757

5858
test_expect_success '"checkout <submodule>" honors submodule.*.ignore from .git/config' '
5959
git config -f .gitmodules submodule.submodule.ignore none &&
6060
git config submodule.submodule.path submodule &&
6161
git config submodule.submodule.ignore all &&
6262
git checkout HEAD >actual 2>&1 &&
63-
! test -s actual
63+
test_must_be_empty actual
6464
'
6565

6666
KNOWN_FAILURE_DIRECTORY_SUBMODULE_CONFLICTS=1

t/t2204-add-ignored.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ do
3131
rm -f .git/index &&
3232
test_must_fail git add "$i" 2>err &&
3333
git ls-files "$i" >out &&
34-
! test -s out
34+
test_must_be_empty out
3535
'
3636

3737
test_expect_success "complaints for ignored $i output" '
@@ -42,7 +42,7 @@ do
4242
rm -f .git/index &&
4343
test_must_fail git add "$i" file 2>err &&
4444
git ls-files "$i" >out &&
45-
! test -s out
45+
test_must_be_empty out
4646
'
4747
test_expect_success "complaints for ignored $i with unignored file output" '
4848
test_i18ngrep -e "Use -f if" err
@@ -57,7 +57,7 @@ do
5757
cd dir &&
5858
test_must_fail git add "$i" 2>err &&
5959
git ls-files "$i" >out &&
60-
! test -s out
60+
test_must_be_empty out
6161
)
6262
'
6363

@@ -77,7 +77,7 @@ do
7777
cd sub &&
7878
test_must_fail git add "$i" 2>err &&
7979
git ls-files "$i" >out &&
80-
! test -s out
80+
test_must_be_empty out
8181
)
8282
'
8383

t/t3600-rm.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ test_expect_success 'rm does not complain when no .gitmodules file is found' '
382382
git submodule update &&
383383
git rm .gitmodules &&
384384
git rm submod >actual 2>actual.err &&
385-
! test -s actual.err &&
385+
test_must_be_empty actual.err &&
386386
! test -d submod &&
387387
! test -f submod/.git &&
388388
git status -s -uno >actual &&
@@ -400,7 +400,7 @@ test_expect_success 'rm will error out on a modified .gitmodules file unless sta
400400
git diff-files --quiet -- submod &&
401401
git add .gitmodules &&
402402
git rm submod >actual 2>actual.err &&
403-
! test -s actual.err &&
403+
test_must_be_empty actual.err &&
404404
! test -d submod &&
405405
! test -f submod/.git &&
406406
git status -s -uno >actual &&
@@ -694,7 +694,7 @@ test_expect_success 'checking out a commit after submodule removal needs manual
694694
test_cmp expected actual &&
695695
rm -rf submod &&
696696
git status -s -uno --ignore-submodules=none >actual &&
697-
! test -s actual
697+
test_must_be_empty actual
698698
'
699699

700700
test_expect_success 'rm of d/f when d has become a non-directory' '

t/t4011-diff-symlink.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ test_expect_success SYMLINKS 'diff symlinks with non-existing targets' '
126126
ln -s take\ over brain &&
127127
test_must_fail git diff --no-index pinky brain >output 2>output.err &&
128128
grep narf output &&
129-
! test -s output.err
129+
test_must_be_empty output.err
130130
'
131131

132132
test_expect_success SYMLINKS 'setup symlinks with attributes' '

t/t4019-diff-wserror.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ test_expect_success 'trailing empty lines (2)' '
260260
261261
echo "F -whitespace" >.gitattributes &&
262262
git diff --check >output &&
263-
! test -s output
263+
test_must_be_empty output
264264
265265
'
266266

0 commit comments

Comments
 (0)