tests: consolidate the `file_size` function into `test-lib-functions.sh`

In 8de7eeb54b6 (compression: unify pack.compression configuration parsing, 2016-11-15), we introduced identical copies of the `file_size` helper into three test scripts, with the plan to eventually consolidate them into a single copy. Let's do that, and adjust the function name to adhere to the `test_*` naming convention. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Reviewed-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Nov 7, 2020 at 01:12 UTC 53b67a801bbce7600f25823c39c7e9e7de8b72b3
5 files changed +24 -42
t/t0021-conversion.sh
+16 -20
@@ -23,10 +23,6 @@ generate_random_characters () {
23 perl -pe "s/./chr((ord($&) % 26) + ord('a'))/sge" >"$TEST_ROOT/$NAME"
24 }
25
26 -file_size () {
27 - test-tool path-utils file-size "$1"
28 -}
29 -
26 filter_git () {
27 rm -f *.log &&
28 git "$@"
@@ -361,9 +357,9 @@ test_expect_success PERL 'required process filter should filter data' '
357 cp "$TEST_ROOT/test3 '\''sq'\'',\$x=.o" "testsubdir/test3 '\''sq'\'',\$x=.r" &&
358 >test4-empty.r &&
359
364 - S=$(file_size test.r) &&
365 - S2=$(file_size test2.r) &&
366 - S3=$(file_size "testsubdir/test3 '\''sq'\'',\$x=.r") &&
360 + S=$(test_file_size test.r) &&
361 + S2=$(test_file_size test2.r) &&
362 + S3=$(test_file_size "testsubdir/test3 '\''sq'\'',\$x=.r") &&
363 M=$(git hash-object test.r) &&
364 M2=$(git hash-object test2.r) &&
365 M3=$(git hash-object "testsubdir/test3 '\''sq'\'',\$x=.r") &&
@@ -432,9 +428,9 @@ test_expect_success PERL 'required process filter should filter data for various
428 (
429 cd repo &&
430
435 - S=$(file_size test.r) &&
436 - S2=$(file_size test2.r) &&
437 - S3=$(file_size "testsubdir/test3 '\''sq'\'',\$x=.r") &&
431 + S=$(test_file_size test.r) &&
432 + S2=$(test_file_size test2.r) &&
433 + S3=$(test_file_size "testsubdir/test3 '\''sq'\'',\$x=.r") &&
434 M=$(git hash-object test.r) &&
435 M2=$(git hash-object test2.r) &&
436 M3=$(git hash-object "testsubdir/test3 '\''sq'\'',\$x=.r") &&
@@ -549,7 +545,7 @@ test_expect_success PERL 'required process filter takes precedence' '
545
546 echo "*.r filter=protocol" >.gitattributes &&
547 cp "$TEST_ROOT/test.o" test.r &&
552 - S=$(file_size test.r) &&
548 + S=$(test_file_size test.r) &&
549
550 # Check that the process filter is invoked here
551 filter_git add . &&
@@ -573,7 +569,7 @@ test_expect_success PERL 'required process filter should be used only for "clean
569
570 echo "*.r filter=protocol" >.gitattributes &&
571 cp "$TEST_ROOT/test.o" test.r &&
576 - S=$(file_size test.r) &&
572 + S=$(test_file_size test.r) &&
573
574 filter_git add . &&
575 cat >expected.log <<-EOF &&
@@ -697,9 +693,9 @@ test_expect_success PERL 'process filter should restart after unexpected write f
693 echo "this is going to fail" >smudge-write-fail.o &&
694 cp smudge-write-fail.o smudge-write-fail.r &&
695
700 - S=$(file_size test.r) &&
701 - S2=$(file_size test2.r) &&
702 - SF=$(file_size smudge-write-fail.r) &&
696 + S=$(test_file_size test.r) &&
697 + S2=$(test_file_size test2.r) &&
698 + SF=$(test_file_size smudge-write-fail.r) &&
699 M=$(git hash-object test.r) &&
700 M2=$(git hash-object test2.r) &&
701 MF=$(git hash-object smudge-write-fail.r) &&
@@ -752,9 +748,9 @@ test_expect_success PERL 'process filter should not be restarted if it signals a
748 echo "this will cause an error" >error.o &&
749 cp error.o error.r &&
750
755 - S=$(file_size test.r) &&
756 - S2=$(file_size test2.r) &&
757 - SE=$(file_size error.r) &&
751 + S=$(test_file_size test.r) &&
752 + S2=$(test_file_size test2.r) &&
753 + SE=$(test_file_size error.r) &&
754 M=$(git hash-object test.r) &&
755 M2=$(git hash-object test2.r) &&
756 ME=$(git hash-object error.r) &&
@@ -797,7 +793,7 @@ test_expect_success PERL 'process filter abort stops processing of all further f
793
794 M="blob=$(git hash-object abort.r)" &&
795 rm -f debug.log &&
800 - SA=$(file_size abort.r) &&
796 + SA=$(test_file_size abort.r) &&
797
798 git add . &&
799 rm -f *.r &&
@@ -859,7 +855,7 @@ test_expect_success PERL 'delayed checkout in process filter' '
855 git commit -m "test commit"
856 ) &&
857
862 - S=$(file_size "$TEST_ROOT/test.o") &&
858 + S=$(test_file_size "$TEST_ROOT/test.o") &&
859 PM="ref=refs/heads/master treeish=$(git -C repo rev-parse --verify master) " &&
860 M="${PM}blob=$(git -C repo rev-parse --verify master:test.a)" &&
861 cat >a.exp <<-EOF &&
t/t1050-large.sh
+1 -7
@@ -5,12 +5,6 @@ test_description='adding and checking out large blobs'
5
6 . ./test-lib.sh
7
8 -# This should be moved to test-lib.sh together with the
9 -# copy in t0021 after both topics have graduated to 'master'.
10 -file_size () {
11 - test-tool path-utils file-size "$1"
12 -}
13 -
8 test_expect_success setup '
9 # clone does not allow us to pass core.bigfilethreshold to
10 # new repos, so set core.bigfilethreshold globally
@@ -29,7 +23,7 @@ do
23 test_expect_success "add with $config" '
24 test_when_finished "rm -f .git/objects/pack/pack-*.* .git/index" &&
25 git $config add large1 &&
32 - sz=$(file_size .git/objects/pack/pack-*.pack) &&
26 + sz=$(test_file_size .git/objects/pack/pack-*.pack) &&
27 case "$expect" in
28 small) test "$sz" -le 100000 ;;
29 large) test "$sz" -ge 100000 ;;
t/t5315-pack-objects-compression.sh
+1 -7
@@ -4,12 +4,6 @@ test_description='pack-object compression configuration'
4
5 . ./test-lib.sh
6
7 -# This should be moved to test-lib.sh together with the
8 -# copy in t0021 after both topics have graduated to 'master'.
9 -file_size () {
10 - test-tool path-utils file-size "$1"
11 -}
12 -
7 test_expect_success setup '
8 printf "%2000000s" X |
9 git hash-object -w --stdin >object-name &&
@@ -24,7 +18,7 @@ do
18 test_expect_success "pack-objects with $config" '
19 test_when_finished "rm -f pack-*.*" &&
20 git $config pack-objects pack <object-name &&
27 - sz=$(file_size pack-*.pack) &&
21 + sz=$(test_file_size pack-*.pack) &&
22 case "$expect" in
23 small) test "$sz" -le 100000 ;;
24 large) test "$sz" -ge 100000 ;;
t/t9303-fast-import-compression.sh
+2 -8
@@ -3,12 +3,6 @@
3 test_description='compression setting of fast-import utility'
4 . ./test-lib.sh
5
6 -# This should be moved to test-lib.sh together with the
7 -# copy in t0021 after both topics have graduated to 'master'.
8 -file_size () {
9 - test-tool path-utils file-size "$1"
10 -}
11 -
6 import_large () {
7 (
8 echo blob
@@ -24,7 +18,7 @@ do
18 test_when_finished "rm -f .git/objects/pack/pack-*.*" &&
19 test_when_finished "rm -rf .git/objects/??" &&
20 import_large -c fastimport.unpacklimit=0 $config &&
27 - sz=$(file_size .git/objects/pack/pack-*.pack) &&
21 + sz=$(test_file_size .git/objects/pack/pack-*.pack) &&
22 case "$expect" in
23 small) test "$sz" -le 100000 ;;
24 large) test "$sz" -ge 100000 ;;
@@ -47,7 +41,7 @@ do
41 test_when_finished "rm -f .git/objects/pack/pack-*.*" &&
42 test_when_finished "rm -rf .git/objects/??" &&
43 import_large -c fastimport.unpacklimit=9 $config &&
50 - sz=$(file_size .git/objects/??/????*) &&
44 + sz=$(test_file_size .git/objects/??/????*) &&
45 case "$expect" in
46 small) test "$sz" -le 100000 ;;
47 large) test "$sz" -ge 100000 ;;
t/test-lib-functions.sh
+4
@@ -783,6 +783,10 @@ test_line_count () {
783 fi
784 }
785
786 +test_file_size () {
787 + test-tool path-utils file-size "$1"
788 +}
789 +
790 # Returns success if a comma separated string of keywords ($1) contains a
791 # given keyword ($2).
792 # Examples: