#path #file-content #assertion #assertions #testing #cleanup #file-path

testpath

companinon crate to bintest/testcall, augments Paths for testing

5 unstable releases

0.2.0 Dec 7, 2021
0.1.1 Jul 20, 2021
0.1.0 Jul 20, 2021
0.0.1 Jul 15, 2021
0.0.0 Jul 13, 2021

#1003 in Filesystem


Used in testcall

MIT/Apache

310KB
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

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

~5–16MB
~205K SLoC