Skip to content

Commit 21f2744

Browse files
committed
Tests: proceed with TruePath everywhere; add stub for multi-file compilation tests
1 parent 2a6c0bb commit 21f2744

17 files changed

+361
-254
lines changed

Cesium.CodeGen.Tests/CodeGenNetInteropTests.cs

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,57 @@
55
using System.Diagnostics.CodeAnalysis;
66
using Cesium.Compiler;
77
using Cesium.TestFramework;
8+
using TruePath;
89
using Xunit.Abstractions;
910

1011
namespace Cesium.CodeGen.Tests;
1112

1213
// TODO[#488]: Make them run in parallel, as all the integration tests
13-
public class CodeGenNetInteropTests : CodeGenTestBase
14+
public class CodeGenNetInteropTests(ITestOutputHelper output) : CodeGenTestBase
1415
{
15-
private readonly ITestOutputHelper _output;
16-
public CodeGenNetInteropTests(ITestOutputHelper output)
17-
{
18-
_output = output;
19-
}
20-
2116
private async Task DoTest(
2217
TargetArchitectureSet architecture,
2318
[StringSyntax("csharp")] string cSharpCode,
2419
[StringSyntax("cpp")] string cCode)
2520
{
2621
var cSharpAssemblyPath = await CSharpCompilationUtil.CompileCSharpAssembly(
27-
_output,
22+
output,
2823
CSharpCompilationUtil.DefaultRuntime,
2924
cSharpCode);
30-
var (cesiumAssembly, assemblyContents) = GenerateAssembly(runtime: null, arch: architecture, sources: new[]{cCode}, referencePaths: new[] { cSharpAssemblyPath });
25+
var (cesiumAssembly, assemblyContents) = GenerateAssembly(
26+
runtime: null,
27+
arch: architecture,
28+
sources: [cCode],
29+
referencePaths: [cSharpAssemblyPath]);
3130
await VerifyTypes(cesiumAssembly, architecture);
3231
await VerifyAssemblyRuns(assemblyContents.ToArray(), cSharpAssemblyPath);
3332
}
3433

35-
private async Task VerifyAssemblyRuns(byte[] assemblyContentToRun, string referencePath)
34+
private async Task VerifyAssemblyRuns(byte[] assemblyContentToRun, AbsolutePath referencePath)
3635
{
37-
var testDirectoryPath = Path.GetTempFileName();
38-
File.Delete(testDirectoryPath);
39-
Directory.CreateDirectory(testDirectoryPath);
40-
36+
var testDirectory = Temporary.CreateTempFolder();
4137
try
4238
{
43-
var assemblyPath = Path.Combine(testDirectoryPath, "EntryPoint.dll");
44-
var runtimeConfigPath = Path.ChangeExtension(assemblyPath, ".runtimeconfig.json");
39+
var assemblyPath = testDirectory / "EntryPoint.dll";
40+
var runtimeConfigPath = Path.ChangeExtension(assemblyPath.Value, ".runtimeconfig.json");
4541

46-
await File.WriteAllBytesAsync(assemblyPath, assemblyContentToRun);
42+
await File.WriteAllBytesAsync(assemblyPath.Value, assemblyContentToRun);
4743
await File.WriteAllTextAsync(runtimeConfigPath, RuntimeConfig.EmitNet9());
4844

4945
DeployReferenceAssembly(CSharpCompilationUtil.CesiumRuntimeLibraryPath);
5046
DeployReferenceAssembly(referencePath);
5147

52-
await ExecUtil.RunToSuccess(_output, "dotnet", testDirectoryPath, new[] { assemblyPath });
48+
await ExecUtil.RunToSuccess(output, new LocalPath("dotnet"), testDirectory, [assemblyPath.Value]);
5349
}
5450
finally
5551
{
56-
Directory.Delete(testDirectoryPath, recursive: true);
52+
Directory.Delete(testDirectory.Value, recursive: true);
5753
}
5854

59-
void DeployReferenceAssembly(string assemblyPath)
55+
void DeployReferenceAssembly(AbsolutePath assemblyPath)
6056
{
61-
var targetFilePath = Path.Combine(testDirectoryPath, Path.GetFileName(assemblyPath));
62-
File.Copy(assemblyPath, targetFilePath);
57+
var targetFilePath = testDirectory / assemblyPath.FileName;
58+
File.Copy(assemblyPath.Value, targetFilePath.Value);
6359
}
6460
}
6561

Cesium.CodeGen.Tests/CodeGenTestBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected static AssemblyDefinition GenerateAssembly(TargetRuntimeDescriptor? ru
2828
runtime,
2929
@namespace: "",
3030
globalTypeFqn: "",
31-
referencePaths: Array.Empty<string>());
31+
referencePaths: []);
3232
return assembly;
3333
}
3434

