Skip to content

Commit 37ed605

Browse files
authored
Add RoslynCompilerType Vbc tests (#48798)
1 parent f7e7c3d commit 37ed605

File tree

3 files changed

+111
-25
lines changed

3 files changed

+111
-25
lines changed

test/Microsoft.NET.Build.Tests/RoslynBuildTaskTests.cs

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,65 +9,86 @@ namespace Microsoft.NET.Build.Tests;
99

1010
public sealed class RoslynBuildTaskTests(ITestOutputHelper log) : SdkTest(log)
1111
{
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";
1422

1523
[FullMSBuildOnlyTheory, CombinatorialData]
16-
public void FullMSBuild_SdkStyle(bool useSharedCompilation)
24+
public void FullMSBuild_SdkStyle(bool useSharedCompilation, Language language)
1725
{
18-
var testAsset = CreateProject(useSharedCompilation);
26+
var testAsset = CreateProject(useSharedCompilation, language);
1927
var buildCommand = BuildAndRunUsingMSBuild(testAsset);
20-
VerifyCompiler(buildCommand, CoreCompilerFileName, useSharedCompilation);
28+
VerifyCompiler(buildCommand, CoreCompilerFileName(language), useSharedCompilation);
2129
}
2230

2331
[FullMSBuildOnlyTheory, CombinatorialData]
24-
public void FullMSBuild_SdkStyle_OptOut(bool useSharedCompilation)
32+
public void FullMSBuild_SdkStyle_OptOut(bool useSharedCompilation, Language language)
2533
{
26-
var testAsset = CreateProject(useSharedCompilation).WithProjectChanges(static doc =>
34+
var testAsset = CreateProject(useSharedCompilation, language).WithProjectChanges(static doc =>
2735
{
2836
doc.Root!.Element("PropertyGroup")!.Add(new XElement("RoslynCompilerType", "Framework"));
2937
});
3038
var buildCommand = BuildAndRunUsingMSBuild(testAsset);
31-
VerifyCompiler(buildCommand, FxCompilerFileName, useSharedCompilation);
39+
VerifyCompiler(buildCommand, FxCompilerFileName(language), useSharedCompilation);
3240
}
3341

3442
[FullMSBuildOnlyTheory, CombinatorialData]
35-
public void FullMSBuild_NonSdkStyle(bool useSharedCompilation)
43+
public void FullMSBuild_NonSdkStyle(bool useSharedCompilation, Language language)
3644
{
37-
var testAsset = CreateProject(useSharedCompilation, static project =>
45+
var testAsset = CreateProject(useSharedCompilation, language, static project =>
3846
{
3947
project.IsSdkProject = false;
4048
project.TargetFrameworkVersion = "v4.7.2";
4149
});
4250
var buildCommand = BuildAndRunUsingMSBuild(testAsset);
43-
VerifyCompiler(buildCommand, FxCompilerFileName, useSharedCompilation);
51+
VerifyCompiler(buildCommand, FxCompilerFileName(language), useSharedCompilation);
4452
}
4553

4654
[Theory, CombinatorialData]
47-
public void DotNet(bool useSharedCompilation)
55+
public void DotNet(bool useSharedCompilation, Language language)
4856
{
49-
var testAsset = CreateProject(useSharedCompilation);
57+
var testAsset = CreateProject(useSharedCompilation, language);
5058
var buildCommand = BuildAndRunUsingDotNet(testAsset);
51-
VerifyCompiler(buildCommand, CoreCompilerFileName, useSharedCompilation);
59+
VerifyCompiler(buildCommand, CoreCompilerFileName(language), useSharedCompilation);
5260
}
5361

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 = "")
5563
{
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+
5685
var project = new TestProject
5786
{
5887
Name = "App1",
5988
IsExe = true,
6089
SourceFiles =
6190
{
62-
["Program.cs"] = """
63-
class Program
64-
{
65-
static void Main()
66-
{
67-
System.Console.WriteLine(40 + 2);
68-
}
69-
}
70-
""",
91+
[sourceName] = sourceText,
7192
},
7293
};
7394

@@ -78,7 +99,7 @@ static void Main()
7899
}
79100

80101
configure?.Invoke(project);
81-
return _testAssetsManager.CreateTestProject(project, callingMethod: callingMethod);
102+
return _testAssetsManager.CreateTestProject(project, callingMethod: callingMethod, targetExtension: projExtension);
82103
}
83104

84105
private TestCommand BuildAndRunUsingMSBuild(TestAsset testAsset)
@@ -125,4 +146,10 @@ private static void VerifyCompiler(TestCommand buildCommand, string compilerFile
125146
? "CompilerServer: server - server processed compilation - "
126147
: "CompilerServer: tool - using command line tool by design");
127148
}
149+
150+
public enum Language
151+
{
152+
CSharp,
153+
VisualBasic,
154+
}
128155
}

test/Microsoft.NET.TestFramework/ProjectConstruction/TestProject.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ internal void Create(TestAsset targetTestAsset, string testProjectsSourceFolder,
139139
{
140140
sourceProject = Path.Combine(sourceProjectBase, "SdkProject", "SdkProject.csproj");
141141
}
142+
else if (targetExtension == ".vbproj")
143+
{
144+
sourceProject = Path.Combine(sourceProjectBase, "NetFrameworkProjectVB", "NetFrameworkProject.vbproj");
145+
}
142146
else
143147
{
144148
sourceProject = Path.Combine(sourceProjectBase, "NetFrameworkProject", "NetFrameworkProject.csproj");
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>00b7995e-fa4d-4d2c-9d22-0bea72cca295</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>$(MSBuildProjectName)</RootNamespace>
11+
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG,TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="System"/>
35+
<Reference Include="System.Core"/>
36+
<Reference Include="System.Xml.Linq"/>
37+
<Reference Include="System.Data.DataSetExtensions"/>
38+
<Reference Include="Microsoft.CSharp"/>
39+
<Reference Include="System.Data"/>
40+
<Reference Include="System.Net.Http"/>
41+
<Reference Include="System.Xml"/>
42+
</ItemGroup>
43+
<ItemGroup>
44+
<Compile Include="**\*.vb" />
45+
</ItemGroup>
46+
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
47+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
48+
Other similar extension points exist, see Microsoft.Common.targets.
49+
<Target Name="BeforeBuild">
50+
</Target>
51+
<Target Name="AfterBuild">
52+
</Target>
53+
-->
54+
55+
</Project>

0 commit comments

Comments
 (0)