feat: add test builtin#179
Open
bartlomieju wants to merge 1 commit into
Open
Conversation
Implements POSIX `test` for a useful subset of operators: - File predicates: `-e`, `-f`, `-d`, `-s` - String predicates: `-n`, `-z` - String comparison: `=`, `!=` - Integer comparison: `-eq`, `-ne`, `-lt`, `-le`, `-gt`, `-ge` - Negation: `!` Returns exit code 0 on true, 1 on false, 2 on syntax error. Composition with `-a` / `-o` / parens is intentionally not supported — chain separate invocations with `&&` / `||` instead, which is the bash-recommended idiom anyway. The `[ ... ]` alias is not registered yet: the shell's glob expansion currently treats an unquoted `[` as the start of a character class and errors on invalid patterns. Exposing `[` cleanly requires teaching the glob expander to fall back to literal on pattern compile errors, which is a separate change. Refs #134.
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.
Implements POSIX
testfor a useful subset of operators:-e,-f,-d,-s-n,-z=,!=-eq,-ne,-lt,-le,-gt,-ge!Returns exit code 0 on true, 1 on false, 2 on syntax error.
Composition with
-a/-o/ parens is intentionally not supported —chain separate invocations with
&&/||instead, which is thebash-recommended idiom anyway and composes with the shell's existing
boolean list support.
The
[ ... ]alias is not registered yet. The shell's glob expansioncurrently treats an unquoted
[as the start of a character class anderrors when the pattern doesn't compile, which makes
[ 1 -eq 1 ]unusable without quoting. Exposing
[cleanly requires teaching theglob expander to fall back to literal on pattern compile errors (what
bash does when
failglobis off). That's a separate change worth doingon its own.
Refs #134.