summaryrefslogtreecommitdiffstats
path: root/tests/expr
diff options
context:
space:
mode:
authorSylvestre Ledru <sylvestre@debian.org>2026-04-03 12:07:44 +0200
committerPádraig Brady <P@draigBrady.com>2026-04-06 18:22:56 +0100
commit793f45e916cb12bf47c4c8dbc8cecfaf3510b1c6 (patch)
tree2d22ef6800f9509461a51618053fd20679219a28 /tests/expr
parent829593317db7768153eee864d46fcb4509360f88 (diff)
downloadcoreutils-793f45e916cb12bf47c4c8dbc8cecfaf3510b1c6.tar.gz
coreutils-793f45e916cb12bf47c4c8dbc8cecfaf3510b1c6.zip
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. https://github.com/uutils/coreutils/pull/11395 https://github.com/coreutils/coreutils/pull/238
Diffstat (limited to 'tests/expr')
-rwxr-xr-xtests/expr/expr.pl6
1 files changed, 6 insertions, 0 deletions
diff --git a/tests/expr/expr.pl b/tests/expr/expr.pl
index fcf994601..b582a85fd 100755
--- a/tests/expr/expr.pl
+++ b/tests/expr/expr.pl
@@ -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}],