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

In 8de7eeb54b (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>
This commit is contained in:
Johannes Schindelin 2020-11-07 01:12:57 +00:00 коммит произвёл Junio C Hamano
Родитель 898f80736c
Коммит 53b67a801b
5 изменённых файлов: 24 добавлений и 42 удалений

Просмотреть файл

@ -23,10 +23,6 @@ generate_random_characters () {
perl -pe "s/./chr((ord($&) % 26) + ord('a'))/sge" >"$TEST_ROOT/$NAME" perl -pe "s/./chr((ord($&) % 26) + ord('a'))/sge" >"$TEST_ROOT/$NAME"
} }
file_size () {
test-tool path-utils file-size "$1"
}
filter_git () { filter_git () {
rm -f *.log && rm -f *.log &&
git "$@" git "$@"
@ -361,9 +357,9 @@ test_expect_success PERL 'required process filter should filter data' '
cp "$TEST_ROOT/test3 '\''sq'\'',\$x=.o" "testsubdir/test3 '\''sq'\'',\$x=.r" && cp "$TEST_ROOT/test3 '\''sq'\'',\$x=.o" "testsubdir/test3 '\''sq'\'',\$x=.r" &&
>test4-empty.r && >test4-empty.r &&
S=$(file_size test.r) && S=$(test_file_size test.r) &&
S2=$(file_size test2.r) && S2=$(test_file_size test2.r) &&
S3=$(file_size "testsubdir/test3 '\''sq'\'',\$x=.r") && S3=$(test_file_size "testsubdir/test3 '\''sq'\'',\$x=.r") &&
M=$(git hash-object test.r) && M=$(git hash-object test.r) &&
M2=$(git hash-object test2.r) && M2=$(git hash-object test2.r) &&
M3=$(git hash-object "testsubdir/test3 '\''sq'\'',\$x=.r") && 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
( (
cd repo && cd repo &&
S=$(file_size test.r) && S=$(test_file_size test.r) &&
S2=$(file_size test2.r) && S2=$(test_file_size test2.r) &&
S3=$(file_size "testsubdir/test3 '\''sq'\'',\$x=.r") && S3=$(test_file_size "testsubdir/test3 '\''sq'\'',\$x=.r") &&
M=$(git hash-object test.r) && M=$(git hash-object test.r) &&
M2=$(git hash-object test2.r) && M2=$(git hash-object test2.r) &&
M3=$(git hash-object "testsubdir/test3 '\''sq'\'',\$x=.r") && M3=$(git hash-object "testsubdir/test3 '\''sq'\'',\$x=.r") &&
@ -549,7 +545,7 @@ test_expect_success PERL 'required process filter takes precedence' '
echo "*.r filter=protocol" >.gitattributes && echo "*.r filter=protocol" >.gitattributes &&
cp "$TEST_ROOT/test.o" test.r && cp "$TEST_ROOT/test.o" test.r &&
S=$(file_size test.r) && S=$(test_file_size test.r) &&
# Check that the process filter is invoked here # Check that the process filter is invoked here
filter_git add . && filter_git add . &&
@ -573,7 +569,7 @@ test_expect_success PERL 'required process filter should be used only for "clean
echo "*.r filter=protocol" >.gitattributes && echo "*.r filter=protocol" >.gitattributes &&
cp "$TEST_ROOT/test.o" test.r && cp "$TEST_ROOT/test.o" test.r &&
S=$(file_size test.r) && S=$(test_file_size test.r) &&
filter_git add . && filter_git add . &&
cat >expected.log <<-EOF && cat >expected.log <<-EOF &&
@ -697,9 +693,9 @@ test_expect_success PERL 'process filter should restart after unexpected write f
echo "this is going to fail" >smudge-write-fail.o && echo "this is going to fail" >smudge-write-fail.o &&
cp smudge-write-fail.o smudge-write-fail.r && cp smudge-write-fail.o smudge-write-fail.r &&
S=$(file_size test.r) && S=$(test_file_size test.r) &&
S2=$(file_size test2.r) && S2=$(test_file_size test2.r) &&
SF=$(file_size smudge-write-fail.r) && SF=$(test_file_size smudge-write-fail.r) &&
M=$(git hash-object test.r) && M=$(git hash-object test.r) &&
M2=$(git hash-object test2.r) && M2=$(git hash-object test2.r) &&
MF=$(git hash-object smudge-write-fail.r) && 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
echo "this will cause an error" >error.o && echo "this will cause an error" >error.o &&
cp error.o error.r && cp error.o error.r &&
S=$(file_size test.r) && S=$(test_file_size test.r) &&
S2=$(file_size test2.r) && S2=$(test_file_size test2.r) &&
SE=$(file_size error.r) && SE=$(test_file_size error.r) &&
M=$(git hash-object test.r) && M=$(git hash-object test.r) &&
M2=$(git hash-object test2.r) && M2=$(git hash-object test2.r) &&
ME=$(git hash-object error.r) && ME=$(git hash-object error.r) &&
@ -797,7 +793,7 @@ test_expect_success PERL 'process filter abort stops processing of all further f
M="blob=$(git hash-object abort.r)" && M="blob=$(git hash-object abort.r)" &&
rm -f debug.log && rm -f debug.log &&
SA=$(file_size abort.r) && SA=$(test_file_size abort.r) &&
git add . && git add . &&
rm -f *.r && rm -f *.r &&
@ -859,7 +855,7 @@ test_expect_success PERL 'delayed checkout in process filter' '
git commit -m "test commit" git commit -m "test commit"
) && ) &&
S=$(file_size "$TEST_ROOT/test.o") && S=$(test_file_size "$TEST_ROOT/test.o") &&
PM="ref=refs/heads/master treeish=$(git -C repo rev-parse --verify master) " && PM="ref=refs/heads/master treeish=$(git -C repo rev-parse --verify master) " &&
M="${PM}blob=$(git -C repo rev-parse --verify master:test.a)" && M="${PM}blob=$(git -C repo rev-parse --verify master:test.a)" &&
cat >a.exp <<-EOF && cat >a.exp <<-EOF &&

Просмотреть файл

@ -5,12 +5,6 @@ test_description='adding and checking out large blobs'
. ./test-lib.sh . ./test-lib.sh
# This should be moved to test-lib.sh together with the
# copy in t0021 after both topics have graduated to 'master'.
file_size () {
test-tool path-utils file-size "$1"
}
test_expect_success setup ' test_expect_success setup '
# clone does not allow us to pass core.bigfilethreshold to # clone does not allow us to pass core.bigfilethreshold to
# new repos, so set core.bigfilethreshold globally # new repos, so set core.bigfilethreshold globally
@ -29,7 +23,7 @@ do
test_expect_success "add with $config" ' test_expect_success "add with $config" '
test_when_finished "rm -f .git/objects/pack/pack-*.* .git/index" && test_when_finished "rm -f .git/objects/pack/pack-*.* .git/index" &&
git $config add large1 && git $config add large1 &&
sz=$(file_size .git/objects/pack/pack-*.pack) && sz=$(test_file_size .git/objects/pack/pack-*.pack) &&
case "$expect" in case "$expect" in
small) test "$sz" -le 100000 ;; small) test "$sz" -le 100000 ;;
large) test "$sz" -ge 100000 ;; large) test "$sz" -ge 100000 ;;

Просмотреть файл

@ -4,12 +4,6 @@ test_description='pack-object compression configuration'
. ./test-lib.sh . ./test-lib.sh
# This should be moved to test-lib.sh together with the
# copy in t0021 after both topics have graduated to 'master'.
file_size () {
test-tool path-utils file-size "$1"
}
test_expect_success setup ' test_expect_success setup '
printf "%2000000s" X | printf "%2000000s" X |
git hash-object -w --stdin >object-name && git hash-object -w --stdin >object-name &&
@ -24,7 +18,7 @@ do
test_expect_success "pack-objects with $config" ' test_expect_success "pack-objects with $config" '
test_when_finished "rm -f pack-*.*" && test_when_finished "rm -f pack-*.*" &&
git $config pack-objects pack <object-name && git $config pack-objects pack <object-name &&
sz=$(file_size pack-*.pack) && sz=$(test_file_size pack-*.pack) &&
case "$expect" in case "$expect" in
small) test "$sz" -le 100000 ;; small) test "$sz" -le 100000 ;;
large) test "$sz" -ge 100000 ;; large) test "$sz" -ge 100000 ;;

Просмотреть файл

@ -3,12 +3,6 @@
test_description='compression setting of fast-import utility' test_description='compression setting of fast-import utility'
. ./test-lib.sh . ./test-lib.sh
# This should be moved to test-lib.sh together with the
# copy in t0021 after both topics have graduated to 'master'.
file_size () {
test-tool path-utils file-size "$1"
}
import_large () { import_large () {
( (
echo blob echo blob
@ -24,7 +18,7 @@ do
test_when_finished "rm -f .git/objects/pack/pack-*.*" && test_when_finished "rm -f .git/objects/pack/pack-*.*" &&
test_when_finished "rm -rf .git/objects/??" && test_when_finished "rm -rf .git/objects/??" &&
import_large -c fastimport.unpacklimit=0 $config && import_large -c fastimport.unpacklimit=0 $config &&
sz=$(file_size .git/objects/pack/pack-*.pack) && sz=$(test_file_size .git/objects/pack/pack-*.pack) &&
case "$expect" in case "$expect" in
small) test "$sz" -le 100000 ;; small) test "$sz" -le 100000 ;;
large) test "$sz" -ge 100000 ;; large) test "$sz" -ge 100000 ;;
@ -47,7 +41,7 @@ do
test_when_finished "rm -f .git/objects/pack/pack-*.*" && test_when_finished "rm -f .git/objects/pack/pack-*.*" &&
test_when_finished "rm -rf .git/objects/??" && test_when_finished "rm -rf .git/objects/??" &&
import_large -c fastimport.unpacklimit=9 $config && import_large -c fastimport.unpacklimit=9 $config &&
sz=$(file_size .git/objects/??/????*) && sz=$(test_file_size .git/objects/??/????*) &&
case "$expect" in case "$expect" in
small) test "$sz" -le 100000 ;; small) test "$sz" -le 100000 ;;
large) test "$sz" -ge 100000 ;; large) test "$sz" -ge 100000 ;;

Просмотреть файл

@ -783,6 +783,10 @@ test_line_count () {
fi fi
} }
test_file_size () {
test-tool path-utils file-size "$1"
}
# Returns success if a comma separated string of keywords ($1) contains a # Returns success if a comma separated string of keywords ($1) contains a
# given keyword ($2). # given keyword ($2).
# Examples: # Examples: