#testing

testpath

companinon crate to bintest/testcall, augments Paths for testing

4 releases

0.1.1 Jul 20, 2021
0.1.0 Jul 20, 2021
0.0.1 Jul 15, 2021
0.0.0 Jul 13, 2021

#235 in Testing


Used in testcall

MIT/Apache

31KB
717 lines

Companinon crate to ‘bintest' and 'testcall’, implements facilities for running tests in directories.

Description

Allows creating of (temporary) test directories, optionally with a custom callback for cleanup. Populating these with content for testing and provide assertion to validate the content.

Example

#[test]
fn test_something() {
    let tmpdir = TempDir::new().expect("TempDir created");
    tmpdir.create_file("path/to/testfile", "Hello File!".as_bytes());
    tmpdir
        .sub_path("path/to/testfile")
        .assert_utf8("Hello File!");
}

Future Plans

New features will be added as needed, PR’s are welcome. This is work in progress.


lib.rs:

Companion crate to ‘bintest' and 'testcall’, implements facilities for running tests in directories.

Description

Allows creating of (temporary) test directories, optionally with a custom callback for cleanup. Populating these with content for testing and provide assertion to validate the content.

Example

# use tempfile::TempDir;
# use testpath::*;
fn test_something() {
    let tmpdir = TempDir::new().expect("TempDir created");
    tmpdir.create_file("path/to/testfile", "Hello File!".as_bytes());
    tmpdir
        .sub_path("path/to/testfile")
        .assert_utf8("Hello File!");
}

Panics vs. Results

'testpath' is made explicitly for writing tests. To ease this it prefers aborting by panic over error handling. When anything goes wrong the test is aborted and the cause is reported.

Dependencies

~3.5–4.5MB
~108K SLoC