Thread (181 messages) 181 messages, 7 authors, 2021-01-20

Re: [PATCH 15/27] t7501: stop losing return codes of git commands

From: Eric Sunshine <hidden>
Date: 2019-11-16 10:35:35

On Thu, Nov 14, 2019 at 8:01 PM Denton Liu [off-list ref] wrote:
quoted hunk ↗ jump to hunk
In a pipe, only the return code of the last command is used. Thus, all
other commands will have their return codes masked. Rewrite pipes so
that there are no git commands upstream so that we will know if a
command fails.

Signed-off-by: Denton Liu <redacted>
---
diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh
@@ -285,9 +285,8 @@ test_expect_success 'overriding author from command line' '
 test_expect_success PERL 'interactive add' '
-       echo 7 |
-       git commit --interactive |
-       grep "What now"
+       echo 7 | test_must_fail git commit --interactive >out &&
+       grep "What now" out
 '
git-commit documentation does not talk about the command's exit code,
so it's not immediately clear why this test should be using
test_must_fail() for the invocation. The implementation of git-commit
is more illuminating, showing that 1 is returned when there are no
changes to commit, and 0 for a successful commit. So, that raises the
question of whether this should be using "test_expect_code 1" rather
than test_must_fail(), however, there is existing precedence which
gives some guidance. In particular, the "nothing to commit" test of
t7501-commit-basic-functionality.sh does use test_must_fail() when
attempting to commit with no changes. It may make sense, therefore, to
mention something about this in the commit message to save future
readers from wondering why the command is "expected to fail".
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help