Skip to content

Commit 898de19

Browse files
committed
tests: avoid calling Perl just to determine file sizes
It is a bit ridiculous to spin up a full-blown Perl instance (especially on Windows, where that means spinning up a full POSIX emulation layer, AKA the MSYS2 runtime) just to tell how large a given file is. So let's just use the test-tool to do that job instead. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 3ee87b3 commit 898de19

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

t/helper/test-path-utils.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,18 @@ int cmd__path_utils(int argc, const char **argv)
291291
return !!res;
292292
}
293293

294+
if (argc > 2 && !strcmp(argv[1], "file-size")) {
295+
int res = 0, i;
296+
struct stat st;
297+
298+
for (i = 2; i < argc; i++)
299+
if (stat(argv[i], &st))
300+
res = error_errno("Cannot stat '%s'", argv[i]);
301+
else
302+
printf("%"PRIuMAX"\n", (uintmax_t)st.st_size);
303+
return !!res;
304+
}
305+
294306
fprintf(stderr, "%s: unknown function name: %s\n", argv[0],
295307
argv[1] ? argv[1] : "(there was none)");
296308
return 1;

t/t0021-conversion.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ generate_random_characters () {
2424
}
2525

2626
file_size () {
27-
perl -e 'print -s $ARGV[0]' "$1"
27+
test-tool path-utils file-size "$1"
2828
}
2929

3030
filter_git () {

t/t1050-large.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test_description='adding and checking out large blobs'
88
# This should be moved to test-lib.sh together with the
99
# copy in t0021 after both topics have graduated to 'master'.
1010
file_size () {
11-
perl -e 'print -s $ARGV[0]' "$1"
11+
test-tool path-utils file-size "$1"
1212
}
1313

1414
test_expect_success setup '

t/t5315-pack-objects-compression.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ test_description='pack-object compression configuration'
77
# This should be moved to test-lib.sh together with the
88
# copy in t0021 after both topics have graduated to 'master'.
99
file_size () {
10-
perl -e 'print -s $ARGV[0]' "$1"
10+
test-tool path-utils file-size "$1"
1111
}
1212

1313
test_expect_success setup '

t/t9303-fast-import-compression.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ test_description='compression setting of fast-import utility'
66
# This should be moved to test-lib.sh together with the
77
# copy in t0021 after both topics have graduated to 'master'.
88
file_size () {
9-
perl -e 'print -s $ARGV[0]' "$1"
9+
test-tool path-utils file-size "$1"
1010
}
1111

1212
import_large () {

0 commit comments

Comments
 (0)