mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-30 14:01:51 +00:00
compiletest: uniformly normalize paths, so they all work on all platforms.
This commit is contained in:
parent
bb1c67dde4
commit
c89a13179e
@ -3154,42 +3154,40 @@ impl<'test> TestCx<'test> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn normalize_output(&self, output: &str, custom_rules: &[(String, String)]) -> String {
|
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 cflags = self.props.compile_flags.join(" ");
|
||||||
let json = cflags.contains("--error-format json")
|
let json = cflags.contains("--error-format json")
|
||||||
|| cflags.contains("--error-format pretty-json")
|
|| cflags.contains("--error-format pretty-json")
|
||||||
|| cflags.contains("--error-format=json")
|
|| cflags.contains("--error-format=json")
|
||||||
|| cflags.contains("--error-format=pretty-json");
|
|| cflags.contains("--error-format=pretty-json");
|
||||||
let parent_dir_str = if json {
|
|
||||||
parent_dir.display().to_string().replace("\\", "\\\\")
|
let mut normalized = output.to_string();
|
||||||
} else {
|
|
||||||
parent_dir.display().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
|
// Paths into the libstd/libcore
|
||||||
let src_dir = self.config.src_base.parent().unwrap().parent().unwrap();
|
let src_dir = self.config.src_base.parent().unwrap().parent().unwrap();
|
||||||
let src_dir_str = if json {
|
normalize_path(src_dir, "$SRC_DIR");
|
||||||
src_dir.display().to_string().replace("\\", "\\\\")
|
|
||||||
} else {
|
|
||||||
src_dir.display().to_string()
|
|
||||||
};
|
|
||||||
normalized = normalized.replace(&src_dir_str, "$SRC_DIR");
|
|
||||||
|
|
||||||
// Paths into the build directory
|
// Paths into the build directory
|
||||||
let test_build_dir = &self.config.build_base;
|
let test_build_dir = &self.config.build_base;
|
||||||
let parent_build_dir = test_build_dir.parent().unwrap().parent().unwrap().parent().unwrap();
|
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
|
// 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
|
// 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.
|
// Paths into lib directory.
|
||||||
let mut lib_dir = parent_build_dir.parent().unwrap().to_path_buf();
|
normalize_path(&parent_build_dir.parent().unwrap().join("lib"), "$LIB_DIR");
|
||||||
lib_dir.push("lib");
|
|
||||||
normalized = normalized.replace(&lib_dir.to_str().unwrap(), "$LIB_DIR");
|
|
||||||
|
|
||||||
if json {
|
if json {
|
||||||
// escaped newlines in json strings should be readable
|
// escaped newlines in json strings should be readable
|
||||||
|
Loading…
Reference in New Issue
Block a user