Skip to content

Commit 6278bba

Browse files
authored
Merge pull request #2428 from rbtcollins/unit-tests
Better tests for cargo_home creation
2 parents 0443b19 + c712813 commit 6278bba

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

src/cli/self_update.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ mod test {
10921092

10931093
use crate::cli::common;
10941094
use crate::dist::dist::ToolchainDesc;
1095-
use crate::test::with_rustup_home;
1095+
use crate::test::{test_dir, with_rustup_home, Env};
10961096
use crate::{currentprocess, for_host};
10971097

10981098
#[test]
@@ -1140,4 +1140,22 @@ info: default host triple is {0}
11401140
})
11411141
.unwrap();
11421142
}
1143+
1144+
#[test]
1145+
fn install_bins_creates_cargo_home() {
1146+
let root_dir = test_dir().unwrap();
1147+
let cargo_home = root_dir.path().join("cargo");
1148+
let mut vars = HashMap::new();
1149+
vars.env("CARGO_HOME", cargo_home.to_string_lossy().to_string());
1150+
let tp = Box::new(currentprocess::TestProcess {
1151+
vars,
1152+
..Default::default()
1153+
});
1154+
currentprocess::with(tp.clone(), || -> anyhow::Result<()> {
1155+
super::install_bins().unwrap();
1156+
Ok(())
1157+
})
1158+
.unwrap();
1159+
assert!(cargo_home.exists());
1160+
}
11431161
}

tests/cli-self-upd.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,23 @@ fn install_twice() {
154154
}
155155

156156
#[test]
157+
/// Smoke test for the entire install process when dirs need to be made :
158+
/// depending just on unit tests here could miss subtle dependencies being added
159+
/// earlier in the code, so a black-box test is needed.
157160
fn install_creates_cargo_home() {
158-
setup(&|config| {
161+
clitools::setup(Scenario::Empty, &|config| {
159162
remove_dir_all(&config.cargodir).unwrap();
160163
config.rustupdir.remove().unwrap();
161-
expect_ok(config, &["rustup-init", "-y"]);
164+
expect_ok(
165+
config,
166+
&[
167+
"rustup-init",
168+
"-y",
169+
"--no-modify-path",
170+
"--default-toolchain",
171+
"none",
172+
],
173+
);
162174
assert!(config.cargodir.exists());
163175
});
164176
}

tests/mock/clitools.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ pub struct Config {
5151
// Building the mock server is slow, so use simple scenario when possible.
5252
#[derive(PartialEq, Copy, Clone)]
5353
pub enum Scenario {
54+
/// No dist server content
55+
Empty,
5456
/// Two dates, two manifests
5557
Full,
5658
/// Two dates, v2 manifests
@@ -750,6 +752,7 @@ impl Release {
750752
// Creates a mock dist server populated with some test data
751753
fn create_mock_dist_server(path: &Path, s: Scenario) {
752754
let chans = match s {
755+
Scenario::Empty => vec![],
753756
Scenario::MissingComponent => vec![
754757
Release::new("nightly", "1.37.0", "2019-09-12", "1"),
755758
Release::new("nightly", "1.37.0", "2019-09-13", "2"),
@@ -808,6 +811,7 @@ fn create_mock_dist_server(path: &Path, s: Scenario) {
808811
};
809812

810813
let vs = match s {
814+
Scenario::Empty => vec![],
811815
Scenario::Full => vec![ManifestVersion::V1, ManifestVersion::V2],
812816
Scenario::SimpleV1 | Scenario::ArchivesV1 => vec![ManifestVersion::V1],
813817
Scenario::SimpleV2

0 commit comments

Comments
 (0)