2 Star 0 Fork 0

mirrors_matklad/rustup

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cli-exact.rs 17.59 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
//! Yet more cli test cases. These are testing that the output
//! is exactly as expected.
pub mod mock;
use crate::mock::clitools::{
self, expect_err_ex, expect_ok, expect_ok_ex, expect_stdout_ok, set_current_dist_date,
this_host_triple, Config, Scenario,
};
macro_rules! for_host {
($s: expr) => {
&format!($s, this_host_triple())
};
}
fn setup(f: &dyn Fn(&mut Config)) {
clitools::setup(Scenario::ArchivesV2, f);
}
#[test]
fn update() {
setup(&|config| {
expect_ok_ex(
config,
&["rustup", "update", "nightly", "--no-self-update"],
for_host!(
r"
nightly-{0} installed - 1.3.0 (hash-nightly-2)
"
),
for_host!(
r"info: syncing channel updates for 'nightly-{0}'
info: latest update on 2015-01-02, rust version 1.3.0 (hash-nightly-2)
info: downloading component 'cargo'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: installing component 'cargo'
info: Defaulting to 500.0 MiB unpack ram
info: installing component 'rust-docs'
info: installing component 'rust-std'
info: installing component 'rustc'
info: default toolchain set to 'nightly-{0}'
"
),
);
});
}
#[test]
fn update_again() {
setup(&|config| {
expect_ok(config, &["rustup", "update", "nightly", "--no-self-update"]);
expect_ok_ex(
config,
&["rustup", "update", "nightly", "--no-self-update"],
for_host!(
r"
nightly-{0} unchanged - 1.3.0 (hash-nightly-2)
"
),
for_host!(
r"info: syncing channel updates for 'nightly-{0}'
"
),
);
});
}
#[test]
fn check_updates_none() {
setup(&|config| {
set_current_dist_date(config, "2015-01-01");
expect_ok(config, &["rustup", "update", "stable", "--no-self-update"]);
expect_ok(config, &["rustup", "update", "beta", "--no-self-update"]);
expect_ok(config, &["rustup", "update", "nightly", "--no-self-update"]);
expect_stdout_ok(
config,
&["rustup", "check"],
for_host!(
r"stable-{0} - Up to date : 1.0.0 (hash-stable-1.0.0)
beta-{0} - Up to date : 1.1.0 (hash-beta-1.1.0)
nightly-{0} - Up to date : 1.2.0 (hash-nightly-1)
"
),
);
})
}
#[test]
fn check_updates_some() {
setup(&|config| {
set_current_dist_date(config, "2015-01-01");
expect_ok(config, &["rustup", "update", "stable", "--no-self-update"]);
expect_ok(config, &["rustup", "update", "beta", "--no-self-update"]);
expect_ok(config, &["rustup", "update", "nightly", "--no-self-update"]);
set_current_dist_date(config, "2015-01-02");
expect_stdout_ok(
config,
&["rustup", "check"],
for_host!(
r"stable-{0} - Update available : 1.0.0 (hash-stable-1.0.0) -> 1.1.0 (hash-stable-1.1.0)
beta-{0} - Update available : 1.1.0 (hash-beta-1.1.0) -> 1.2.0 (hash-beta-1.2.0)
nightly-{0} - Update available : 1.2.0 (hash-nightly-1) -> 1.3.0 (hash-nightly-2)
"
),
);
})
}
#[test]
fn check_updates_with_update() {
setup(&|config| {
set_current_dist_date(config, "2015-01-01");
expect_ok(config, &["rustup", "update", "stable", "--no-self-update"]);
expect_ok(config, &["rustup", "update", "beta", "--no-self-update"]);
expect_ok(config, &["rustup", "update", "nightly", "--no-self-update"]);
expect_stdout_ok(
config,
&["rustup", "check"],
for_host!(
r"stable-{0} - Up to date : 1.0.0 (hash-stable-1.0.0)
beta-{0} - Up to date : 1.1.0 (hash-beta-1.1.0)
nightly-{0} - Up to date : 1.2.0 (hash-nightly-1)
"
),
);
set_current_dist_date(config, "2015-01-02");
expect_stdout_ok(
config,
&["rustup", "check"],
for_host!(
r"stable-{0} - Update available : 1.0.0 (hash-stable-1.0.0) -> 1.1.0 (hash-stable-1.1.0)
beta-{0} - Update available : 1.1.0 (hash-beta-1.1.0) -> 1.2.0 (hash-beta-1.2.0)
nightly-{0} - Update available : 1.2.0 (hash-nightly-1) -> 1.3.0 (hash-nightly-2)
"
),
);
expect_ok(config, &["rustup", "update", "beta", "--no-self-update"]);
expect_stdout_ok(
config,
&["rustup", "check"],
for_host!(
r"stable-{0} - Update available : 1.0.0 (hash-stable-1.0.0) -> 1.1.0 (hash-stable-1.1.0)
beta-{0} - Up to date : 1.2.0 (hash-beta-1.2.0)
nightly-{0} - Update available : 1.2.0 (hash-nightly-1) -> 1.3.0 (hash-nightly-2)
"
),
);
})
}
#[test]
fn default() {
setup(&|config| {
expect_ok_ex(
config,
&["rustup", "default", "nightly"],
for_host!(
r"
nightly-{0} installed - 1.3.0 (hash-nightly-2)
"
),
for_host!(
r"info: syncing channel updates for 'nightly-{0}'
info: latest update on 2015-01-02, rust version 1.3.0 (hash-nightly-2)
info: downloading component 'cargo'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: installing component 'cargo'
info: Defaulting to 500.0 MiB unpack ram
info: installing component 'rust-docs'
info: installing component 'rust-std'
info: installing component 'rustc'
info: default toolchain set to 'nightly-{0}'
"
),
);
});
}
#[test]
fn override_again() {
setup(&|config| {
let cwd = config.current_dir();
expect_ok(config, &["rustup", "override", "add", "nightly"]);
expect_ok_ex(
config,
&["rustup", "override", "add", "nightly"],
for_host!(
r"
nightly-{} unchanged - 1.3.0 (hash-nightly-2)
"
),
&format!(
r"info: using existing install for 'nightly-{1}'
info: override toolchain for '{}' set to 'nightly-{1}'
",
cwd.display(),
&this_host_triple()
),
);
});
}
#[test]
fn remove_override() {
for keyword in &["remove", "unset"] {
setup(&|config| {
let cwd = config.current_dir();
expect_ok(config, &["rustup", "override", "add", "nightly"]);
expect_ok_ex(
config,
&["rustup", "override", keyword],
r"",
&format!("info: override toolchain for '{}' removed\n", cwd.display()),
);
});
}
}
#[test]
fn remove_override_none() {
for keyword in &["remove", "unset"] {
setup(&|config| {
let cwd = config.current_dir();
expect_ok_ex(
config,
&["rustup", "override", keyword],
r"",
&format!(
"info: no override toolchain for '{}'
info: you may use `--path <path>` option to remove override toolchain for a specific path\n",
cwd.display()
),
);
});
}
}
#[test]
fn remove_override_with_path() {
for keyword in &["remove", "unset"] {
setup(&|config| {
let dir = tempfile::Builder::new()
.prefix("rustup-test")
.tempdir()
.unwrap();
config.change_dir(dir.path(), || {
expect_ok(config, &["rustup", "override", "add", "nightly"]);
});
expect_ok_ex(
config,
&[
"rustup",
"override",
keyword,
"--path",
dir.path().to_str().unwrap(),
],
r"",
&format!(
"info: override toolchain for '{}' removed\n",
dir.path().display()
),
);
});
}
}
#[test]
fn remove_override_with_path_deleted() {
for keyword in &["remove", "unset"] {
setup(&|config| {
let path = {
let dir = tempfile::Builder::new()
.prefix("rustup-test")
.tempdir()
.unwrap();
let path = std::fs::canonicalize(dir.path()).unwrap();
config.change_dir(&path, || {
expect_ok(config, &["rustup", "override", "add", "nightly"]);
});
path
};
expect_ok_ex(
config,
&[
"rustup",
"override",
keyword,
"--path",
path.to_str().unwrap(),
],
r"",
&format!(
"info: override toolchain for '{}' removed\n",
path.display()
),
);
});
}
}
#[test]
#[cfg_attr(target_os = "windows", ignore)] // FIXME #1103
fn remove_override_nonexistent() {
for keyword in &["remove", "unset"] {
setup(&|config| {
let path = {
let dir = tempfile::Builder::new()
.prefix("rustup-test")
.tempdir()
.unwrap();
let path = std::fs::canonicalize(dir.path()).unwrap();
config.change_dir(&path, || {
expect_ok(config, &["rustup", "override", "add", "nightly"]);
});
path
};
// FIXME TempDir seems to succumb to difficulties removing dirs on windows
let _ = rustup::utils::raw::remove_dir(&path);
assert!(!path.exists());
expect_ok_ex(
config,
&["rustup", "override", keyword, "--nonexistent"],
r"",
&format!(
"info: override toolchain for '{}' removed\n",
path.display()
),
);
});
}
}
#[test]
fn list_overrides() {
setup(&|config| {
let cwd = std::fs::canonicalize(config.current_dir()).unwrap();
let mut cwd_formatted = format!("{}", cwd.display());
if cfg!(windows) {
cwd_formatted = cwd_formatted[4..].to_owned();
}
let trip = this_host_triple();
expect_ok(config, &["rustup", "override", "add", "nightly"]);
expect_ok_ex(
config,
&["rustup", "override", "list"],
&format!(
"{:<40}\t{:<20}\n",
cwd_formatted,
&format!("nightly-{}", trip)
),
r"",
);
});
}
#[test]
fn list_overrides_with_nonexistent() {
setup(&|config| {
let trip = this_host_triple();
let nonexistent_path = {
let dir = tempfile::Builder::new()
.prefix("rustup-test")
.tempdir()
.unwrap();
config.change_dir(dir.path(), || {
expect_ok(config, &["rustup", "override", "add", "nightly"]);
});
std::fs::canonicalize(dir.path()).unwrap()
};
// FIXME TempDir seems to succumb to difficulties removing dirs on windows
let _ = rustup::utils::raw::remove_dir(&nonexistent_path);
assert!(!nonexistent_path.exists());
let mut path_formatted = format!("{}", nonexistent_path.display());
if cfg!(windows) {
path_formatted = path_formatted[4..].to_owned();
}
expect_ok_ex(
config,
&["rustup", "override", "list"],
&format!(
"{:<40}\t{:<20}\n\n",
path_formatted + " (not a directory)",
&format!("nightly-{}", trip)
),
"info: you may remove overrides for non-existent directories with
`rustup override unset --nonexistent`\n",
);
});
}
#[test]
fn update_no_manifest() {
setup(&|config| {
expect_err_ex(
config,
&["rustup", "update", "nightly-2016-01-01"],
r"",
for_host!(
r"info: syncing channel updates for 'nightly-2016-01-01-{0}'
error: no release found for 'nightly-2016-01-01'
"
),
);
});
}
// Issue #111
#[test]
fn update_invalid_toolchain() {
setup(&|config| {
expect_err_ex(
config,
&["rustup", "update", "nightly-2016-03-1"],
r"",
r"info: syncing channel updates for 'nightly-2016-03-1'
info: latest update on 2015-01-02, rust version 1.3.0 (hash-nightly-2)
error: target '2016-03-1' not found in channel. Perhaps check https://forge.rust-lang.org/release/platform-support.html for available targets
",
);
});
}
#[test]
fn default_invalid_toolchain() {
setup(&|config| {
expect_err_ex(
config,
&["rustup", "default", "nightly-2016-03-1"],
r"",
r"info: syncing channel updates for 'nightly-2016-03-1'
info: latest update on 2015-01-02, rust version 1.3.0 (hash-nightly-2)
error: target '2016-03-1' not found in channel. Perhaps check https://forge.rust-lang.org/release/platform-support.html for available targets
",
);
});
}
#[test]
fn list_targets() {
setup(&|config| {
let trip = this_host_triple();
let mut sorted = vec![
format!("{} (installed)", &*trip),
format!("{} (installed)", clitools::CROSS_ARCH1),
clitools::CROSS_ARCH2.to_string(),
];
sorted.sort();
let expected = format!("{}\n{}\n{}\n", sorted[0], sorted[1], sorted[2]);
expect_ok(config, &["rustup", "default", "nightly"]);
expect_ok(config, &["rustup", "target", "add", clitools::CROSS_ARCH1]);
expect_ok_ex(config, &["rustup", "target", "list"], &expected, r"");
});
}
#[test]
fn list_installed_targets() {
setup(&|config| {
let trip = this_host_triple();
let mut sorted = vec![
trip,
clitools::CROSS_ARCH1.to_string(),
clitools::CROSS_ARCH2.to_string(),
];
sorted.sort();
let expected = format!("{}\n{}\n{}\n", sorted[0], sorted[1], sorted[2]);
expect_ok(config, &["rustup", "default", "nightly"]);
expect_ok(config, &["rustup", "target", "add", clitools::CROSS_ARCH1]);
expect_ok(config, &["rustup", "target", "add", clitools::CROSS_ARCH2]);
expect_ok_ex(
config,
&["rustup", "target", "list", "--installed"],
&expected,
r"",
);
});
}
#[test]
fn cross_install_indicates_target() {
setup(&|config| {
expect_ok(config, &["rustup", "default", "nightly"]);
// TODO error 'nightly-x86_64-apple-darwin' is not installed
expect_ok_ex(
config,
&["rustup", "target", "add", clitools::CROSS_ARCH1],
r"",
&format!(
r"info: downloading component 'rust-std' for '{0}'
info: installing component 'rust-std' for '{0}'
info: Defaulting to 500.0 MiB unpack ram
",
clitools::CROSS_ARCH1
),
);
});
}
// issue #927
#[test]
fn undefined_linked_toolchain() {
setup(&|config| {
expect_err_ex(
config,
&["cargo", "+bogus", "test"],
r"",
"error: toolchain 'bogus' is not installed\n",
);
});
}
#[test]
fn install_by_version_number() {
setup(&|config| {
expect_ok(config, &["rustup", "default", "0.100.99"]);
})
}
// issue #2191
#[test]
fn install_unreleased_component() {
clitools::setup(Scenario::MissingComponentMulti, &|config| {
// Initial channel content is host + rls + multiarch-std
set_current_dist_date(config, "2019-09-12");
expect_ok(config, &["rustup", "default", "nightly"]);
expect_ok(config, &["rustup", "component", "add", "rls"]);
expect_ok(config, &["rustup", "target", "add", clitools::MULTI_ARCH1]);
// Next channel variant should have host + rls but not multiarch-std
set_current_dist_date(config, "2019-09-13");
expect_ok_ex(
config,
&["rustup", "update", "nightly", "--no-self-update"],
&for_host!(
r"
nightly-{} unchanged - 1.37.0 (hash-nightly-1)
"
),
&format!(
r"info: syncing channel updates for 'nightly-{0}'
info: latest update on 2019-09-13, rust version 1.37.0 (hash-nightly-2)
info: skipping nightly which is missing installed component 'rust-std-{1}'
info: syncing channel updates for 'nightly-2019-09-12-{0}'
",
clitools::this_host_triple(),
clitools::MULTI_ARCH1
),
);
// Next channel variant should have host + multiarch-std but have rls missing
set_current_dist_date(config, "2019-09-14");
expect_ok_ex(
config,
&["rustup", "update", "nightly", "--no-self-update"],
&for_host!(
r"
nightly-{} unchanged - 1.37.0 (hash-nightly-1)
"
),
&format!(
r"info: syncing channel updates for 'nightly-{0}'
info: latest update on 2019-09-14, rust version 1.37.0 (hash-nightly-3)
info: skipping nightly which is missing installed component 'rls'
info: syncing channel updates for 'nightly-2019-09-13-{0}'
info: latest update on 2019-09-13, rust version 1.37.0 (hash-nightly-2)
info: skipping nightly which is missing installed component 'rust-std-{1}'
info: syncing channel updates for 'nightly-2019-09-12-{0}'
",
clitools::this_host_triple(),
clitools::MULTI_ARCH1,
),
);
})
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_matklad/rustup.git
git@gitee.com:mirrors_matklad/rustup.git
mirrors_matklad
rustup
rustup
master

搜索帮助