[][src]Struct test4a::Runner

pub struct Runner<'a, T, E> { /* fields omitted */ }

Describes and runs multiple tests.

Examples

use test4a::{Message, Equal, Runner, PanicWhen};

fn add_0(message: &mut Message, value: &mut usize) {
    message.set("Add 0");
    *value += 0;
}

fn add_1(message: &mut Message, value: &mut usize) {
    message.set("Add 1");
    *value += 1;
}

fn subtract_1(message: &mut Message, value: &mut usize) {
    message.set("Subtract 1");
    *value -= 1;
}

fn value_expected(
    message: &mut Message,
    value: usize,
    expected: Expected,
) -> Equal<usize> {
    message.set("Value is expected");
    Equal::new(value, expected.value)
}

struct Expected {
    value: usize
}


// Test #1
Runner::arrange(|message| {
    message.set("Initial value of 1");
    1
})
.act(add_0, || Expected { value: 1 })
.act(add_1, || Expected { value: 2 })
.act(subtract_1, || Expected { value: 0 })
.assert(value_expected);

// Test #2
Runner::arrange(|message| {
    message.set("Initial value of 42");
    42
})
.act(add_0, || Expected { value: 42 })
.act(add_1, || Expected { value: 43 })
.act(subtract_1, || Expected { value: 41 })
.assert(value_expected);

// ...

Methods

impl<'a, T, E> Runner<'a, T, E>[src]

pub fn arrange(function: impl Fn(&mut Message) -> T + 'a) -> Self[src]

Constructor.

function defines how the value to test should be initialized.
It isn't called immediately, but only for each defined test.

pub fn act(
    &mut self,
    action: impl Fn(&mut Message, &mut T) + 'a,
    expectation: impl Fn() -> E + 'a
) -> &mut Self
[src]

Define an action to execute after the value to test has been created.

The Arrange step is executed before each defined Act step to have independent tests.

pub fn act_panic(
    &self,
    when: PanicWhen,
    function: impl Fn(&mut Message, &mut T) + 'a
) -> &Self
[src]

Define an action that should panic.

The check is done immediately on method call.
The when parameter allows you to specify when the panic occurs.
For example, integer overflow panics only in debug mode.

pub fn assert<A: Assert>(
    &self,
    function: impl Fn(&mut Message, T, E) -> A + 'a
) -> &Self
[src]

Define an assertion to check.

The check is done immediately on method call.
The assertion is tested independently with all defined actions.

pub fn assert_panic<A: Assert>(
    &self,
    when: PanicWhen,
    function: impl Fn(&mut Message, T, E) -> A + 'a
) -> &Self
[src]

Defines an assertion that should panic.

The check is done immediately on method call.
The assertion is tested independently with all defined actions.

Auto Trait Implementations

impl<'a, T, E> !Send for Runner<'a, T, E>

impl<'a, T, E> !Sync for Runner<'a, T, E>

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]