feat(assert): assert_true and assert_false accept a command with arguments - #999
Merged
Conversation
…ments Closes #994. assert_true test -d /tmp assert_true grep -q foo ./file assert_false test -d /nope The argument used to be run as a single command word. Anything with arguments was looked up as a command whose name contained spaces, so the natural spelling was the broken one and the workaround was an `eval ` prefix nobody had documented until #993. Arguments are now passed through as arguments. Nothing is re-parsed, so a path containing a space survives -- which the eval form cannot promise. Additive by construction: with exactly one argument the old path runs unchanged, including the literal `true`/`false`/`0`/`1` fast path and the `eval ` prefix. So every existing call means what it meant. The literal check is guarded on the argument count, because `assert_true true --version` is the command named true, not the boolean. The exit code is captured with `|| exit_code=$?` rather than a bare call: under --strict a failing command as a statement would abort the whole test. The alternative of splitting the single-argument string on whitespace was rejected. It would silently change what an existing string means, break arguments that legitimately contain spaces, and make the assertion sometimes-word-splitting. Passing real arguments needs no re-parsing at all. Verified across all eight shapes: literal true, literal 0, bare function, eval prefix, variadic, variadic with a space in a path, variadic assert_false, and `true --version` where the literal and the command collide. 1713 sequential / 1672 parallel; baseline + 5, RED first.
4 tasks
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.
🤔 Background
Related #994
The argument used to be run as a single command word. Anything with arguments was looked up as a command whose name contained spaces — so the natural spelling was the broken one, and the workaround was an
evalprefix nobody had documented until #993.💡 Changes
Arguments are now passed through as arguments. Nothing is re-parsed, so a path containing a space survives — which the
evalform cannot promise.Additive by construction. With exactly one argument the old path runs unchanged, including the literal
true/false/0/1fast path and theevalprefix. Every existing call means what it meant. The literal check is guarded on argument count, becauseassert_true true --versionis the command namedtrue, not the boolean.The exit code is captured with
|| exit_code=$?rather than a bare call — under--stricta failing command as a statement would abort the whole test.🚫 Why not split the string instead
Splitting the single-argument form on whitespace would silently change what an existing string means, break arguments that legitimately contain spaces, and make the assertion sometimes-word-splitting. Passing real arguments needs no re-parsing at all.
✅ Verification
All eight shapes checked: literal
true, literal0, bare function,evalprefix, variadic, variadic with a space in a path, variadicassert_false, andtrue --versionwhere the literal and the command collide.5 new tests, RED first.
make sa·make lint·bash build.sh bin -v→✅ Build verified ✅· 1713 sequential / 1672 parallel-simple-strict.