Skip to content

Commit 2332ad8

Browse files
committed
chore(rustup): test installed toolchains
1 parent 51f46f2 commit 2332ad8

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

src/rustup.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,19 @@ pub fn active_toolchain(msg_info: &mut MessageInfo) -> Result<String> {
8484
}
8585

8686
pub fn installed_toolchains(msg_info: &mut MessageInfo) -> Result<Vec<String>> {
87-
let out = rustup_command(msg_info, true)
88-
.args(["toolchain", "list"]) // --quiet would be available from 1.28.0
89-
.run_and_get_stdout(msg_info)?;
87+
Ok(remove_toolchain_suffixes(
88+
rustup_command(msg_info, true)
89+
.args(["toolchain", "list"]) // --quiet would be available from 1.28.0
90+
.run_and_get_stdout(msg_info)?,
91+
))
92+
}
9093

91-
// Emulate --quiet by removing suffixes like " (active, default)" or " (override)" manually
92-
Ok(out
94+
pub(crate) fn remove_toolchain_suffixes<S: AsRef<str>>(out: S) -> Vec<String> {
95+
// Emulate --quiet by removing suffixes like " (active, default)" manually
96+
out.as_ref()
9397
.lines()
9498
.map(|l| l.split_once(" (").map_or(l.trim(), |(a, _)| a).to_owned())
95-
.collect())
99+
.collect()
96100
}
97101

98102
pub fn available_targets(

src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mod rustup;
12
mod toml;
23

34
use std::{

src/tests/rustup.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use crate::rustup;
2+
3+
#[test]
4+
fn remove_toolchain_suffixes() {
5+
// no overrides (default is active)
6+
assert_eq!(
7+
rustup::remove_toolchain_suffixes(
8+
"stable-aarch64-apple-darwin (active, default)\n\
9+
stable-x86_64-unknown-linux-gnu"
10+
),
11+
vec![
12+
"stable-aarch64-apple-darwin",
13+
"stable-x86_64-unknown-linux-gnu",
14+
]
15+
);
16+
// with overrides (default is not active)
17+
assert_eq!(
18+
rustup::remove_toolchain_suffixes(
19+
"stable-aarch64-apple-darwin (default)\n\
20+
stable-x86_64-unknown-linux-gnu\n\
21+
nightly-aarch64-apple-darwin (active)"
22+
),
23+
vec![
24+
"stable-aarch64-apple-darwin",
25+
"stable-x86_64-unknown-linux-gnu",
26+
"nightly-aarch64-apple-darwin",
27+
]
28+
);
29+
}

0 commit comments

Comments
 (0)