File tree Expand file tree Collapse file tree 1 file changed +31
-6
lines changed Expand file tree Collapse file tree 1 file changed +31
-6
lines changed Original file line number Diff line number Diff line change @@ -29,9 +29,17 @@ pub fn active_toolchain(path: &Path) -> Result<String> {
29
29
. args ( [ "show" , "active-toolchain" ] )
30
30
. logged_output ( true ) ?;
31
31
let stdout = std:: str:: from_utf8 ( & output. stdout ) ?;
32
- stdout
33
- . split_once ( ' ' )
34
- . map ( |( s, _) | s. to_owned ( ) )
32
+
33
+ // split at the first whitespace character
34
+ parse_active_toolchain ( stdout)
35
+ }
36
+
37
+ fn parse_active_toolchain ( active : & str ) -> Result < String > {
38
+ active
39
+ . split_ascii_whitespace ( )
40
+ . take ( 1 )
41
+ . map ( |s| s. to_owned ( ) )
42
+ . next ( )
35
43
. ok_or_else ( || anyhow ! ( "Could not determine active toolchain" ) )
36
44
}
37
45
@@ -54,7 +62,24 @@ pub fn is_rustc<T: AsRef<OsStr> + ?Sized>(arg: &T) -> bool {
54
62
Path :: new ( arg) . file_stem ( ) == Some ( OsStr :: new ( "rustc" ) )
55
63
}
56
64
57
- #[ test]
58
- fn rustc_is_rustc ( ) {
59
- assert ! ( is_rustc( "rustc" ) ) ;
65
+ #[ cfg( test) ]
66
+ mod rustup_test {
67
+
68
+ use crate :: rustup:: { is_rustc, parse_active_toolchain} ;
69
+
70
+ #[ test]
71
+ fn rustc_is_rustc ( ) {
72
+ assert ! ( is_rustc( "rustc" ) ) ;
73
+ }
74
+
75
+ #[ test]
76
+ fn test_parse_active_toolchain ( ) {
77
+ let output = r#"nightly-aarch64-apple-darwin
78
+ active because: it's the default toolchain
79
+ "# ;
80
+ assert_eq ! (
81
+ parse_active_toolchain( output) . unwrap( ) ,
82
+ "nightly-aarch64-apple-darwin" . to_owned( )
83
+ ) ;
84
+ }
60
85
}
You can’t perform that action at this time.
0 commit comments