Skip to content

Commit

Permalink
[monotouch-test] Adjust how we detect when protocols are registered.
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne committed Sep 5, 2024
1 parent 3f6da31 commit a6dca9d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions tests/common/TestRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,31 @@ public static bool IsLinkAll {
}
class LinkerSentinel { }

// Determine if any assemblies were linked by checking if a few uncommon classes in corlib are still here.
static bool? link_any;
#if NET
[UnconditionalSuppressMessage ("Trimming", "IL2026", Justification = "This property checks whether the trimmer is enabled by checking if a type survived trimming; it's thus trimmer safe in that the any behavioral difference when the trimmer is enabled is exactly what it's looking for.")]
#endif
public static bool IsLinkAny {
get {
if (!link_any.HasValue) {
var uncommonTypes = new string [] {
"System.Action`14",
"System.DBNull",
"System.Diagnostics.Debugger",
"System.Func`15",
};
link_any = false;
foreach (var uncommonType in uncommonTypes) {
link_any = typeof (int).Assembly.GetType (uncommonType) is null;
if (link_any == true)
break;
}
}
return link_any.Value;
}
}

public static bool IsOptimizeAll {
get {
#if OPTIMIZEALL
Expand Down
2 changes: 1 addition & 1 deletion tests/monotouch-test/ObjCRuntime/RegistrarTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5555,7 +5555,7 @@ void AssertMemberCount (Type type)
#if OPTIMIZEALL || NATIVEAOT
var expectNoMembers = true;
#elif !__MACOS__
var expectNoMembers = global::XamarinTests.ObjCRuntime.Registrar.IsStaticRegistrar;
var expectNoMembers = global::XamarinTests.ObjCRuntime.Registrar.IsStaticRegistrar && TestRuntime.IsLinkAny;
#else
var expectNoMembers = false;
#endif
Expand Down

0 comments on commit a6dca9d

Please sign in to comment.