Skip to content

Commit fbc39af

Browse files
committed
Privatize most TestProcess fields
1 parent bbb3e6e commit fbc39af

File tree

5 files changed

+26
-32
lines changed

5 files changed

+26
-32
lines changed

src/cli/self_update.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,17 +1341,17 @@ mod tests {
13411341
use crate::cli::self_update::InstallOpts;
13421342
use crate::dist::dist::{PartialToolchainDesc, Profile};
13431343
use crate::test::{test_dir, with_rustup_home, Env};
1344-
use crate::{currentprocess, for_host};
1344+
use crate::{
1345+
currentprocess::{self, TestProcess},
1346+
for_host,
1347+
};
13451348

13461349
#[test]
13471350
fn default_toolchain_is_stable() {
13481351
with_rustup_home(|home| {
13491352
let mut vars = HashMap::new();
13501353
home.apply(&mut vars);
1351-
let tp = currentprocess::TestProcess {
1352-
vars,
1353-
..Default::default()
1354-
};
1354+
let tp = TestProcess::with_vars(vars);
13551355

13561356
let opts = InstallOpts {
13571357
default_host_triple: None,
@@ -1399,10 +1399,7 @@ info: default host triple is {0}
13991399
let cargo_home = root_dir.path().join("cargo");
14001400
let mut vars = HashMap::new();
14011401
vars.env("CARGO_HOME", cargo_home.to_string_lossy().to_string());
1402-
let tp = currentprocess::TestProcess {
1403-
vars,
1404-
..Default::default()
1405-
};
1402+
let tp = TestProcess::with_vars(vars);
14061403
currentprocess::with(tp.clone().into(), || -> Result<()> {
14071404
let process = tp.clone().into();
14081405
super::install_bins(&process).unwrap();

src/cli/self_update/windows.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -836,13 +836,12 @@ mod tests {
836836
#[test]
837837
fn windows_doesnt_mess_with_a_non_string_path() {
838838
// This writes an error, so we want a sink for it.
839-
let tp = currentprocess::TestProcess {
840-
vars: [("HOME".to_string(), "/unused".to_string())]
839+
let tp = currentprocess::TestProcess::with_vars(
840+
[("HOME".to_string(), "/unused".to_string())]
841841
.iter()
842842
.cloned()
843843
.collect(),
844-
..Default::default()
845-
};
844+
);
846845
let process = Process::from(tp.clone());
847846
with_saved_path(&mut || {
848847
currentprocess::with(tp.clone().into(), || {

src/currentprocess.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,22 @@ impl Default for OSProcess {
283283
#[derive(Clone, Debug, Default)]
284284
pub struct TestProcess {
285285
pub cwd: PathBuf,
286-
pub args: Vec<String>,
287-
pub vars: HashMap<String, String>,
288-
pub stdin: filesource::TestStdinInner,
289-
pub stdout: filesource::TestWriterInner,
290-
pub stderr: filesource::TestWriterInner,
286+
args: Vec<String>,
287+
vars: HashMap<String, String>,
288+
stdin: filesource::TestStdinInner,
289+
stdout: filesource::TestWriterInner,
290+
stderr: filesource::TestWriterInner,
291291
}
292292

293293
#[cfg(feature = "test")]
294294
impl TestProcess {
295+
pub fn with_vars(vars: HashMap<String, String>) -> Self {
296+
Self {
297+
vars,
298+
..Default::default()
299+
}
300+
}
301+
295302
pub fn new<P: AsRef<Path>, A: AsRef<str>>(
296303
cwd: P,
297304
args: &[A],

src/diskio/test.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustup_macros::unit_test as test;
77
use crate::test::test_dir;
88

99
use super::{get_executor, Executor, Item, Kind};
10-
use crate::currentprocess;
10+
use crate::currentprocess::{self, TestProcess};
1111

1212
impl Item {
1313
/// The length of the file, for files (for stats)
@@ -23,10 +23,7 @@ fn test_incremental_file(io_threads: &str) -> Result<()> {
2323
let work_dir = test_dir()?;
2424
let mut vars = HashMap::new();
2525
vars.insert("RUSTUP_IO_THREADS".to_string(), io_threads.to_string());
26-
let tp = currentprocess::TestProcess {
27-
vars,
28-
..Default::default()
29-
};
26+
let tp = TestProcess::with_vars(vars);
3027
currentprocess::with(tp.clone().into(), || -> Result<()> {
3128
let mut written = 0;
3229
let mut file_finished = false;
@@ -97,10 +94,7 @@ fn test_complete_file(io_threads: &str) -> Result<()> {
9794
let work_dir = test_dir()?;
9895
let mut vars = HashMap::new();
9996
vars.insert("RUSTUP_IO_THREADS".to_string(), io_threads.to_string());
100-
let tp = currentprocess::TestProcess {
101-
vars,
102-
..Default::default()
103-
};
97+
let tp = TestProcess::with_vars(vars);
10498
currentprocess::with(tp.clone().into(), || -> Result<()> {
10599
let process = tp.clone().into();
106100
let mut io_executor: Box<dyn Executor> = get_executor(None, 32 * 1024 * 1024, &process)?;

src/env_var.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ mod tests {
4949
use rustup_macros::unit_test as test;
5050

5151
use super::*;
52-
use crate::currentprocess;
52+
use crate::currentprocess::{self, TestProcess};
5353
use crate::test::{with_saved_path, Env};
5454

5555
#[test]
@@ -59,10 +59,7 @@ mod tests {
5959
"PATH",
6060
env::join_paths(["/home/a/.cargo/bin", "/home/b/.cargo/bin"].iter()).unwrap(),
6161
);
62-
let tp = currentprocess::TestProcess {
63-
vars,
64-
..Default::default()
65-
};
62+
let tp = TestProcess::with_vars(vars);
6663
with_saved_path(&mut || {
6764
currentprocess::with(tp.clone().into(), || {
6865
let mut path_entries = vec![];

0 commit comments

Comments
 (0)