Struct term_transcript::test::TestConfig
source · pub struct TestConfig<Cmd = Command> { /* private fields */ }
test
only.Expand description
Implementations§
source§impl<Cmd: SpawnShell + Debug> TestConfig<Cmd>
impl<Cmd: SpawnShell + Debug> TestConfig<Cmd>
sourcepub fn test<I: Into<UserInput>>(
&mut self,
snapshot_path: impl AsRef<Path>,
inputs: impl IntoIterator<Item = I>
)
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.
sourcepub fn test_transcript(&mut self, transcript: &Transcript<Parsed>)
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.
sourcepub fn test_transcript_for_stats(
&mut self,
transcript: &Transcript<Parsed>
) -> Result<(TestStats, Transcript)>
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>
impl<Cmd: SpawnShell> TestConfig<Cmd>
sourcepub fn new(shell_options: ShellOptions<Cmd>) -> Self
pub fn new(shell_options: ShellOptions<Cmd>) -> Self
Creates a new config.
Panics
- Panics if the
svg
crate feature is enabled and theTERM_TRANSCRIPT_UPDATE
variable is set to an incorrect value. SeeUpdateMode::from_env()
for more details.
sourcepub fn with_match_kind(self, kind: MatchKind) -> Self
pub fn with_match_kind(self, kind: MatchKind) -> Self
Sets the matching kind applied.
sourcepub fn with_color_choice(self, color_choice: ColorChoice) -> Self
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.
sourcepub fn with_output(self, output: TestOutputConfig) -> Self
pub fn with_output(self, output: TestOutputConfig) -> Self
Configures test output.
sourcepub fn with_template(self, template: Template) -> Self
Available on crate feature svg
only.
pub fn with_template(self, template: Template) -> Self
svg
only.Sets the template for rendering new snapshots.
sourcepub fn with_update_mode(self, update_mode: UpdateMode) -> Self
Available on crate feature svg
only.
pub fn with_update_mode(self, update_mode: UpdateMode) -> Self
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.