forked from dotnet/macios
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tests] Add
.cctor
execution to introspection
This will spot cases like dotnet#7959 where a type (static) constructor can fail at runtime, leading to `TypeLoadException` Ideally it's covered by it's own tests but it's better covered twice than never :)
- Loading branch information
1 parent
dd83fbe
commit 8879f8e
Showing
3 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters