Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests] Add .cctor execution to introspection #7976

Merged
merged 2 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions tests/introspection/ApiTypeTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;

using NUnit.Framework;
using Xamarin.Utils;

using Foundation;
using ObjCRuntime;

namespace Introspection {

[TestFixture]
// we want the tests to be available because we use the linker
[Preserve (AllMembers = true)]
public class ApiTypeTest : ApiBaseTest {

[Test]
public void StaticCtor ()
{
ContinueOnFailure = true;
foreach (Type t in Assembly.GetTypes ()) {
var cctor = t.GetConstructor (BindingFlags.Static | BindingFlags.NonPublic, null, Type.EmptyTypes, null);
if (cctor == null)
continue;
// we don't skip based on availability attributes since the execution of .cctor can easily happen indirectly and
// we rather catch them all here *now* than trying to figure out how to replicate the specific conditions *later*
try {
RuntimeHelpers.RunClassConstructor (t.TypeHandle);
}
catch (TypeInitializationException e) {
ReportError ($"{t.FullName} .cctor could not execute properly: {e}");
}
}
AssertIfErrors ($"{Errors} execution failure(s)");
}
}
}
3 changes: 3 additions & 0 deletions tests/introspection/Mac/introspection-mac.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
<Compile Include="..\ApiFrameworkTest.cs">
<Link>ApiFrameworkTest.cs</Link>
</Compile>
<Compile Include="..\ApiTypeTest.cs">
<Link>ApiTypeTest.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\external\guiunit\src\framework\GuiUnit_NET_4_5.csproj">
Expand Down
3 changes: 3 additions & 0 deletions tests/introspection/iOS/introspection-ios.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@
<Compile Include="..\ApiFrameworkTest.cs">
<Link>ApiFrameworkTest.cs</Link>
</Compile>
<Compile Include="..\ApiTypeTest.cs">
<Link>ApiTypeTest.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="Info.plist">
Expand Down