#directory #test #per #create #run #macro #fixture-attribute

per_test_directory

fixture/attribute macro to create one directory per test run

1 unstable release

0.1.0 Sep 10, 2019

#30 in #per

MIT license

4KB
56 lines

per_test_directory

This crate introduces an attribute macro #[per_test_directory] that will create a directory test_runs/module_name.test_function_name and change the current working directory to it while running.

If the test is successful, the directory is removed. Otherwise, it is being kept for your inspection. Either way, the current directory is reset after the test run.

Example:

#[cfg(test)]
mod tests {
    use std::fs::File;
    use std::io::prelude;

    #[test]
    #[per_test_directory_macros]
    fn test_example() {
        let mut f = File::create("foo.txt")?;
        //actually in test_runs/tests.test_example/foo.txt
        file.write_all(b"hello");
        panic!("let's keep the file!");
    } }

Dependencies

~1.5MB
~34K SLoC