Struct credibility::TestBlock [−][src]
pub struct TestBlock<'a, St> where
St: 'a + TestReporter + Sized, { /* fields omitted */ }
A RAII test result accumulator. The TestBlock
defines a unit of
test functionality, within which assertions using the macro
aver!
can fail without aborting the test.
Lifetime & Usage
As soon as a TestBlock
variable gets dropped, it kicks off its
status tracker's tally
method, which (by default) asserts that no failures occurred.
Using results in tests
Since error results are the other "big" cause of early test
aborts, test blocks optionally allow code blocks that use them to
return results early with ?
or try!
. To do so ergonomically,
use the test_block!
macro.
Methods
impl<'a, St> TestBlock<'a, St> where
St: TestReporter + Sized,
[src]
impl<'a, St> TestBlock<'a, St> where
St: TestReporter + Sized,
pub fn new(name: &'a str, tracker: &'a mut St) -> TestBlock<'a, St>
[src]
pub fn new(name: &'a str, tracker: &'a mut St) -> TestBlock<'a, St>
Creates a new TestBlock
with a tracker.
pub fn eval_aver(
&mut self,
closure: impl FnOnce() + UnwindSafe
)
[src]
pub fn eval_aver(
&mut self,
closure: impl FnOnce() + UnwindSafe
)
Evaluate an aver
expression as an assert
, catching any
panics. Calls the test reporter's
averred
method with
the result of capturing any unwinds.
pub fn ran(&mut self, res: Result<(), Error>)
[src]
pub fn ran(&mut self, res: Result<(), Error>)
Called at the end of a block of code that returns a Result
.
Trait Implementations
impl<'a, St> Drop for TestBlock<'a, St> where
St: TestReporter + Sized,
[src]
impl<'a, St> Drop for TestBlock<'a, St> where
St: TestReporter + Sized,
When dropped, TestBlock
s call their test reporter's
tally
method.