From ec14be84aaa9180f9fc543aff102336f48e76fd7 Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Sun, 27 Mar 2016 03:05:55 -0400 Subject: [PATCH] tests/pwd: fix broken Windows test Due to canonicalize()'s use of GetFinalPathNameByHandleW() on Windows, the resolved path starts with '\\?\' to extend the limit of a given path to 32,767 wide characters. To address this issue, we remove this prepended string if available. --- tests/common/util.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/common/util.rs b/tests/common/util.rs index 8225f921a..4ee5e3218 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -252,7 +252,21 @@ impl AtPath { pub fn root_dir_resolved(&self) -> String { log_info("current_directory_resolved", ""); - self.subdir.canonicalize().unwrap().to_str().unwrap().to_owned() + let s = self.subdir.canonicalize().unwrap().to_str().unwrap().to_owned(); + + // Due to canonicalize()'s use of GetFinalPathNameByHandleW() on Windows, the resolved path + // starts with '\\?\' to extend the limit of a given path to 32,767 wide characters. + // + // To address this issue, we remove this prepended string if available. + // + // Source: + // http://stackoverflow.com/questions/31439011/getfinalpathnamebyhandle-without-prepended + let prefix = "\\\\?\\"; + if s.starts_with(prefix) { + String::from(&s[prefix.len()..]) + } else { + s + } } }