t7406: prefer test_* helper functions to test -[feds]

test -e, test -s, etc. do not provide nice error messages when we hit test failures, so use the test_* helper functions from test-lib-functions.sh. Also, add test_path_exists() to test-lib-function.sh while at it, so that we don't need to worry whether submodule/.git is a file or a directory. It currently is a file with contents of the form gitdir: ../.git/modules/submodule but it could be changed in the future to be a directory; this test only really cares that it exists. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Aug 8, 2018 at 09:31 UTC 7e9055bb0062fa7163b55b56fdc7532a04685862
2 files changed +11 -3
t/t7406-submodule-update.sh
+3 -3
@@ -174,7 +174,7 @@ test_expect_success 'submodule update does not fetch already present commits' '
174 git submodule update > ../actual 2> ../actual.err
175 ) &&
176 test_i18ncmp expected actual &&
177 - ! test -s actual.err
177 + test_must_be_empty actual.err
178 '
179
180 test_expect_success 'submodule update should fail due to local changes' '
@@ -620,8 +620,8 @@ test_expect_success 'submodule update --init skips submodule with update=none' '
620 git clone super cloned &&
621 (cd cloned &&
622 git submodule update --init &&
623 - test -e submodule/.git &&
624 - test_must_fail test -e none/.git
623 + test_path_exists submodule/.git &&
624 + test_path_is_missing none/.git
625 )
626 '
627
t/test-lib-functions.sh
+8
@@ -565,6 +565,14 @@ test_path_is_dir () {
565 fi
566 }
567
568 +test_path_exists () {
569 + if ! test -e "$1"
570 + then
571 + echo "Path $1 doesn't exist. $2"
572 + false
573 + fi
574 +}
575 +
576 # Check if the directory exists and is empty as expected, barf otherwise.
577 test_dir_is_empty () {
578 test_path_is_dir "$1" &&