]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: expr: add short-circuit tests with parenthesized branches
authorSylvestre Ledru <sylvestre@debian.org>
Fri, 3 Apr 2026 10:07:44 +0000 (12:07 +0200)
committerPádraig Brady <P@draigBrady.com>
Mon, 6 Apr 2026 17:22:56 +0000 (18:22 +0100)
* tests/expr/expr.pl: Add tests to verify that short-circuit
evaluation of | and & correctly skips parenthesized dead branches,
including nested parenthesized expressions containing division by zero.
https://github.com/uutils/coreutils/pull/11395
https://github.com/coreutils/coreutils/pull/238

tests/expr/expr.pl

index fcf994601fc69f41f4d41d3f17009220443fdd8c..b582a85fd1c5433585e56831fd8387d1e70d7914 100755 (executable)
@@ -69,6 +69,12 @@ my @Tests =
      ['andand', '0 \& 1 / 0', {OUT => '0'}, {EXIT => 1}],
      ['oror', '1 \| 1 / 0', {OUT => '1'}, {EXIT => 0}],
 
+     # Short-circuit must also skip parenthesized dead branches.
+     ['or-paren', '1 \| \( 1 / 0 \)', {OUT => '1'}, {EXIT => 0}],
+     ['and-paren', '0 \& \( 1 / 0 \)', {OUT => '0'}, {EXIT => 1}],
+     ['or-nested', '1 \| \( 0 \& \( 1 / 0 \) \)', {OUT => '1'}, {EXIT => 0}],
+     ['and-nested', '0 \& \( 1 \| \( 1 / 0 \) \)', {OUT => '0'}, {EXIT => 1}],
+
      # In 5.1.3 and earlier, this would output the empty string.
      ['orempty', '"" \| ""', {OUT => '0'}, {EXIT => 1}],