Skip to content

Commit

Permalink
t3501: remove test -f and stop ignoring git <cmd> exit code
Browse files Browse the repository at this point in the history
In the test 'cherry-pick after renaming branch', stop checking for
the presence of a file (opos) because we are going to "grep" in it in
the same test and the lack of it will be noticed as a failure anyway.

In the test 'revert after renaming branch', instead of allowing any
random contents as long as a known phrase is not there in it, we can
expect the exact outcome---after the successful revert of "added", the
contents of file "spoo" should become identical to what was in file
"oops" in the "initial" commit. This test also contains 'test -f' that
verifies presence of a file, but we have a helper function to do the same
thing. Replace it with appropriate helper function 'test_path_is_file'
for better readability and better error messages.

In both tests, we will not notice when "git rev-parse" starts segfaulting
without emitting any output. The 'test' command will end up being just
"test =", which yields success. Use the 'test_cmp_rev' helper to make
sure we will notice such a breakage.

Signed-off-by: Khalid Masum <khalid.masum.92@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Labnann authored and gitster committed Apr 6, 2022
1 parent 4c53a8c commit 82b28c4
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions t/t3501-revert-cherry-pick.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ test_expect_success 'cherry-pick after renaming branch' '
git checkout rename2 &&
git cherry-pick added &&
test $(git rev-parse HEAD^) = $(git rev-parse rename2) &&
test -f opos &&
test_cmp_rev rename2 HEAD^ &&
grep "Add extra line at the end" opos &&
git reflog -1 | grep cherry-pick
Expand All @@ -77,9 +76,9 @@ test_expect_success 'revert after renaming branch' '
git checkout rename1 &&
git revert added &&
test $(git rev-parse HEAD^) = $(git rev-parse rename1) &&
test -f spoo &&
! grep "Add extra line at the end" spoo &&
test_cmp_rev rename1 HEAD^ &&
test_path_is_file spoo &&
test_cmp_rev initial:oops HEAD:spoo &&
git reflog -1 | grep revert
'
Expand Down

0 comments on commit 82b28c4

Please sign in to comment.