@@ -34,12 +34,15 @@ pub fn active_toolchain(path: &Path) -> Result<String> {
34
34
parse_active_toolchain ( stdout)
35
35
}
36
36
37
+ // Split from the first whitespace character
38
+ //
39
+ // Note:
40
+ // Unicode whitespace characters are not considered as whitespace characters.
37
41
fn parse_active_toolchain ( active : & str ) -> Result < String > {
38
42
active
39
43
. split_ascii_whitespace ( )
40
- . take ( 1 )
41
- . map ( |s| s. to_owned ( ) )
42
44
. next ( )
45
+ . map ( str:: to_owned)
43
46
. ok_or_else ( || anyhow ! ( "Could not determine active toolchain" ) )
44
47
}
45
48
@@ -74,12 +77,23 @@ mod rustup_test {
74
77
75
78
#[ test]
76
79
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
- ) ;
80
+ let outputs = [
81
+ "nightly-aarch64-apple-darwin\r active because: it's the default toolchain" ,
82
+ "nightly-x86_64-pc-windows-msvc (default)\r \n active toolchain" ,
83
+ "1.85.0-rv64gc-unknown-linux-gnu\n active because: overridden by '/home/user/rust-with-riscv/rust-toolchain'" ,
84
+ // allow full width space (\u3000)
85
+ "自定义 rust\n active because: overridden by '/root/app/rust-toolchain.toml'" ,
86
+ "私の rust\r \n active because: overridden by 'C:\\ Users\\ watashi\\ rust-練習\\ rust-toolchain.toml'" ,
87
+ ] ;
88
+ let expects = [
89
+ "nightly-aarch64-apple-darwin" ,
90
+ "nightly-x86_64-pc-windows-msvc" ,
91
+ "1.85.0-rv64gc-unknown-linux-gnu" ,
92
+ "自定义 rust" ,
93
+ "私の rust" ,
94
+ ] ;
95
+ for ( output, expect) in outputs. iter ( ) . zip ( expects. iter ( ) ) {
96
+ assert_eq ! ( parse_active_toolchain( output) . unwrap( ) , * expect) ;
97
+ }
84
98
}
85
99
}
0 commit comments