#unit-testing #temporary #test-files #file #unit #temp

testfile

Temporary test file/dir management for unit tests

17 releases

new 0.2.0-alpha.7 May 11, 2025
0.2.0-alpha.6 May 9, 2025
0.1.5 Jun 26, 2024
0.1.4 Mar 22, 2023
0.0.2 Jun 14, 2020

#251 in Filesystem

Download history 84/week @ 2025-01-19 27/week @ 2025-01-26 50/week @ 2025-02-02 40/week @ 2025-02-09 20/week @ 2025-02-16 8/week @ 2025-02-23 29/week @ 2025-03-02 11/week @ 2025-03-09 25/week @ 2025-03-16 51/week @ 2025-03-23 13/week @ 2025-03-30 54/week @ 2025-04-06 48/week @ 2025-04-13 100/week @ 2025-04-20 432/week @ 2025-04-27 634/week @ 2025-05-04

1,215 downloads per month
Used in 2 crates

MIT license

50KB
922 lines

testfile/dir management for Rust unit tests

License: MIT Crates.io Crates.io MSRV dependency status Documentation Lines of code Gitlab pipeline Downloads

Library for creating automaticaly deleted test files or directories for use in your Rust unit tests. Do not worry about manual temporary file/dir cleanups anymore.

Managed temporary files/directories are created in system temporary directory with unique file names. They can be dereferenced as ordinary File and are automatically deleted during Drop.

Functions do not return Result <T,E> but panic! allowing you to focus on your tests and not on error handling.

Because of panic! style error handling its not recommended to use this library outside of unit/integration tests.

Implemented traits for TestFile

  1. Testfile can be dereferenced as File making it drop in replacement.
  2. implements AsRef / AsMut for Read, Write, File, PathBuf, Path.
  3. implements From String, &str, &Path and PathBuf.
  4. self-referential for flexible usage.

Implemented traits for TestDir

  1. TestDir can be dereferenced as Path and PathBuf.
  2. self-referential for flexible usage.
  3. implements From PathBuf, &Path.

Rust 2021 Edition fully compatible

Runs on MSRV 1.56 including its own unit tests. It can be used on any version of Rust 2021 edition. Compiles and runs on Rust edition 2024 without warnings.

Lightweight dependencies

Depends only on small stdrandom crate which is MSRV 1.56 compatible.

License

Licensed under permissive MIT License.

Dependencies