Warn when a template lacks the guard lines past ARGBASH_GO - #211
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Guard matching, macro-boundary handling, and POSIX test coverage remain unresolved.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds warnings when templates lack required Argbash guard lines, with regression coverage and synchronized generator updates.
Changes:
- Adds guard detection and warnings.
- Adds missing-guard fixture and regression tests.
- Updates the generated executable and changelog.
File summaries
| File | Description |
|---|---|
tests/regressiontests/Makefile |
Registers the regression test. |
tests/regressiontests/make/tests/tests-base.m4 |
Defines warning assertions. |
tests/regressiontests/gen-test-missing-guards.m4 |
Provides the malformed template fixture. |
src/argbash.m4 |
Implements missing-guard warning logic. |
ChangeLog |
Documents the bug fix. |
bin/argbash |
Mirrors the generator changes. |
Review details
Suppressed comments (3)
src/argbash.m4:209
- The detector also matches
ARGBASH_PREPARE, but this warning names onlyARGBASH_GOand says the code is pastARGBASH_GO. For a DIY template using onlyARGBASH_PREPARE, the diagnostic points at a marker that is not present and is misleading about the affected section.
"Warning: The ARGBASH_GO line is not followed by the '# [ <-- needed because of Argbash' guard line (with the matching '# ] <-- needed because of Argbash' line at the end of the file)." \
"Square brackets in the code past ARGBASH_GO will be stripped, and the script can't be regenerated correctly. See the 'Template layout' section of the documentation." >&2
src/argbash.m4:203
- Because this expression is not bounded after
GO|PREPARE, it also classifies names such as the existing# ARGBASH_GOOtypo (tests/regressiontests/gen-test-misspelled.m4:6) as action macros. That produces a misleading missing-guards warning for an input with no action macro; require a token boundary while still accepting the supported(),[and end-of-line forms.
/^#[[:space:]]*ARGBASH_(GO|PREPARE)/ { seen_go = 1 }
tests/regressiontests/make/tests/tests-base.m4:352
- The implementation explicitly supports both bash and POSIX script types via the
*scriptcheck, but this regression only invokes the default bash type. Add equivalent--type posix-scriptassertions (at least the warning and--stripsuppression) so the advertised POSIX path is covered; this suite already has dedicated POSIX tests.
ADD_TEST_BASH([test-missing-guards], [[
$(ARGBASH_EXEC) $< -o - 2>&1 > /dev/null | grep -q 'needed because of Argbash'
$(ARGBASH_EXEC) $< --strip user-content -o - 2>&1 > /dev/null | $(REVERSE) grep -q 'needed because of Argbash'
$(ARGBASH_EXEC) $(TESTDIR)/test-simple.m4 -o - 2>&1 > /dev/null | $(REVERSE) grep -q 'needed because of Argbash'
]], [$(TESTDIR)/test-simple.m4], [$(TESTDIR)/gen-test-missing-guards.m4])
- Files reviewed: 5/6 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| awk ' | ||
| /^#[[:space:]]*ARGBASH_(GO|PREPARE)/ { seen_go = 1 } | ||
| seen_go && /^#[[:space:]]*\[/ { seen_guard = 1 } # ] <-- needed because of Argbash | ||
| END { exit !(seen_go && !seen_guard) } | ||
| ' "$1" || return 0 |
There was a problem hiding this comment.
A template with the opening guard but without the closing one does not pass silently: the unmatched quote makes autom4te fail with "end of file in string", and argbash reports the unmatched square bracket and aborts. The warning is meant for the case that is silent (no opening guard at all), so I am leaving the detector as it is.
0e17c6d to
d21217e
Compare
The user code past ARGBASH_GO has to be enclosed in the
'# [ <-- needed because of Argbash' and '# ] <-- needed because of Argbash'
lines, otherwise m4 strips square brackets from it (e.g. array
expansions such as "${arr[@]}" become "${arr@}"), and the script gets
corrupted silently.
Print a warning that names the guard lines when a bash or POSIX script
is generated (without --strip) from such a template.
Related to matejak#205
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017DxhC3HmTM7TQUzkBZnyH2
d21217e to
7400056
Compare
|
Addressed the suppressed remarks as well: the detector requires a token boundary after ARGBASH_GO/ARGBASH_PREPARE (so the ARGBASH_GOO typo template no longer triggers it), the message mentions ARGBASH_PREPARE, and the test also covers --type posix-script and the misspelled-macro template. |
Related to #205
The user code past
ARGBASH_GOhas to be enclosed in the# [ <-- needed because of Argbashand# ] <-- needed because of Argbashlines, otherwise m4 strips square brackets from it (for example"${_arg_leftovers[@]}"becomes"${_arg_leftovers@}", which is the symptom reported in #205) and the script gets corrupted silently.argbashnow prints a warning that names the guard lines when it generates a bash or POSIX script (without--strip) from a template that hasARGBASH_GO/ARGBASH_PREPAREbut no guard line after it. Generation itself is unchanged.New regression test
test-missing-guardschecks that the warning is printed for such a template and not printed for a regular one nor with--strip.🤖 Generated with Claude Code
https://claude.ai/code/session_017DxhC3HmTM7TQUzkBZnyH2