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", "ok")
.file("b/c/d.txt", "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", "ok")?
.try_file("b/c/d.txt", "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 Freeze for TestFiles
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