#proc-macro #temp #test

macro with_tempdir

Inject a temporary directory and provide as an argument to the function

1 unstable release

0.1.0 Aug 9, 2019

#14 in #temp

GPL-3.0-or-later

18KB
137 lines

Crates.io Gitlab pipeline status License GPL-3.0+

Tempdir injection for tests

This small project is providing you a procedural macro to inject a temporary directory in your test.

#[with_tempdir]
#[test]
fn my_test(path: &Path) {
  // do stuff in folder `path`
}

Look at the documentation for more.


lib.rs:

This crate provide the with_tempdir macro.

use with_tempdir::with_tempdir;

#[with_tempdir(path = "/tmp/foo")]
#[test]
fn my_test(path: &Path) {
  let file_path = path.join("some_file.txt");
  let mut file = File::create(&file_path).expect("Failed to create the file");
}

Read the documentation of with_tempdir macro to know more.

Dependencies

~3–14MB
~161K SLoC