Skip to content

Commit 5a946de

Browse files
committed
test-cargo-miri: normalize slashes before comparing paths
1 parent decb784 commit 5a946de

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

test-cargo-miri/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ fn main() {
2222
// If there were no arguments, access stdin and test working dir.
2323
if std::env::args().len() <= 1 {
2424
let env_dir = env::current_dir().unwrap();
25+
// CWD should be crate root.
2526
let crate_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
27+
// We have to normalize slashes, as the env var might be set for a different target's conventions.
28+
let env_dir = env_dir.to_string_lossy().replace("\\", "/");
29+
let crate_dir = crate_dir.to_string_lossy().replace("\\", "/");
2630
assert_eq!(env_dir, crate_dir);
2731

2832
#[cfg(unix)]

test-cargo-miri/subcrate/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ fn main() {
55
println!("subcrate running");
66

77
let env_dir = env::current_dir().unwrap();
8-
let crate_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
98
// CWD should be workspace root, i.e., one level up from crate root.
10-
assert_eq!(env_dir, crate_dir.parent().unwrap());
9+
let crate_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
10+
let crate_dir = crate_dir.parent().unwrap();
11+
// We have to normalize slashes, as the env var might be set for a different target's conventions.
12+
let env_dir = env_dir.to_string_lossy().replace("\\", "/");
13+
let crate_dir = crate_dir.to_string_lossy().replace("\\", "/");
14+
assert_eq!(env_dir, crate_dir);
1115
}

test-cargo-miri/subcrate/test.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ fn main() {
55
println!("subcrate testing");
66

77
let env_dir = env::current_dir().unwrap();
8-
let crate_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
98
// CWD should be crate root.
9+
let crate_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
10+
// We have to normalize slashes, as the env var might be set for a different target's conventions.
11+
let env_dir = env_dir.to_string_lossy().replace("\\", "/");
12+
let crate_dir = crate_dir.to_string_lossy().replace("\\", "/");
1013
assert_eq!(env_dir, crate_dir);
1114
}

0 commit comments

Comments
 (0)