Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ sysinfo = { version = "0.38", default-features = false, features = ["system"] }
whoami = "2"

[dev-dependencies]
rstest = "0.26.1"
tempfile = "3"
41 changes: 41 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,44 @@ where
});
func(test_dir)
}

#[cfg(test)]
mod test_rstests {
use rstest::rstest;

use super::*;

#[rstest]
#[case(1)]
#[case(2)]
fn test_1(#[case] _num: u8) {
let dir = testdir!();
println!("Created tmp_dir {}", dir.display());
let mut parts = dir.components();
match parts.next_back().map(|c| c.as_os_str().to_str().unwrap()) {
Some("case_1") | Some("case_2") => (),
_ => panic!("wrong case directory"),
}
match parts.next_back().map(|c| c.as_os_str().to_str().unwrap()) {
Some("test_1") => (),
_ => panic!("wrong test directory"),
}
}

#[rstest]
#[case(1)]
#[case(2)]
fn test_2(#[case] _num: u8) {
let dir = testdir!();
println!("Created tmp_dir {}", dir.display());
let mut parts = dir.components();
match parts.next_back().map(|c| c.as_os_str().to_str().unwrap()) {
Some("case_1") | Some("case_2") => (),
_ => panic!("wrong case directory"),
}
match parts.next_back().map(|c| c.as_os_str().to_str().unwrap()) {
Some("test_2") => (),
_ => panic!("wrong test directory"),
}
}
}
10 changes: 7 additions & 3 deletions src/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,19 @@ fn cargo_pid() -> Option<Pid> {
pub fn extract_test_name(module_path: &str) -> String {
let mut name = std::thread::current()
.name()
.expect("Test thread has no name, can not find test name")
.unwrap_or_default()
.to_string();
if name == "main" {
name = extract_test_name_from_backtrace(module_path);
}
if let Some(tail) = name.rsplit("::").next() {
if let Some((_head, tail)) = name.split_once("::") {
// The test name usually starts with the module name, so skip that.
name = tail.to_string();
}
name
// When using rstest the test name still contains multiple module paths entries, they
// are named "test_name::case_name". So we turn the name into several path entries:
// "test_name/case_name".
name.replace("::", ::std::path::MAIN_SEPARATOR_STR)
}

/// Extracts the name of the currently executing tests using [`backtrace`].
Expand Down
Loading