Skip to content

Commit e7884b3

Browse files
avargitster
authored andcommitted
test-lib-functions: assert correct parameter count
Add assertions of the correct parameter count of various functions, in particularly the wrappers for the shell "test" built-in. In an earlier commit we fixed a bug with an incorrect number of arguments being passed to "test_path_is_{file,missing}". Let's also guard other similar functions from the same sort of misuse. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 45a2686 commit e7884b3

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

t/test-lib-functions.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ test_path_is_file () {
728728
}
729729

730730
test_path_is_dir () {
731+
test "$#" -ne 1 && BUG "1 param"
731732
if ! test -d "$1"
732733
then
733734
echo "Directory $1 doesn't exist"
@@ -746,6 +747,7 @@ test_path_exists () {
746747

747748
# Check if the directory exists and is empty as expected, barf otherwise.
748749
test_dir_is_empty () {
750+
test "$#" -ne 1 && BUG "1 param"
749751
test_path_is_dir "$1" &&
750752
if test -n "$(ls -a1 "$1" | egrep -v '^\.\.?$')"
751753
then
@@ -757,6 +759,7 @@ test_dir_is_empty () {
757759

758760
# Check if the file exists and has a size greater than zero
759761
test_file_not_empty () {
762+
test "$#" = 2 && BUG "2 param"
760763
if ! test -s "$1"
761764
then
762765
echo "'$1' is not a non-empty file."
@@ -765,6 +768,7 @@ test_file_not_empty () {
765768
}
766769

767770
test_path_is_missing () {
771+
test "$#" -ne 1 && BUG "1 param"
768772
if test -e "$1"
769773
then
770774
echo "Path exists:"
@@ -801,6 +805,7 @@ test_line_count () {
801805
}
802806

803807
test_file_size () {
808+
test "$#" -ne 1 && BUG "1 param"
804809
test-tool path-utils file-size "$1"
805810
}
806811

@@ -973,6 +978,7 @@ test_expect_code () {
973978
# - not all diff versions understand "-u"
974979

975980
test_cmp () {
981+
test "$#" -ne 2 && BUG "2 param"
976982
eval "$GIT_TEST_CMP" '"$@"'
977983
}
978984

@@ -1002,6 +1008,7 @@ test_cmp_config () {
10021008
# test_cmp_bin - helper to compare binary files
10031009

10041010
test_cmp_bin () {
1011+
test "$#" -ne 2 && BUG "2 param"
10051012
cmp "$@"
10061013
}
10071014

@@ -1071,6 +1078,7 @@ verbose () {
10711078
# otherwise.
10721079

10731080
test_must_be_empty () {
1081+
test "$#" -ne 1 && BUG "1 param"
10741082
test_path_is_file "$1" &&
10751083
if test -s "$1"
10761084
then

0 commit comments

Comments
 (0)