@@ -7,8 +7,9 @@ namespace DotNetLab;
77public sealed class CompilerProxyTests ( ITestOutputHelper output )
88{
99 [ Theory ]
10- [ InlineData ( "4.12.0-2.24409.2" , "4.12.0-2.24409.2 (2158b591)" ) ]
11- [ InlineData ( "main" , "-ci (<developer build>)" ) ]
10+ [ InlineData ( "4.12.0-2.24409.2" , "4.12.0-2.24409.2 (2158b591)" ) ] // preview version is downloaded from an AzDo feed
11+ [ InlineData ( "4.14.0" , "4.14.0-3.25262.10 (8edf7bcd)" ) ] // non-preview version is downloaded from nuget.org
12+ [ InlineData ( "main" , "-ci (<developer build>)" ) ] // a branch can be downloaded
1213 public async Task SpecifiedNuGetRoslynVersion ( string version , string expectedDiagnostic )
1314 {
1415 var services = WorkerServices . CreateTest ( new MockHttpMessageHandler ( output ) ) ;
@@ -25,12 +26,31 @@ await services.GetRequiredService<CompilerDependencyProvider>()
2526 Assert . Contains ( expectedDiagnostic , diagnosticsText ) ;
2627
2728 // Language services should also pick up the custom compiler version.
29+ // There are bunch of tests that do not assert much but they verify no type load exceptions happen.
30+ // Some older versions of Roslyn are not compatible though (until we actually download the corresponding older DLLs
31+ // for language services as well but we might never actually want to support that).
32+
2833 var languageServices = await compiler . GetLanguageServicesAsync ( ) ;
2934 await languageServices . OnDidChangeWorkspaceAsync ( [ new ( "Input.cs" , "Input.cs" ) { NewContent = "#error version" } ] ) ;
3035
3136 var markers = await languageServices . GetDiagnosticsAsync ( "Input.cs" ) ;
3237 markers . Should ( ) . Contain ( m => m . Message . Contains ( expectedDiagnostic ) ) ;
3338
39+ var loadSemanticTokens = async ( ) =>
40+ {
41+ var semanticTokensJson = await languageServices . ProvideSemanticTokensAsync ( "Input.cs" , null , false , TestContext . Current . CancellationToken ) ;
42+ semanticTokensJson . Should ( ) . NotBeNull ( ) ;
43+ } ;
44+
45+ if ( version . StartsWith ( "4.12." ) )
46+ {
47+ await loadSemanticTokens . Should ( ) . ThrowAsync < TypeLoadException > ( ) ;
48+ }
49+ else
50+ {
51+ await loadSemanticTokens ( ) ;
52+ }
53+
3454 var codeActionsJson = await languageServices . ProvideCodeActionsAsync ( "Input.cs" , null , TestContext . Current . CancellationToken ) ;
3555 codeActionsJson . Should ( ) . NotBeNull ( ) ;
3656 }
@@ -65,7 +85,7 @@ await services.GetRequiredService<CompilerDependencyProvider>()
6585 // /Input.cs(1,8): error CS8304: Compiler version: '{ version } ({ commit } )'. Language version: 10.0.
6686 // #error version
6787 Diagnostic(ErrorCode.ERR_CompilerAndLanguageVersion, "version").WithArguments("{ version } ({ commit } )", "10.0").WithLocation(1, 8)
68- """ , diagnosticsText ) ;
88+ """ . ReplaceLineEndings ( ) , diagnosticsText ) ;
6989 }
7090
7191 [ Theory ]
@@ -129,6 +149,10 @@ public async Task SpecifiedRazorOptions(RazorToolchain toolchain, RazorStrategy
129149
130150 string code = """
131151 <div>@Param</div>
152+ @if (Param == 0)
153+ {
154+ <TestComponent Param="1" />
155+ }
132156
133157 @code {
134158 [Parameter] public int Param { get; set; } = 42;
@@ -150,6 +174,7 @@ public async Task SpecifiedRazorOptions(RazorToolchain toolchain, RazorStrategy
150174 var cSharpText = await compiled . GetRequiredGlobalOutput ( "cs" ) . GetTextAsync ( outputFactory : null ) ;
151175 output . WriteLine ( cSharpText ) ;
152176 Assert . Contains ( "class TestComponent" , cSharpText ) ;
177+ Assert . Contains ( "AddComponentParameter" , cSharpText ) ;
153178
154179 var htmlText = await compiled . Files . Single ( ) . Value . GetRequiredOutput ( "html" ) . GetTextAsync ( outputFactory : null ) ;
155180 output . WriteLine ( htmlText ) ;
0 commit comments