Repository navigation
fix(builtins): test and [ reject the operands bash rejects - #2612
Merged
Merged
Conversation
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | 276a244 | Commit Preview URL Branch Preview URL |
Oct 08 2026, 02:28 AM |
A non-integer operand of -eq and friends parsed as 0, so `[ a -lt 2 ]` answered true. It is a usage error in bash: the shell says `test: a: integer expression expected` and exits 2. The same applies to a two-word expression whose first word is not a unary operator, an unknown three-word operator, and four or more operands. `-a` and `-o` now evaluate both sides, since bash's connectives do not short-circuit. Claude-Session: https://claude.ai/code/session_019aFikmptPc91Fj4N2iDXQA
chaliy
force-pushed
the
claude/test-integer-errors
branch
from
October 8, 2026 02:27
5317263 to
276a244
Compare
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.
Requested by Михайло · project thread
What changed
testand[now treat an operand bash cannot use as an error instead ofguessing a value:
-eq/-ne/-lt/-le/-gt/-gereportsinteger expression expectedand exits 2unary operator expectedbinary operator expectedtoo many arguments-aand-oevaluate both sides, because bash'stestconnectives do not short-circuitAn integer operand may carry surrounding whitespace, a sign and leading zeros,
but not a base prefix, an exponent, or a value past 64 bits — same as bash.
Why
The old evaluator parsed any non-numeric operand as 0 and answered the
comparison, so a typo or an unset variable silently flipped a condition. The
worst case is a false positive:
bash writes
[: a: integer expression expected, exits 2 and the guard does notpass. Bashkit printed
guard passed.Before / After
test 1 -eq abctest: abc: integer expression expected, 2test: abc: integer expression expected, 2[ a -lt 2 ][: a: integer expression expected, 2[: a: integer expression expected, 2[ a -lt ][: a: unary operator expected, 2[: a: unary operator expected, 2test a foo btest: foo: binary operator expected, 2test: foo: binary operator expected, 2test a b c dtest: too many arguments, 2test: too many arguments, 2[ 1 -eq 2 -a abc -eq 1 ][: abc: integer expression expected, 2[: abc: integer expression expected, 2test 0x10 -eq 16test: 0x10: integer expression expected, 2test: 0x10: integer expression expected, 2test " 5 " -eq 5bash also prefixes the diagnostic with the script and line; the interpreter does
not track a script path, which is a separate known gap.
Risk
Medium: a script that relied on a bad operand comparing as 0 now fails loudly.
That is the point — bash fails there too — but it is a behavior change, not
only a message change.
[[ ... ]]is untouched and still answers false.The evaluator's return type changed from
booltoResult<bool, TestError>,so every branch now states explicitly whether it is an answer or an error. One
unit test asserted the old parse-as-zero behavior and was rewritten.
Checklist
cargo test -p bashkit --lib(2908 passed)cargo test -p bashkit --test integration(1351 passed)bash_comparisondifferential tests against real bashcargo clippy -p bashkit --all-targets -- -D warningscargo fmt --all --checkcargo test -p bashkit-cli(56 passed)just check-okflog.md)https://claude.ai/code/session_019aFikmptPc91Fj4N2iDXQA
Generated by Claude Code