Crate erudite

Crate erudite 

Source
Expand description

Erudite is an asynchronous test runner that can run a suites of tests in concurrently.

There are a couple of key structures which make up Erudite:

§TestContext

A test context holds information about how a test suite should be run. Information such as the commands needed to run the tests, the restrictions to apply to said commands, and the tests themselves are included in a test context.

A test context is designed with the intention that it can be placed into an Arc and be used throughout the program, creating test runners, which can be used to run tests.

In a test context, individual tests are associated via groups. A group can be anything (with some restrictions, see TestContextBuilder::test for details).

§TestRunner

A test runner is created from a test context by selecting a single group and is used to run a test suite. There are some additional configurations that can be added to the test runner for run-specific settings. Once a runner has been created, it can compile and then run the tests, giving a handle to those tests.

§TestHandle

A test handle is a handle to an actively running suite of tests. A test handle can wait for the tests to finish one at a time or for all of them to finish. Test handles return TestResults which contain information about the output of a test, the time it took, and whether that test passed.

§Usage

let context = TestContext::builder()
    .compile_command(["rustc", "-o", "runner", "runner.rs"])
    .run_command(["./runner"])
    .test("group", "hello", "olleh", ())
    .test("group", "world", "dlrow", ())
    .test("group", "rust", "tsur", ())
    .test("group", "tacocat", "tacocat", ())
    .trim_output(true)
    .file(FileContent::string(runner_code), "runner.rs")
    .build();

let context = Arc::new(context);

let mut handle = context
    .test_runner(&"group")
    .expect("This group was added above")
    .file(BorrowedFileContent::string(solution_code), Path::new("solution.rs"))
    .compile_and_run()
    .await?;

let results = handle.wait_all().await?;

assert_eq!(results[0].state(), TestResultState::Pass);

Modules§

cases
Test Cases
error
Errors that may arise while using erudite
runner
Definitions and functions related to the execution of test suites

Structs§

BorrowedFileConfig
Configuration for how a file should be setup for test cases to be run
BorrowedFileContent
Some form of content that will be used to create a file when a test is compiled
FileConfig
Configuration for how a file should be setup for test cases to be run
MemorySize
Representation of some amount of digital space
Output
The output of a finished process, containing standard output, standard error, and the exit status
Rules
Struct which holds the rules for restrictions. For more information, see Ruleset.
TestContext
Context around a test suite. This contains information about how a test suite is supposed to be run.
TestContextBuilder
A builder that will crate a TestContext. This builder uses a type-state pattern to ensure that the require fields are all present.

Enums§

Bytes
Represents some data that may either be a string or a series of bytes. The recommended method for constructing this type is to use From::from which will automatically choose the appropriate variant for the data.
FileContent
Representation of the content of a file to be added into a test environment