chainlint.sed: tolerate harmless ";" at end of last line in block
chainlint.sed flags ";" when used as a command terminator since it breaks the &&-chain, thus can allow failures to go undetected. However, when a command terminated by ";" is the last command in the body of a compound statement, such as `command-2` in: if test $# -gt 1 then command-1 && command-2; fi then the ";" is harmless and the exit code from `command-2` is passed through untouched and becomes the exit code of the compound statement, as if the ";" was not present. Therefore, tolerate a trailing ";" in this position rather than complaining about broken &&-chain. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Eric Sunshine committed
Dec 13, 2021 at 01:30 UTC
3865a7e36dd762f57860faac0d1a1aa9c52d9404
2 files changed
+8
-7
t/chainlint.sed
+6
-5
@@ -47,8 +47,9 @@
47
# "?!AMP?!" violation is removed from the "bar" line (retrieved from the "hold"
48
# area) since the final statement of a subshell must not end with "&&". The
49
# final line of a subshell may still break the &&-chain by using ";" internally
50
-# to chain commands together rather than "&&", so "?!SEMI?!" is never removed
51
-# from a line (even though "?!AMP?!" might be).
50
+# to chain commands together rather than "&&", so "?!SEMI?!" is not removed
51
+# from such a line; however, if the line ends with "?!SEMI?!", then the ";" is
52
+# harmless and the annotation is removed.
53
#
54
# Care is taken to recognize the last _statement_ of a multi-line subshell, not
55
# necessarily the last textual _line_ within the subshell, since &&-chaining
@@ -303,7 +304,7 @@ bcase
304
# that line legitimately lacks "&&"
305
:else
306
x
306
-s/ ?!AMP?!$//
307
+s/\( ?!SEMI?!\)* ?!AMP?!$//
308
x
309
bcont
310
@@ -311,7 +312,7 @@ bcont
312
# "suspect" from final contained line since that line legitimately lacks "&&"
313
:done
314
x
314
-s/ ?!AMP?!$//
315
+s/\( ?!SEMI?!\)* ?!AMP?!$//
316
x
317
# is 'done' or 'fi' cuddled with ")" to close subshell?
318
/done.*)/bclose
@@ -354,7 +355,7 @@ bblock
355
# since that line legitimately lacks "&&" and exit subshell loop
356
:clssolo
357
x
357
-s/ ?!AMP?!$//
358
+s/\( ?!SEMI?!\)* ?!AMP?!$//
359
p
360
x
361
s/^/>/
t/chainlint/semicolon.expect
+2
-2
@@ -11,10 +11,10 @@
11
cat foo; ?!SEMI?! echo bar
12
>) &&
13
(
14
- foo; ?!SEMI?!
14
+ foo;
15
>) &&
16
(
17
cd foo &&
18
for i in a b c; do
19
- echo; ?!SEMI?!
19
+ echo;
20
> done)