Skip to content

feat: add test builtin#179

Open
bartlomieju wants to merge 1 commit into
mainfrom
feat/test-builtin
Open

feat: add test builtin#179
bartlomieju wants to merge 1 commit into
mainfrom
feat/test-builtin

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

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 and composes with the shell's existing
boolean list support.

The [ ... ] alias is not registered yet. The shell's glob expansion
currently treats an unquoted [ as the start of a character class and
errors when the pattern doesn't compile, which makes [ 1 -eq 1 ]
unusable without quoting. Exposing [ cleanly requires teaching the
glob expander to fall back to literal on pattern compile errors (what
bash does when failglob is off). That's a separate change worth doing
on its own.

Refs #134.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant