Struct term_transcript::test::TestConfig
source · pub struct TestConfig<Cmd = Command, F = fn(_: &mut Transcript)> { /* private fields */ }
test
only.Expand description
Implementations§
source§impl<Cmd: SpawnShell + Debug, F: FnMut(&mut Transcript)> TestConfig<Cmd, F>
impl<Cmd: SpawnShell + Debug, F: FnMut(&mut Transcript)> TestConfig<Cmd, F>
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_transform<F>(self, transform: F) -> TestConfig<Cmd, F>where
F: FnMut(&mut Transcript),
pub fn with_transform<F>(self, transform: F) -> TestConfig<Cmd, F>where
F: FnMut(&mut Transcript),
Sets the transcript transform for these options. This can be used to transform the captured transcript (e.g., to remove / replace uncontrollably varying data) before it’s compared to the snapshot.
source§impl<Cmd: SpawnShell, F: FnMut(&mut Transcript)> TestConfig<Cmd, F>
impl<Cmd: SpawnShell, F: FnMut(&mut Transcript)> TestConfig<Cmd, F>
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, F> Freeze for TestConfig<Cmd, F>
impl<Cmd = Command, F = fn(_: &mut Transcript)> !RefUnwindSafe for TestConfig<Cmd, F>
impl<Cmd = Command, F = fn(_: &mut Transcript)> !Send for TestConfig<Cmd, F>
impl<Cmd = Command, F = fn(_: &mut Transcript)> !Sync for TestConfig<Cmd, F>
impl<Cmd, F> Unpin for TestConfig<Cmd, F>
impl<Cmd = Command, F = fn(_: &mut Transcript)> !UnwindSafe for TestConfig<Cmd, F>
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>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute
] value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
[Quirk
] value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition
] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);