File tree Expand file tree Collapse file tree 3 files changed +40
-6
lines changed
Expand file tree Collapse file tree 3 files changed +40
-6
lines changed Original file line number Diff line number Diff line change @@ -84,15 +84,19 @@ pub fn active_toolchain(msg_info: &mut MessageInfo) -> Result<String> {
8484}
8585
8686pub 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
98102pub fn available_targets (
Original file line number Diff line number Diff line change 1+ mod rustup;
12mod toml;
23
34use std:: {
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments