JustBash.SpecTest.Parser (JustBash v0.4.0)
View SourceParser for Oils spec test format (.test.sh files).
A file is a run of cases. Each case opens with #### <name>; every line
after that up to the next #### is either a ## directive or a line of the
script, in any order — Oils puts ## SKIP above the script and the
expectations below it.
Directives:
## stdout: LINE/## stderr: LINE— one expected line. The value may be empty (## stdout:with nothing after the colon), which is how the format spells "one empty line".## stdout-json: "…"/## stderr-json: "…"— an escaped expectation, the only way to express output with no trailing newline## STDOUT:…## END/## STDERR:…## END— multiline## status: N— expected exit status (default 0)## SKIP (why): reason— do not run this case## N-I <shells> KEY: …,## BUG <shells> KEY: …,## OK <shells> KEY: …(and the-2/-3numbered spellings) — what those shells actually do, overriding the unannotated default for them per key. The unannotated default records osh, so an annotation namingbashis bash's recorded behaviour and is the expectation we want;just-bashis this repo's own recorded behaviour and wins overbash. An annotation naming neither is dropped, and a multiline one is consumed to## ENDso its body does not fall through into the script.## compare_shells:,## oils_failures_allowed:,## tags:, … — file- or case-level metadata we have no use for
The script is kept byte-for-byte between its first and last non-blank line.
Only whole blank lines at either end — the file's layout, not the case's —
are dropped: $LINENO, set -x traces and bash's own line N diagnostics
count from the first surviving line, and a trailing space on the last
command is part of what the case tests.
Example:
#### Add one to var
i=1
echo $(($i+1))
## stdout: 2
Summary
Functions
Parse spec test content and return a list of test cases.
Parse a spec test file and return a list of test cases.
Functions
@spec parse(String.t()) :: [JustBash.SpecTest.Parser.TestCase.t()]
Parse spec test content and return a list of test cases.
@spec parse_file(String.t()) :: {:ok, [JustBash.SpecTest.Parser.TestCase.t()]} | {:error, String.t()}
Parse a spec test file and return a list of test cases.