@@ -6,10 +6,14 @@ namespace KS.RustAnalyzer.TestAdapter.UnitTests.Cargo;
66using System . IO ;
77using System . Linq ;
88using System . Threading . Tasks ;
9+ using ApprovalTests ;
10+ using ApprovalTests . Namers ;
11+ using ApprovalTests . Reporters ;
912using FluentAssertions ;
1013using KS . RustAnalyzer . TestAdapter . Cargo ;
1114using KS . RustAnalyzer . TestAdapter . Common ;
1215using KS . RustAnalyzer . Tests . Common ;
16+ using Newtonsoft . Json ;
1317using Xunit ;
1418
1519public sealed class ToolchainServiceExtensionsTests
@@ -41,15 +45,100 @@ public async Task TestGetBinAndLibPathsAsync()
4145 ( binPath + Constants . CargoExe ) . FileExists ( ) . Should ( ) . BeTrue ( ) ;
4246 }
4347
44- [ Fact ]
45- public async Task TestGetInstalledToolchainsBasicAsync ( )
48+ /// <summary>
49+ /// In cases of test failure:
50+ /// a. use "rustup show --verbose" to update the inline data first.
51+ /// b. 2 cases: one with same active and default toolchain, and another with separate active & default toolchains.
52+ /// </summary>
53+ [ Theory ]
54+ [ UseReporter ( typeof ( RaVsDiffReporter ) ) ]
55+ [ InlineData (
56+ #pragma warning disable SA1118 // Parameter should not span multiple lines
57+ "separate_active_and_default" ,
58+ @"Default host: x86_64-pc-windows-msvc
59+ rustup home: C:\Users\parth\scoop\persist\rustup\.rustup
60+
61+ installed toolchains
62+ --------------------
63+ stable-x86_64-pc-windows-msvc (active)
64+ rustc 1.86.0 (05f9846f8 2025-03-31)
65+ path: C:\Users\parth\scoop\persist\rustup\.rustup\toolchains\stable-x86_64-pc-windows-msvc
66+
67+ nightly-x86_64-pc-windows-msvc (default)
68+ rustc 1.89.0-nightly (8405332bd 2025-05-12)
69+ path: C:\Users\parth\scoop\persist\rustup\.rustup\toolchains\nightly-x86_64-pc-windows-msvc
70+
71+ nightly-2024-03-27-x86_64-pc-windows-msvc
72+ rustc 1.79.0-nightly (47ecded35 2024-03-26)
73+ path: C:\Users\parth\scoop\persist\rustup\.rustup\toolchains\nightly-2024-03-27-x86_64-pc-windows-msvc
74+
75+ 1.75.0-x86_64-pc-windows-msvc
76+ rustc 1.75.0 (82e1608df 2023-12-21)
77+ path: C:\Users\parth\scoop\persist\rustup\.rustup\toolchains\1.75.0-x86_64-pc-windows-msvc
78+
79+ 1.76.0-x86_64-pc-windows-msvc
80+ rustc 1.76.0 (07dca489a 2024-02-04)
81+ path: C:\Users\parth\scoop\persist\rustup\.rustup\toolchains\1.76.0-x86_64-pc-windows-msvc
82+
83+ active toolchain
84+ ----------------
85+ name: stable-x86_64-pc-windows-msvc
86+ active because: directory override for 'D:\'
87+ compiler: rustc 1.86.0 (05f9846f8 2025-03-31)
88+ path: C:\Users\parth\scoop\persist\rustup\.rustup\toolchains\stable-x86_64-pc-windows-msvc
89+ installed targets:
90+ aarch64-unknown-none
91+ wasm32-unknown-unknown
92+ x86_64-pc-windows-msvc" ) ]
93+ #pragma warning restore SA1118 // Parameter should not span multiple lines
94+ [ InlineData (
95+ #pragma warning disable SA1118 // Parameter should not span multiple lines
96+ "same_active_and_default" ,
97+ @"Default host: x86_64-pc-windows-msvc
98+ rustup home: C:\Users\parth\scoop\persist\rustup\.rustup
99+
100+ installed toolchains
101+ --------------------
102+ stable-x86_64-pc-windows-msvc
103+ rustc 1.86.0 (05f9846f8 2025-03-31)
104+ path: C:\Users\parth\scoop\persist\rustup\.rustup\toolchains\stable-x86_64-pc-windows-msvc
105+
106+ nightly-x86_64-pc-windows-msvc (active, default)
107+ rustc 1.89.0-nightly (8405332bd 2025-05-12)
108+ path: C:\Users\parth\scoop\persist\rustup\.rustup\toolchains\nightly-x86_64-pc-windows-msvc
109+
110+ nightly-2024-03-27-x86_64-pc-windows-msvc
111+ rustc 1.79.0-nightly (47ecded35 2024-03-26)
112+ path: C:\Users\parth\scoop\persist\rustup\.rustup\toolchains\nightly-2024-03-27-x86_64-pc-windows-msvc
113+
114+ 1.75.0-x86_64-pc-windows-msvc
115+ rustc 1.75.0 (82e1608df 2023-12-21)
116+ path: C:\Users\parth\scoop\persist\rustup\.rustup\toolchains\1.75.0-x86_64-pc-windows-msvc
117+
118+ 1.76.0-x86_64-pc-windows-msvc
119+ rustc 1.76.0 (07dca489a 2024-02-04)
120+ path: C:\Users\parth\scoop\persist\rustup\.rustup\toolchains\1.76.0-x86_64-pc-windows-msvc
121+
122+ active toolchain
123+ ----------------
124+ name: nightly-x86_64-pc-windows-msvc
125+ active because: directory override for 'D:\src'
126+ compiler: rustc 1.89.0-nightly (8405332bd 2025-05-12)
127+ path: C:\Users\parth\scoop\persist\rustup\.rustup\toolchains\nightly-x86_64-pc-windows-msvc
128+ installed targets:
129+ aarch64-unknown-none
130+ wasm32-unknown-unknown
131+ x86_64-pc-windows-msvc" ) ]
132+ #pragma warning restore SA1118 // Parameter should not span multiple lines
133+ public async Task TestGetInstalledToolchainsBasicAsync ( string testName , string output )
46134 {
47- var installToolchains = await ToolchainServiceExtensions . GetInstalledToolchainsAsync ( TestHelpers . ThisTestRoot , default ) ;
135+ NamerFactory . AdditionalInformation = testName ;
136+ var installToolchains = await ToolchainServiceExtensions . GetInstalledToolchainsAsync (
137+ new ToolchainServiceExtensions . RustupShowOutput . Simulated ( output . Split ( '\r ' , '\n ' ) ) ,
138+ TestHelpers . ThisTestRoot ,
139+ default ) ;
48140
49- installToolchains . Should ( ) . NotBeEmpty ( ) ;
50- installToolchains . Select ( x => x . Name ) . Should ( ) . Contain ( x => ! x . IsNullOrEmptyOrWhiteSpace ( ) ) ;
51- installToolchains . Select ( x => x . Version ) . Should ( ) . Contain ( x => ! x . IsNullOrEmptyOrWhiteSpace ( ) ) ;
52- installToolchains . Where ( x => x . IsDefault ) . Should ( ) . HaveCount ( 1 ) ;
141+ Approvals . VerifyAll ( installToolchains . OrderBy ( x => x . Name ) . Select ( o => o . SerializeObject ( Formatting . Indented ) ) , label : string . Empty ) ;
53142 }
54143
55144 [ Fact ]
@@ -58,7 +147,7 @@ public async Task TestGetTargetsAsync()
58147 var targets = await ToolchainServiceExtensions . GetTargets ( default ) ;
59148
60149 targets . Should ( ) . NotContain ( ToolchainServiceExtensions . AlwaysAvailableTarget ) ;
61- targets . Should ( ) . OnlyContain ( t => ! t . Contains ( " (" ) ) ;
150+ targets . Should ( ) . OnlyContain ( t => ! t . Contains ( "(" ) ) ;
62151 targets . Take ( ToolchainServiceExtensions . CommonTargets . Length )
63152 . Should ( )
64153 . ContainInOrder ( ToolchainServiceExtensions . CommonTargets . OrderBy ( x => x ) ) ;
0 commit comments