Rollup merge of #126072 - Zalathar:run-flags, r=jieyouxu

compiletest: Allow multiple `//@ run-flags:` headers

While working on some tests, I was annoyed to find that multiple `// `@run-flags:`` headers do not combine with each other (as `//@ compile-flags:` headers do), and instead all but one are silently discarded.

This makes it impossible to split long flag lists into multiple lines.

Fortunately it's easy to just recycle the existing logic from the other command-line-flags headers.
This commit is contained in:
Jubilee 2024-06-06 14:46:23 -07:00 committed by GitHub
commit f4016e2bf5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 10 deletions

View File

@ -94,7 +94,7 @@ pub struct TestProps {
// Extra flags to pass to the compiler // Extra flags to pass to the compiler
pub compile_flags: Vec<String>, pub compile_flags: Vec<String>,
// Extra flags to pass when the compiled code is run (such as --bench) // Extra flags to pass when the compiled code is run (such as --bench)
pub run_flags: Option<String>, pub run_flags: Vec<String>,
// If present, the name of a file that this test should match when // If present, the name of a file that this test should match when
// pretty-printed // pretty-printed
pub pp_exact: Option<PathBuf>, pub pp_exact: Option<PathBuf>,
@ -262,7 +262,7 @@ pub fn new() -> Self {
error_patterns: vec![], error_patterns: vec![],
regex_error_patterns: vec![], regex_error_patterns: vec![],
compile_flags: vec![], compile_flags: vec![],
run_flags: None, run_flags: vec![],
pp_exact: None, pp_exact: None,
aux_builds: vec![], aux_builds: vec![],
aux_bins: vec![], aux_bins: vec![],
@ -399,7 +399,9 @@ fn split_flags(flags: &str) -> Vec<String> {
config.parse_and_update_revisions(ln, &mut self.revisions); config.parse_and_update_revisions(ln, &mut self.revisions);
config.set_name_value_directive(ln, RUN_FLAGS, &mut self.run_flags, |r| r); if let Some(flags) = config.parse_name_value_directive(ln, RUN_FLAGS) {
self.run_flags.extend(split_flags(&flags));
}
if self.pp_exact.is_none() { if self.pp_exact.is_none() {
self.pp_exact = config.parse_pp_exact(ln, testfile); self.pp_exact = config.parse_pp_exact(ln, testfile);

View File

@ -2355,7 +2355,7 @@ fn make_run_args(&self) -> ProcArgs {
args.push(exe_file.into_os_string()); args.push(exe_file.into_os_string());
// Add the arguments in the run_flags directive // Add the arguments in the run_flags directive
args.extend(self.split_maybe_args(&self.props.run_flags)); args.extend(self.props.run_flags.iter().map(OsString::from));
let prog = args.remove(0); let prog = args.remove(0);
ProcArgs { prog, args } ProcArgs { prog, args }
@ -4174,10 +4174,12 @@ fn get_mir_dump_dir(&self) -> PathBuf {
} }
fn normalize_output(&self, output: &str, custom_rules: &[(String, String)]) -> String { fn normalize_output(&self, output: &str, custom_rules: &[(String, String)]) -> String {
let rflags = self.props.run_flags.as_ref(); // Crude heuristic to detect when the output should have JSON-specific
// normalization steps applied.
let rflags = self.props.run_flags.join(" ");
let cflags = self.props.compile_flags.join(" "); let cflags = self.props.compile_flags.join(" ");
let json = rflags let json = rflags.contains("--format json")
.map_or(false, |s| s.contains("--format json") || s.contains("--format=json")) || rflags.contains("--format=json")
|| cflags.contains("--error-format 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")

View File

@ -123,9 +123,7 @@ fn main() -> Result<(), ()> {
cargo.env("RUSTDOCFLAGS", test_props.compile_flags.join(" ")); cargo.env("RUSTDOCFLAGS", test_props.compile_flags.join(" "));
} }
if let Some(flags) = &test_props.run_flags { cargo.args(&test_props.run_flags);
cargo.arg(flags);
}
} }
if try_run(&mut cargo, config.verbose).is_err() { if try_run(&mut cargo, config.verbose).is_err() {