-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Maintainer Edit: There are two problems that we became aware of in this issue
- Confusion over function names which was addressed by fix(persist): Clarify API behavior #56
- Wanting to support a workflow that auto-persists on panic which is still not resolved and this issue is focused on.
There are trade offs though. If someone is unaware, it could really eat up their disk space, for example.
Original title: TempDir::persist_if(false)
should make sure that TempDir
is not persisted.
Original body:
Currently, persist_if(false)
returns immediately, assuming that the TempDir
was not persistent to begin with and that nothing needs to be done. This doesn't work if persist_if(true)
had been called earlier.
I'd expect an API that takes a bool to allow switching between two states, but this one can only switch from false to true.
Use-case: I'd like to automatically persist files for failed tests only, so that I can debug failures without bloating my disk. A simple way to do this would be to persist_if(true)
at the start and persist_if(false)
after asserts have passed:
#[test]
fn foo() {
let td = TempDir::new().unwrap().persist_if(true);
assert!(write_files_and_return_true(&td));
td.persist_if(false);
}