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 9f6569c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
7 changes: 5 additions & 2 deletions test-cargo-miri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use byteorder::{BigEndian, ByteOrder};
use std::env;
use std::path::PathBuf;
#[cfg(unix)]
use std::io::{self, BufRead};

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

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

#[cfg(unix)]
Expand Down
11 changes: 8 additions & 3 deletions test-cargo-miri/subcrate/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ use std::path::PathBuf;
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());
// We have to normalize slashes, as the env var might be set for a different target's conventions.
let env_dir = env::current_dir().unwrap();
let env_dir = env_dir.to_string_lossy().replace("\\", "/");
let crate_dir = env::var_os("CARGO_MANIFEST_DIR").unwrap();
let crate_dir = crate_dir.to_string_lossy().replace("\\", "/");
let crate_dir = PathBuf::from(crate_dir);
let crate_dir = crate_dir.parent().unwrap().to_string_lossy();
assert_eq!(env_dir, crate_dir);
}
8 changes: 5 additions & 3 deletions test-cargo-miri/subcrate/test.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::env;
use std::path::PathBuf;

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.
// We have to normalize slashes, as the env var might be set for a different target's conventions.
let env_dir = env::current_dir().unwrap();
let env_dir = env_dir.to_string_lossy().replace("\\", "/");
let crate_dir = env::var_os("CARGO_MANIFEST_DIR").unwrap();
let crate_dir = crate_dir.to_string_lossy().replace("\\", "/");
assert_eq!(env_dir, crate_dir);
}

0 comments on commit 9f6569c

Please sign in to comment.