Skip to content

Commit

Permalink
test-cargo-miri: normalize slashes before comparing paths
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Sep 12, 2020
1 parent decb784 commit 5a946de
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions test-cargo-miri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ fn main() {
// If there were no arguments, access stdin and test working dir.
if std::env::args().len() <= 1 {
let env_dir = env::current_dir().unwrap();
// CWD should be crate root.
let crate_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
// We have to normalize slashes, as the env var might be set for a different target's conventions.
let env_dir = env_dir.to_string_lossy().replace("\\", "/");
let crate_dir = crate_dir.to_string_lossy().replace("\\", "/");
assert_eq!(env_dir, crate_dir);

#[cfg(unix)]
Expand Down
8 changes: 6 additions & 2 deletions test-cargo-miri/subcrate/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ fn main() {
println!("subcrate running");

let env_dir = env::current_dir().unwrap();
let crate_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
// CWD should be workspace root, i.e., one level up from crate root.
assert_eq!(env_dir, crate_dir.parent().unwrap());
let crate_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
let crate_dir = crate_dir.parent().unwrap();
// We have to normalize slashes, as the env var might be set for a different target's conventions.
let env_dir = env_dir.to_string_lossy().replace("\\", "/");
let crate_dir = crate_dir.to_string_lossy().replace("\\", "/");
assert_eq!(env_dir, crate_dir);
}
5 changes: 4 additions & 1 deletion test-cargo-miri/subcrate/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ fn main() {
println!("subcrate testing");

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

0 comments on commit 5a946de

Please sign in to comment.