#temp-dir #cargo-toml

outdir-tempdir

A crate for cargo-test to create temporary directories in the OUT_DIR

2 unstable releases

0.2.0 Aug 26, 2023
0.1.0 Feb 10, 2023

#519 in Testing

Download history 51/week @ 2024-08-30 45/week @ 2024-09-06 1/week @ 2024-09-13 27/week @ 2024-09-20 132/week @ 2024-09-27 20/week @ 2024-10-04 15/week @ 2024-10-11 15/week @ 2024-10-18 141/week @ 2024-10-25 30/week @ 2024-11-01 18/week @ 2024-11-08 45/week @ 2024-11-15 19/week @ 2024-11-22 14/week @ 2024-11-29 34/week @ 2024-12-06 9/week @ 2024-12-13

108 downloads per month
Used in 2 crates

MIT license

14KB
182 lines

OUTDIR-TEMPDIR

A crate for cargo-test to create temporary directories.
The temporary directories are always created in the OUT_DIR.

Usage

Add dependency to your Cargo.toml.

[dev-dependencies]
outdir-tempdir = "0.2"

Examples

Create a temporary directory with automatic removal.

use outdir_tempdir::TempDir;

#[test]
fn test_something() {
    // Create a randomly named temporary directory
    // and automatically remove it upon dropping
    let dir = TempDir::new().autorm();

    // Get temporary directory
    // (/path/to/crate/target/(debug|release)/build/outdir-tempdir-<random>/out/test-<random>)
    let tempdir = dir.path();

    // Test your code using `tempdir`
    // ...

    // Remove the temporary directory when the `dir` variable is dropped
}

Create a temporary directory without automatic removal.

use outdir_tempdir::TempDir;

#[test]
fn test_something() {
    // Create a randomly named temporary directory
    let dir = TempDir::new();

    // Get temporary directory
    // (/path/to/crate/target/(debug|release)/build/outdir-tempdir-<random>/out/test-<random>)
    let tempdir = dir.path();

    // Test your code using `tempdir`
    // ...

    // The temporary directory will not be deleted even when the `dir` variable is dropped
}

Create a temporary directory using the specified path.

use outdir_tempdir::TempDir;

#[test]
fn test_something() {
    // Create a temporary directory with a specified path 'foo/bar/baz'
    // and automatically remove it upon dropping
    let dir = TempDir::with_path("foo/bar/baz").autorm();

    // Get temporary directory
    // (/path/to/crate/target/(debug|release)/build/outdir-tempdir-<random>/out/foo/bar/baz)
    let tempdir = dir.path();

    // Test your code using `tempdir`
    // ...

    // Remove the temporary directory when the `dir` variable is dropped
}

Dependencies

~540KB