@@ -38,7 +38,7 @@ protected static AssemblyDefinition GenerateAssembly(
3838
string @namespace = "",
3939
string globalTypeFqn = "", params string[] sources)
4040
{
41-
var (assembly, _) = GenerateAssembly(sources, runtime, arch, @namespace, globalTypeFqn, Array.Empty<string>());
41+
var (assembly, _) = GenerateAssembly(sources, runtime, arch, @namespace, globalTypeFqn, []);
4242
return assembly;
4343
}
4444

@@ -48,7 +48,7 @@ protected static (AssemblyDefinition, byte[]) GenerateAssembly(
4848
TargetArchitectureSet arch = TargetArchitectureSet.Dynamic,
4949
string @namespace = "",
5050
string globalTypeFqn = "",
51-
string[]? referencePaths = null)
51+
AbsolutePath[]? referencePaths = null)
5252
{
5353
var context = CreateAssembly(
5454
runtime,

Cesium.Compiler.Tests/JsonObjectFileTests.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,4 @@ public void CorrectExtensions(string fileName, bool result) =>
1515

1616
[Fact]
1717
public void ObjectFileGetsReadCorrectly() => Assert.Fail();
18-
19-
[Fact]
20-
public void CompilationSucceedsForObjectFile() => Assert.Fail("Migrate me to the integration tests");
2118
}

Cesium.IntegrationTests/Cesium.IntegrationTests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,9 @@ SPDX-License-Identifier: MIT
3030
<ProjectReference Include="..\Cesium.TestFramework\Cesium.TestFramework.csproj" />
3131
</ItemGroup>
3232

33+
<ItemGroup>
34+
<ClCompile Include="multi-file\function.c" />
35+
<ClCompile Include="multi-file\program.c" />
36+
</ItemGroup>
37+
3338
</Project>

Cesium.IntegrationTests/IntegrationTestContext.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Cesium.Solution.Metadata;
77
using Cesium.TestFramework;
88
using JetBrains.Annotations;
9+
using TruePath;
910
using Xunit.Abstractions;
1011

1112
namespace Cesium.IntegrationTests;
@@ -22,7 +23,7 @@ public class IntegrationTestContext : IAsyncDisposable
2223
private bool _initialized;
2324
private Exception? _initializationException;
2425

25-
public string? VisualStudioPath { get; private set; }
26+
public AbsolutePath? VisualStudioPath { get; private set; }
2627

2728
public async Task WrapTestBody(Func<Task> testBody)
2829
{
@@ -62,7 +63,7 @@ private async Task InitializeOnce(ITestOutputHelper output)
6263
{
6364
if (OperatingSystem.IsWindows())
6465
{
65-
VisualStudioPath = await WindowsEnvUtil.FindVCCompilerInstallationFolder(output);
66+
VisualStudioPath = await WindowsEnvUtil.FindVcCompilerInstallationFolder(output);
6667
}
6768

6869
await BuildRuntime(output);
@@ -76,17 +77,13 @@ public async ValueTask DisposeAsync()
7677

7778
private static async Task BuildRuntime(ITestOutputHelper output)
7879
{
79-
var runtimeProjectFile = Path.Combine(
80-
SolutionMetadata.SourceRoot,
81-
"Cesium.Runtime/Cesium.Runtime.csproj");
80+
var runtimeProjectFile = SolutionMetadata.SourceRoot / "Cesium.Runtime/Cesium.Runtime.csproj";
8281
await DotNetCliHelper.BuildDotNetProject(output, BuildConfiguration, runtimeProjectFile);
8382
}
8483

8584
private static async Task BuildCompiler(ITestOutputHelper output)
8685
{
87-
var compilerProjectFile = Path.Combine(
88-
SolutionMetadata.SourceRoot,
89-
"Cesium.Compiler/Cesium.Compiler.csproj");
86+
var compilerProjectFile = SolutionMetadata.SourceRoot / "Cesium.Compiler/Cesium.Compiler.csproj";
9087
await DotNetCliHelper.BuildDotNetProject(output, BuildConfiguration, compilerProjectFile);
9188
}
9289
}

0 commit comments

Comments
 (0)