Skip to content
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

Testdir collision for doctests #11

Open
wiktor-k opened this issue Sep 11, 2024 · 1 comment
Open

Testdir collision for doctests #11

wiktor-k opened this issue Sep 11, 2024 · 1 comment

Comments

@wiktor-k
Copy link
Contributor

wiktor-k commented Sep 11, 2024

Hi,

I believe this may be out of scope for testdir but I think it still needs to be documented as it surprised me.

testdir::testdir!() generates the same directories when executed in a doctest.

Minimal reproducer (src/lib.rs):

/// Does one thing well.
///
/// ```
/// let dir = testdir::testdir!();
/// eprintln!("One: {dir:?}");
/// assert!(false);
/// ```
pub fn one() {}

/// Does another thing well.
///
/// ```
/// let dir = testdir::testdir!();
/// eprintln!("Two: {dir:?}");
/// assert!(false);
/// ```
pub fn two() {}

Running it with cargo test shows this output:

tderr:
Two: "/home/wiktor/tmp/cargo/testdir-198/rust_out/h9f5ab6561c35996e"
thread 'main' panicked at src/lib.rs:5:1:
assertion failed: false
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


---- src/lib.rs - one (line 3) stdout ----
Test executable failed (exit status: 101).

stderr:
One: "/home/wiktor/tmp/cargo/testdir-198/rust_out/h9f5ab6561c35996e"
thread 'main' panicked at src/lib.rs:5:1:
assertion failed: false
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Both of them generated the same path: "/home/wiktor/tmp/cargo/testdir-198/rust_out/h9f5ab6561c35996e" and some test may want to use isolated dirs.

This is similar to #6 but instead of rstest it's doctests.

@flub
Copy link
Owner

flub commented Sep 19, 2024

I think this is fair to consider in-scope, thanks for reporting.

I think the entire directory structure created here is not intuitive. Ideally this would indicate it is a doc test and still have the module structure somehow. Not sure if this is possible though.

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

2 participants