Skip to content

Commit c2c26ed

Browse files
committed
Remove currentprocess::with()
1 parent fbc39af commit c2c26ed

File tree

10 files changed

+333
-384
lines changed

10 files changed

+333
-384
lines changed

src/cli/self_update.rs

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,25 +1333,23 @@ pub(crate) fn cleanup_self_updater(process: &Process) -> Result<()> {
13331333
mod tests {
13341334
use std::collections::HashMap;
13351335

1336-
use anyhow::Result;
1337-
13381336
use rustup_macros::unit_test as test;
13391337

13401338
use crate::cli::common;
13411339
use crate::cli::self_update::InstallOpts;
13421340
use crate::dist::dist::{PartialToolchainDesc, Profile};
13431341
use crate::test::{test_dir, with_rustup_home, Env};
1344-
use crate::{
1345-
currentprocess::{self, TestProcess},
1346-
for_host,
1347-
};
1342+
use crate::{currentprocess::TestProcess, for_host};
13481343

13491344
#[test]
13501345
fn default_toolchain_is_stable() {
13511346
with_rustup_home(|home| {
13521347
let mut vars = HashMap::new();
13531348
home.apply(&mut vars);
13541349
let tp = TestProcess::with_vars(vars);
1350+
let mut cfg =
1351+
common::set_globals(tp.process.current_dir().unwrap(), false, false, &tp.process)
1352+
.unwrap();
13551353

13561354
let opts = InstallOpts {
13571355
default_host_triple: None,
@@ -1363,30 +1361,23 @@ mod tests {
13631361
no_update_toolchain: false,
13641362
};
13651363

1366-
currentprocess::with(tp.clone().into(), || -> Result<()> {
1367-
// TODO: we could pass in a custom cfg to get notification
1368-
// callbacks rather than output to the tp sink.
1369-
let process = tp.clone().into();
1370-
let mut cfg = common::set_globals(tp.cwd.clone(), false, false, &process).unwrap();
1371-
assert_eq!(
1372-
"stable"
1373-
.parse::<PartialToolchainDesc>()
1374-
.unwrap()
1375-
.resolve(&cfg.get_default_host_triple().unwrap())
1376-
.unwrap(),
1377-
opts.install(&mut cfg)
1378-
.unwrap() // result
1379-
.unwrap() // option
1380-
);
1381-
Ok(())
1382-
})?;
1364+
assert_eq!(
1365+
"stable"
1366+
.parse::<PartialToolchainDesc>()
1367+
.unwrap()
1368+
.resolve(&cfg.get_default_host_triple().unwrap())
1369+
.unwrap(),
1370+
opts.install(&mut cfg)
1371+
.unwrap() // result
1372+
.unwrap() // option
1373+
);
13831374
assert_eq!(
13841375
for_host!(
13851376
r"info: profile set to 'default'
13861377
info: default host triple is {0}
13871378
"
13881379
),
1389-
&String::from_utf8(tp.get_stderr()).unwrap()
1380+
&String::from_utf8(tp.stderr()).unwrap()
13901381
);
13911382
Ok(())
13921383
})
@@ -1400,12 +1391,7 @@ info: default host triple is {0}
14001391
let mut vars = HashMap::new();
14011392
vars.env("CARGO_HOME", cargo_home.to_string_lossy().to_string());
14021393
let tp = TestProcess::with_vars(vars);
1403-
currentprocess::with(tp.clone().into(), || -> Result<()> {
1404-
let process = tp.clone().into();
1405-
super::install_bins(&process).unwrap();
1406-
Ok(())
1407-
})
1408-
.unwrap();
1394+
super::install_bins(&tp.process).unwrap();
14091395
assert!(cargo_home.exists());
14101396
}
14111397
}

src/cli/self_update/windows.rs

Lines changed: 67 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ mod tests {
730730

731731
use rustup_macros::unit_test as test;
732732

733-
use crate::currentprocess::{self, Process};
733+
use crate::currentprocess::TestProcess;
734734
use crate::test::with_saved_path;
735735

736736
fn wide(str: &str) -> Vec<u16> {
@@ -771,28 +771,25 @@ mod tests {
771771
#[test]
772772
fn windows_path_regkey_type() {
773773
// per issue #261, setting PATH should use REG_EXPAND_SZ.
774-
let tp = currentprocess::TestProcess::default();
775774
with_saved_path(&mut || {
776-
currentprocess::with(tp.clone().into(), || {
777-
let root = RegKey::predef(HKEY_CURRENT_USER);
778-
let environment = root
779-
.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE)
780-
.unwrap();
781-
environment.delete_value("PATH").unwrap();
782-
783-
{
784-
// Can't compare the Results as Eq isn't derived; thanks error-chain.
785-
#![allow(clippy::unit_cmp)]
786-
assert_eq!((), super::_apply_new_path(Some(wide("foo"))).unwrap());
787-
}
788-
let root = RegKey::predef(HKEY_CURRENT_USER);
789-
let environment = root
790-
.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE)
791-
.unwrap();
792-
let path = environment.get_raw_value("PATH").unwrap();
793-
assert_eq!(path.vtype, RegType::REG_EXPAND_SZ);
794-
assert_eq!(super::to_winreg_bytes(wide("foo")), &path.bytes[..]);
795-
})
775+
let root = RegKey::predef(HKEY_CURRENT_USER);
776+
let environment = root
777+
.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE)
778+
.unwrap();
779+
environment.delete_value("PATH").unwrap();
780+
781+
{
782+
// Can't compare the Results as Eq isn't derived; thanks error-chain.
783+
#![allow(clippy::unit_cmp)]
784+
assert_eq!((), super::_apply_new_path(Some(wide("foo"))).unwrap());
785+
}
786+
let root = RegKey::predef(HKEY_CURRENT_USER);
787+
let environment = root
788+
.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE)
789+
.unwrap();
790+
let path = environment.get_raw_value("PATH").unwrap();
791+
assert_eq!(path.vtype, RegType::REG_EXPAND_SZ);
792+
assert_eq!(super::to_winreg_bytes(wide("foo")), &path.bytes[..]);
796793
});
797794
}
798795

@@ -801,87 +798,78 @@ mod tests {
801798
use std::io;
802799
// during uninstall the PATH key may end up empty; if so we should
803800
// delete it.
804-
let tp = currentprocess::TestProcess::default();
805801
with_saved_path(&mut || {
806-
currentprocess::with(tp.clone().into(), || {
807-
let root = RegKey::predef(HKEY_CURRENT_USER);
808-
let environment = root
809-
.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE)
810-
.unwrap();
811-
environment
812-
.set_raw_value(
813-
"PATH",
814-
&RegValue {
815-
bytes: super::to_winreg_bytes(wide("foo")),
816-
vtype: RegType::REG_EXPAND_SZ,
817-
},
818-
)
819-
.unwrap();
820-
821-
{
822-
// Can't compare the Results as Eq isn't derived; thanks error-chain.
823-
#![allow(clippy::unit_cmp)]
824-
assert_eq!((), super::_apply_new_path(Some(Vec::new())).unwrap());
825-
}
826-
let reg_value = environment.get_raw_value("PATH");
827-
match reg_value {
828-
Ok(_) => panic!("key not deleted"),
829-
Err(ref e) if e.kind() == io::ErrorKind::NotFound => {}
830-
Err(ref e) => panic!("error {e}"),
831-
}
832-
})
802+
let root = RegKey::predef(HKEY_CURRENT_USER);
803+
let environment = root
804+
.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE)
805+
.unwrap();
806+
environment
807+
.set_raw_value(
808+
"PATH",
809+
&RegValue {
810+
bytes: super::to_winreg_bytes(wide("foo")),
811+
vtype: RegType::REG_EXPAND_SZ,
812+
},
813+
)
814+
.unwrap();
815+
816+
{
817+
// Can't compare the Results as Eq isn't derived; thanks error-chain.
818+
#![allow(clippy::unit_cmp)]
819+
assert_eq!((), super::_apply_new_path(Some(Vec::new())).unwrap());
820+
}
821+
let reg_value = environment.get_raw_value("PATH");
822+
match reg_value {
823+
Ok(_) => panic!("key not deleted"),
824+
Err(ref e) if e.kind() == io::ErrorKind::NotFound => {}
825+
Err(ref e) => panic!("error {e}"),
826+
}
833827
});
834828
}
835829

