Skip to content

docs(test): explain posixtest's arg(1) in parenthesized sub-expressions - #672

Merged
brianjfox merged 1 commit into
mainfrom
fix/test-paren-subexpr-arg
Aug 20, 2026
Merged

docs(test): explain posixtest's arg(1) in parenthesized sub-expressions#672
brianjfox merged 1 commit into
mainfrom
fix/test-paren-subexpr-arg

Conversation

@brianjfox

Copy link
Copy Markdown
Owner

Summary

Issue #670 reports that TestEval::posixtest() case 1 evaluates arg(1) instead of arg(pos), producing a "wrong" result for test '(' '' ')' -a b.

Investigation shows this is deliberate bug-for-bug compatibility with bash 5.3, not an index bug:

  • bash 5.3's test.c posixtest() does exactly the same thing: case 1: value = ONE_ARG_TEST(argv[1]); — even when term() calls it recursively for a parenthesized sub-expression with pos > 1 (the forward-scan added in bash 5.3, CHANGES entry ee, which concedes "Such expressions remain ambiguous").
  • Reference bash 5.3.15 exits 0 for test '(' '' ')' -a b — the issue's expected exit 1 comes from an older bash (≤ 5.2, where shell_compatibility_level > 52 routes the paren scan to expr() instead).
  • Verified gnash matches bash 5.3.15 on 11 paren/-a/-o combinations, including test '(' '' ')' -a b, test x -a '(' '' ')', [ '(' '' ')' -a b ], and nested forms — all OK. Applying the proposed arg(pos) change makes 4 of the 11 diverge from bash.

This PR adds a comment documenting the quirk so it is not "fixed" into a divergence later. No behavior change.

Closes #670

🤖 Generated with Claude Code

TestEval::posixtest() case 1 evaluates arg(1) rather than arg(pos), which
looks like an index bug when term() calls it recursively for a
parenthesized sub-expression (pos > 1).  It is deliberate: bash 5.3's
posixtest evaluates ONE_ARG_TEST(argv[1]) in exactly the same situation,
so `test '(' '' ')' -a b' tests "(" -- not the empty string -- and
exits 0 in both shells.  Verified against bash 5.3.15 across paren/-a/-o
combinations; bash's CHANGES entry for the forward-scan notes "Such
expressions remain ambiguous".

Document the quirk so it is not "fixed" into a divergence.

Closes #670
@brianjfox
brianjfox merged commit ab65aa3 into main Aug 20, 2026
1 check passed
@brianjfox
brianjfox deleted the fix/test-paren-subexpr-arg branch August 20, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TestEval::posixtest() evaluates wrong argument for parenthesised sub-expressions

1 participant