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

[GSOC][PATCH v2] t3701: don't lose "git" exit codes in test scripts

From
EFEdwin Fernando <edwinfernando734@gmail.com>
Date
Apr 1, 2023, 19:47 UTC
Message-ID
<20230401194756.5954-1-edwinfernando734@gmail.com>
In-Reply-To
<20230326173147.39626-1-edwinfernando734@gmail.com>
Exit codes were lost due to piping and command substitution:
- "git ... | <command>"
- "<command> $(git ... )"
Fix these issues using the intermediate step of writing output to file.
---
Changes in response to review:
- addressed code style issues: ">diff" not  "> diff_file"
- a more direct alternative to "test -z $(cat ...)"
- commit message similar to previous commits accomplishing same goals
- revert unnecessary change. keep "<var> = $(git ...)"
 t/t3701-add-interactive.sh | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index 80446b311d..77aad9032a 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -292,10 +292,10 @@ test_expect_success FILEMODE 'patch does not affect mode' '
 	echo content >>file &&
 	chmod +x file &&
 	printf "n\\ny\\n" | git add -p &&
-	git show :file > show_file &&
-	grep content show_file &&
-	git diff file > diff_file &&
-	grep "new mode" diff_file
+	git show :file >show &&
+	grep content show &&
+	git diff file >diff &&
+	grep "new mode" diff
 '
 
 test_expect_success FILEMODE 'stage mode but not hunk' '
@@ -303,10 +303,10 @@ test_expect_success FILEMODE 'stage mode but not hunk' '
 	echo content >>file &&
 	chmod +x file &&
 	printf "y\\nn\\n" | git add -p &&
-	git diff --cached file > diff_file &&
-	grep "new mode" diff_file &&
-	git diff file > diff_file &&
-	grep "+content" diff_file
+	git diff --cached file >diff &&
+	grep "new mode" diff &&
+	git diff file >diff &&
+	grep "+content" diff
 '
 
 
@@ -315,12 +315,11 @@ test_expect_success FILEMODE 'stage mode and hunk' '
 	echo content >>file &&
 	chmod +x file &&
 	printf "y\\ny\\n" | git add -p &&
-	git diff --cached file > diff_file &&
-	grep "new mode" diff_file &&
-	git diff --cached file diff_file &&
-	grep "+content" diff_file &&
-	git diff file > diff_file &&
-	test -z $(cat diff_file)
+	git diff --cached file >diff &&
+	grep "new mode" diff &&
+	grep "+content" diff &&
+	git diff file >diff &&
+	test_must_be_empty diff
 '
 
 # end of tests disabled when filemode is not usable
@@ -977,8 +976,8 @@ test_expect_success 'handle submodules' '
 
 	force_color git -C for-submodules add -p dirty-head >output 2>&1 <y &&
 	git -C for-submodules ls-files --stage dirty-head >actual &&
-	git -C for-submodules/dirty-head rev-parse HEAD > rev &&
-	grep -f rev actual
+	rev="$(git -C for-submodules/dirty-head rev-parse HEAD)" &&
+	grep "$rev" actual
 '
 
 test_expect_success 'set up pathological context' '
-- 
2.40.0
Previous: Eric SunshineNext: Andrei Rybak
Message 5 of 13 in “Avoid suppression of git's exit code in tests”
  1. Edwin FernandoMar 26, 2023
  2. [GSOC][PATCH 1/1] t3701: Avoid suppression of exit status of gitEdwin Fernando, Mar 26, 2023
  3. Andrei RybakMar 26, 2023
  4. Eric SunshineMar 27, 2023
  5. [GSOC][PATCH v2] t3701: don't lose "git" exit codes in test scriptsEdwin Fernando, Apr 1, 2023
  6. Andrei RybakApr 2, 2023
  7. [GSOC][PATCH v3] t3701: don't lose "git" exit codes in test scriptsEdwin Fernando, Apr 2, 2023
  8. Eric SunshineApr 2, 2023
  9. [GSOC][PATCH v4] t3701: don't lose "git" exit codes in test scriptsEdwin Fernando, Apr 2, 2023
  10. Eric SunshineApr 3, 2023
  11. Edwin FernandoApr 3, 2023
  12. Edwin FernandoApr 3, 2023
  13. Eric SunshineApr 3, 2023

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.