Skip to content

add methods to create subdirs #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
glehmann opened this issue Jan 2, 2019 · 4 comments
Closed

add methods to create subdirs #36

glehmann opened this issue Jan 2, 2019 · 4 comments
Labels
enhancement Improve the expected

Comments

@glehmann
Copy link

glehmann commented Jan 2, 2019

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 :)

@epage epage added the enhancement Improve the expected label Jan 2, 2019
@epage
Copy link
Contributor

epage commented Jan 2, 2019

Huh, surprised that this was overlooked. Thanks for pointing this out!

@epage epage closed this as completed in f7adecd Jan 29, 2019
@glehmann
Copy link
Author

I think that the ability to create a sub clild path is missing in you commit:

let foo = subdir.child("foo.txt");

or maybe I just missed it :)

@epage
Copy link
Contributor

epage commented Jan 29, 2019

Oh, I thought you were only asking about the mkdir part and missed the subdir part.

As a work around, you can do temp.child("foo/bar.txt").

@epage epage reopened this Jan 29, 2019
@epage epage closed this as completed Jan 29, 2019
epage added a commit that referenced this issue Jan 29, 2019
Fixes the other half of #36
@glehmann
Copy link
Author

thanks! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve the expected
Projects
None yet
Development

No branches or pull requests

2 participants