Skip to content

Commit

Permalink
Extract a common function for setting up environment vars
Browse files Browse the repository at this point in the history
  • Loading branch information
Zalathar committed Jun 28, 2023
1 parent d8d09b0 commit 5b51d9c
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,15 @@ impl<'test> TestCx<'test> {
}

fn exec_compiled_test(&self) -> ProcRes {
let env = &self.props.exec_env;
let prepare_env = |cmd: &mut Command| {
for key in &self.props.unset_exec_env {
cmd.env_remove(key);
}

for (key, val) in &self.props.exec_env {
cmd.env(key, val);
}
};

let proc_res = match &*self.config.target {
// This is pretty similar to below, we're transforming:
Expand Down Expand Up @@ -1635,10 +1643,7 @@ impl<'test> TestCx<'test> {
.args(support_libs)
.args(args);

for key in &self.props.unset_exec_env {
test_client.env_remove(key);
}
test_client.envs(env.clone());
prepare_env(&mut test_client);

self.compose_and_run(
test_client,
Expand All @@ -1653,10 +1658,7 @@ impl<'test> TestCx<'test> {
let mut wr_run = Command::new("wr-run");
wr_run.args(&[&prog]).args(args);

for key in &self.props.unset_exec_env {
wr_run.env_remove(key);
}
wr_run.envs(env.clone());
prepare_env(&mut wr_run);

self.compose_and_run(
wr_run,
Expand All @@ -1671,10 +1673,7 @@ impl<'test> TestCx<'test> {
let mut program = Command::new(&prog);
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());
prepare_env(&mut program);

self.compose_and_run(
program,
Expand Down

0 comments on commit 5b51d9c

Please sign in to comment.