Skip to content

Commit

Permalink
add support for // unset-exec-env in compiletest
Browse files Browse the repository at this point in the history
  • Loading branch information
pietroalbini committed Apr 21, 2023
1 parent 2bf5f77 commit 4edba55
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ pub struct TestProps {
pub unset_rustc_env: Vec<String>,
// 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<String>,
// 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
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
25 changes: 21 additions & 4 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand Down

0 comments on commit 4edba55

Please sign in to comment.