@@ -9,65 +9,86 @@ namespace Microsoft.NET.Build.Tests;
9
9
10
10
public sealed class RoslynBuildTaskTests ( ITestOutputHelper log ) : SdkTest ( log )
11
11
{
12
- private const string CoreCompilerFileName = "csc.dll" ;
13
- private const string FxCompilerFileName = "csc.exe" ;
12
+ private static string CompilerFileNameWithoutExtension ( Language language ) => language switch
13
+ {
14
+ Language . CSharp => "csc" ,
15
+ Language . VisualBasic => "vbc" ,
16
+ _ => throw new ArgumentOutOfRangeException ( paramName : nameof ( language ) ) ,
17
+ } ;
18
+
19
+ private static string CoreCompilerFileName ( Language language ) => CompilerFileNameWithoutExtension ( language ) + ".dll" ;
20
+
21
+ private static string FxCompilerFileName ( Language language ) => CompilerFileNameWithoutExtension ( language ) + ".exe" ;
14
22
15
23
[ FullMSBuildOnlyTheory , CombinatorialData ]
16
- public void FullMSBuild_SdkStyle ( bool useSharedCompilation )
24
+ public void FullMSBuild_SdkStyle ( bool useSharedCompilation , Language language )
17
25
{
18
- var testAsset = CreateProject ( useSharedCompilation ) ;
26
+ var testAsset = CreateProject ( useSharedCompilation , language ) ;
19
27
var buildCommand = BuildAndRunUsingMSBuild ( testAsset ) ;
20
- VerifyCompiler ( buildCommand , CoreCompilerFileName , useSharedCompilation ) ;
28
+ VerifyCompiler ( buildCommand , CoreCompilerFileName ( language ) , useSharedCompilation ) ;
21
29
}
22
30
23
31
[ FullMSBuildOnlyTheory , CombinatorialData ]
24
- public void FullMSBuild_SdkStyle_OptOut ( bool useSharedCompilation )
32
+ public void FullMSBuild_SdkStyle_OptOut ( bool useSharedCompilation , Language language )
25
33
{
26
- var testAsset = CreateProject ( useSharedCompilation ) . WithProjectChanges ( static doc =>
34
+ var testAsset = CreateProject ( useSharedCompilation , language ) . WithProjectChanges ( static doc =>
27
35
{
28
36
doc . Root ! . Element ( "PropertyGroup" ) ! . Add ( new XElement ( "RoslynCompilerType" , "Framework" ) ) ;
29
37
} ) ;
30
38
var buildCommand = BuildAndRunUsingMSBuild ( testAsset ) ;
31
- VerifyCompiler ( buildCommand , FxCompilerFileName , useSharedCompilation ) ;
39
+ VerifyCompiler ( buildCommand , FxCompilerFileName ( language ) , useSharedCompilation ) ;
32
40
}
33
41
34
42
[ FullMSBuildOnlyTheory , CombinatorialData ]
35
- public void FullMSBuild_NonSdkStyle ( bool useSharedCompilation )
43
+ public void FullMSBuild_NonSdkStyle ( bool useSharedCompilation , Language language )
36
44
{
37
- var testAsset = CreateProject ( useSharedCompilation , static project =>
45
+ var testAsset = CreateProject ( useSharedCompilation , language , static project =>
38
46
{
39
47
project . IsSdkProject = false ;
40
48
project . TargetFrameworkVersion = "v4.7.2" ;
41
49
} ) ;
42
50
var buildCommand = BuildAndRunUsingMSBuild ( testAsset ) ;
43
- VerifyCompiler ( buildCommand , FxCompilerFileName , useSharedCompilation ) ;
51
+ VerifyCompiler ( buildCommand , FxCompilerFileName ( language ) , useSharedCompilation ) ;
44
52
}
45
53
46
54
[ Theory , CombinatorialData ]
47
- public void DotNet ( bool useSharedCompilation )
55
+ public void DotNet ( bool useSharedCompilation , Language language )
48
56
{
49
- var testAsset = CreateProject ( useSharedCompilation ) ;
57
+ var testAsset = CreateProject ( useSharedCompilation , language ) ;
50
58
var buildCommand = BuildAndRunUsingDotNet ( testAsset ) ;
51
- VerifyCompiler ( buildCommand , CoreCompilerFileName , useSharedCompilation ) ;
59
+ VerifyCompiler ( buildCommand , CoreCompilerFileName ( language ) , useSharedCompilation ) ;
52
60
}
53
61
54
- private TestAsset CreateProject ( bool useSharedCompilation , Action < TestProject > ? configure = null , [ CallerMemberName ] string callingMethod = "" )
62
+ private TestAsset CreateProject ( bool useSharedCompilation , Language language , Action < TestProject > ? configure = null , [ CallerMemberName ] string callingMethod = "" )
55
63
{
64
+ var ( projExtension , sourceName , sourceText ) = language switch
65
+ {
66
+ Language . CSharp => ( ".csproj" , "Program.cs" , """
67
+ class Program
68
+ {
69
+ static void Main()
70
+ {
71
+ System.Console.WriteLine(40 + 2);
72
+ }
73
+ }
74
+ """ ) ,
75
+ Language . VisualBasic => ( ".vbproj" , "Program.vb" , """
76
+ Module Program
77
+ Sub Main()
78
+ System.Console.WriteLine(40 + 2)
79
+ End Sub
80
+ End Module
81
+ """ ) ,
82
+ _ => throw new ArgumentOutOfRangeException ( paramName : nameof ( language ) ) ,
83
+ } ;
84
+
56
85
var project = new TestProject
57
86
{
58
87
Name = "App1" ,
59
88
IsExe = true ,
60
89
SourceFiles =
61
90
{
62
- [ "Program.cs" ] = """
63
- class Program
64
- {
65
- static void Main()
66
- {
67
- System.Console.WriteLine(40 + 2);
68
- }
69
- }
70
- """ ,
91
+ [ sourceName ] = sourceText ,
71
92
} ,
72
93
} ;
73
94
@@ -78,7 +99,7 @@ static void Main()
78
99
}
79
100
80
101
configure ? . Invoke ( project ) ;
81
- return _testAssetsManager . CreateTestProject ( project , callingMethod : callingMethod ) ;
102
+ return _testAssetsManager . CreateTestProject ( project , callingMethod : callingMethod , targetExtension : projExtension ) ;
82
103
}
83
104
84
105
private TestCommand BuildAndRunUsingMSBuild ( TestAsset testAsset )
@@ -125,4 +146,10 @@ private static void VerifyCompiler(TestCommand buildCommand, string compilerFile
125
146
? "CompilerServer: server - server processed compilation - "
126
147
: "CompilerServer: tool - using command line tool by design" ) ;
127
148
}
149
+
150
+ public enum Language
151
+ {
152
+ CSharp ,
153
+ VisualBasic ,
154
+ }
128
155
}
0 commit comments