pub struct TestConfig<Cmd = Command> { /* private fields */ }
Available on crate feature test only.
Expand description

Testing configuration.

Examples

See the module docs for the examples of usage.

Implementations§

source§

impl<Cmd: SpawnShell + Debug> TestConfig<Cmd>

source

pub fn test<I: Into<UserInput>>( &mut self, snapshot_path: impl AsRef<Path>, inputs: impl IntoIterator<Item = I> )

Tests a snapshot at the specified path with the provided inputs.

If the path is relative, it is resolved relative to the current working dir, which in the case of tests is the root directory of the including crate (i.e., the dir where the crate manifest is located). You may specify an absolute path using env vars that Cargo sets during build, such as env!("CARGO_MANIFEST_DIR").

Similar to other kinds of snapshot testing, a new snapshot will be generated if there is no existing snapshot or there are mismatches between inputs or outputs in the original and reproduced transcripts. This new snapshot will have the same path as the original snapshot, but with the .new.svg extension. As an example, if the snapshot at snapshots/help.svg is tested, the new snapshot will be saved at snapshots/help.new.svg.

Generation of new snapshots will only happen if the svg crate feature is enabled (which it is by default), and if the update mode is not UpdateMode::Never, either because it was set explicitly or inferred from the execution environment.

The snapshot template can be customized via Self::with_template().

Panics
  • Panics if there is no snapshot at the specified path, or if the path points to a directory.
  • Panics if an error occurs during reproducing the transcript or processing its output.
  • Panics if there are mismatches between inputs or outputs in the original and reproduced transcripts.
source

pub fn test_transcript(&mut self, transcript: &Transcript<Parsed>)

Tests the transcript. This is a lower-level alternative to Self::test().

Panics
  • Panics if an error occurs during reproducing the transcript or processing its output.
  • Panics if there are mismatches between outputs in the original and reproduced transcripts.
source

pub fn test_transcript_for_stats( &mut self, transcript: &Transcript<Parsed> ) -> Result<(TestStats, Transcript)>

Tests the transcript and returns testing stats together with the reproduced Transcript. This is a lower-level alternative to Self::test().

Errors
  • Returns an error if an error occurs during reproducing the transcript or processing its output.
source§

impl<Cmd: SpawnShell> TestConfig<Cmd>

source

pub fn new(shell_options: ShellOptions<Cmd>) -> Self

Creates a new config.

Panics
  • Panics if the svg crate feature is enabled and the TERM_TRANSCRIPT_UPDATE variable is set to an incorrect value. See UpdateMode::from_env() for more details.
source

pub fn with_match_kind(self, kind: MatchKind) -> Self

Sets the matching kind applied.

source

pub fn with_color_choice(self, color_choice: ColorChoice) -> Self

Sets coloring of the output.

On Windows, color_choice has slightly different semantics than its usage in the termcolor crate. Namely, if colors can be used (stdout is a tty with color support), ANSI escape sequences will always be used.

source

pub fn with_output(self, output: TestOutputConfig) -> Self

Configures test output.

source

pub fn with_template(self, template: Template) -> Self

Available on crate feature svg only.

Sets the template for rendering new snapshots.

source

pub fn with_update_mode(self, update_mode: UpdateMode) -> Self

Available on crate feature svg only.

Overrides the strategy for saving new snapshots for failed tests.

By default, the strategy is determined from the execution environment using UpdateMode::from_env().

Trait Implementations§

source§

impl<Cmd: Debug> Debug for TestConfig<Cmd>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Cmd = Command> !RefUnwindSafe for TestConfig<Cmd>

§

impl<Cmd = Command> !Send for TestConfig<Cmd>

§

impl<Cmd = Command> !Sync for TestConfig<Cmd>

§

impl<Cmd> Unpin for TestConfig<Cmd>where Cmd: Unpin,

§

impl<Cmd = Command> !UnwindSafe for TestConfig<Cmd>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for Twhere T: Any,

§

fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more