Skip to main content

Runner

Struct Runner 

Source
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

Source

pub fn new(parse: impl Fn(&str) -> Result<Value, Failure> + 'static) -> Self

A runner over a parse hook that sees only the input.

Source

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.

Source

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.

Source

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.

Source

pub fn normalize(self, hook: impl Fn(Value) -> Value + 'static) -> Self

Rewrite values before comparison; see equal_value_with.

Source

pub fn input(self, column: impl Into<Column>) -> Self

The column holding the parser input, by position or header name. Default: position 0.

Source

pub fn expected(self, column: impl Into<Column>) -> Self

The column holding the expected result. Default: position 1.

Source

pub fn load(self, options: SpecOptions) -> Self

Fixture-file loading options, passed through to the loader.

Source

pub fn load_options(&self) -> &SpecOptions

The loading options in force.

Source

pub fn input_column(&self) -> &Column

The input column selector in force.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn file(&self, path: impl AsRef<Path>)

Load one fixture file by path and run it, panicking on failure.

Source

pub fn dir(&self, dir: impl AsRef<Path>)

Load and run every *.tsv in a directory, panicking on failure.

Trait Implementations§

Source§

impl Clone for Runner

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Runner

§

impl !Send for Runner

§

impl !Sync for Runner

§

impl !UnwindSafe for Runner

§

impl Forget for Runner

§

impl Freeze for Runner
where *const RcInner<dyn Fn(&str, &Row) -> Result<Value, Failure>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&str, &Row) -> Result<Value, Failure>>>: Freeze, *const RcInner<dyn Fn(&Failure, &str, &Row) -> bool> is !null: Freeze, PhantomData<RcInner<dyn Fn(&Failure, &str, &Row) -> bool>>: Freeze, *const RcInner<dyn Fn(&str, &Row) -> Result<Value, Error>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&str, &Row) -> Result<Value, Error>>>: Freeze, *const RcInner<dyn Fn(Value) -> Value> is !null: Freeze, PhantomData<RcInner<dyn Fn(Value) -> Value>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl Move for Runner

§

impl Unpin for Runner
where Rc<dyn Fn(&str, &Row) -> Result<Value, Failure>>: Unpin, Rc<dyn Fn(&Failure, &str, &Row) -> bool>: Unpin, Rc<dyn Fn(&str, &Row) -> Result<Value, Error>>: Unpin, Rc<dyn Fn(Value) -> Value>: Unpin, *const u8 is !null: Unpin,

§

impl UnsafeUnpin for Runner
where *const RcInner<dyn Fn(&str, &Row) -> Result<Value, Failure>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&str, &Row) -> Result<Value, Failure>>>: UnsafeUnpin, *const RcInner<dyn Fn(&Failure, &str, &Row) -> bool> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&Failure, &str, &Row) -> bool>>: UnsafeUnpin, *const RcInner<dyn Fn(&str, &Row) -> Result<Value, Error>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&str, &Row) -> Result<Value, Error>>>: UnsafeUnpin, *const RcInner<dyn Fn(Value) -> Value> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(Value) -> Value>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.