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

Improve windows support, test more platforms in ci #9

Merged
merged 12 commits into from
Dec 14, 2023
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
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