Skip to content

add methods to create subdirs #36

@glehmann

Description

@glehmann

I've extended the ChildPath in my project in order to do that — see glehmann/hld@00bc932#diff-475a9530a9c1e888d097445199b74c2fR402

pub trait TestPathChild {
    fn child<P>(&self, path: P) -> assert_fs::fixture::ChildPath
    where
        P: AsRef<std::path::Path>;
    fn mkdir_all(&self) -> std::io::Result<()>;
}

impl TestPathChild for assert_fs::fixture::ChildPath {
    fn child<P>(&self, path: P) -> assert_fs::fixture::ChildPath
    where
        P: AsRef<std::path::Path>,
    {
        assert_fs::fixture::ChildPath::new(self.path().join(path))
    }
    fn mkdir_all(&self) -> std::io::Result<()> {
        std::fs::create_dir_all(self.path())
    }
}

used this way:

let tmp = assert_fs::TempDir::new().unwrap();
let subdir = tmp.child("hop").child("hop").child("hop");
let foo = subdir.child("foo.txt");
subdir.mkdir_all().unwrap();
foo.write_str(&lorem_ipsum).unwrap();

It might be good to support this feature natively :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions