Skip to content

Commit

Permalink
Improve windows support, test more platforms in ci (#9)
Browse files Browse the repository at this point in the history
This fixes a few bugs on windows. Previously the numbered testdir would
cylcle
too fast as the test runner was not detected correctly.

Also expand CI tests to run on more platforms so we find those things a
bit
faster.
  • Loading branch information
flub authored Dec 14, 2023
1 parent 6ba223a commit 1badfe7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/numbered_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +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();
assert_eq!(dir_1.path(), current);
// We know that on windows the first symlink probably didn't get removed, symlinks
// are best-effort there.
#[cfg(target_family = "unix")]
{
let current = fs::read_link(parent.path().join("base-current")).unwrap();
assert_eq!(dir_1.path(), current);
}
}

#[test]
Expand Down
19 changes: 17 additions & 2 deletions src/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ const CARGO_PID_FILE_NAME: &str = "cargo-pid";
/// Whether we are a cargo sub-process.
static CARGO_PID: Lazy<Option<Pid>> = 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.
Expand All @@ -43,7 +55,7 @@ fn cargo_pid() -> Option<Pid> {
let parent = sys.process(ppid)?;
let parent_exe = parent.exe();
let parent_file_name = 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()?;
Expand Down Expand Up @@ -127,7 +139,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 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")
}

#[cfg(test)]
Expand Down

0 comments on commit 1badfe7

Please sign in to comment.