836830
#[test]
837831
fn windows_doesnt_mess_with_a_non_string_path() {
838832
// This writes an error, so we want a sink for it.
839-
let tp = currentprocess::TestProcess::with_vars(
833+
let tp = TestProcess::with_vars(
840834
[("HOME".to_string(), "/unused".to_string())]
841835
.iter()
842836
.cloned()
843837
.collect(),
844838
);
845-
let process = Process::from(tp.clone());
846839
with_saved_path(&mut || {
847-
currentprocess::with(tp.clone().into(), || {
848-
let root = RegKey::predef(HKEY_CURRENT_USER);
849-
let environment = root
850-
.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE)
851-
.unwrap();
852-
let reg_value = RegValue {
853-
bytes: vec![0x12, 0x34],
854-
vtype: RegType::REG_BINARY,
855-
};
856-
environment.set_raw_value("PATH", &reg_value).unwrap();
857-
// Ok(None) signals no change to the PATH setting layer
858-
assert_eq!(
859-
None,
860-
super::_with_path_cargo_home_bin(|_, _| panic!("called"), &process).unwrap()
861-
);
862-
})
840+
let root = RegKey::predef(HKEY_CURRENT_USER);
841+
let environment = root
842+
.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE)
843+
.unwrap();
844+
let reg_value = RegValue {
845+
bytes: vec![0x12, 0x34],
846+
vtype: RegType::REG_BINARY,
847+
};
848+
environment.set_raw_value("PATH", &reg_value).unwrap();
849+
// Ok(None) signals no change to the PATH setting layer
850+
assert_eq!(
851+
None,
852+
super::_with_path_cargo_home_bin(|_, _| panic!("called"), &tp.process).unwrap()
853+
);
863854
});
864855
assert_eq!(
865856
r"warning: the registry key HKEY_CURRENT_USER\Environment\PATH is not a string. Not modifying the PATH variable
866857
",
867-
String::from_utf8(tp.get_stderr()).unwrap()
858+
String::from_utf8(tp.stderr()).unwrap()
868859
);
869860
}
870861

871862
#[test]
872863
fn windows_treat_missing_path_as_empty() {
873864
// during install the PATH key may be missing; treat it as empty
874-
let tp = currentprocess::TestProcess::default();
875865
with_saved_path(&mut || {
876-
currentprocess::with(tp.clone().into(), || {
877-
let root = RegKey::predef(HKEY_CURRENT_USER);
878-
let environment = root
879-
.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE)
880-
.unwrap();
881-
environment.delete_value("PATH").unwrap();
882-
883-
assert_eq!(Some(Vec::new()), super::get_windows_path_var().unwrap());
884-
})
866+
let root = RegKey::predef(HKEY_CURRENT_USER);
867+
let environment = root
868+
.open_subkey_with_flags("Environment", KEY_READ | KEY_WRITE)
869+
.unwrap();
870+
environment.delete_value("PATH").unwrap();
871+
872+
assert_eq!(Some(Vec::new()), super::get_windows_path_var().unwrap());
885873
});
886874
}
887875

0 commit comments

Comments
 (0)