Skip to content

Commit 793f45e

Browse files
sylvestrepixelb
authored andcommitted
tests: expr: add short-circuit tests with parenthesized branches
* 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. uutils/coreutils#11395 coreutils/coreutils#238
1 parent 8295933 commit 793f45e

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

tests/expr/expr.pl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@
6969
['andand', '0 \& 1 / 0', {OUT => '0'}, {EXIT => 1}],
7070
['oror', '1 \| 1 / 0', {OUT => '1'}, {EXIT => 0}],
7171

72+
# Short-circuit must also skip parenthesized dead branches.
73+
['or-paren', '1 \| \( 1 / 0 \)', {OUT => '1'}, {EXIT => 0}],
74+
['and-paren', '0 \& \( 1 / 0 \)', {OUT => '0'}, {EXIT => 1}],
75+
['or-nested', '1 \| \( 0 \& \( 1 / 0 \) \)', {OUT => '1'}, {EXIT => 0}],
76+
['and-nested', '0 \& \( 1 \| \( 1 / 0 \) \)', {OUT => '0'}, {EXIT => 1}],
77+
7278
# In 5.1.3 and earlier, this would output the empty string.
7379
['orempty', '"" \| ""', {OUT => '0'}, {EXIT => 1}],
7480

0 commit comments

Comments
 (0)