Skip to content

Commit 018d7a6

Browse files
committed
Added AOT compatibility test
Part of the ongoing work for issue #1844
1 parent 94d9283 commit 018d7a6

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<PublishAot>true</PublishAot>
9+
<TrimmerSingleWarn>false</TrimmerSingleWarn>
10+
<SelfContained>true</SelfContained>
11+
<InvariantGlobalization>true</InvariantGlobalization>
12+
<UseMailKitLite Condition=" '$(UseMailKitLite)' == '' ">false</UseMailKitLite>
13+
</PropertyGroup>
14+
15+
<ItemGroup>
16+
<PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<ProjectReference Include="..\MailKit\MailKit.csproj" Condition=" '$(UseMailKitLite)' == 'false' " />
21+
<ProjectReference Include="..\submodules\MimeKit\MimeKit.csproj" Condition=" '$(UseMailKitLite)' == 'false' " />
22+
<TrimmerRootAssembly Include="MailKit" Path="..\MailKit\MailKit.csproj" Condition=" '$(UseMailKitLite)' == 'false' " />
23+
<TrimmerRootAssembly Include="MimeKit" Path="..\submodules\MimeKit\MimeKit.csproj" Condition=" '$(UseMailKitLite)' == 'false' " />
24+
25+
<ProjectReference Include="..\MailKit\MailKitLite.csproj" Condition=" '$(UseMailKitLite)' == 'true' " />
26+
<ProjectReference Include="..\submodules\MimeKit\MimeKitLite.csproj" Condition=" '$(UseMailKitLite)' == 'true' " />
27+
<TrimmerRootAssembly Include="MailKit" Path="..\MailKit\MailKitLite.csproj" Condition=" '$(UseMailKitLite)' == 'true' " />
28+
<TrimmerRootAssembly Include="MimeKitLite" Path="..\submodules\MimeKit\MimeKitLite.csproj" Condition=" '$(UseMailKitLite)' == 'true' " />
29+
</ItemGroup>
30+
31+
</Project>

AotCompatibility/Program.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//
2+
// Program.cs
3+
//
4+
// Author: Jeffrey Stedfast <[email protected]>
5+
//
6+
// Copyright (c) 2013-2024 .NET Foundation and Contributors
7+
//
8+
// Permission is hereby granted, free of charge, to any person obtaining a copy
9+
// of this software and associated documentation files (the "Software"), to deal
10+
// in the Software without restriction, including without limitation the rights
11+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
// copies of the Software, and to permit persons to whom the Software is
13+
// furnished to do so, subject to the following conditions:
14+
//
15+
// The above copyright notice and this permission notice shall be included in
16+
// all copies or substantial portions of the Software.
17+
//
18+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
// THE SOFTWARE.
25+
//
26+
27+
using System.Text;
28+
29+
using MimeKit;
30+
using MailKit;
31+
using MailKit.Net;
32+
using MailKit.Net.Imap;
33+
using MailKit.Net.Pop3;
34+
using MailKit.Net.Smtp;
35+
36+
namespace AotCompatibility {
37+
class Program
38+
{
39+
static int Main (string[] args)
40+
{
41+
try {
42+
Encoding.RegisterProvider (CodePagesEncodingProvider.Instance);
43+
44+
var message = new MimeMessage ();
45+
46+
using (var imap = new ImapClient ()) {}
47+
using (var pop3 = new Pop3Client ()) {}
48+
using (var smtp = new SmtpClient ()) {}
49+
50+
return 0;
51+
} catch (Exception ex) {
52+
Console.WriteLine (ex);
53+
return -1;
54+
}
55+
}
56+
}
57+
}

scripts/test-aot-compatibility.ps1

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
param([string]$useMailKitLite)
2+
3+
$rootDirectory = Split-Path $PSScriptRoot -Parent
4+
$publishOutput = dotnet publish $rootDirectory/AotCompatibility/AotCompatibility.csproj -nodeReuse:false /p:UseSharedCompilation=false /p:ExposeExperimentalFeatures=true /p:UseMailKitLite=$useMailKitLite
5+
6+
$actualWarningCount = 0
7+
8+
foreach ($line in $($publishOutput -split "`r`n"))
9+
{
10+
if ($line -like "*warning IL*")
11+
{
12+
Write-Host $line
13+
14+
$actualWarningCount += 1
15+
}
16+
}
17+
18+
pushd $rootDirectory/AotCompatibility/bin/Release/net8.0/win-x64/publish
19+
20+
Write-Host "Executing test App..."
21+
./AotCompatibility.exe
22+
Write-Host "Finished executing test App"
23+
24+
if ($LastExitCode -ne 0)
25+
{
26+
Write-Host "There was an error while executing AotCompatibility Test App. LastExitCode is:", $LastExitCode
27+
}
28+
29+
popd
30+
31+
Write-Host "Actual warning count is:", $actualWarningCount
32+
$expectedWarningCount = 0
33+
34+
$testPassed = 0
35+
if ($actualWarningCount -ne $expectedWarningCount)
36+
{
37+
$testPassed = 1
38+
Write-Host "Actual warning count:", actualWarningCount, "is not as expected. Expected warning count is:", $expectedWarningCount
39+
}
40+
41+
Exit $testPassed

0 commit comments

Comments
 (0)