Repository navigation
Keep the [@] array expansion when forwarding wrapped multi-valued positionals #217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -262,6 +262,14 @@ ADD_TEST_BASH([test-wrapping-excl], [[ | |
| $(_test_onlypos) | ||
| ]], [$(TESTDIR)/test-onlypos.m4]) | ||
|
|
||
| dnl Wrapping a script that declares ARG_LEFTOVERS and ARG_POSITIONAL_MULTI has to keep the [@] array expansion | ||
| dnl in the generated forwarding code of the wrapper (the [@] used to be stripped by m4 as a quote). | ||
| ADD_TEST_BASH([test-wrapleftovers], [[ | ||
| ! grep -q '@}' $< | ||
| $< hello a b | grep -q 'CMD=hello,PAIR=<a><b>,LEFTOVERS=0,<>,CMDLINE=2,<a><b>,' | ||
| $< hello 'a b' c 'd e' '' | grep -q 'CMD=hello,PAIR=<a b><c>,LEFTOVERS=2,<d e><>,CMDLINE=4,<a b><c><d e><>,' | ||
| ]], [$(TESTDIR)/test-wrapleftovers-lib.m4]) | ||
|
Comment on lines
+267
to
+271
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed: the wrapped library now declares ARG_POSITIONAL_MULTI as well as ARG_LEFTOVERS, and the assertions print each element in angle brackets together with the element count, using a value with whitespace and an empty value. Regarding the empty-leftovers remark in the summary: multi-valued positionals are always initialized as arrays ( |
||
|
|
||
| ADD_SCRIPT([test-wrapping2]) | ||
| ADD_TEST_BASH([stability-wrapping], [[ | ||
| diff -q $< $(word 2,$^) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # ARG_POSITIONAL_MULTI([pair], [Two values], 2) | ||
| # ARG_LEFTOVERS([args]) | ||
| # ARGBASH_GO | ||
|
|
||
| # [ <-- needed because of Argbash | ||
|
|
||
| printf 'PAIR='; printf '<%s>' "${_arg_pair[@]}" | ||
| printf ',LEFTOVERS=%s,' "${#_arg_leftovers[@]}"; printf '<%s>' "${_arg_leftovers[@]}" | ||
| echo ',' | ||
|
|
||
| # ] <-- needed because of Argbash |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # SC2154: the wrapped library has no optional args, so _args_*_opt is referenced but not assigned. | ||
| # shellcheck disable=SC2154 | ||
|
|
||
| m4_define(_DEFAULT_WRAP_FLAGS, []) | ||
|
|
||
| # ARG_POSITIONAL_SINGLE([cmd], [the command]) | ||
| # ARGBASH_WRAP([test-wrapleftovers-lib]) | ||
| # ARG_DEFAULTS_POS() | ||
| # ARGBASH_GO | ||
|
|
||
| # [ <-- needed because of Argbash | ||
|
|
||
| printf 'CMD=%s,PAIR=' "$_arg_cmd"; printf '<%s>' "${_arg_pair[@]}" | ||
| printf ',LEFTOVERS=%s,' "${#_arg_leftovers[@]}"; printf '<%s>' "${_arg_leftovers[@]}" | ||
| printf ',CMDLINE=%s,' "${#_args_test_wrapleftovers_lib[@]}"; printf '<%s>' "${_args_test_wrapleftovers_lib[@]}" | ||
| echo ',' | ||
|
|
||
| # ] <-- needed because of Argbash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like those trigraphs, it's definitely not wrong, but it is the nuclear option.
The kind of mistake looks obvious to me now, one level of quoting is stripped and therefore lost forever. So I would increase the nesting of quotes by one to
[[@]]-_varnameexpands intom4_quote, and that's only one level of quotes.It's great that you have added tests.