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 68deacd commit 8cd7ebe
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 28 deletions.
15 changes: 6 additions & 9 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1366,17 +1366,17 @@ mod tests {
use crate::cli::common;
use crate::dist::dist::PartialToolchainDesc;
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);
currentprocess::with(tp.clone().into(), || -> Result<()> {
// TODO: we could pass in a custom cfg to get notification
// callbacks rather than output to the tp sink.
Expand Down Expand Up @@ -1421,10 +1421,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
16 changes: 11 additions & 5 deletions src/currentprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,21 @@ 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 {
let mut new = Self::default();
new.vars = vars;
new
}

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 8cd7ebe

Please sign in to comment.