Skip to content

Commit f1dd90b

Browse files
peffgitster
authored andcommitted
t5304: use test_path_is_* instead of "test -f"
This is slightly more robust (checking "! test -f" would not notice a directory of the same name, though that is not likely to happen here). It also makes debugging easier, as the test script will output a message on failure. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 63a4513 commit f1dd90b

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

t/t5304-prune.sh

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ add_blob() {
1414
BLOB=$(echo aleph_0 | git hash-object -w --stdin) &&
1515
BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") &&
1616
test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
17-
test -f $BLOB_FILE &&
17+
test_path_is_file $BLOB_FILE &&
1818
test-chmtime =+0 $BLOB_FILE
1919
}
2020

@@ -35,9 +35,9 @@ test_expect_success 'prune stale packs' '
3535
: > .git/objects/tmp_2.pack &&
3636
test-chmtime =-86501 .git/objects/tmp_1.pack &&
3737
git prune --expire 1.day &&
38-
test -f $orig_pack &&
39-
test -f .git/objects/tmp_2.pack &&
40-
! test -f .git/objects/tmp_1.pack
38+
test_path_is_file $orig_pack &&
39+
test_path_is_file .git/objects/tmp_2.pack &&
40+
test_path_is_missing .git/objects/tmp_1.pack
4141
4242
'
4343

@@ -46,11 +46,11 @@ test_expect_success 'prune --expire' '
4646
add_blob &&
4747
git prune --expire=1.hour.ago &&
4848
test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
49-
test -f $BLOB_FILE &&
49+
test_path_is_file $BLOB_FILE &&
5050
test-chmtime =-86500 $BLOB_FILE &&
5151
git prune --expire 1.day &&
5252
test $before = $(git count-objects | sed "s/ .*//") &&
53-
! test -f $BLOB_FILE
53+
test_path_is_missing $BLOB_FILE
5454
5555
'
5656

@@ -60,11 +60,11 @@ test_expect_success 'gc: implicit prune --expire' '
6060
test-chmtime =-$((2*$week-30)) $BLOB_FILE &&
6161
git gc &&
6262
test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
63-
test -f $BLOB_FILE &&
63+
test_path_is_file $BLOB_FILE &&
6464
test-chmtime =-$((2*$week+1)) $BLOB_FILE &&
6565
git gc &&
6666
test $before = $(git count-objects | sed "s/ .*//") &&
67-
! test -f $BLOB_FILE
67+
test_path_is_missing $BLOB_FILE
6868
6969
'
7070

@@ -110,7 +110,7 @@ test_expect_success 'prune: do not prune detached HEAD with no reflog' '
110110
git commit --allow-empty -m "detached commit" &&
111111
# verify that there is no reflogs
112112
# (should be removed and disabled by previous test)
113-
test ! -e .git/logs &&
113+
test_path_is_missing .git/logs &&
114114
git prune -n >prune_actual &&
115115
: >prune_expected &&
116116
test_cmp prune_actual prune_expected
@@ -145,18 +145,18 @@ test_expect_success 'gc --no-prune' '
145145
git config gc.pruneExpire 2.days.ago &&
146146
git gc --no-prune &&
147147
test 1 = $(git count-objects | sed "s/ .*//") &&
148-
test -f $BLOB_FILE
148+
test_path_is_file $BLOB_FILE
149149
150150
'
151151

152152
test_expect_success 'gc respects gc.pruneExpire' '
153153
154154
git config gc.pruneExpire 5002.days.ago &&
155155
git gc &&
156-
test -f $BLOB_FILE &&
156+
test_path_is_file $BLOB_FILE &&
157157
git config gc.pruneExpire 5000.days.ago &&
158158
git gc &&
159-
test ! -f $BLOB_FILE
159+
test_path_is_missing $BLOB_FILE
160160
161161
'
162162

@@ -165,19 +165,19 @@ test_expect_success 'gc --prune=<date>' '
165165
add_blob &&
166166
test-chmtime =-$((5001*$day)) $BLOB_FILE &&
167167
git gc --prune=5002.days.ago &&
168-
test -f $BLOB_FILE &&
168+
test_path_is_file $BLOB_FILE &&
169169
git gc --prune=5000.days.ago &&
170-
test ! -f $BLOB_FILE
170+
test_path_is_missing $BLOB_FILE
171171
172172
'
173173

174174
test_expect_success 'gc --prune=never' '
175175
176176
add_blob &&
177177
git gc --prune=never &&
178-
test -f $BLOB_FILE &&
178+
test_path_is_file $BLOB_FILE &&
179179
git gc --prune=now &&
180-
test ! -f $BLOB_FILE
180+
test_path_is_missing $BLOB_FILE
181181
182182
'
183183

@@ -186,20 +186,20 @@ test_expect_success 'gc respects gc.pruneExpire=never' '
186186
git config gc.pruneExpire never &&
187187
add_blob &&
188188
git gc &&
189-
test -f $BLOB_FILE &&
189+
test_path_is_file $BLOB_FILE &&
190190
git config gc.pruneExpire now &&
191191
git gc &&
192-
test ! -f $BLOB_FILE
192+
test_path_is_missing $BLOB_FILE
193193
194194
'
195195

196196
test_expect_success 'prune --expire=never' '
197197
198198
add_blob &&
199199
git prune --expire=never &&
200-
test -f $BLOB_FILE &&
200+
test_path_is_file $BLOB_FILE &&
201201
git prune &&
202-
test ! -f $BLOB_FILE
202+
test_path_is_missing $BLOB_FILE
203203
204204
'
205205

@@ -210,10 +210,10 @@ test_expect_success 'gc: prune old objects after local clone' '
210210
(
211211
cd aclone &&
212212
test 1 = $(git count-objects | sed "s/ .*//") &&
213-
test -f $BLOB_FILE &&
213+
test_path_is_file $BLOB_FILE &&
214214
git gc --prune &&
215215
test 0 = $(git count-objects | sed "s/ .*//") &&
216-
! test -f $BLOB_FILE
216+
test_path_is_missing $BLOB_FILE
217217
)
218218
'
219219

@@ -250,7 +250,7 @@ test_expect_success 'prune .git/shallow' '
250250
grep $SHA1 .git/shallow &&
251251
grep $SHA1 out &&
252252
git prune &&
253-
! test -f .git/shallow
253+
test_path_is_missing .git/shallow
254254
'
255255

256256
test_done

0 commit comments

Comments
 (0)