#temporary-files #temporary #file #convenience #testing #temp

test-files

temporary file creation convenience library

3 releases

0.1.2 Oct 7, 2023
0.1.1 Oct 7, 2023
0.1.0 Oct 19, 2021

#499 in Filesystem

Download history 1/week @ 2023-12-22 1/week @ 2024-01-05 1/week @ 2024-01-12 1/week @ 2024-01-26 3/week @ 2024-02-02 5/week @ 2024-02-09 15/week @ 2024-02-16 30/week @ 2024-02-23 21/week @ 2024-03-01 15/week @ 2024-03-08 19/week @ 2024-03-15 21/week @ 2024-03-22 65/week @ 2024-03-29 42/week @ 2024-04-05

148 downloads per month
Used in 7 crates

MIT license

8KB
77 lines

test-files

test-files temporary file creation convenience library


lib.rs:

Test Files

test_files implements some convenient patterns for creating temporary files with given paths (relative to a temporary root) and content.

A temporary directory is created on instantiation, and torn down when the returned object falls out of scope.

Example

use test_files::TestFiles;

let temp_dir = TestFiles::new();
temp_dir
    .file("a/b/c.txt", "ok")
    .file("b/c/d.txt", "fine");

let file_path = temp_dir.path().join("a").join("b").join("c.txt");
let written_content = std::fs::read_to_string(file_path).unwrap();
assert_eq!(written_content, "ok");

let file_path = temp_dir.path().join("b").join("c").join("d.txt");
let written_content = std::fs::read_to_string(file_path).unwrap();
assert_eq!(written_content, "fine");

The pain of creating intermediate directories is abstracted away, so you can just write relative paths, content, and use the created files in tests or otherwise. The root of the temporary directory is exposed by the .path() method.

Dependencies

~2–13MB
~137K SLoC