Skip to content

Use auto-cleanup temporary files in unit tests #281

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
alxiord opened this issue May 17, 2018 · 2 comments
Closed

Use auto-cleanup temporary files in unit tests #281

alxiord opened this issue May 17, 2018 · 2 comments
Assignees

Comments

@alxiord
Copy link

alxiord commented May 17, 2018

Unit tests that require creating temporary files on disk need to remove the files explicitly before starting to assert!, so that the files don't remain there if the tests fail.
There's a tempfile crate that can help. According to the documentation:

The temporary file will be automatically removed by the OS when the last handle to it is closed. This doesn't rely on Rust destructors being run, so will (almost) never fail to clean up the temporary file.

This works if the name of the file isn't needed. If it is, cleanup is not guaranteed and our unit tests can remain unchanged (remove before assert!).

@andreeaflorescu
Copy link
Member

We cannot use tempfile from tempfile crate. We will have to use NamedTempFile because we need the path of the file.

From the crate documentation:
"When choosing between the temporary file variants, prefer tempfile unless you either need to know the file's path or to be able to persist it." https://docs.rs/tempfile/3.0.2/tempfile/index.html

I just wrote another test that needs temporary files, so I can also pick this one up.

@andreeaflorescu
Copy link
Member

Addressed by #367

@andreeaflorescu andreeaflorescu self-assigned this Jun 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants