Struct test_files::TestFiles
source · pub struct TestFiles(/* private fields */);Implementations§
source§impl TestFiles
impl TestFiles
sourcepub fn file(&self, path: &str, content: &str) -> &Self
pub fn file(&self, path: &str, content: &str) -> &Self
Creates a plain file under temporary directory, with specified content.
Examples
use indoc::indoc;
use std::fs;
let temp_dir = test_files::TestFiles::new();
temp_dir.file("a/b/c.txt", indoc!{"
ok
"})
.file("b/c/d.txt", indoc!{"
fine
"});
let file_path = temp_dir.path().join("a").join("b").join("c.txt");
let written_content = 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 = fs::read_to_string(file_path).unwrap();
assert_eq!(written_content, "fine");sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new temporary directory that is removed when it goes out of scope.
Panics on failure
Examples
let temp_dir = test_files::TestFiles::new();
assert!(temp_dir.path().is_dir());sourcepub fn path(&self) -> &Path
pub fn path(&self) -> &Path
Returns the path of the underlying temporary directory.
Examples
let temp_dir = test_files::TestFiles::new();
assert!(temp_dir.path().is_dir());sourcepub fn try_file(&self, path: &str, content: &str) -> Result<&Self>
pub fn try_file(&self, path: &str, content: &str) -> Result<&Self>
Tries to create a plain file under temporary directory with specified content.
Examples
use indoc::indoc;
use std::fs;
let temp_dir = test_files::TestFiles::new();
temp_dir.try_file("a/b/c.txt", indoc!{"
ok
"})?
.try_file("b/c/d.txt", indoc!{"
fine
"})?;
let file_path = temp_dir.path().join("a").join("b").join("c.txt");
let written_content = 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 = fs::read_to_string(file_path).unwrap();
assert_eq!(written_content, "fine");Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for TestFiles
impl Send for TestFiles
impl Sync for TestFiles
impl Unpin for TestFiles
impl UnwindSafe for TestFiles
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more