Struct libtest_mimic::Trial

source ·
pub struct Trial { /* private fields */ }
Expand description

A single test or benchmark.

libtest often treats benchmarks as “tests”, which is a bit confusing. So in this library, it is called “trial”.

A trial is create via Trial::test or Trial::bench. The trial’s name is printed and used for filtering. The runner is called when the test/benchmark is executed to determine its outcome. If runner panics, the trial is considered “failed”. If you need the behavior of #[should_panic] you need to catch the panic yourself. You likely want to compare the panic payload to an expected value anyway.

Implementations§

Creates a (non-benchmark) test with the given name and runner.

The runner returning Ok(()) is interpreted as the test passing. If the runner returns Err(_), the test is considered failed.

Creates a benchmark with the given name and runner.

If the runner’s parameter test_mode is true, the runner function should run all code just once, without measuring, just to make sure it does not panic. If the parameter is false, it should perform the actual benchmark. If test_mode is true you may return Ok(None), but if it’s false, you have to return a Measurement, or else the benchmark is considered a failure.

test_mode is true if neither --bench nor --test are set, and false when --bench is set. If --test is set, benchmarks are not ran at all, and both flags cannot be set at the same time.

Sets the “kind” of this test/benchmark. If this string is not empty, it is printed in brackets before the test name (e.g. test [my-kind] test_name). (Default: empty)

This is the only extension to the original libtest.

Sets whether or not this test is considered “ignored”. (Default: false)

With the built-in test suite, you can annotate #[ignore] on tests to not execute them by default (for example because they take a long time or require a special environment). If the --ignored flag is set, ignored tests are executed, too.

Returns the name of this trial.

Returns the kind of this trial. If you have not set a kind, this is an empty string.

Returns whether this trial has been marked as ignored.

Returns true iff this trial is a test (as opposed to a benchmark).

Returns true iff this trial is a benchmark (as opposed to a test).

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.