compiletest: uniformly normalize paths, so they all work on all platforms.

This commit is contained in:
Eduard-Mihai Burtescu 2019-05-07 04:49:26 +03:00
parent bb1c67dde4
commit c89a13179e

View File

@ -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