compiletest: Support running with a remapped base directory.
This commit is contained in:
parent
d792072738
commit
10fe7bfc73
@ -162,6 +162,9 @@ pub struct TestProps {
|
||||
pub stderr_per_bitwidth: bool,
|
||||
// The MIR opt to unit test, if any
|
||||
pub mir_unit_test: Option<String>,
|
||||
// Whether to tell `rustc` to remap the "src base" directory to a fake
|
||||
// directory.
|
||||
pub remap_src_base: bool,
|
||||
}
|
||||
|
||||
mod directives {
|
||||
@ -196,6 +199,7 @@ mod directives {
|
||||
pub const INCREMENTAL: &'static str = "incremental";
|
||||
pub const KNOWN_BUG: &'static str = "known-bug";
|
||||
pub const MIR_UNIT_TEST: &'static str = "unit-test";
|
||||
pub const REMAP_SRC_BASE: &'static str = "remap-src-base";
|
||||
// This isn't a real directive, just one that is probably mistyped often
|
||||
pub const INCORRECT_COMPILER_FLAGS: &'static str = "compiler-flags";
|
||||
}
|
||||
@ -241,6 +245,7 @@ impl TestProps {
|
||||
should_ice: false,
|
||||
stderr_per_bitwidth: false,
|
||||
mir_unit_test: None,
|
||||
remap_src_base: false,
|
||||
}
|
||||
}
|
||||
|
||||
@ -433,6 +438,7 @@ impl TestProps {
|
||||
config.set_name_value_directive(ln, MIR_UNIT_TEST, &mut self.mir_unit_test, |s| {
|
||||
s.trim().to_string()
|
||||
});
|
||||
config.set_name_directive(ln, REMAP_SRC_BASE, &mut self.remap_src_base);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,8 @@ use debugger::{check_debugger_output, DebuggerCommands};
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
const FAKE_SRC_BASE: &str = "fake-test-src-base";
|
||||
|
||||
#[cfg(windows)]
|
||||
fn disable_error_reporting<F: FnOnce() -> R, R>(f: F) -> R {
|
||||
use std::sync::Mutex;
|
||||
@ -1328,12 +1330,19 @@ impl<'test> TestCx<'test> {
|
||||
return;
|
||||
}
|
||||
|
||||
// On Windows, translate all '\' path separators to '/'
|
||||
let file_name = format!("{}", self.testpaths.file.display()).replace(r"\", "/");
|
||||
|
||||
// On Windows, keep all '\' path separators to match the paths reported in the JSON output
|
||||
// from the compiler
|
||||
let os_file_name = self.testpaths.file.display().to_string();
|
||||
|
||||
// on windows, translate all '\' path separators to '/'
|
||||
let file_name = format!("{}", self.testpaths.file.display()).replace(r"\", "/");
|
||||
let diagnostic_file_name = if self.props.remap_src_base {
|
||||
let mut p = PathBuf::from(FAKE_SRC_BASE);
|
||||
p.push(&self.testpaths.relative_dir);
|
||||
p.push(self.testpaths.file.file_name().unwrap());
|
||||
p.display().to_string()
|
||||
} else {
|
||||
self.testpaths.file.display().to_string()
|
||||
};
|
||||
|
||||
// If the testcase being checked contains at least one expected "help"
|
||||
// message, then we'll ensure that all "help" messages are expected.
|
||||
@ -1343,7 +1352,7 @@ impl<'test> TestCx<'test> {
|
||||
let expect_note = expected_errors.iter().any(|ee| ee.kind == Some(ErrorKind::Note));
|
||||
|
||||
// Parse the JSON output from the compiler and extract out the messages.
|
||||
let actual_errors = json::parse_output(&os_file_name, &proc_res.stderr, proc_res);
|
||||
let actual_errors = json::parse_output(&diagnostic_file_name, &proc_res.stderr, proc_res);
|
||||
let mut unexpected = Vec::new();
|
||||
let mut found = vec![false; expected_errors.len()];
|
||||
for actual_error in &actual_errors {
|
||||
@ -1970,6 +1979,14 @@ impl<'test> TestCx<'test> {
|
||||
}
|
||||
}
|
||||
|
||||
if self.props.remap_src_base {
|
||||
rustc.arg(format!(
|
||||
"--remap-path-prefix={}={}",
|
||||
self.config.src_base.display(),
|
||||
FAKE_SRC_BASE,
|
||||
));
|
||||
}
|
||||
|
||||
match emit {
|
||||
Emit::None => {}
|
||||
Emit::Metadata if is_rustdoc => {}
|
||||
@ -3545,6 +3562,14 @@ impl<'test> TestCx<'test> {
|
||||
let parent_dir = self.testpaths.file.parent().unwrap();
|
||||
normalize_path(parent_dir, "$DIR");
|
||||
|
||||
if self.props.remap_src_base {
|
||||
let mut remapped_parent_dir = PathBuf::from(FAKE_SRC_BASE);
|
||||
if self.testpaths.relative_dir != Path::new("") {
|
||||
remapped_parent_dir.push(&self.testpaths.relative_dir);
|
||||
}
|
||||
normalize_path(&remapped_parent_dir, "$DIR");
|
||||
}
|
||||
|
||||
let source_bases = &[
|
||||
// Source base on the current filesystem (calculated as parent of `tests/$suite`):
|
||||
Some(self.config.src_base.parent().unwrap().parent().unwrap().into()),
|
||||
|
Loading…
x
Reference in New Issue
Block a user