From 2bf5f77696504d86426162364a1e2f9ef8c29f02 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Mon, 17 Apr 2023 11:00:10 +0200 Subject: [PATCH 1/4] treat the dev channel as nightly in compiletest --- src/tools/compiletest/src/header/cfg.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/tools/compiletest/src/header/cfg.rs b/src/tools/compiletest/src/header/cfg.rs index a9694d4d52c..86a749b935d 100644 --- a/src/tools/compiletest/src/header/cfg.rs +++ b/src/tools/compiletest/src/header/cfg.rs @@ -165,11 +165,15 @@ pub(super) fn parse_cfg_name_directive<'a>( 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! { - name: &config.channel, + name: if config.channel == "dev" { "nightly" } else { &config.channel }, allowed_names: &["stable", "beta", "nightly"], message: "when the release channel is {name}", } + condition! { name: "cross-compile", condition: config.target != config.host, From 4edba553c3999ae8b6204484be5e1460be30d741 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Mon, 17 Apr 2023 11:00:29 +0200 Subject: [PATCH 2/4] add support for `// unset-exec-env` in compiletest --- src/tools/compiletest/src/header.rs | 11 +++++++++++ src/tools/compiletest/src/runtest.rs | 25 +++++++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index ccce62bd5b0..89df2b54de3 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -90,6 +90,9 @@ pub struct TestProps { pub unset_rustc_env: Vec, // Environment settings to use during execution 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, // Build documentation for all specified aux-builds as well pub build_aux_docs: bool, // 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 EXEC_ENV: &'static str = "exec-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 FORBID_OUTPUT: &'static str = "forbid-output"; pub const CHECK_TEST_LINE_NUMBERS_MATCH: &'static str = "check-test-line-numbers-match"; @@ -231,6 +235,7 @@ impl TestProps { rustc_env: vec![], unset_rustc_env: vec![], exec_env: vec![], + unset_exec_env: vec![], build_aux_docs: false, force_host: false, check_stdout: false, @@ -382,6 +387,12 @@ impl TestProps { &mut self.exec_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( ln, RUSTC_ENV, diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index f6597c72938..e88074961a6 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1613,8 +1613,13 @@ impl<'test> TestCx<'test> { test_client .args(&["run", &support_libs.len().to_string(), &prog]) .args(support_libs) - .args(args) - .envs(env.clone()); + .args(args); + + for key in &self.props.unset_exec_env { + test_client.env_remove(key); + } + test_client.envs(env.clone()); + self.compose_and_run( test_client, self.config.run_lib_path.to_str().unwrap(), @@ -1626,7 +1631,13 @@ impl<'test> TestCx<'test> { let aux_dir = self.aux_output_dir_name(); let ProcArgs { prog, args } = self.make_run_args(); 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( wr_run, self.config.run_lib_path.to_str().unwrap(), @@ -1638,7 +1649,13 @@ impl<'test> TestCx<'test> { let aux_dir = self.aux_output_dir_name(); let ProcArgs { prog, args } = self.make_run_args(); 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( program, self.config.run_lib_path.to_str().unwrap(), From eb0045973710aa9444bc1e6b3634c2ccc0b99c12 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Mon, 17 Apr 2023 11:00:50 +0200 Subject: [PATCH 3/4] update tests for the test harness's json formatting --- .../feature-gates/test-listing-format-json.rs | 18 ++++++++++++++++++ .../test-listing-format-json.run.stderr | 1 + .../ui/test-attrs/tests-listing-format-json.rs | 1 + 3 files changed, 20 insertions(+) create mode 100644 tests/ui/feature-gates/test-listing-format-json.rs create mode 100644 tests/ui/feature-gates/test-listing-format-json.run.stderr diff --git a/tests/ui/feature-gates/test-listing-format-json.rs b/tests/ui/feature-gates/test-listing-format-json.rs new file mode 100644 index 00000000000..2dd0e10b521 --- /dev/null +++ b/tests/ui/feature-gates/test-listing-format-json.rs @@ -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() {} diff --git a/tests/ui/feature-gates/test-listing-format-json.run.stderr b/tests/ui/feature-gates/test-listing-format-json.run.stderr new file mode 100644 index 00000000000..e81cb81f32c --- /dev/null +++ b/tests/ui/feature-gates/test-listing-format-json.run.stderr @@ -0,0 +1 @@ +error: the option `Z` is only accepted on the nightly compiler diff --git a/tests/ui/test-attrs/tests-listing-format-json.rs b/tests/ui/test-attrs/tests-listing-format-json.rs index 18f1521eeeb..5afc2746fe4 100644 --- a/tests/ui/test-attrs/tests-listing-format-json.rs +++ b/tests/ui/test-attrs/tests-listing-format-json.rs @@ -3,6 +3,7 @@ // run-flags: --list --format json -Zunstable-options // run-pass // 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/" From dc9452207246594ef0d4221b332d218f86750d10 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 28 Apr 2023 09:22:29 -0700 Subject: [PATCH 4/4] bless line changes in tests-listing-format-json.run.stdout --- tests/ui/test-attrs/tests-listing-format-json.run.stdout | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ui/test-attrs/tests-listing-format-json.run.stdout b/tests/ui/test-attrs/tests-listing-format-json.run.stdout index b4131e97c34..33cc939b59f 100644 --- a/tests/ui/test-attrs/tests-listing-format-json.run.stdout +++ b/tests/ui/test-attrs/tests-listing-format-json.run.stdout @@ -1,5 +1,5 @@ { "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": "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": "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": "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": 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": 18, "start_col": 4, "end_line": 18, "end_col": 10 } { "type": "suite", "event": "completed", "tests": 3, "benchmarks": 0, "total": 3, "ignored": 1 }