Skip to content

Commit a78acde

Browse files
authored
Merge pull request #7 from sunshowers/windows
make tests pass on Windows
2 parents 08fabb3 + 090ed94 commit a78acde

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

.github/workflows/rust.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ env:
1111

1212
jobs:
1313
build:
14+
strategy:
15+
matrix:
16+
os: [ubuntu-latest, windows-latest]
1417

15-
runs-on: ubuntu-latest
18+
runs-on: ${{ matrix.os }}
1619

1720
steps:
1821
- uses: actions/checkout@v2

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ all-features = true
1414

1515
[dependencies]
1616
camino = { version = "1.0.5", optional = true }
17+
18+
[dev-dependencies]
19+
cfg-if = "1.0.0"

src/lib.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ mod utf8_paths {
8282

8383
/// Construct a relative UTF-8 path from a provided base directory path to the provided path.
8484
///
85+
/// Requires the `camino` feature.
86+
///
8587
/// ```rust
8688
/// # extern crate camino;
8789
/// use camino::*;
@@ -152,12 +154,24 @@ pub use crate::utf8_paths::*;
152154
#[cfg(test)]
153155
mod tests {
154156
use super::*;
157+
use cfg_if::cfg_if;
155158

156159
#[test]
157160
fn test_absolute() {
158-
assert_diff_paths("/foo", "/bar", Some("../foo"));
159-
assert_diff_paths("/foo", "bar", Some("/foo"));
160-
assert_diff_paths("foo", "/bar", None);
161+
fn abs(path: &str) -> String {
162+
// Absolute paths look different on Windows vs Unix.
163+
cfg_if! {
164+
if #[cfg(windows)] {
165+
format!("C:\\{}", path)
166+
} else {
167+
format!("/{}", path)
168+
}
169+
}
170+
}
171+
172+
assert_diff_paths(&abs("foo"), &abs("bar"), Some("../foo"));
173+
assert_diff_paths(&abs("foo"), "bar", Some(&abs("foo")));
174+
assert_diff_paths("foo", &abs("bar"), None);
161175
assert_diff_paths("foo", "bar", Some("../foo"));
162176
}
163177

0 commit comments

Comments
 (0)