fix use of "! test_path_is_foo" in tests
cover fix use of "! test_path_is_foo" in tests
During recent review of a topic, I noticed that there are a handful of places where we misuse test_path_is_{file,directory} test helper functions. They are designed to be silent when the given path is of the expected type, so
! test_path_is_file foo
when you do not want 'foo' to be a file, while making the test pass, does not help debugging when things go wrong.
These small patches touch the places where
$ git grep -e '! test_path_' t/
shows hits, except for test_path_is_hidden that shares the same name pattern but is not designed to help debugging like others.
Junio C Hamano (3):
tests: do not negate test_path_exists
t2021: do not negate test_path_is_dir
test: do not negate test_path_is_* to assert absense
t/lib-submodule-update.sh | 2 +- t/t2021-checkout-overwrite.sh | 2 +- t/t4067-diff-partial-clone.sh | 4 ++-- t/t4115-apply-symlink.sh | 2 +- t/t5572-pull-submodule.sh | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-)
Signature · 1 line
2.41.0-rc0
PATCH 1/3 tests: do not negate test_path_exists
As a way to assert the path 'foo' is missing, "! test_path_exists foo" a poor way to do so, as the helper is designed to complain when 'foo' is missing, but the intention of the author who used negated form was to make sure it does not exist. This does not help debugging the tests.
Use test_path_is_missing instead, which is a more appropriate helper.
--- t/t4067-diff-partial-clone.sh | 4 ++-- t/t4115-apply-symlink.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
t/t4067-diff-partial-clone.sh +2 -2
@@ -151,7 +151,7 @@ test_expect_success 'diff does not fetch anything if inexact rename detection is # Ensure no fetches. GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff --raw -M HEAD^ HEAD && - ! test_path_exists trace + test_path_is_missing trace ' test_expect_success 'diff --break-rewrites fetches only if necessary, and batches blobs if it does' '
@@ -171,7 +171,7 @@ test_expect_success 'diff --break-rewrites fetches only if necessary, and batche # Ensure no fetches. GIT_TRACE_PACKET="$(pwd)/trace" git -C client diff --raw -M HEAD^ HEAD && - ! test_path_exists trace && + test_path_is_missing trace && # But with --break-rewrites, ensure that there is exactly 1 negotiation # by checking that there is only 1 "done" line sent. ("done" marks the
t/t4115-apply-symlink.sh +1 -1
@@ -74,7 +74,7 @@ test_expect_success SYMLINKS 'symlink escape when creating new files' ' error: affected file ${SQ}renamed-symlink/create-me${SQ} is beyond a symbolic link EOF test_cmp expected_stderr stderr && - ! test_path_exists .git/create-me + test_path_is_missing .git/create-me ' test_expect_success SYMLINKS 'symlink escape when modifying file' '
Signature · 1 line
2.41.0-rc0
Re: [PATCH 1/3] tests: do not negate test_path_exists
Quoted 4 lines · Junio C Hamano
As a way to assert the path 'foo' is missing, "!
test_path_existsfoo" a poor way to do so, as the helper is designed to complain when 'foo' is missing, but the intention of the author who used negated form was to make sure it does not exist. This does not help debugging the tests.
s/a poor/is &/
Quoted 3 lines
Use
test_path_is_missinginstead, which is a more appropriate helper.Signed-off-by Junio C Hamano <[email protected]>
Re: [PATCH 1/3] tests: do not negate test_path_exists
Quoted 7 lines · Eric Sunshine
Quoted 4 lines · Junio C Hamano
As a way to assert the path 'foo' is missing, "!
test_path_existsfoo" a poor way to do so, as the helper is designed to complain when 'foo' is missing, but the intention of the author who used negated form was to make sure it does not exist. This does not help debugging the tests.s/a poor/is &/
Thanks.
Quoted 4 lines
Quoted 4 lines
Use
test_path_is_missinginstead, which is a more appropriate helper.Signed-off-by Junio C Hamano <[email protected]>
PATCH 2/3 t2021: do not negate test_path_is_dir
In reply to Junio C HamanoIn this test, a path (some_dir) that is originally a directory is to be removed and then to be replaced with a file of the same name. The expectation is that the path becomes a file at the end. However, "! test_path_is_dir some_dir" is used to catch a breakage that leaves the path as a directory.
But as with all the "test_path_is..." helpers, this use of the helper makes it loud when the expectation (i.e. it is a directory) is met, and otherwise is silent when it is not---this does not help debugging.
Be more explicit and state that we expect the path to become a file.
--- t/t2021-checkout-overwrite.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
t/t2021-checkout-overwrite.sh +1 -1
@@ -77,7 +77,7 @@ test_expect_success 'checkout --overwrite-ignore should succeed if only ignored echo autogenerated information >some_dir/ignore && echo ignore >.git/info/exclude && git checkout --overwrite-ignore df_conflict && - ! test_path_is_dir some_dir + test_path_is_file some_dir ' test_done
Signature · 1 line
2.41.0-rc0
PATCH 3/3 test: do not negate test_path_is_* to assert absense
In reply to Junio C HamanoThese tests use "! test_path_is_dir" or "! test_path_is_file" to ensure that the path is not recursively checked out or "submodule update" did not touch the working tree.
Use "test_path_is_missing" to assert that the path does not exist, instead of negating test_path_is_* helpers; they are designed to be loud in wrong occasions. Besides, negating "test_path_is_dir" would mean we would be happy if a file exists there, which is not the case for these tests.
--- t/lib-submodule-update.sh | 2 +- t/t5572-pull-submodule.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
t/lib-submodule-update.sh +1 -1
@@ -802,7 +802,7 @@ test_submodule_recursing_with_args_common () { git branch -t no_submodule origin/no_submodule && $command no_submodule && test_superproject_content origin/no_submodule && - ! test_path_is_dir sub1 && + test_path_is_missing sub1 && test_must_fail git config -f .git/modules/sub1/config core.worktree && test_must_fail git config -f .git/modules/sub1/modules/sub2/config core.worktree )
t/t5572-pull-submodule.sh +2 -2
@@ -121,7 +121,7 @@ test_expect_success "fetch.recurseSubmodules option triggers recursive fetch (bu sub_oid=$(git -C child rev-parse HEAD) && git -C super/sub cat-file -e $sub_oid && # Check that the submodule worktree did not update - ! test_path_is_file super/sub/merge_strategy_5.t + test_path_is_missing super/sub/merge_strategy_5.t ' test_expect_success "fetch.recurseSubmodules takes precedence over submodule.recurse" '
@@ -134,7 +134,7 @@ test_expect_success "fetch.recurseSubmodules takes precedence over submodule.rec sub_oid=$(git -C child rev-parse HEAD) && git -C super/sub cat-file -e $sub_oid && # Check that the submodule worktree did not update - ! test_path_is_file super/sub/merge_strategy_6.t + test_path_is_missing super/sub/merge_strategy_6.t ' test_expect_success 'pull --rebase --recurse-submodules (remote superproject submodule changes, local submodule changes)' '
Signature · 1 line
2.41.0-rc0