docs(test): explain posixtest's arg(1) in parenthesized sub-expressions - #672
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Issue #670 reports that
TestEval::posixtest()case 1 evaluatesarg(1)instead ofarg(pos), producing a "wrong" result fortest '(' '' ')' -a b.Investigation shows this is deliberate bug-for-bug compatibility with bash 5.3, not an index bug:
test.cposixtest()does exactly the same thing:case 1: value = ONE_ARG_TEST(argv[1]);— even whenterm()calls it recursively for a parenthesized sub-expression withpos > 1(the forward-scan added in bash 5.3, CHANGES entry ee, which concedes "Such expressions remain ambiguous").test '(' '' ')' -a b— the issue's expected exit 1 comes from an older bash (≤ 5.2, whereshell_compatibility_level > 52routes the paren scan toexpr()instead).-a/-ocombinations, includingtest '(' '' ')' -a b,test x -a '(' '' ')',[ '(' '' ')' -a b ], and nested forms — all OK. Applying the proposedarg(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