pub struct IsolatedFilesystem { /* private fields */ }Expand description
A temporary filesystem context for isolated testing.
Creates a temporary directory that is automatically cleaned up when dropped. The current working directory is changed to the temporary directory for the duration of the test.
§Example
use click::testing::IsolatedFilesystem;
use std::fs;
{
let isolated = IsolatedFilesystem::new().unwrap();
let path = isolated.path();
// Create files in the isolated directory
fs::write(path.join("test.txt"), "hello").unwrap();
assert!(path.join("test.txt").exists());
}
// Directory is automatically cleaned up hereImplementations§
Source§impl IsolatedFilesystem
impl IsolatedFilesystem
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Create a new isolated filesystem.
This creates a temporary directory and changes to it.
Sourcepub fn with_name(name: &str) -> Result<Self>
pub fn with_name(name: &str) -> Result<Self>
Create an isolated filesystem with a specific name.
Sourcepub fn create_file(&self, name: &str, content: &str) -> Result<PathBuf>
pub fn create_file(&self, name: &str, content: &str) -> Result<PathBuf>
Create a file in the isolated filesystem.
Sourcepub fn create_dir(&self, name: &str) -> Result<PathBuf>
pub fn create_dir(&self, name: &str) -> Result<PathBuf>
Create a directory in the isolated filesystem.
Sourcepub fn read_file(&self, name: &str) -> Result<String>
pub fn read_file(&self, name: &str) -> Result<String>
Read a file from the isolated filesystem.
Sourcepub fn file_exists(&self, name: &str) -> bool
pub fn file_exists(&self, name: &str) -> bool
Check if a file exists in the isolated filesystem.
Sourcepub fn list_files(&self) -> Result<Vec<String>>
pub fn list_files(&self) -> Result<Vec<String>>
List files in the isolated filesystem.
Trait Implementations§
Source§impl Debug for IsolatedFilesystem
impl Debug for IsolatedFilesystem
Source§impl Drop for IsolatedFilesystem
impl Drop for IsolatedFilesystem
Auto Trait Implementations§
impl Freeze for IsolatedFilesystem
impl RefUnwindSafe for IsolatedFilesystem
impl Send for IsolatedFilesystem
impl Sync for IsolatedFilesystem
impl Unpin for IsolatedFilesystem
impl UnsafeUnpin for IsolatedFilesystem
impl UnwindSafe for IsolatedFilesystem
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