-
Notifications
You must be signed in to change notification settings - Fork 10
TempDir: Provide an API to not delete-dir-on-drop without consuming the TempDir #31
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
Comments
Could you describe the motivation for keeping the temp dir? |
I'm running unit tests that create files in the tempdir. Most of the time I want them deleted, but if tests start failing I want to look at the files to figure out what happened. Even outside of unittesting, there are many tools that implement some kind of |
For what it's worth, I eventually managed to make my usecase work with the current API: let tempdir = TempDir::new().unwrap();
let mut cwd = PathBuf::new();
match env::var("ASSERTFS_KEEP_TEMP") {
Ok(_) => cwd.push(&tempdir.into_path()),
Err(_) => cwd.push(tempdir.path()),
}
assert!(dostuff(cwd).is_ok()); It works but it's not elegant (copying the path like this seems like a hack), and took me a while to come up with. An obvious TempDir API to do the same would still be welcome. |
Thanks for describing that. For tests, that hasn't been as important to me because they have been things I could always exercise with the |
I think another important aspect for the user, whether its done inside of assert_fs or the tests, is to print the path in case the failure message doesn't have it. |
Yes, I wouldn't mind replacing my |
I think I'm going to give making a newtype for TempDir a try which gives me more flexibility in implementing this idea. |
The current API offers
into_path(self) -> PathBuf
which is nice and clean (not sure whyPathBuf
instead ofPath
, but I can live with that), but forces you to decide ahead of time if you want a temporary or persisted path.I'd like to change the behaviour at runtime, but am hitting the following snags:
into_path()
near the end of my scope, it might not get called because of asserts that triggered earlyer (precisely when I'd have liked to keep the tempdir).PathBuf/TempDir
type mismatches, or intotemporary value does not live long enough
problems:Perhaps I missed an easy solution, but I doubt it would be as easy as having some kind of
delete_on_drop(bool)
API:Workaround
The text was updated successfully, but these errors were encountered: