Skip to content

Commit a8f30ee

Browse files
sunshinecogitster
authored andcommitted
chainlint.pl: don't flag broken &&-chain if $? handled explicitly
There are cases in which tests capture and check a command's exit code explicitly without employing test_expect_code(). They do so by intentionally breaking the &&-chain since it would be impossible to capture "$?" in the failing case if the `status=$?` assignment was part of the &&-chain. Since such constructs are manually checking the exit code, their &&-chain breakage is legitimate and safe, thus should not be flagged. Therefore, stop flagging &&-chain breakage in such cases. Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aabc325 commit a8f30ee

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

t/chainlint.pl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,12 @@ sub accumulate {
497497
# did previous command end with "&&", "|", "|| return" or similar?
498498
goto DONE if match_ending($tokens, \@safe_endings);
499499

500+
# if this command handles "$?" specially, then okay for previous
501+
# command to be missing "&&"
502+
for my $token (@$cmd) {
503+
goto DONE if $token =~ /\$\?/;
504+
}
505+
500506
# flag missing "&&" at end of previous command
501507
my $n = find_non_nl($tokens);
502508
splice(@$tokens, $n + 1, 0, '?!AMP?!') unless $n < 0;

t/chainlint/chain-break-status.expect

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
OUT=$(( ( large_git ; echo $? 1 >& 3 ) | : ) 3 >& 1) &&
2+
test_match_signal 13 "$OUT" &&
3+
4+
{ test-tool sigchain > actual ; ret=$? ; } &&
5+
{
6+
test_match_signal 15 "$ret" ||
7+
test "$ret" = 3
8+
} &&
9+
test_cmp expect actual

t/chainlint/chain-break-status.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# LINT: broken &&-chain okay if next command handles "$?" explicitly
2+
OUT=$( ((large_git; echo $? 1>&3) | :) 3>&1 ) &&
3+
test_match_signal 13 "$OUT" &&
4+
5+
# LINT: broken &&-chain okay if next command handles "$?" explicitly
6+
{ test-tool sigchain >actual; ret=$?; } &&
7+
{
8+
test_match_signal 15 "$ret" ||
9+
test "$ret" = 3
10+
} &&
11+
test_cmp expect actual

0 commit comments

Comments
 (0)