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

[Outreachy][PATCH v4] t2400: avoid losing exit status to pipes

From
Achu Luma <ach.lumap@gmail.com>
Date
Jan 20, 2024, 02:15 UTC
Message-ID
<20240120021547.199-1-ach.lumap@gmail.com>
In-Reply-To
<20231204153740.2992-1-ach.lumap@gmail.com>

The exit code of the preceding command in a pipe is disregarded. So if that preceding command is a Git command that fails, the test would not fail. Instead, by saving the output of that Git command to a file, and removing the pipe, we make sure the test will fail if that Git command fails.

Signed-off-by: Achu Luma <ach.lumap@gmail.com>
---
 The difference between v3 and v4 is:
 - Changed subject to better reflect what the patch is doing.
 - Updated the commit message.
 t/t2400-worktree-add.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh
index 3742971105..b597004adb 100755
--- a/t/t2400-worktree-add.sh
+++ b/t/t2400-worktree-add.sh
@@ -490,7 +490,8 @@ test_expect_success 'put a worktree under rebase' '
 		cd under-rebase &&
 		set_fake_editor &&
 		FAKE_LINES="edit 1" git rebase -i HEAD^ &&
-		git worktree list | grep "under-rebase.*detached HEAD"
+		git worktree list >actual &&
+		grep "under-rebase.*detached HEAD" actual
 	)
 '

@@ -531,7 +532,8 @@ test_expect_success 'checkout a branch under bisect' '
 		git bisect start &&
 		git bisect bad &&
 		git bisect good HEAD~2 &&
-		git worktree list | grep "under-bisect.*detached HEAD" &&
+		git worktree list >actual &&
+		grep "under-bisect.*detached HEAD" actual &&
 		test_must_fail git worktree add new-bisect under-bisect &&
 		! test -d new-bisect
 	)
--
2.43.0.windows.1
Previous: Junio C Hamano
Message 10 of 10 in “*** Avoid using Pipes ***”
  1. 0/1 *** Avoid using Pipes ***ach.lumap@gmail.com, Oct 3, 2023
  2. 1/1 t2400: avoid using pipesach.lumap@gmail.com, Oct 3, 2023
  3. Eric SunshineOct 3, 2023
  4. Junio C HamanoOct 3, 2023
  5. 0/1 *** Avoid using Pipes ***Achu Luma, Nov 30, 2023
  6. 1/1 t2400: avoid using pipesAchu Luma, Nov 30, 2023
  7. Christian CouderNov 30, 2023
  8. [Outreachy][PATCH v3] t2400: avoid using pipesAchu Luma, Dec 4, 2023
  9. Junio C HamanoDec 8, 2023
  10. [Outreachy][PATCH v4] t2400: avoid losing exit status to pipesAchu Luma, Jan 20, 2024

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.