Skip to content

Commit

Permalink
Privatize most TestProcess fields
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Jun 15, 2024
1 parent bbb3e6e commit fbc39af
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 32 deletions.
15 changes: 6 additions & 9 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,17 +1341,17 @@ mod tests {
use crate::cli::self_update::InstallOpts;
use crate::dist::dist::{PartialToolchainDesc, Profile};
use crate::test::{test_dir, with_rustup_home, Env};
use crate::{currentprocess, for_host};
use crate::{
currentprocess::{self, TestProcess},
for_host,
};

#[test]
fn default_toolchain_is_stable() {
with_rustup_home(|home| {
let mut vars = HashMap::new();
home.apply(&mut vars);
let tp = currentprocess::TestProcess {
vars,
..Default::default()
};
let tp = TestProcess::with_vars(vars);

let opts = InstallOpts {
default_host_triple: None,
Expand Down Expand Up @@ -1399,10 +1399,7 @@ info: default host triple is {0}
let cargo_home = root_dir.path().join("cargo");
let mut vars = HashMap::new();
vars.env("CARGO_HOME", cargo_home.to_string_lossy().to_string());
let tp = currentprocess::TestProcess {
vars,
..Default::default()
};
let tp = TestProcess::with_vars(vars);
currentprocess::with(tp.clone().into(), || -> Result<()> {
let process = tp.clone().into();
super::install_bins(&process).unwrap();
Expand Down
7 changes: 3 additions & 4 deletions src/cli/self_update/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,13 +836,12 @@ mod tests {
#[test]
fn windows_doesnt_mess_with_a_non_string_path() {
// This writes an error, so we want a sink for it.
let tp = currentprocess::TestProcess {
vars: [("HOME".to_string(), "/unused".to_string())]
let tp = currentprocess::TestProcess::with_vars(
[("HOME".to_string(), "/unused".to_string())]
.iter()
.cloned()
.collect(),
..Default::default()
};
);
let process = Process::from(tp.clone());
with_saved_path(&mut || {
currentprocess::with(tp.clone().into(), || {
Expand Down
17 changes: 12 additions & 5 deletions src/currentprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,22 @@ impl Default for OSProcess {
#[derive(Clone, Debug, Default)]
pub struct TestProcess {
pub cwd: PathBuf,
pub args: Vec<String>,
pub vars: HashMap<String, String>,
pub stdin: filesource::TestStdinInner,
pub stdout: filesource::TestWriterInner,
pub stderr: filesource::TestWriterInner,
args: Vec<String>,
vars: HashMap<String, String>,
stdin: filesource::TestStdinInner,
stdout: filesource::TestWriterInner,
stderr: filesource::TestWriterInner,
}

#[cfg(feature = "test")]
impl TestProcess {
pub fn with_vars(vars: HashMap<String, String>) -> Self {
Self {
vars,
..Default::default()
}
}

pub fn new<P: AsRef<Path>, A: AsRef<str>>(
cwd: P,
args: &[A],
Expand Down
12 changes: 3 additions & 9 deletions src/diskio/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustup_macros::unit_test as test;
use crate::test::test_dir;

use super::{get_executor, Executor, Item, Kind};
use crate::currentprocess;
use crate::currentprocess::{self, TestProcess};

impl Item {
/// The length of the file, for files (for stats)
Expand All @@ -23,10 +23,7 @@ fn test_incremental_file(io_threads: &str) -> Result<()> {
let work_dir = test_dir()?;
let mut vars = HashMap::new();
vars.insert("RUSTUP_IO_THREADS".to_string(), io_threads.to_string());
let tp = currentprocess::TestProcess {
vars,
..Default::default()
};
let tp = TestProcess::with_vars(vars);
currentprocess::with(tp.clone().into(), || -> Result<()> {
let mut written = 0;
let mut file_finished = false;
Expand Down Expand Up @@ -97,10 +94,7 @@ fn test_complete_file(io_threads: &str) -> Result<()> {
let work_dir = test_dir()?;
let mut vars = HashMap::new();
vars.insert("RUSTUP_IO_THREADS".to_string(), io_threads.to_string());
let tp = currentprocess::TestProcess {
vars,
..Default::default()
};
let tp = TestProcess::with_vars(vars);
currentprocess::with(tp.clone().into(), || -> Result<()> {
let process = tp.clone().into();
let mut io_executor: Box<dyn Executor> = get_executor(None, 32 * 1024 * 1024, &process)?;
Expand Down
7 changes: 2 additions & 5 deletions src/env_var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mod tests {
use rustup_macros::unit_test as test;

use super::*;
use crate::currentprocess;
use crate::currentprocess::{self, TestProcess};
use crate::test::{with_saved_path, Env};

#[test]
Expand All @@ -59,10 +59,7 @@ mod tests {
"PATH",
env::join_paths(["/home/a/.cargo/bin", "/home/b/.cargo/bin"].iter()).unwrap(),
);
let tp = currentprocess::TestProcess {
vars,
..Default::default()
};
let tp = TestProcess::with_vars(vars);
with_saved_path(&mut || {
currentprocess::with(tp.clone().into(), || {
let mut path_entries = vec![];
Expand Down

0 comments on commit fbc39af

Please sign in to comment.