Rollup merge of #110644 - pietroalbini:pa-json-formatting-tests, r=Mark-Simulacrum

Update tests for libtest `--format json`

This PR makes the test work on beta and stable, and adds a test ensuring the option is not available on beta and stable. Backported these commits from https://github.com/rust-lang/rust/pull/110414.
This commit is contained in:
Matthias Krüger 2023-04-29 15:51:15 +02:00 committed by GitHub
commit 957a6ad4d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 60 additions and 8 deletions

View File

@ -90,6 +90,9 @@ pub struct TestProps {
pub unset_rustc_env: Vec<String>, pub unset_rustc_env: Vec<String>,
// Environment settings to use during execution // Environment settings to use during execution
pub exec_env: Vec<(String, String)>, pub exec_env: Vec<(String, String)>,
// Environment variables to unset prior to execution.
// Variables are unset before applying 'exec_env'
pub unset_exec_env: Vec<String>,
// Build documentation for all specified aux-builds as well // Build documentation for all specified aux-builds as well
pub build_aux_docs: bool, pub build_aux_docs: bool,
// Flag to force a crate to be built with the host architecture // Flag to force a crate to be built with the host architecture
@ -198,6 +201,7 @@ mod directives {
pub const AUX_CRATE: &'static str = "aux-crate"; pub const AUX_CRATE: &'static str = "aux-crate";
pub const EXEC_ENV: &'static str = "exec-env"; pub const EXEC_ENV: &'static str = "exec-env";
pub const RUSTC_ENV: &'static str = "rustc-env"; pub const RUSTC_ENV: &'static str = "rustc-env";
pub const UNSET_EXEC_ENV: &'static str = "unset-exec-env";
pub const UNSET_RUSTC_ENV: &'static str = "unset-rustc-env"; pub const UNSET_RUSTC_ENV: &'static str = "unset-rustc-env";
pub const FORBID_OUTPUT: &'static str = "forbid-output"; pub const FORBID_OUTPUT: &'static str = "forbid-output";
pub const CHECK_TEST_LINE_NUMBERS_MATCH: &'static str = "check-test-line-numbers-match"; pub const CHECK_TEST_LINE_NUMBERS_MATCH: &'static str = "check-test-line-numbers-match";
@ -231,6 +235,7 @@ pub fn new() -> Self {
rustc_env: vec![], rustc_env: vec![],
unset_rustc_env: vec![], unset_rustc_env: vec![],
exec_env: vec![], exec_env: vec![],
unset_exec_env: vec![],
build_aux_docs: false, build_aux_docs: false,
force_host: false, force_host: false,
check_stdout: false, check_stdout: false,
@ -382,6 +387,12 @@ fn load_from(&mut self, testfile: &Path, cfg: Option<&str>, config: &Config) {
&mut self.exec_env, &mut self.exec_env,
Config::parse_env, Config::parse_env,
); );
config.push_name_value_directive(
ln,
UNSET_EXEC_ENV,
&mut self.unset_exec_env,
|r| r,
);
config.push_name_value_directive( config.push_name_value_directive(
ln, ln,
RUSTC_ENV, RUSTC_ENV,

View File

@ -165,11 +165,15 @@ macro_rules! condition {
message: "when the architecture is part of the Thumb family" message: "when the architecture is part of the Thumb family"
} }
// Technically the locally built compiler uses the "dev" channel rather than the "nightly"
// channel, even though most people don't know or won't care about it. To avoid confusion, we
// treat the "dev" channel as the "nightly" channel when processing the directive.
condition! { condition! {
name: &config.channel, name: if config.channel == "dev" { "nightly" } else { &config.channel },
allowed_names: &["stable", "beta", "nightly"], allowed_names: &["stable", "beta", "nightly"],
message: "when the release channel is {name}", message: "when the release channel is {name}",
} }
condition! { condition! {
name: "cross-compile", name: "cross-compile",
condition: config.target != config.host, condition: config.target != config.host,

View File

@ -1614,8 +1614,13 @@ fn exec_compiled_test(&self) -> ProcRes {
test_client test_client
.args(&["run", &support_libs.len().to_string(), &prog]) .args(&["run", &support_libs.len().to_string(), &prog])
.args(support_libs) .args(support_libs)
.args(args) .args(args);
.envs(env.clone());
for key in &self.props.unset_exec_env {
test_client.env_remove(key);
}
test_client.envs(env.clone());
self.compose_and_run( self.compose_and_run(
test_client, test_client,
self.config.run_lib_path.to_str().unwrap(), self.config.run_lib_path.to_str().unwrap(),
@ -1627,7 +1632,13 @@ fn exec_compiled_test(&self) -> ProcRes {
let aux_dir = self.aux_output_dir_name(); let aux_dir = self.aux_output_dir_name();
let ProcArgs { prog, args } = self.make_run_args(); let ProcArgs { prog, args } = self.make_run_args();
let mut wr_run = Command::new("wr-run"); let mut wr_run = Command::new("wr-run");
wr_run.args(&[&prog]).args(args).envs(env.clone()); wr_run.args(&[&prog]).args(args);
for key in &self.props.unset_exec_env {
wr_run.env_remove(key);
}
wr_run.envs(env.clone());
self.compose_and_run( self.compose_and_run(
wr_run, wr_run,
self.config.run_lib_path.to_str().unwrap(), self.config.run_lib_path.to_str().unwrap(),
@ -1639,7 +1650,13 @@ fn exec_compiled_test(&self) -> ProcRes {
let aux_dir = self.aux_output_dir_name(); let aux_dir = self.aux_output_dir_name();
let ProcArgs { prog, args } = self.make_run_args(); let ProcArgs { prog, args } = self.make_run_args();
let mut program = Command::new(&prog); let mut program = Command::new(&prog);
program.args(args).current_dir(&self.output_base_dir()).envs(env.clone()); program.args(args).current_dir(&self.output_base_dir());
for key in &self.props.unset_exec_env {
program.env_remove(key);
}
program.envs(env.clone());
self.compose_and_run( self.compose_and_run(
program, program,
self.config.run_lib_path.to_str().unwrap(), self.config.run_lib_path.to_str().unwrap(),

View File

@ -0,0 +1,18 @@
// no-prefer-dynamic
// compile-flags: --test
// run-flags: --list --format json -Zunstable-options
// run-fail
// check-run-results
// ignore-nightly
// unset-exec-env:RUSTC_BOOTSTRAP
#![cfg(test)]
#[test]
fn m_test() {}
#[test]
#[ignore = "not yet implemented"]
fn z_test() {}
#[test]
fn a_test() {}

View File

@ -0,0 +1 @@
error: the option `Z` is only accepted on the nightly compiler

View File

@ -3,6 +3,7 @@
// run-flags: --list --format json -Zunstable-options // run-flags: --list --format json -Zunstable-options
// run-pass // run-pass
// check-run-results // check-run-results
// only-nightly
// normalize-stdout-test: "fake-test-src-base/test-attrs/" -> "$$DIR/" // normalize-stdout-test: "fake-test-src-base/test-attrs/" -> "$$DIR/"
// normalize-stdout-test: "fake-test-src-base\\test-attrs\\" -> "$$DIR/" // normalize-stdout-test: "fake-test-src-base\\test-attrs\\" -> "$$DIR/"

View File

@ -1,5 +1,5 @@
{ "type": "suite", "event": "discovery" } { "type": "suite", "event": "discovery" }
{ "type": "test", "event": "discovered", "name": "a_test", "ignore": false, "ignore_message": "", "source_path": "$DIR/tests-listing-format-json.rs", "start_line": 20, "start_col": 4, "end_line": 20, "end_col": 10 } { "type": "test", "event": "discovered", "name": "a_test", "ignore": false, "ignore_message": "", "source_path": "$DIR/tests-listing-format-json.rs", "start_line": 21, "start_col": 4, "end_line": 21, "end_col": 10 }
{ "type": "test", "event": "discovered", "name": "m_test", "ignore": false, "ignore_message": "", "source_path": "$DIR/tests-listing-format-json.rs", "start_line": 13, "start_col": 4, "end_line": 13, "end_col": 10 } { "type": "test", "event": "discovered", "name": "m_test", "ignore": false, "ignore_message": "", "source_path": "$DIR/tests-listing-format-json.rs", "start_line": 14, "start_col": 4, "end_line": 14, "end_col": 10 }
{ "type": "test", "event": "discovered", "name": "z_test", "ignore": true, "ignore_message": "not yet implemented", "source_path": "$DIR/tests-listing-format-json.rs", "start_line": 17, "start_col": 4, "end_line": 17, "end_col": 10 } { "type": "test", "event": "discovered", "name": "z_test", "ignore": true, "ignore_message": "not yet implemented", "source_path": "$DIR/tests-listing-format-json.rs", "start_line": 18, "start_col": 4, "end_line": 18, "end_col": 10 }
{ "type": "suite", "event": "completed", "tests": 3, "benchmarks": 0, "total": 3, "ignored": 1 } { "type": "suite", "event": "completed", "tests": 3, "benchmarks": 0, "total": 3, "ignored": 1 }