|
5 | 5 | using System.Diagnostics.CodeAnalysis; |
6 | 6 | using Cesium.Compiler; |
7 | 7 | using Cesium.TestFramework; |
| 8 | +using TruePath; |
8 | 9 | using Xunit.Abstractions; |
9 | 10 |
|
10 | 11 | namespace Cesium.CodeGen.Tests; |
11 | 12 |
|
12 | 13 | // TODO[#488]: Make them run in parallel, as all the integration tests |
13 | | -public class CodeGenNetInteropTests : CodeGenTestBase |
| 14 | +public class CodeGenNetInteropTests(ITestOutputHelper output) : CodeGenTestBase |
14 | 15 | { |
15 | | - private readonly ITestOutputHelper _output; |
16 | | - public CodeGenNetInteropTests(ITestOutputHelper output) |
17 | | - { |
18 | | - _output = output; |
19 | | - } |
20 | | - |
21 | 16 | private async Task DoTest( |
22 | 17 | TargetArchitectureSet architecture, |
23 | 18 | [StringSyntax("csharp")] string cSharpCode, |
24 | 19 | [StringSyntax("cpp")] string cCode) |
25 | 20 | { |
26 | 21 | var cSharpAssemblyPath = await CSharpCompilationUtil.CompileCSharpAssembly( |
27 | | - _output, |
| 22 | + output, |
28 | 23 | CSharpCompilationUtil.DefaultRuntime, |
29 | 24 | 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]); |
31 | 30 | await VerifyTypes(cesiumAssembly, architecture); |
32 | 31 | await VerifyAssemblyRuns(assemblyContents.ToArray(), cSharpAssemblyPath); |
33 | 32 | } |
34 | 33 |
|
35 | | - private async Task VerifyAssemblyRuns(byte[] assemblyContentToRun, string referencePath) |
| 34 | + private async Task VerifyAssemblyRuns(byte[] assemblyContentToRun, AbsolutePath referencePath) |
36 | 35 | { |
37 | | - var testDirectoryPath = Path.GetTempFileName(); |
38 | | - File.Delete(testDirectoryPath); |
39 | | - Directory.CreateDirectory(testDirectoryPath); |
40 | | - |
| 36 | + var testDirectory = Temporary.CreateTempFolder(); |
41 | 37 | try |
42 | 38 | { |
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"); |
45 | 41 |
|
46 | | - await File.WriteAllBytesAsync(assemblyPath, assemblyContentToRun); |
| 42 | + await File.WriteAllBytesAsync(assemblyPath.Value, assemblyContentToRun); |
47 | 43 | await File.WriteAllTextAsync(runtimeConfigPath, RuntimeConfig.EmitNet9()); |
48 | 44 |
|
49 | 45 | DeployReferenceAssembly(CSharpCompilationUtil.CesiumRuntimeLibraryPath); |
50 | 46 | DeployReferenceAssembly(referencePath); |
51 | 47 |
|
52 | | - await ExecUtil.RunToSuccess(_output, "dotnet", testDirectoryPath, new[] { assemblyPath }); |
| 48 | + await ExecUtil.RunToSuccess(output, new LocalPath("dotnet"), testDirectory, [assemblyPath.Value]); |
53 | 49 | } |
54 | 50 | finally |
55 | 51 | { |
56 | | - Directory.Delete(testDirectoryPath, recursive: true); |
| 52 | + Directory.Delete(testDirectory.Value, recursive: true); |
57 | 53 | } |
58 | 54 |
|
59 | | - void DeployReferenceAssembly(string assemblyPath) |
| 55 | + void DeployReferenceAssembly(AbsolutePath assemblyPath) |
60 | 56 | { |
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); |
63 | 59 | } |
64 | 60 | } |
65 | 61 |
|
|
0 commit comments