Skip to content

Commit 8b89146

Browse files
committed
Added AOT compatibility tests
1 parent 1fd2580 commit 8b89146

5 files changed

Lines changed: 120 additions & 0 deletions

File tree

src/Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<ItemGroup>
2626
<!--Test packages-->
2727
<PackageVersion Include="xunit.v3.mtp-v2" Version="4.0.0" />
28+
<PackageVersion Include="xunit.v3.aot.mtp-v2" Version="4.0.0" />
2829
<PackageVersion Include="Microsoft.Testing.Extensions.TrxReport" Version="2.3.3" />
2930
<PackageVersion Include="Microsoft.Testing.Extensions.CodeCoverage" Version="18.10.0" />
3031
</ItemGroup>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace DotNext;
2+
3+
public class DelegateHelpersTests : Assert
4+
{
5+
[Fact]
6+
public static unsafe void CreateAction()
7+
{
8+
Throws<PlatformNotSupportedException>(static () => Action.FromPointer(&DoAction));
9+
10+
static void DoAction()
11+
{
12+
}
13+
}
14+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net10.0</TargetFramework>
5+
<OutputType>Exe</OutputType>
6+
<RootNamespace>DotNext</RootNamespace>
7+
<LangVersion>latest</LangVersion>
8+
<ImplicitUsings>true</ImplicitUsings>
9+
<EnableNETAnalyzers>false</EnableNETAnalyzers>
10+
<PublishAot>true</PublishAot>
11+
<InvariantGlobalization>true</InvariantGlobalization>
12+
<Authors>.NET Foundation and Contributors</Authors>
13+
<Product>.NEXT Family of Libraries</Product>
14+
<Description>Unit tests for AOT compatibility of .NEXT libraries</Description>
15+
<Copyright>Copyright © .NET Foundation and Contributors</Copyright>
16+
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
17+
</PropertyGroup>
18+
19+
<PropertyGroup>
20+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
21+
</PropertyGroup>
22+
23+
<ItemGroup>
24+
<PackageReference Include="xunit.v3.aot.mtp-v2"/>
25+
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" />
26+
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" />
27+
</ItemGroup>
28+
29+
<ItemGroup>
30+
<ProjectReference Include="..\DotNext\DotNext.csproj"/>
31+
</ItemGroup>
32+
33+
<ItemGroup>
34+
<Using Include="Xunit" />
35+
</ItemGroup>
36+
37+
<ItemGroup>
38+
<CodeCoverageExclude Include="**/*.g.cs" />
39+
</ItemGroup>
40+
</Project>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
namespace DotNext.Runtime;
2+
3+
public sealed class BoxedValueTests : Assert
4+
{
5+
[Fact]
6+
public static void BoxUnbox()
7+
{
8+
var obj = (BoxedValue<int>)42;
9+
Equal(42.GetHashCode(), obj.GetHashCode());
10+
Equal(42, obj.Value);
11+
Equal(42, obj);
12+
Equal(typeof(int), obj.GetType());
13+
}
14+
15+
[Fact]
16+
public static void Unwrap()
17+
{
18+
object obj = null;
19+
Null(BoxedValue<int>.GetTypedReference(obj));
20+
21+
obj = 42;
22+
Equal(42, BoxedValue<int>.GetTypedReference(obj));
23+
24+
obj = string.Empty;
25+
Throws<ArgumentException>(() => BoxedValue<int>.GetTypedReference(obj));
26+
}
27+
28+
[Fact]
29+
public static void ToUntypedReference()
30+
{
31+
ValueType obj = BoxedValue<int>.Box(42);
32+
Equal(42, obj);
33+
}
34+
35+
private struct MutableStruct
36+
{
37+
public int Value;
38+
}
39+
40+
[Fact]
41+
public static void BitwiseCopyImmutable()
42+
{
43+
var boxed1 = (BoxedValue<int>)42;
44+
var boxed2 = boxed1.Copy();
45+
NotSame(boxed1, boxed2);
46+
Equal(42, boxed1);
47+
Equal(42, boxed2);
48+
}
49+
50+
[Fact]
51+
public static void BitwiseCopyMutable()
52+
{
53+
var boxed1 = (BoxedValue<MutableStruct>)new MutableStruct();
54+
var boxed2 = boxed1.Copy();
55+
NotSame(boxed1, boxed2);
56+
57+
boxed1.Value.Value = 42;
58+
boxed2.Value.Value = 43;
59+
60+
NotEqual(boxed1.Value.Value, boxed2.Value.Value);
61+
}
62+
}

src/DotNext.slnx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
</Project>
2828
</Folder>
2929
<Folder Name="/Misc/">
30+
<Project Path="DotNext.Aot.Tests/DotNext.Aot.Tests.csproj">
31+
<BuildType Solution="Bench|*" Project="Debug" />
32+
</Project>
3033
<Project Path="DotNext.Benchmarks.WAL/DotNext.Benchmarks.WAL.csproj">
3134
<BuildType Solution="Bench|*" Project="Debug" />
3235
</Project>

0 commit comments

Comments
 (0)