diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 6acf724..a44161e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -11,8 +11,11 @@ env: jobs: build: + strategy: + matrix: + os: [ubuntu-latest, windows-latest] - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 diff --git a/Cargo.toml b/Cargo.toml index 5c7ef6b..ab6a47b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,6 @@ all-features = true [dependencies] camino = { version = "1.0.5", optional = true } + +[dev-dependencies] +cfg-if = "1.0.0" diff --git a/src/lib.rs b/src/lib.rs index 3860c2d..101650a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -152,12 +152,24 @@ pub use crate::utf8_paths::*; #[cfg(test)] mod tests { use super::*; + use cfg_if::cfg_if; #[test] fn test_absolute() { - assert_diff_paths("/foo", "/bar", Some("../foo")); - assert_diff_paths("/foo", "bar", Some("/foo")); - assert_diff_paths("foo", "/bar", None); + fn abs(path: &str) -> String { + // Absolute paths look different on Windows vs Unix. + cfg_if! { + if #[cfg(windows)] { + format!("C:\\{}", path) + } else { + format!("/{}", path) + } + } + } + + assert_diff_paths(&abs("foo"), &abs("bar"), Some("../foo")); + assert_diff_paths(&abs("foo"), "bar", Some(&abs("foo"))); + assert_diff_paths("foo", &abs("bar"), None); assert_diff_paths("foo", "bar", Some("../foo")); }