testsuite batch94: declare/unalias/exec/hash/unset diagnostics + ${a[@]@A} - #305
Merged
Conversation
Match bash's declare-family error handling: - Reject a non-identifier operand (`declare /bin/sh', or a `-z' left as an operand after `--') with `not a valid identifier', reporting and skipping each while still processing the rest. `local -' stays exempt as bash's special save-options operand. - Reject `-f'/`-F' carrying an assignment (`declare -f f=...') with `cannot use `-f' to make functions'. - Prefix a readonly-assignment failure with the builtin name (`declare: VAR: readonly variable') as bind_variable does, where a bare assignment and readonly/export stay unprefixed, and propagate the failed assignment's non-zero exit status. - Refuse to clear an existing readonly attribute via `+r', reporting the variable as readonly and leaving the flag set.
`unalias' with neither `-a' nor a name operand now prints its usage string and returns 2, and `exec' follows an invalid-option error with its usage line, both matching bash.
`hashall' was accepted as a no-op. Track it as opt_hashall (on by default) and wire it through `set -h'/`+h', `set -o hashall', the `-h' invocation flag, $SHELLOPTS and $-. With hashing disabled every form of the `hash' builtin now fails first with `hash: hashing disabled', and `$-' drops the `h' flag, both matching bash.
`unset a[-2]' on an empty or too-short indexed array silently did nothing. array_unset now returns whether the subscript resolved in range, and `unset' reports `unset: [SUB]: bad array subscript' (exit 1) when a negative index falls below the first element, as bash does. A positive out-of-range index and an associative key remain no-ops.
The array `@A' transform applied the per-element scalar operator, so
${a[@]@A} produced a garbled `declare -A a=<element>' per value instead
of one statement recreating the array. Extract declare -p's rendering
into declare_var_string and reuse it: ${a[@]@A} now emits the three
top-level words `declare', `-flags' and `name=(...)' -- staying three
words when quoted and IFS-splitting the last when unquoted -- so
`eval "${a[@]@A}"' round-trips byte for byte, matching bash.
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.
Batch 94 of bash 5.3 test-suite conformance work, driven by the
errorstest (2nd-largest byte-diff afterintl). Five independent conformance fixes:declare/typeset/local diagnostics — reject non-identifier operands (
declare /bin/sh, a-zleft after--) with not a valid identifier; reject-f/-Fwith an assignment (*cannot use-f' to make functions*); prefix a readonly-assignment failure with the builtin name and propagate its exit status; refuse+rclearing an existing readonly.local -` stays exempt as bash's save-options operand.unalias / exec usage — bare
unalias(no name) andexecwith a bad option now print their usage lines.set +o hashall— replaced the no-op with a realopt_hashallstate wired throughset -h/+h,set -o hashall, the-hinvocation flag,$SHELLOPTSand$-.hashnow fails with hashing disabled when off;$-dropsh.unset bad subscript —
unset a[-2]on an empty/too-short indexed array now reports unset: [SUB]: bad array subscript (exit 1) instead of silently no-op'ing.${a[@]@A}— the whole-array@Atransform applied the per-element scalar operator (garbagedeclare -A a=<value>per element). Extracteddeclare -p's formatting intodeclare_var_stringand reused it, so${a[@]@A}recreates the array andeval "${a[@]@A}"round-trips byte for byte.Scoreboard impact (byte-diffs vs bash 5.3)
No regressions in any other test.
ctest22/22 andrun_diffall 234 scripts match bash.