#temp-dir #temp #test #testing-debugging

dev temp_testdir

Little crate to use temp directory in crate. You can chose if delete it after use or not to debugging purpose.

4 releases

Uses old Rust 2015

0.2.3 Oct 3, 2019
0.2.2 Oct 15, 2018
0.2.1 Oct 14, 2018
0.2.0 Oct 14, 2018

#301 in Testing

Download history 2891/week @ 2024-09-17 3362/week @ 2024-09-24 2972/week @ 2024-10-01 3495/week @ 2024-10-08 3265/week @ 2024-10-15 3145/week @ 2024-10-22 5055/week @ 2024-10-29 4376/week @ 2024-11-05 4462/week @ 2024-11-12 9392/week @ 2024-11-19 10666/week @ 2024-11-26 11974/week @ 2024-12-03 39589/week @ 2024-12-10 43005/week @ 2024-12-17 13342/week @ 2024-12-24 23908/week @ 2024-12-31

121,943 downloads per month
Used in 30 crates (27 directly)

MIT/Apache

8KB
159 lines

Working with temporary directories in Rust test

A zero dependencies crate to deal with temporary directories in tests. To use it add

[dev-dependencies]
temp_testdir = "0.2"

How to use

#[test]
fn should_delete_temp_dir() {
    let temp = TempDir::default();
    // You can use `temp` as a `Path`

    let mut file_path = PathBuf::from(temp.as_ref());
    file_path.push("hello.txt");

    let mut f = File::create(file_path.clone()).unwrap();

    f.write_all("Hello World!".as_bytes());

    my_app.process(&file_path);

    // Temp dir will be deleted at the end of the test
}

If you need to not delete the dir when test is done you can use

let temp = TempDir::default().permanent();

Where the dirs are

All dirs will be in your system standard temp dir follow by rstest.<nr> where nr is the lowest integer that can be used to crate it.

You can change this behaviour by two envirorment variables:

  • RSTEST_TEMP_DIR_ROOT: root of all temp dir (default system temp dir)
  • RSTEST_TEMP_DIR_ROOT_NAME: prefix dir name (default system rstest)

License

Licensed under either of

at your option.

No runtime deps