Struct TestCases

Source
pub struct TestCases { /* private fields */ }
Expand description

Entry point for running tests

Implementations§

Source§

impl TestCases

Source

pub fn new() -> Self

Source

pub fn case(&self, glob: impl AsRef<Path>) -> &Self

Load tests from glob

Source

pub fn pass(&self, glob: impl AsRef<Path>) -> &Self

Overwrite expected status for a test

Source

pub fn fail(&self, glob: impl AsRef<Path>) -> &Self

Overwrite expected status for a test

Source

pub fn interrupted(&self, glob: impl AsRef<Path>) -> &Self

Overwrite expected status for a test

Source

pub fn skip(&self, glob: impl AsRef<Path>) -> &Self

Overwrite expected status for a test

Source

pub fn default_bin_path(&self, path: impl AsRef<Path>) -> &Self

Set default bin, by path, for commands

Source

pub fn default_bin_name(&self, name: impl AsRef<str>) -> &Self

Set default bin, by name, for commands

Source

pub fn timeout(&self, time: Duration) -> &Self

Set default timeout for commands

Source

pub fn env(&self, key: impl Into<String>, value: impl Into<String>) -> &Self

Set default environment variable

Source

pub fn register_bin( &self, name: impl Into<String>, path: impl Into<Bin>, ) -> &Self

Add a bin to the “PATH” for cases to use

Source

pub fn register_bins<N: Into<String>, B: Into<Bin>>( &self, bins: impl IntoIterator<Item = (N, B)>, ) -> &Self

Add a series of bins to the “PATH” for cases to use

Source

pub fn insert_var( &self, var: &'static str, value: impl Into<Cow<'static, str>>, ) -> Result<&Self, Error>

Add a variable for normalizing output

Variable names must be

  • Surrounded by []
  • Consist of uppercase letters

Variables will be preserved through TRYCMD=overwrite / TRYCMD=dump.

NOTE: We do basic search/replaces so new any new output will blindly be replaced.

Reserved names:

  • [..]
  • [EXE]
  • [CWD]
  • [ROOT]
§Example
#[test]
fn cli_tests() {
    trycmd::TestCases::new()
        .case("tests/cmd/*.trycmd")
        .insert_var("[VAR]", "value");
}
Source

pub fn extend_vars( &self, vars: impl IntoIterator<Item = (&'static str, impl Into<Cow<'static, str>>)>, ) -> Result<&Self, Error>

Batch add variables for normalizing output

See TestCases::insert_var.

Source

pub fn clear_var(&self, var: &'static str) -> Result<&Self, Error>

Remove an existing var values

See TestCases::insert_var.

Source

pub fn run(&self)

Run tests

This will happen on drop if not done explicitly

Trait Implementations§

Source§

impl Debug for TestCases

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for TestCases

Source§

fn default() -> TestCases

Returns the “default value” for a type. Read more
Source§

impl RefUnwindSafe for TestCases

Auto Trait Implementations§

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<D> ToDebug for D
where D: Debug,

Source§

fn to_debug(&self) -> Data

Source§

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

Source§

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