From 1765f529f3342dcd48b404cc8132d536b022f8af Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Thu, 14 Dec 2023 16:43:05 +0100 Subject: [PATCH 01/12] Test more platforms --- .github/workflows/ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0bf06db..733e83f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,7 +29,11 @@ jobs: - run: cargo doc --no-deps --document-private-items test: - runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable From 1011100c8263cbce952692ee497824538e54e851 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Thu, 14 Dec 2023 16:57:47 +0100 Subject: [PATCH 02/12] show some stuff --- src/private.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/private.rs b/src/private.rs index 688d9d5..e73bd13 100644 --- a/src/private.rs +++ b/src/private.rs @@ -42,7 +42,7 @@ fn cargo_pid() -> Option { sys.refresh_process_specifics(ppid, what); let parent = sys.process(ppid)?; let parent_exe = parent.exe(); - let parent_file_name = parent_exe.file_name()?; + let parent_file_name = dbg!(parent_exe.file_name()?); if parent_file_name == OsStr::new("cargo") || parent_file_name == OsStr::new("cargo-nextest") { Some(parent.pid()) } else if parent_file_name == OsStr::new("rustdoc") { From 7229e338540da4a225bc071c7d83ca6331730dd4 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Thu, 14 Dec 2023 17:06:29 +0100 Subject: [PATCH 03/12] Try to support windows --- src/private.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/private.rs b/src/private.rs index e73bd13..a5b9ab0 100644 --- a/src/private.rs +++ b/src/private.rs @@ -20,6 +20,18 @@ const CARGO_PID_FILE_NAME: &str = "cargo-pid"; /// Whether we are a cargo sub-process. static CARGO_PID: Lazy> = Lazy::new(cargo_pid); +#[cfg(target_family == "unix")] +const CARGO_NAME: &str = "cargo"; + +#[cfg(target_family == "unix")] +const NEXTEST_NAME: &str = "cargo-nextest"; + +#[cfg(target_family == "windows")] +const CARGO_NAME: &str = "cargo.exe"; + +#[cfg(target_family == "windows")] +const NEXTEST_NAME: &str = "cargo-nextest.exe"; + /// Returns the process ID of our parent Cargo process. /// /// If our parent process is not Cargo, `None` is returned. @@ -43,7 +55,7 @@ fn cargo_pid() -> Option { let parent = sys.process(ppid)?; let parent_exe = parent.exe(); let parent_file_name = dbg!(parent_exe.file_name()?); - if parent_file_name == OsStr::new("cargo") || parent_file_name == OsStr::new("cargo-nextest") { + if parent_file_name == OsStr::new(CARGO_NAME) || parent_file_name == OsStr::new(NEXTEST_NAME) { Some(parent.pid()) } else if parent_file_name == OsStr::new("rustdoc") { let ppid = parent.parent()?; From df592b1aa92d6a856f293ddba575f4b8aaa1c677 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Thu, 14 Dec 2023 17:08:17 +0100 Subject: [PATCH 04/12] syntax --- src/private.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/private.rs b/src/private.rs index a5b9ab0..f9dbc6a 100644 --- a/src/private.rs +++ b/src/private.rs @@ -20,16 +20,16 @@ const CARGO_PID_FILE_NAME: &str = "cargo-pid"; /// Whether we are a cargo sub-process. static CARGO_PID: Lazy> = Lazy::new(cargo_pid); -#[cfg(target_family == "unix")] +#[cfg(target_family = "unix")] const CARGO_NAME: &str = "cargo"; -#[cfg(target_family == "unix")] +#[cfg(target_family = "unix")] const NEXTEST_NAME: &str = "cargo-nextest"; -#[cfg(target_family == "windows")] +#[cfg(target_family = "windows")] const CARGO_NAME: &str = "cargo.exe"; -#[cfg(target_family == "windows")] +#[cfg(target_family = "windows")] const NEXTEST_NAME: &str = "cargo-nextest.exe"; /// Returns the process ID of our parent Cargo process. From 45c7e09f90bc574572fdb0bef0f8d784c0d91646 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Thu, 14 Dec 2023 17:24:02 +0100 Subject: [PATCH 05/12] Only assert this on unix --- src/numbered_dir.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/numbered_dir.rs b/src/numbered_dir.rs index b2e2ea3..18ccce1 100644 --- a/src/numbered_dir.rs +++ b/src/numbered_dir.rs @@ -315,6 +315,10 @@ mod tests { assert!(dir_1.path().is_dir()); let current = fs::read_link(parent.path().join("base-current")).unwrap(); + + // We know that on windows the first symlink probably didn't get removed, symlinks + // are best-effort there. + #[cfg(target_family = "unix")] assert_eq!(dir_1.path(), current); } From 8545ab62706e176d967ea32d4adcfbba0cebb383 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Thu, 14 Dec 2023 17:27:54 +0100 Subject: [PATCH 06/12] try again --- src/numbered_dir.rs | 7 ++++--- src/private.rs | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/numbered_dir.rs b/src/numbered_dir.rs index 18ccce1..f59e1e9 100644 --- a/src/numbered_dir.rs +++ b/src/numbered_dir.rs @@ -314,12 +314,13 @@ mod tests { assert!(dir_0.path().is_dir()); assert!(dir_1.path().is_dir()); - let current = fs::read_link(parent.path().join("base-current")).unwrap(); - // We know that on windows the first symlink probably didn't get removed, symlinks // are best-effort there. #[cfg(target_family = "unix")] - assert_eq!(dir_1.path(), current); + { + let current = fs::read_link(parent.path().join("base-current")).unwrap(); + assert_eq!(dir_1.path(), current); + } } #[test] diff --git a/src/private.rs b/src/private.rs index f9dbc6a..a796bcb 100644 --- a/src/private.rs +++ b/src/private.rs @@ -54,7 +54,7 @@ fn cargo_pid() -> Option { sys.refresh_process_specifics(ppid, what); let parent = sys.process(ppid)?; let parent_exe = parent.exe(); - let parent_file_name = dbg!(parent_exe.file_name()?); + let parent_file_name = parent_exe.file_name()?; if parent_file_name == OsStr::new(CARGO_NAME) || parent_file_name == OsStr::new(NEXTEST_NAME) { Some(parent.pid()) } else if parent_file_name == OsStr::new("rustdoc") { From bc37cce4ae0e1c6312504cbda2eba8c849857d6a Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Thu, 14 Dec 2023 17:40:26 +0100 Subject: [PATCH 07/12] debug things again --- src/private.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/private.rs b/src/private.rs index a796bcb..d03bb4c 100644 --- a/src/private.rs +++ b/src/private.rs @@ -131,7 +131,7 @@ pub fn extract_test_name_from_backtrace(module_path: &str) -> String { .filter_map(|x| x.name()) .map(|x| x.to_string()) { - if let Some(symbol) = symbol.strip_prefix(module_path) { + if let Some(symbol) = dbg!(symbol.strip_prefix(module_path)) { if let Some(symbol) = symbol.strip_suffix("::{{closure}}") { return symbol.to_string(); } else { From 4bd1349dcce96719d2ff75457225f4a16e9d6745 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Thu, 14 Dec 2023 17:44:37 +0100 Subject: [PATCH 08/12] hello --- src/private.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/private.rs b/src/private.rs index d03bb4c..ea5c811 100644 --- a/src/private.rs +++ b/src/private.rs @@ -131,6 +131,7 @@ pub fn extract_test_name_from_backtrace(module_path: &str) -> String { .filter_map(|x| x.name()) .map(|x| x.to_string()) { + dbg!(&symbol); if let Some(symbol) = dbg!(symbol.strip_prefix(module_path)) { if let Some(symbol) = symbol.strip_suffix("::{{closure}}") { return symbol.to_string(); From 0676c10dae77ff602af78fb8ae199629adc16220 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Thu, 14 Dec 2023 17:50:16 +0100 Subject: [PATCH 09/12] dbg --- src/private.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/private.rs b/src/private.rs index ea5c811..4c8b37e 100644 --- a/src/private.rs +++ b/src/private.rs @@ -123,6 +123,7 @@ pub fn extract_test_name(module_path: &str) -> String { /// Extracts the name of the currently executing tests using [`backtrace`]. pub fn extract_test_name_from_backtrace(module_path: &str) -> String { + dbg!(module_path); for symbol in backtrace::Backtrace::new() .frames() .iter() From 28d294210de9610bde62888af0877a8e7b4a621f Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Thu, 14 Dec 2023 17:55:49 +0100 Subject: [PATCH 10/12] try a workaround real life is messy --- src/private.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/private.rs b/src/private.rs index 4c8b37e..ee0b980 100644 --- a/src/private.rs +++ b/src/private.rs @@ -141,7 +141,10 @@ pub fn extract_test_name_from_backtrace(module_path: &str) -> String { } } } - panic!("Cannot determine test name from backtrace"); + + // We know that on windows doc tests fallthrough as the module_path is something like + // "rust_out" which is not very useful. We'll have to just use something. + String::from("unknown_test") } #[cfg(test)] From 3e25feea83b5f3d85d5ac688e18ec85d0d676734 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Thu, 14 Dec 2023 18:01:11 +0100 Subject: [PATCH 11/12] cleanup --- src/private.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/private.rs b/src/private.rs index ee0b980..e8a7ad1 100644 --- a/src/private.rs +++ b/src/private.rs @@ -123,7 +123,6 @@ pub fn extract_test_name(module_path: &str) -> String { /// Extracts the name of the currently executing tests using [`backtrace`]. pub fn extract_test_name_from_backtrace(module_path: &str) -> String { - dbg!(module_path); for symbol in backtrace::Backtrace::new() .frames() .iter() @@ -132,8 +131,8 @@ pub fn extract_test_name_from_backtrace(module_path: &str) -> String { .filter_map(|x| x.name()) .map(|x| x.to_string()) { - dbg!(&symbol); - if let Some(symbol) = dbg!(symbol.strip_prefix(module_path)) { + &symbol; + if let Some(symbol) = symbol.strip_prefix(module_path) { if let Some(symbol) = symbol.strip_suffix("::{{closure}}") { return symbol.to_string(); } else { @@ -142,7 +141,7 @@ pub fn extract_test_name_from_backtrace(module_path: &str) -> String { } } - // We know that on windows doc tests fallthrough as the module_path is something like + // We know that on windows doc tests fall through as the module_path is something like // "rust_out" which is not very useful. We'll have to just use something. String::from("unknown_test") } From 3e1ed862b89cb9609a290c1d41ca92eb43813eee Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Thu, 14 Dec 2023 18:02:58 +0100 Subject: [PATCH 12/12] lol --- src/private.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/private.rs b/src/private.rs index e8a7ad1..556ce42 100644 --- a/src/private.rs +++ b/src/private.rs @@ -131,7 +131,6 @@ pub fn extract_test_name_from_backtrace(module_path: &str) -> String { .filter_map(|x| x.name()) .map(|x| x.to_string()) { - &symbol; if let Some(symbol) = symbol.strip_prefix(module_path) { if let Some(symbol) = symbol.strip_suffix("::{{closure}}") { return symbol.to_string();