test-lib-functions: remove bug-inducing "diagnostics" helper param

Remove the optional "diagnostics" parameter of the test_path_is_{file,dir,missing} functions. We have a lot of uses of these functions, but the only legitimate use of the diagnostics parameter is from when the functions themselves were introduced in 2caf20c52b7 (test-lib: user-friendly alternatives to test [-d|-f|-e], 2010-08-10). But as the the rest of this diff demonstrates its presence did more to silently introduce bugs in our tests. Fix such bugs in the tests added in ae4e89e549b (gc: add --keep-largest-pack option, 2018-04-15), and c04ba51739a (t6046: testcases checking whether updates can be skipped in a merge, 2018-04-19). Let's also assert that those functions are called with exactly one parameter, a follow-up commit will add similar asserts to other functions in test-lib-functions.sh that we didn't have existing misuse of. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Feb 12, 2021 at 14:29 UTC 45a2686441b0ea53ad9acef8b01dad2efdd98a90
5 files changed +26 -16
t/README
+4 -4
@@ -917,13 +917,13 @@ library for your script to use.
917
918 Check whether a file has the length it is expected to.
919
920 - - test_path_is_file <path> [<diagnosis>]
921 - test_path_is_dir <path> [<diagnosis>]
922 - test_path_is_missing <path> [<diagnosis>]
920 + - test_path_is_file <path>
921 + test_path_is_dir <path>
922 + test_path_is_missing <path>
923
924 Check if the named path is a file, if the named path is a
925 directory, or if the named path does not exist, respectively,
926 - and fail otherwise, showing the <diagnosis> text.
926 + and fail otherwise.
927
928 - test_when_finished <script>
929
t/t3404-rebase-interactive.sh
+2 -1
@@ -101,7 +101,8 @@ test_expect_success 'rebase -i with the exec command' '
101 ) &&
102 test_path_is_file touch-one &&
103 test_path_is_file touch-two &&
104 - test_path_is_missing touch-three " (should have stopped before)" &&
104 + # Missing because we should have stopped by now.
105 + test_path_is_missing touch-three &&
106 test_cmp_rev C HEAD &&
107 git rebase --continue &&
108 test_path_is_file touch-three &&
t/t6426-merge-skip-unneeded-updates.sh
+12 -4
@@ -492,7 +492,9 @@ test_expect_success '3a-L: bq_1->foo/bq_2 on A, foo/->bar/ on B' '
492 test_cmp expect actual &&
493
494 test_must_fail git rev-parse HEAD:bq HEAD:foo/bq &&
495 - test_path_is_missing bq foo/bq foo/whatever
495 + test_path_is_missing bq &&
496 + test_path_is_missing foo/bq &&
497 + test_path_is_missing foo/whatever
498 )
499 '
500
@@ -522,7 +524,9 @@ test_expect_success '3a-R: bq_1->foo/bq_2 on A, foo/->bar/ on B' '
524 test_cmp expect actual &&
525
526 test_must_fail git rev-parse HEAD:bq HEAD:foo/bq &&
525 - test_path_is_missing bq foo/bq foo/whatever
527 + test_path_is_missing bq &&
528 + test_path_is_missing foo/bq &&
529 + test_path_is_missing foo/whatever
530 )
531 '
532
@@ -588,7 +592,9 @@ test_expect_success '3b-L: bq_1->foo/bq_2 on A, foo/->bar/ on B' '
592 test_cmp expect actual &&
593
594 test_must_fail git rev-parse HEAD:bq HEAD:foo/bq &&
591 - test_path_is_missing bq foo/bq foo/whatever
595 + test_path_is_missing bq &&
596 + test_path_is_missing foo/bq &&
597 + test_path_is_missing foo/whatever
598 )
599 '
600
@@ -618,7 +624,9 @@ test_expect_success '3b-R: bq_1->foo/bq_2 on A, foo/->bar/ on B' '
624 test_cmp expect actual &&
625
626 test_must_fail git rev-parse HEAD:bq HEAD:foo/bq &&
621 - test_path_is_missing bq foo/bq foo/whatever
627 + test_path_is_missing bq &&
628 + test_path_is_missing foo/bq &&
629 + test_path_is_missing foo/whatever
630 )
631 '
632
t/t6500-gc.sh
+2 -2
@@ -78,7 +78,7 @@ test_expect_success 'gc --keep-largest-pack' '
78 git gc &&
79 ( cd .git/objects/pack && ls *.pack ) >pack-list &&
80 test_line_count = 1 pack-list &&
81 - BASE_PACK=.git/objects/pack/pack-*.pack &&
81 + cp pack-list base-pack-list &&
82 test_commit four &&
83 git repack -d &&
84 test_commit five &&
@@ -90,7 +90,7 @@ test_expect_success 'gc --keep-largest-pack' '
90 test_line_count = 2 pack-list &&
91 awk "/^P /{print \$2}" <.git/objects/info/packs >pack-info &&
92 test_line_count = 2 pack-info &&
93 - test_path_is_file $BASE_PACK &&
93 + test_path_is_file .git/objects/pack/$(cat base-pack-list) &&
94 git fsck
95 )
96 '
t/test-lib-functions.sh
+6 -5
@@ -717,12 +717,12 @@ test_external_without_stderr () {
717 }
718
719 # debugging-friendly alternatives to "test [-f|-d|-e]"
720 -# The commands test the existence or non-existence of $1. $2 can be
721 -# given to provide a more precise diagnosis.
720 +# The commands test the existence or non-existence of $1
721 test_path_is_file () {
722 + test "$#" -ne 1 && BUG "1 param"
723 if ! test -f "$1"
724 then
725 - echo "File $1 doesn't exist. $2"
725 + echo "File $1 doesn't exist"
726 false
727 fi
728 }
@@ -730,15 +730,16 @@ test_path_is_file () {
730 test_path_is_dir () {
731 if ! test -d "$1"
732 then
733 - echo "Directory $1 doesn't exist. $2"
733 + echo "Directory $1 doesn't exist"
734 false
735 fi
736 }
737
738 test_path_exists () {
739 + test "$#" -ne 1 && BUG "1 param"
740 if ! test -e "$1"
741 then
741 - echo "Path $1 doesn't exist. $2"
742 + echo "Path $1 doesn't exist"
743 false
744 fi
745 }