Skip to main content

Expectation

Struct Expectation 

Source
pub struct Expectation<T> { /* private fields */ }

Implementations§

Source§

impl<T> Expectation<T>

Source

pub fn not(self) -> Self

Source§

impl<T> Expectation<T>
where T: PartialEq + Debug,

Source

pub fn to_be(self, expected: T)

Examples found in repository?
examples/example_smoke.rs (line 10)
5fn main() {
6    let tests = collect_tests(|| {
7        describe!("math", {
8            test!("adds two numbers", |ctx| {
9                ctx.stdout("ok\n");
10                expect(2 + 3).to_be(5);
11            });
12
13            test!("handles negatives", id = "math/handles-negatives", |ctx| {
14                assert!(ctx.observe().metric("wall_time_ns", 42.0));
15                expect(-2 + 1).to_be(-1);
16            });
17        });
18    })
19    .expect("collection should validate");
20
21    for test in &tests {
22        let outcome = run_test(test);
23        println!("{} => {}", test.canonical_name(), outcome.exit);
24    }
25}
Source

pub fn to_equal(self, expected: T)

Source§

impl<T> Expectation<T>
where T: Truthy + Debug,

Source

pub fn to_be_truthy(self)

Examples found in repository?
examples/host_example.rs (line 10)
5fn main() {
6    let tests = collect_tests(|| {
7        describe!("pkg", {
8            test!("smoke test", id = "pkg::smoke", |ctx| {
9                ctx.stdout("ok\n");
10                expect(true).to_be_truthy();
11            });
12
13            test!("failing test", id = "pkg::fail", |ctx| {
14                ctx.stderr("failure\n");
15                ctx.set_exit(1);
16            });
17        });
18    })
19    .expect("collection should validate");
20
21    let exit_code = match observer_host_main("rust", &tests) {
22        Ok(()) => 0,
23        Err(error) => {
24            eprintln!("{error}");
25            2
26        }
27    };
28    std::process::exit(exit_code);
29}
More examples
Hide additional examples
examples/host_embed_example.rs (line 14)
9fn main() {
10    let tests = collect_tests(|| {
11        describe!("pkg", {
12            test!("embedded smoke test", id = "pkg::embedded-smoke", |ctx| {
13                ctx.stdout("ok\n");
14                expect(true).to_be_truthy();
15            });
16        });
17    })
18    .expect("collection should validate");
19
20    let args = std::env::args().collect::<Vec<_>>();
21    if args.get(1).map(String::as_str) == Some("observe") {
22        let exit_code = match observer_host_dispatch_embedded("rust", "observe", &tests, args) {
23            Ok(()) => 0,
24            Err(error) => {
25                eprintln!("{error}");
26                2
27            }
28        };
29        std::process::exit(exit_code);
30    }
31
32    app_main(&args);
33}
Source

pub fn to_be_falsy(self)

Source§

impl<T> Expectation<T>
where T: AsRef<str> + Debug,

Source

pub fn to_contain<S>(self, expected: S)
where S: AsRef<str> + Debug,

Source

pub fn to_match<P>(self, pattern: P)
where P: StrPattern,

Auto Trait Implementations§

§

impl<T> Freeze for Expectation<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Expectation<T>
where T: RefUnwindSafe,

§

impl<T> Send for Expectation<T>
where T: Send,

§

impl<T> Sync for Expectation<T>
where T: Sync,

§

impl<T> Unpin for Expectation<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Expectation<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Expectation<T>
where T: UnwindSafe,

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