chainlint.pl: allow `|| echo` to signal failure upstream of a pipe
commitae0c55abf8217bb06422f9eafcd7a30b2c8f9e8b
authorEric Sunshine <sunshine@sunshineco.com>
Thu, 1 Sep 2022 00:29:51 +0000 (1 00:29 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 1 Sep 2022 17:07:41 +0000 (1 10:07 -0700)
tree3317c729b00d12ef0d11f31b04ceb9f3ca441259
parentfd4094c3cad7c62adb0b7080e0dca37f66bf0c6e
chainlint.pl: allow `|| echo` to signal failure upstream of a pipe

The use of `|| return` (or `|| exit`) to signal failure within a loop
isn't effective when the loop is upstream of a pipe since the pipe
swallows all upstream exit codes and returns only the exit code of the
final command in the pipeline.

To work around this limitation, tests may adopt an alternative strategy
of signaling failure by emitting text which would never be emitted in
the non-failing case. For instance:

    while condition
    do
        command1 &&
        command2 ||
        echo "impossible text"
    done |
    sort >actual &&

Such usage indicates deliberate thought about failure cases by the test
author, thus flagging them as missing `|| return` (or `|| exit`) is not
helpful. Therefore, take this case into consideration when checking for
explicit loop termination.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/chainlint.pl
t/chainlint/loop-upstream-pipe.expect [new file with mode: 0644]
t/chainlint/loop-upstream-pipe.test [new file with mode: 0644]