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 file_extension_loader( &self, extension: impl Into<OsString>, loader: TryCmdLoader ) -> &Self

Define a function used to load a filesystem path into a test.

extension is the file extension to register the loader for, without the leading dot. e.g. toml, json, or trycmd.

By default there are loaders for toml, trycmd, and md extensions. Calling this function with those extensions will overwrite the default loaders.

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_indygreg_fork::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 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 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
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.