pub struct Files { /* private fields */ }Expand description
files: reading, writing, listing, and removing files under one root.
Implementations§
Source§impl Files
impl Files
Sourcepub fn rooted(root: PathBuf) -> Self
pub fn rooted(root: PathBuf) -> Self
The real filesystem, reachable only inside root.
The root is the host’s choice, never the program’s: no path a program
writes can name a place outside it, so granting files grants exactly
this directory.
root need not exist yet. Until it does, every read answers that the
path is not there; the first write creates it, along with any
directories the written path names below it, so a program does not
have to know whether the host prepared the tree.
Sourcepub fn in_memory(files: BTreeMap<String, String>) -> Self
pub fn in_memory(files: BTreeMap<String, String>) -> Self
A fake filesystem that lives only in this process, for tests.
Each key is a /-separated relative path, exactly as a program would
write it, and its value is the file’s contents. A path with no key of
its own but with keys below it is a directory.
Sourcepub fn tree(&self) -> Tree
pub fn tree(&self) -> Tree
The fake tree as this host holds it, for a test to read back.
A test drives the program and then asks this what the run left behind, which is the only way to assert on a file the program wrote rather than on the console line that says it did. A rooted host answers an empty tree: what a run wrote is on the filesystem, under the root the test chose, where the test can go and read it.