Skip to content

Commit 1fc5a9a

Browse files
committed
NativeAotTests run on TUnit
1 parent e2b8e7d commit 1fc5a9a

File tree

7 files changed

+107
-117
lines changed

7 files changed

+107
-117
lines changed

.github/workflows/build-debug.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ jobs:
2020
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
2121
- run: dotnet build -c Release
2222
- run: dotnet test -c Release --no-build
23+
24+
# Native AOT tests
25+
- run: dotnet publish -r linux-x64 tests/ConsoleAppFramework.NativeAotTests/ConsoleAppFramework.NativeAotTests.csproj
26+
- run: tests/ConsoleAppFramework.NativeAotTests/bin/Release/net10.0/linux-x64/publish/ConsoleAppFramework.NativeAotTests
27+
2328
- run: dotnet pack -c Release --no-build -p:IncludeSymbols=true -o $GITHUB_WORKSPACE/artifacts

.github/workflows/build-release.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ jobs:
2121
steps:
2222
- uses: Cysharp/Actions/.github/actions/checkout@main
2323
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
24-
# pack nuget
2524
- run: dotnet build -c Release -p:Version=${{ inputs.tag }}
2625
- run: dotnet test -c Release --no-build
26+
# Native AOT tests
27+
- run: dotnet publish -r linux-x64 tests/ConsoleAppFramework.NativeAotTests/ConsoleAppFramework.NativeAotTests.csproj
28+
- run: tests/ConsoleAppFramework.NativeAotTests/bin/Release/net10.0/linux-x64/publish/ConsoleAppFramework.NativeAotTests
29+
# pack nuget
2730
- run: dotnet pack -c Release --no-build -p:Version=${{ inputs.tag }} -o ./publish
2831
- uses: Cysharp/Actions/.github/actions/upload-artifact@main
2932
with:

ConsoleAppFramework.slnx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
<Folder Name="/tests/">
2222
<File Path="tests/Directory.Build.props" />
2323
<Project Path="tests/ConsoleAppFramework.GeneratorTests/ConsoleAppFramework.GeneratorTests.csproj" />
24-
<Project Path="tests/NativeAotTrimming/NativeAotTrimming.csproj" />
24+
<Project Path="tests/ConsoleAppFramework.NativeAotTests/ConsoleAppFramework.NativeAotTests.csproj" Id="7e8dede0-5954-4474-b660-905dd18b6799" />
2525
</Folder>
2626
</Solution>

tests/ConsoleAppFramework.GeneratorTests/NativeAotTrimmingTests.cs

Lines changed: 0 additions & 62 deletions
This file was deleted.

tests/NativeAotTrimming/NativeAotTrimming.csproj renamed to tests/ConsoleAppFramework.NativeAotTests/ConsoleAppFramework.NativeAotTests.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net9.0</TargetFramework>
5+
<TargetFramework>net10.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
8-
<TrimMode>Full</TrimMode>
98
<PublishAot>true</PublishAot>
9+
<IsAotCompatible>true</IsAotCompatible>
1010
<PublishTrimmed>true</PublishTrimmed>
1111
<PublishSingleFile>true</PublishSingleFile>
1212
<SelfContained>true</SelfContained>
1313
<IlcGenerateCompleteTypeMetadata>false</IlcGenerateCompleteTypeMetadata>
14+
<InvariantGlobalization>true</InvariantGlobalization>
1415
</PropertyGroup>
1516

1617
<ItemGroup>
18+
<PackageReference Include="TUnit" Version="1.2.11" />
1719
<ProjectReference Include="..\..\src\ConsoleAppFramework\ConsoleAppFramework.csproj">
1820
<OutputItemType>Analyzer</OutputItemType>
1921
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using ConsoleAppFramework;
2+
using System.ComponentModel.DataAnnotations;
3+
4+
// not parallel to check exit-code
5+
[assembly: NotInParallel]
6+
7+
namespace ConsoleAppFramework.NativeAotTests;
8+
9+
public class NativeAotTest
10+
{
11+
ConsoleApp.ConsoleAppBuilder app;
12+
13+
public NativeAotTest()
14+
{
15+
Environment.ExitCode = 0; // reset ExitCode
16+
17+
this.app = ConsoleApp.Create();
18+
19+
app.UseFilter<LoggingFilter>();
20+
app.Add("", Commands.Root);
21+
app.Add("json", Commands.RecordJson);
22+
}
23+
24+
[Test]
25+
public async Task RunWithFilter()
26+
{
27+
// check NativeAot trimming,command requires [DynamicDependency]
28+
string[] runArgs =
29+
[
30+
"input.txt",
31+
"--count", "3",
32+
"--quiet"
33+
];
34+
35+
await app.RunAsync(runArgs);
36+
await Assert.That(Environment.ExitCode).IsEqualTo(0);
37+
}
38+
39+
[Test]
40+
public async Task JsonInvalid()
41+
{
42+
string[] runArgs =
43+
[
44+
"json",
45+
"--record",
46+
"{ \"X\" = 10, \"Y\" = 20 }"
47+
];
48+
49+
await app.RunAsync(runArgs);
50+
await Assert.That(Environment.ExitCode).IsNotEqualTo(0);
51+
}
52+
}
53+
54+
internal static class Commands
55+
{
56+
public static async Task<int> Root(
57+
[Argument] string path,
58+
[Range(1, 10)] int count = 1,
59+
bool quiet = false,
60+
CancellationToken cancellationToken = default)
61+
{
62+
await Task.Delay(10, cancellationToken);
63+
if (!quiet)
64+
{
65+
Console.WriteLine($"Processing {path} with count {count}");
66+
}
67+
return 0;
68+
}
69+
70+
public static void RecordJson(MyRecord record)
71+
{
72+
Console.WriteLine($"Record: X={record.X}, Y={record.Y}");
73+
}
74+
}
75+
76+
77+
internal sealed class LoggingFilter(ConsoleAppFilter next) : ConsoleAppFilter(next)
78+
{
79+
public override async Task InvokeAsync(ConsoleAppContext context, CancellationToken cancellationToken)
80+
{
81+
try
82+
{
83+
await Next.InvokeAsync(context, cancellationToken);
84+
}
85+
catch (Exception ex)
86+
{
87+
Console.WriteLine($"Unhandled exception: {ex.Message}");
88+
throw;
89+
}
90+
}
91+
}
92+
93+
public record MyRecord(int X, int Y);

tests/NativeAotTrimming/Program.cs

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)