Skip to content
Permalink
Browse files

compiletest: uniformly normalize paths, so they all work on all platf…

…orms.
  • Loading branch information...
eddyb committed May 7, 2019
1 parent bb1c67d commit c89a13179ea1d8431868508d79d57ab3c6ce0ac7
Showing with 15 additions and 17 deletions.
  1. +15 −17 src/tools/compiletest/src/runtest.rs
@@ -3154,42 +3154,40 @@ impl<'test> TestCx<'test> {
}

fn normalize_output(&self, output: &str, custom_rules: &[(String, String)]) -> String {
let parent_dir = self.testpaths.file.parent().unwrap();
let cflags = self.props.compile_flags.join(" ");
let json = cflags.contains("--error-format json")
|| cflags.contains("--error-format pretty-json")
|| cflags.contains("--error-format=json")
|| cflags.contains("--error-format=pretty-json");
let parent_dir_str = if json {
parent_dir.display().to_string().replace("\\", "\\\\")
} else {
parent_dir.display().to_string()

let mut normalized = output.to_string();

let mut normalize_path = |from: &Path, to: &str| {
let mut from = from.display().to_string();
if json {
from = from.replace("\\", "\\\\");
}
normalized = normalized.replace(&from, to);
};

let mut normalized = output.replace(&parent_dir_str, "$DIR");
let parent_dir = self.testpaths.file.parent().unwrap();
normalize_path(parent_dir, "$DIR");

// Paths into the libstd/libcore
let src_dir = self.config.src_base.parent().unwrap().parent().unwrap();
let src_dir_str = if json {
src_dir.display().to_string().replace("\\", "\\\\")
} else {
src_dir.display().to_string()
};
normalized = normalized.replace(&src_dir_str, "$SRC_DIR");
normalize_path(src_dir, "$SRC_DIR");

// Paths into the build directory
let test_build_dir = &self.config.build_base;
let parent_build_dir = test_build_dir.parent().unwrap().parent().unwrap().parent().unwrap();

// eg. /home/user/rust/build/x86_64-unknown-linux-gnu/test/ui
normalized = normalized.replace(test_build_dir.to_str().unwrap(), "$TEST_BUILD_DIR");
normalize_path(test_build_dir, "$TEST_BUILD_DIR");
// eg. /home/user/rust/build
normalized = normalized.replace(&parent_build_dir.to_str().unwrap(), "$BUILD_DIR");
normalize_path(parent_build_dir, "$BUILD_DIR");

// Paths into lib directory.
let mut lib_dir = parent_build_dir.parent().unwrap().to_path_buf();
lib_dir.push("lib");
normalized = normalized.replace(&lib_dir.to_str().unwrap(), "$LIB_DIR");
normalize_path(&parent_build_dir.parent().unwrap().join("lib"), "$LIB_DIR");

if json {
// escaped newlines in json strings should be readable

0 comments on commit c89a131

Please sign in to comment.
You can’t perform that action at this time.