Skip to content

Commit f7adecd

Browse files
committed
feat(fixture): Support creating dirs
Fixes #36
1 parent cbd5ef7 commit f7adecd

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/fixture.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,32 @@ impl ChildPath {
9696
}
9797
}
9898

99+
/// Create empty directories at [`ChildPath`].
100+
///
101+
/// [`ChildPath`]: struct.ChildPath.html
102+
pub trait PathCreateDir {
103+
/// Create an empty file at [`ChildPath`].
104+
///
105+
/// # Examples
106+
///
107+
/// ```rust
108+
/// use assert_fs::prelude::*;
109+
///
110+
/// let temp = assert_fs::TempDir::new().unwrap();
111+
/// temp.child("subdir").create_dir_all().unwrap();
112+
/// temp.close().unwrap();
113+
/// ```
114+
///
115+
/// [`ChildPath`]: struct.ChildPath.html
116+
fn create_dir_all(&self) -> io::Result<()>;
117+
}
118+
119+
impl PathCreateDir for ChildPath {
120+
fn create_dir_all(&self) -> io::Result<()> {
121+
create_dir_all(self.path())
122+
}
123+
}
124+
99125
/// Create empty files at [`ChildPath`].
100126
///
101127
/// [`ChildPath`]: struct.ChildPath.html
@@ -222,6 +248,11 @@ impl PathCopy for ChildPath {
222248
}
223249
}
224250

251+
fn create_dir_all(path: &path::Path) -> io::Result<()> {
252+
fs::create_dir_all(path)?;
253+
Ok(())
254+
}
255+
225256
fn touch(path: &path::Path) -> io::Result<()> {
226257
fs::File::create(path)?;
227258
Ok(())

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ pub use fixture::TempDir;
7878
/// Extension traits that are useful to have available.
7979
pub mod prelude {
8080
pub use assert::PathAssert;
81+
pub use fixture::PathCreateDir;
8182
pub use fixture::FileTouch;
8283
pub use fixture::FileWriteBin;
8384
pub use fixture::FileWriteStr;

0 commit comments

Comments
 (0)