[][src]Crate mimicaw

A library for writing asynchronous tests.

This library provides a framework for writing the free-style, asynchronous tests without using the default test harness provided by rustc.

The concept and design are strongly inspired by libtest-mimic, but also focuses on the affinity with the async/.await syntax.

Example

use mimicaw::{Args, Test, TestDesc, Outcome};

// Parse command line arguments.
let args = Args::from_env().unwrap_or_else(|st| st.exit());

// Each test case is described using `Test` having one associated data.
//
// The data will be used by the runner described below to run tests.
let tests = vec![
    Test::test("case1", "foo"),
    Test::test("case2", "bar"),
    Test::test("case3_long_computation", "baz").ignore(true),
    Test::test("case4", "The quick brown fox jumps over the lazy dog."),
];

// A function for running the test cases.
//
// Each test result is asynchronous and a future is returned to acquire the result.
let runner = |_desc: TestDesc, data: &'static str| {
    async move {
        match data {
            "foo" | "baz" => Outcome::passed(),
            "bar" => Outcome::failed().error_message("`bar' is forbidden"),
            data => Outcome::failed().error_message(format!("unknown data: {}", data)),
        }
    }
};

// Run the process of test suite.
//
// The test cases are filtered according to the command line arguments, and then executed concurrently from the top.
let status = mimicaw::run_tests(&args, tests, runner).await;
status.exit()

Structs

Args

Command line arguments.

ExitStatus

Exit status code used as a result of the test process.

Outcome

The outcome of performing a test.

Report

A report on test suite execution.

Test

Data that describes a single test.

TestDesc

Description about a test.

Enums

ColorConfig

The color configuration.

OutputFormat

The output format.

Traits

TestRunner

The runner of test cases.

Functions

run_tests

Run a test suite using the specified test runner.

run_tests_with_report

Run a test suite and report the summary.