pub struct Fixture { /* private fields */ }Expand description
A declaration of what a directory must contain, built with chained calls.
use shellgame::engine::fixture::Fixture;
let fixture = Fixture::new()
.dirs(["alpha", "gamma/deep/a/b/c"])
.file("alpha/inside.txt", "first step")
.file_mode("run.sh", "#!/bin/sh\n", 0o755)
.dir_mode("locked", 0o550)
.clean(["scratch"]);
assert!(!fixture.is_empty());Implementations§
Source§impl Fixture
impl Fixture
Sourcepub fn dir(self, path: impl Into<String>) -> Self
pub fn dir(self, path: impl Into<String>) -> Self
Declare a directory (and its parents). Its mode becomes 0o755.
Sourcepub fn file(self, path: impl Into<String>, content: impl Into<Content>) -> Self
pub fn file(self, path: impl Into<String>, content: impl Into<Content>) -> Self
Declare a file that is rewritten on every apply. Its mode becomes 0o644.
Sourcepub fn file_mode(
self,
path: impl Into<String>,
content: impl Into<Content>,
mode: u32,
) -> Self
pub fn file_mode( self, path: impl Into<String>, content: impl Into<Content>, mode: u32, ) -> Self
Declare a file with an explicit mode (0..=0o7777).
Sourcepub fn keep_file(
self,
path: impl Into<String>,
content: impl Into<Content>,
) -> Self
pub fn keep_file( self, path: impl Into<String>, content: impl Into<Content>, ) -> Self
Declare a file that is only written when missing: a regular file already there is kept, content, mode and all (unless a mode is declared). Section fixtures use this for files the player is expected to have edited.
Sourcepub fn dir_mode(self, path: impl Into<String>, mode: u32) -> Self
pub fn dir_mode(self, path: impl Into<String>, mode: u32) -> Self
Declare a directory with an explicit mode (0..=0o7777). Modes are applied after
everything else, deepest directory first.
Sourcepub fn clean<I, S>(self, paths: I) -> Self
pub fn clean<I, S>(self, paths: I) -> Self
Remove these paths (files, directory trees or symlinks) before anything is created.
Sourcepub fn merge(self, other: Fixture) -> Self
pub fn merge(self, other: Fixture) -> Self
Add everything other declares after what this fixture declares.
Sourcepub fn file_entries(&self) -> impl Iterator<Item = (&str, &Content)>
pub fn file_entries(&self) -> impl Iterator<Item = (&str, &Content)>
The declared files with their content, as written.
Sourcepub fn clean_paths(&self) -> &[String]
pub fn clean_paths(&self) -> &[String]
The declared cleanup paths, as written.
Sourcepub fn dir_mode_entries(&self) -> impl Iterator<Item = (&str, u32)>
pub fn dir_mode_entries(&self) -> impl Iterator<Item = (&str, u32)>
The declared directory modes, as written.
Sourcepub fn declared_paths(&self) -> impl Iterator<Item = &str>
pub fn declared_paths(&self) -> impl Iterator<Item = &str>
Every path this fixture declares, as written.
Sourcepub fn problems(&self) -> Vec<FixtureError>
pub fn problems(&self) -> Vec<FixtureError>
Everything wrong with the declarations themselves (bad paths, modes out of range, declarations that target the root), without touching the filesystem.
Sourcepub fn apply(&self, root: &Path) -> Result<(), FixtureError>
pub fn apply(&self, root: &Path) -> Result<(), FixtureError>
Make root match this fixture; see the module documentation for the repair
rules and the explicit-mode guarantee.
The root is created when missing and repaired when its owner permissions were taken
away; either way it ends 0o755. A root that is a symlink is refused. Nothing is
applied when the declarations are invalid.