Skip to content

Commit

Permalink
Rollup merge of #126072 - Zalathar:run-flags, r=jieyouxu
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
workingjubilee committed Jun 6, 2024
2 parents 2c1e71b + 2692d44 commit f4016e2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub struct TestProps {
// Extra flags to pass to the compiler
pub compile_flags: Vec<String>,
// 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
// pretty-printed
pub pp_exact: Option<PathBuf>,
Expand Down Expand Up @@ -262,7 +262,7 @@ impl TestProps {
error_patterns: vec![],
regex_error_patterns: vec![],
compile_flags: vec![],
run_flags: None,
run_flags: vec![],
pp_exact: None,
aux_builds: vec![],
aux_bins: vec![],
Expand Down Expand Up @@ -399,7 +399,9 @@ impl TestProps {

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() {
self.pp_exact = config.parse_pp_exact(ln, testfile);
Expand Down
10 changes: 6 additions & 4 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2355,7 +2355,7 @@ impl<'test> TestCx<'test> {
args.push(exe_file.into_os_string());

// 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);
ProcArgs { prog, args }
Expand Down Expand Up @@ -4174,10 +4174,12 @@ impl<'test> TestCx<'test> {
}

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 json = rflags
.map_or(false, |s| s.contains("--format json") || s.contains("--format=json"))
let json = rflags.contains("--format json")
|| rflags.contains("--format=json")
|| cflags.contains("--error-format json")
|| cflags.contains("--error-format pretty-json")
|| cflags.contains("--error-format=json")
Expand Down
4 changes: 1 addition & 3 deletions src/tools/rustdoc-gui-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ If you want to install the `browser-ui-test` dependency, run `npm install browse
cargo.env("RUSTDOCFLAGS", test_props.compile_flags.join(" "));
}

if let Some(flags) = &test_props.run_flags {
cargo.arg(flags);
}
cargo.args(&test_props.run_flags);
}

if try_run(&mut cargo, config.verbose).is_err() {
Expand Down

0 comments on commit f4016e2

Please sign in to comment.