Skip to content

Commit 9f6569c

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

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

test-cargo-miri/src/main.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use byteorder::{BigEndian, ByteOrder};
22
use std::env;
3-
use std::path::PathBuf;
43
#[cfg(unix)]
54
use std::io::{self, BufRead};
65

@@ -21,8 +20,12 @@ fn main() {
2120

2221
// If there were no arguments, access stdin and test working dir.
2322
if std::env::args().len() <= 1 {
23+
// CWD should be crate root.
24+
// We have to normalize slashes, as the env var might be set for a different target's conventions.
2425
let env_dir = env::current_dir().unwrap();
25-
let crate_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
26+
let env_dir = env_dir.to_string_lossy().replace("\\", "/");
27+
let crate_dir = env::var_os("CARGO_MANIFEST_DIR").unwrap();
28+
let crate_dir = crate_dir.to_string_lossy().replace("\\", "/");
2629
assert_eq!(env_dir, crate_dir);
2730

2831
#[cfg(unix)]

test-cargo-miri/subcrate/main.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ use std::path::PathBuf;
44
fn main() {
55
println!("subcrate running");
66

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

test-cargo-miri/subcrate/test.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use std::env;
2-
use std::path::PathBuf;
32

43
fn main() {
54
println!("subcrate testing");
65

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

0 commit comments

Comments
 (0)