compiletest: Support running with a remapped base directory.
This commit is contained in:
parent
d792072738
commit
10fe7bfc73
2 changed files with 36 additions and 5 deletions
|
@ -162,6 +162,9 @@ pub struct TestProps {
|
||||||
pub stderr_per_bitwidth: bool,
|
pub stderr_per_bitwidth: bool,
|
||||||
// The MIR opt to unit test, if any
|
// The MIR opt to unit test, if any
|
||||||
pub mir_unit_test: Option<String>,
|
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 {
|
mod directives {
|
||||||
|
@ -196,6 +199,7 @@ mod directives {
|
||||||
pub const INCREMENTAL: &'static str = "incremental";
|
pub const INCREMENTAL: &'static str = "incremental";
|
||||||
pub const KNOWN_BUG: &'static str = "known-bug";
|
pub const KNOWN_BUG: &'static str = "known-bug";
|
||||||
pub const MIR_UNIT_TEST: &'static str = "unit-test";
|
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
|
// This isn't a real directive, just one that is probably mistyped often
|
||||||
pub const INCORRECT_COMPILER_FLAGS: &'static str = "compiler-flags";
|
pub const INCORRECT_COMPILER_FLAGS: &'static str = "compiler-flags";
|
||||||
}
|
}
|
||||||
|
@ -241,6 +245,7 @@ impl TestProps {
|
||||||
should_ice: false,
|
should_ice: false,
|
||||||
stderr_per_bitwidth: false,
|
stderr_per_bitwidth: false,
|
||||||
mir_unit_test: None,
|
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| {
|
config.set_name_value_directive(ln, MIR_UNIT_TEST, &mut self.mir_unit_test, |s| {
|
||||||
s.trim().to_string()
|
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)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
|
const FAKE_SRC_BASE: &str = "fake-test-src-base";
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
fn disable_error_reporting<F: FnOnce() -> R, R>(f: F) -> R {
|
fn disable_error_reporting<F: FnOnce() -> R, R>(f: F) -> R {
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
@ -1328,12 +1330,19 @@ impl<'test> TestCx<'test> {
|
||||||
return;
|
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
|
// On Windows, keep all '\' path separators to match the paths reported in the JSON output
|
||||||
// from the compiler
|
// from the compiler
|
||||||
let os_file_name = self.testpaths.file.display().to_string();
|
let diagnostic_file_name = if self.props.remap_src_base {
|
||||||
|
let mut p = PathBuf::from(FAKE_SRC_BASE);
|
||||||
// on windows, translate all '\' path separators to '/'
|
p.push(&self.testpaths.relative_dir);
|
||||||
let file_name = format!("{}", self.testpaths.file.display()).replace(r"\", "/");
|
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"
|
// If the testcase being checked contains at least one expected "help"
|
||||||
// message, then we'll ensure that all "help" messages are expected.
|
// 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));
|
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.
|
// 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 unexpected = Vec::new();
|
||||||
let mut found = vec![false; expected_errors.len()];
|
let mut found = vec![false; expected_errors.len()];
|
||||||
for actual_error in &actual_errors {
|
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 {
|
match emit {
|
||||||
Emit::None => {}
|
Emit::None => {}
|
||||||
Emit::Metadata if is_rustdoc => {}
|
Emit::Metadata if is_rustdoc => {}
|
||||||
|
@ -3545,6 +3562,14 @@ impl<'test> TestCx<'test> {
|
||||||
let parent_dir = self.testpaths.file.parent().unwrap();
|
let parent_dir = self.testpaths.file.parent().unwrap();
|
||||||
normalize_path(parent_dir, "$DIR");
|
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 = &[
|
let source_bases = &[
|
||||||
// Source base on the current filesystem (calculated as parent of `tests/$suite`):
|
// Source base on the current filesystem (calculated as parent of `tests/$suite`):
|
||||||
Some(self.config.src_base.parent().unwrap().parent().unwrap().into()),
|
Some(self.config.src_base.parent().unwrap().parent().unwrap().into()),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue