3 releases
0.1.2 | Oct 7, 2023 |
---|---|
0.1.1 | Oct 7, 2023 |
0.1.0 | Oct 19, 2021 |
#1124 in Filesystem
70 downloads per month
Used in 7 crates
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–10MB
~129K SLoC