Add shell metacharacter tests and fix error message quoting in exec runner#34
Open
JoshuaOliphant wants to merge 1 commit into
Open
Add shell metacharacter tests and fix error message quoting in exec runner#34JoshuaOliphant wants to merge 1 commit into
JoshuaOliphant wants to merge 1 commit into
Conversation
… tests Shell interpreters (bash, sh, zsh) already handle metacharacters correctly via the existing `exec.Command(lang, "-c", code)` dispatch. This commit adds explicit test coverage for pipes, redirects, and `&&` chaining to document and protect that behaviour. Also improves the error message when an interpreter cannot be found: the binary name is now quoted with %q, making "executing \"python3\": ..." unambiguous in output. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
I was using showboat to build a demo document that needed piped commands —
echo hello | wc -l,ls | head -3, that kind of thing. Nothing special. While reading through the runner code I noticed two things: the existing behaviour for shell metacharacters was already correct (bash/sh/zsh get-c, which naturally interprets|,>,&&), but there were no tests proving it. I also spotted the error message using%sto format the interpreter name, which produces ambiguous output when the binary name runs up against punctuation.This PR adds explicit test coverage for the metacharacter cases and tightens the error formatting. No behaviour change to the runner itself.
Changes
exec/runner_test.go— three new tests:TestRunWithPipe: runsecho hello | wc -lvia bash, asserts exit 0 and output1TestRunWithRedirect: runsecho redirected > file, asserts the file was created with the right contentTestRunShellMetacharacters: runsecho one && echo twovia sh, asserts both lines appear and exit code is 0All three check exit codes explicitly, not just output content.
exec/runner.go— one-character change:%s→%qin the startup-failure error path. Before:executing python3: exec: "python3": executable file not found. After:executing "python3": exec: .... The quotes make it unambiguous where the binary name ends and the error begins.Evidence of testing
Built the binary locally and ran a full demo document exercising every metacharacter case:
verifypassing confirms the round-trip:python3blocks still execute as Python, not bash.langstays as the actual interpreter.Full test suite: