git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] t3501: remove test -f and stop ignoring git <cmd> exit code

From
LGLabnan via GitGitGadget <gitgitgadget@gmail.com>
Date
Apr 22, 2022, 11:26 UTC
Message-ID
<pull.1195.v2.git.1650626787628.gitgitgadget@gmail.com>
In-Reply-To
<pull.1195.git.1648676585765.gitgitgadget@gmail.com>
From: Khalid Masum <khalid.masum.92@gmail.com>

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>
---
    t3501: remove redundant test -f and use of git rev-parse
    
    Two test -f are present in t3501. They can be replaced with appropriate
    helper function: test_path_is_file. Which makes the script more readable
    and gives better error messages.
    
    Signed-off-by: Labnann khalid.masum.92@gmail.com
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1195%2FLabnann%2Ft3501-helper-functions-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1195/Labnann/t3501-helper-functions-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/1195
Range-diff vs v1:
 1:  8b7d38a66f8 ! 1:  1090429b865 t3501: use test_path_is_* functions
     @@
       ## Metadata ##
     -Author: Labnann <khalid.masum.92@gmail.com>
     +Author: Khalid Masum <khalid.masum.92@gmail.com>
      
       ## Commit message ##
     -    t3501: use test_path_is_* functions
     +    t3501: remove test -f and stop ignoring git <cmd> exit code
      
     -    Two test -f are present in t3501. They can be replaced with appropriate
     -    helper function: test_path_is_file
     +    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.
      
     -    Signed-off-by: Labnann <khalid.masum.92@gmail.com>
     +    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>
      
       ## t/t3501-revert-cherry-pick.sh ##
      @@ t/t3501-revert-cherry-pick.sh: 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 $(git rev-parse HEAD^) = $(git rev-parse rename2) &&
      -	test -f opos &&
     -+	test_path_is_file opos &&
     ++	test_cmp_rev rename2 HEAD^ &&
       	grep "Add extra line at the end" opos &&
       	git reflog -1 | grep cherry-pick
       
      @@ t/t3501-revert-cherry-pick.sh: test_expect_success 'revert after renaming branch' '
     + 
       	git checkout rename1 &&
       	git revert added &&
     - 	test $(git rev-parse HEAD^) = $(git rev-parse rename1) &&
     +-	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 &&
     - 	! grep "Add extra line at the end" spoo &&
     ++	test_cmp_rev initial:oops HEAD:spoo &&
       	git reflog -1 | grep revert
       
     + '
 t/t3501-revert-cherry-pick.sh | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/t/t3501-revert-cherry-pick.sh b/t/t3501-revert-cherry-pick.sh
index 8617efaaf1e..9eb19204ac7 100755
--- a/t/t3501-revert-cherry-pick.sh
+++ b/t/t3501-revert-cherry-pick.sh
@@ -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
 
@@ -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
 
 '

base-commit: 805e0a68082a217f0112db9ee86a022227a9c81b
-- 
gitgitgadget
Previous: Khalid Masum
Message 16 of 16 in “t3501: use test_path_is_* functions”
  1. t3501: use test_path_is_* functionsLabnan via GitGitGadget, Mar 30, 2022
  2. Ævar Arnfjörð BjarmasonMar 30, 2022
  3. 0/3 [GSoC] t3501: remove test and test -fLabnann, Mar 31, 2022
  4. 1/3 t3501: use test_path_is_* functionsLabnann, Mar 31, 2022
  5. 2/3 t3501: don't ignore "git <cmd>" exit codeLabnann, Mar 31, 2022
  6. Junio C HamanoApr 1, 2022
  7. 3/3 t3501: test cherry-pick revert with oidsLabnann, Mar 31, 2022
  8. Junio C HamanoApr 1, 2022
  9. 0/1 [GSoC] t3501: remove redundant file checking and stop ignoring git <cmd> exit codeLabnann, Apr 2, 2022
  10. 1/1 t3501: remove redundant file check and stop ignoring git <cmd> exit codeLabnann, Apr 2, 2022
  11. Junio C HamanoApr 4, 2022
  12. 0/1 [GSoC] t3501: remove test -f and stop ignoring git <cmd> exit codeKhalid Masum, Apr 5, 2022
  13. 1/1 t3501: remove test -f and stop ignoring git <cmd> exit codeKhalid Masum, Apr 5, 2022
  14. 0/1 [GSoC] t3501: remove test -f and stop ignoring git <cmd> exit codeKhalid Masum, Apr 5, 2022
  15. 1/1 t3501: remove test -f and stop ignoring git <cmd> exit codeKhalid Masum, Apr 5, 2022
  16. t3501: remove test -f and stop ignoring git <cmd> exit codeLabnan via GitGitGadget, Apr 22, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.