pub struct Runner { /* private fields */ }Expand description
Drives fixture rows through one parser. Reuse it across files.
Built with Runner::new (a parse hook taking the input) or
Runner::new_with_row (one taking the row as well, for a fixture
whose other columns take part in the parse, an opts column of plugin
options being the common one), then adjusted with the builder methods.
Implementations§
Source§impl Runner
impl Runner
Sourcepub fn new(parse: impl Fn(&str) -> Result<Value, Failure> + 'static) -> Self
pub fn new(parse: impl Fn(&str) -> Result<Value, Failure> + 'static) -> Self
A runner over a parse hook that sees only the input.
Sourcepub fn new_with_row(
parse: impl Fn(&str, &Row) -> Result<Value, Failure> + 'static,
) -> Self
pub fn new_with_row( parse: impl Fn(&str, &Row) -> Result<Value, Failure> + 'static, ) -> Self
A runner over a parse hook that sees the row as well.
Sourcepub fn match_error(
self,
hook: impl Fn(&Failure, &str, &Row) -> bool + 'static,
) -> Self
pub fn match_error( self, hook: impl Fn(&Failure, &str, &Row) -> bool + 'static, ) -> Self
Decide whether a failure satisfies an ERROR:<want> row, when
comparing a code cannot. It replaces the code comparison entirely.
A code is the contract this crate prefers, but some grammars have
no stable code to pin: a parser whose failures are distinguished
only by their message, or a fixture that names a position rather
than a kind. Those fixtures would otherwise have to weaken to a
bare ERROR, which asserts nothing more than “it failed”.
A bare ERROR cell still means “any error”, and does not reach
here. Nor does a trailing @<row>:<col>: want is the code with
any position expectation already stripped.
Sourcepub fn parse_expected(
self,
hook: impl Fn(&str, &Row) -> Result<Value> + 'static,
) -> Self
pub fn parse_expected( self, hook: impl Fn(&str, &Row) -> Result<Value> + 'static, ) -> Self
Read the expected cell, when the fixture’s vocabulary is wider than
JSON (JSON5’s NaN and Infinity, or the UNDEFINED several repos
use for “no value at all”). It replaces parse_expect, and is
reached only for a value row. Call parse_expect for the cells the
hook does not claim, so the ordinary rows keep the ordinary rules.
Sourcepub fn normalize(self, hook: impl Fn(Value) -> Value + 'static) -> Self
pub fn normalize(self, hook: impl Fn(Value) -> Value + 'static) -> Self
Rewrite values before comparison; see equal_value_with.
Sourcepub fn input(self, column: impl Into<Column>) -> Self
pub fn input(self, column: impl Into<Column>) -> Self
The column holding the parser input, by position or header name. Default: position 0.
Sourcepub fn expected(self, column: impl Into<Column>) -> Self
pub fn expected(self, column: impl Into<Column>) -> Self
The column holding the expected result. Default: position 1.
Sourcepub fn load(self, options: SpecOptions) -> Self
pub fn load(self, options: SpecOptions) -> Self
Fixture-file loading options, passed through to the loader.
Sourcepub fn load_options(&self) -> &SpecOptions
pub fn load_options(&self) -> &SpecOptions
The loading options in force.
Sourcepub fn input_column(&self) -> &Column
pub fn input_column(&self) -> &Column
The input column selector in force.
Sourcepub fn check_spec(&self, spec: &SpecFile) -> Result<()>
pub fn check_spec(&self, spec: &SpecFile) -> Result<()>
Why a fixture cannot be run, or Ok when it can. Runner::spec
calls it and fails; it is public so the guard itself can be
asserted.
A fixture that loads but holds no rows is the case that matters: it is a silent pass, and a silent pass is indistinguishable from coverage that was never there.
Sourcepub fn check_row(&self, row: &Row, input: &str, expected: &str) -> Result<()>
pub fn check_row(&self, row: &Row, input: &str, expected: &str) -> Result<()>
Run one row and return the failure rather than reporting it, for a suite that does its own reporting.
Sourcepub fn run_spec(&self, spec: &SpecFile) -> Result<Vec<String>>
pub fn run_spec(&self, spec: &SpecFile) -> Result<Vec<String>>
Run every row of an already-loaded fixture. Err when the fixture
cannot be run at all; otherwise the failures, one per failing row,
empty when every row passed.
Sourcepub fn run_file(&self, path: impl AsRef<Path>) -> Result<Vec<String>>
pub fn run_file(&self, path: impl AsRef<Path>) -> Result<Vec<String>>
Load one fixture file by path and run it; see Runner::run_spec.
Sourcepub fn run_dir(&self, dir: impl AsRef<Path>) -> Result<Vec<String>>
pub fn run_dir(&self, dir: impl AsRef<Path>) -> Result<Vec<String>>
Load and run every *.tsv in a directory; see Runner::run_spec.
An empty directory is an error: a runner that finds nothing to run
must not report green.
Sourcepub fn spec(&self, spec: &SpecFile)
pub fn spec(&self, spec: &SpecFile)
Run an already-loaded fixture, panicking with every failing row at once when any fails or the fixture cannot be run.