#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

#1124 in Filesystem

Download history 10/week @ 2024-06-17 17/week @ 2024-06-24 18/week @ 2024-07-15 11/week @ 2024-07-22 9/week @ 2024-07-29 14/week @ 2024-08-05 4/week @ 2024-08-12 21/week @ 2024-08-26 3/week @ 2024-09-02 4/week @ 2024-09-16 29/week @ 2024-09-23 36/week @ 2024-09-30

70 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–10MB
~129K SLoC