From 49d08155884a5b968550612a11a7b7ce5c66fd49 Mon Sep 17 00:00:00 2001 From: Arcterus Date: Sun, 10 Jan 2016 02:47:57 -0800 Subject: [PATCH] tests: fix tests that broke when using a symlinked /tmp --- tests/common/util.rs | 16 ++++++---------- tests/pwd.rs | 4 ++-- tests/readlink.rs | 10 +++++----- tests/realpath.rs | 4 ++-- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/tests/common/util.rs b/tests/common/util.rs index 716e5aeae..113e56b49 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -53,16 +53,6 @@ pub struct CmdResult { pub stderr: String, } -#[cfg(target_os = "macos")] -pub fn trim_private(input: &str) -> &str { - input.trim_left_matches("/private") -} - -#[cfg(not(target_os = "macos"))] -pub fn trim_private(input: &str) -> &str { - input -} - pub fn log_info, U: AsRef>(msg: T, par: U) { println!("{}: {}", msg.as_ref(), par.as_ref()); } @@ -215,10 +205,16 @@ impl AtPath { Err(_) => {} } } + pub fn root_dir(&self) -> String { log_info("current_directory", ""); self.subdir.to_str().unwrap().to_owned() } + + pub fn root_dir_resolved(&self) -> String { + log_info("current_directory_resolved", ""); + self.subdir.canonicalize().unwrap().to_str().unwrap().to_owned() + } } pub struct TestSet { diff --git a/tests/pwd.rs b/tests/pwd.rs index 7d389c979..5ac5fcf43 100644 --- a/tests/pwd.rs +++ b/tests/pwd.rs @@ -11,6 +11,6 @@ fn test_default() { let (at, mut ucmd) = testing(UTIL_NAME); let out = ucmd.run().stdout; - let expected = at.root_dir(); - assert_eq!(trim_private(out.trim_right()), expected); + let expected = at.root_dir_resolved(); + assert_eq!(out.trim_right(), expected); } diff --git a/tests/readlink.rs b/tests/readlink.rs index 15bee26c0..eb138e712 100644 --- a/tests/readlink.rs +++ b/tests/readlink.rs @@ -16,7 +16,7 @@ fn test_canonicalize() { .run() .stdout; - assert_eq!(trim_private(out.trim_right()), at.root_dir()); + assert_eq!(out.trim_right(), at.root_dir_resolved()); } #[test] @@ -27,13 +27,13 @@ fn test_canonicalize_existing() { .run() .stdout; - assert_eq!(trim_private(out.trim_right()), at.root_dir()); + assert_eq!(out.trim_right(), at.root_dir_resolved()); } #[test] fn test_canonicalize_missing() { let (at, mut ucmd) = testing(UTIL_NAME); - let mut expected = at.root_dir(); + let mut expected = at.root_dir_resolved(); expected.push_str("/"); expected.push_str(GIBBERISH); @@ -42,7 +42,7 @@ fn test_canonicalize_missing() { .run() .stdout; - assert_eq!(trim_private(out.trim_right()), expected); + assert_eq!(out.trim_right(), expected); } #[test] @@ -56,7 +56,7 @@ fn test_long_redirection_to_current_dir() { .run() .stdout; - assert_eq!(trim_private(&out), at.root_dir()); + assert_eq!(out, at.root_dir_resolved()); } #[test] diff --git a/tests/realpath.rs b/tests/realpath.rs index cf3c20a28..fa775da21 100644 --- a/tests/realpath.rs +++ b/tests/realpath.rs @@ -10,7 +10,7 @@ fn test_current_directory() { let (at, mut ucmd) = testing(UTIL_NAME); let out = ucmd.arg(".").run().stdout; - assert_eq!(trim_private(out.trim_right()), at.root_dir()); + assert_eq!(out.trim_right(), at.root_dir_resolved()); } #[test] @@ -20,7 +20,7 @@ fn test_long_redirection_to_current_dir() { let dir = repeat_str("./", 128); let out = ucmd.arg(dir).run().stdout; - assert_eq!(trim_private(out.trim_right()), at.root_dir()); + assert_eq!(out.trim_right(), at.root_dir_resolved()); } #[test]