Skip to content

Commit

Permalink
(#380) IntegrationTests: .NET Framework support on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Jul 21, 2023
1 parent 568a098 commit a659a37
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 22 deletions.
86 changes: 64 additions & 22 deletions Cesium.IntegrationTests/IntegrationTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,32 @@ public static IEnumerable<object[]> TestCaseProvider()
.Select(path => new object[] { path });
}

private enum TargetFramework
{
NetFramework,
Net
}

[Theory]
[MemberData(nameof(TestCaseProvider))]
public async Task TestNetFramework(string relativeSourcePath)
{
if (OperatingSystem.IsWindows())
{
await DoTest(relativeSourcePath, TargetFramework.NetFramework);
}
}

[Theory]
[MemberData(nameof(TestCaseProvider))]
public async Task TestCompiler(string relativeFilePath)
public Task TestNet(string relativeSourcePath) => DoTest(relativeSourcePath, TargetFramework.Net);

private async Task DoTest(string relativeSourcePath, TargetFramework targetFramework)
{
var outRootPath = CreateTempDir();
try
{
_output.WriteLine($"Testing file \"{relativeFilePath}\" in directory \"{outRootPath}\".");
_output.WriteLine($"Testing file \"{relativeSourcePath}\" in directory \"{outRootPath}\".");

var binDirPath = Path.Combine(outRootPath, "bin");
var objDirPath = Path.Combine(outRootPath, "obj");
Expand All @@ -45,14 +63,25 @@ public async Task TestCompiler(string relativeFilePath)
var sourceFilePath = Path.Combine(
IntegrationTestContext.SolutionRootPath,
"Cesium.IntegrationTests",
relativeFilePath);
relativeSourcePath);

var nativeExecutable = await BuildExecutableWithNativeCompiler(binDirPath, objDirPath, sourceFilePath);
var nativeResult = await ExecUtil.Run(_output, nativeExecutable, outRootPath, Array.Empty<string>());
Assert.Equal(42, nativeResult.ExitCode);

var managedExecutable = await BuildExecutableWithCesium(binDirPath, objDirPath, sourceFilePath);
var managedResult = await ExecUtil.Run(_output, "dotnet", outRootPath, new[] { managedExecutable }); // TODO: Only .NET for now
var managedExecutable = await BuildExecutableWithCesium(
binDirPath,
objDirPath,
sourceFilePath,
targetFramework);
var managedResult = await (targetFramework switch
{
TargetFramework.Net => ExecUtil.Run(_output, "dotnet", outRootPath, new[] { managedExecutable }),
TargetFramework.NetFramework => ExecUtil.Run(_output, managedExecutable, outRootPath,
Array.Empty<string>()),
_ => throw new ArgumentOutOfRangeException(nameof(targetFramework), targetFramework, null)
});

Assert.Equal(42, managedResult.ExitCode);

Assert.Equal(
Expand Down Expand Up @@ -139,30 +168,43 @@ private async Task<string> BuildExecutableWithCesium(
string binDirPath,
string objDirPath,
string sourceFilePath,
string targetFramework = "Net") // TODO: NET Framework support
TargetFramework targetFramework)
{
_output.WriteLine($"Compiling \"{sourceFilePath}\" with Cesium.");
// TODO: Workaround for .NET Framework, see in Run-Tests.ps1

var executableFilePath = Path.Combine(binDirPath, "out_cs.exe");

await ExecUtil.RunToSuccess(
_output,
"dotnet",
objDirPath,
new[]
var args = new List<string>
{
"run",
"--no-build",
"--configuration", IntegrationTestContext.BuildConfiguration,
"--project", Path.Combine(IntegrationTestContext.SolutionRootPath, "Cesium.Compiler"),
"--",
"--nologo",
sourceFilePath,
"--out", executableFilePath,
"-D__TEST_DEFINE",
"--framework", targetFramework.ToString()
};

if (targetFramework == TargetFramework.NetFramework)
{
var coreLibPath = WindowsEnvUtil.MsCorLibPath;
var runtimeLibPath = Path.Combine(
IntegrationTestContext.SolutionRootPath,
"Cesium.Runtime/bin",
IntegrationTestContext.BuildConfiguration,
"netstandard2.0/Cesium.Runtime.dll"
);
args.AddRange(new[]
{
"run",
"--no-build",
"--configuration", IntegrationTestContext.BuildConfiguration,
"--project", Path.Combine(IntegrationTestContext.SolutionRootPath, "Cesium.Compiler"),
"--",
"--nologo",
sourceFilePath,
"--out", executableFilePath,
"-D__TEST_DEFINE",
"--framework", targetFramework
"--corelib", coreLibPath,
"--runtime", runtimeLibPath
});
}

await ExecUtil.RunToSuccess(_output, "dotnet", objDirPath, args.ToArray());

return executableFilePath;
}
Expand Down
2 changes: 2 additions & 0 deletions Cesium.IntegrationTests/WindowsEnvUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace Cesium.IntegrationTests;

internal static class WindowsEnvUtil
{
public const string MsCorLibPath = @"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll";

public static async Task<string> FindVCCompilerInstallationFolder(ITestOutputHelper output)
{
var vswhereLocation =
Expand Down
1 change: 1 addition & 0 deletions Cesium.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<s:Boolean x:Key="/Default/UserDictionary/Words/=Alignof/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=constness/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=corelib/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Initializable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=modulekind/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=nint/@EntryIndexedValue">True</s:Boolean>
Expand Down

0 comments on commit a659a37

Please sign in to comment.