Skip to content

Provide a write_file() method for ChildPath #34

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
vincentdephily opened this issue Oct 22, 2018 · 2 comments
Closed

Provide a write_file() method for ChildPath #34

vincentdephily opened this issue Oct 22, 2018 · 2 comments
Labels
enhancement Improve the expected
Milestone

Comments

@vincentdephily
Copy link

What this would bring over using the existing copy_from() for a single file is the ability to copy the file to a different name. Basically I'd like the semantics of write_binary() and write_str() but using an existing file as source.

use assert_fs::prelude::*;

let temp = assert_fs::TempDir::new().unwrap();
temp
   .child("input.txt")
   .write_file("unittest.42.txt")
   .unwrap();
temp.close().unwrap();

The rationale is that my program uses fixed names for various input files (and/or I don't want to bother configuring my program to use other filenames), but I have many different input files for as many different unittests. I want to say "for this test, the content of input.txt will be taken from that example file".

@vincentdephily
Copy link
Author

The workaround seems to be fs::copy(Path::new(".").join(src), tempdir.path().join(dst)), which is arguably simple enough. But it feels weird to not be able to use assert_fs directly for this.

@epage epage added the enhancement Improve the expected label Oct 22, 2018
@epage
Copy link
Contributor

epage commented Oct 22, 2018

Thanks for using assert_fs and letting me know about this! I definitely see the value in this. Besides the ability to rename, this just in general is simpler than having to use copy_from which I think would be worthwhile.

@epage epage added this to the 1.0 milestone Oct 22, 2018
@epage epage closed this as completed in 4209ad2 Jan 29, 2019
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