Skip to content

#[files] produces incorrect test names on Windows #287

@GermanCoding

Description

@GermanCoding

Steps to reproduce

  1. cargo new reproducer && cd reproducer && cargo add --dev rstest
  2. main.rs
fn main() {
    println!("Hello, world!");
}

#[cfg(test)]
mod test {
	use rstest::rstest;
	use std::path::PathBuf;
	
	#[rstest]
	fn wrong_testname(#[files("src/main.rs")] _p: PathBuf) {}
}
  1. Run this test on Linux & Windows. Compare names of the generated test cases.

Expected output

cargo test

running 1 test
test test::wrong_testname::_p_1_src_main_rs ... ok

This is what happens when running on Linux.

Actual output

However, when running on Windows 11, this happens:

cargo test

running 1 test
test test::wrong_testname::_p_1__UP_D_Rust_projectsreproducersrcmain_rs ... ok

The test seems to use the full path up from the drive's root, not from the crate's base directory. It is also missing some _ in place of path separators.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions