Crate test_files

source ·
Expand description

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.

Structs

Enums

Type Aliases