From 905caafbb2365e45318629e83068c9b15a1a37d4 Mon Sep 17 00:00:00 2001 From: Paul Irwin Date: Sun, 27 Oct 2024 14:22:16 -0600 Subject: [PATCH] Exclude generated code from ApiScanTestBase tests --- .../Support/ApiScanTestBase.cs | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/Lucene.Net.TestFramework/Support/ApiScanTestBase.cs b/src/Lucene.Net.TestFramework/Support/ApiScanTestBase.cs index bb5ac1fd75..99b0d359a6 100644 --- a/src/Lucene.Net.TestFramework/Support/ApiScanTestBase.cs +++ b/src/Lucene.Net.TestFramework/Support/ApiScanTestBase.cs @@ -1,5 +1,6 @@ using Lucene.Net.Support; using System; +using System.CodeDom.Compiler; using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -407,7 +408,7 @@ private static IEnumerable GetInvalidPrivateFields(Assembly assembly, st { var result = new List(); - var classes = assembly.GetTypes().Where(t => t.IsClass); + var classes = GetTypesToTest(assembly).Where(t => t.IsClass); foreach (var c in classes) { @@ -443,7 +444,7 @@ private static IEnumerable GetInvalidProtectedFields(Assembly assembly) { var result = new List(); - var classes = assembly.GetTypes().Where(t => t.IsClass); + var classes = GetTypesToTest(assembly).Where(t => t.IsClass); foreach (var c in classes) { @@ -489,7 +490,7 @@ private static IEnumerable GetInvalidPublicFields(Assembly assembly, str { var result = new List(); - var classes = assembly.GetTypes().Where(t => t.IsClass && !t.HasAttribute(inherit: false)); + var classes = GetTypesToTest(assembly).Where(t => t.IsClass); foreach (var c in classes) { @@ -535,7 +536,7 @@ private static IEnumerable GetInvalidMethodParameterNames(Assembly assem { var result = new List(); - var classes = assembly.GetTypes().Where(t => t.IsClass); + var classes = GetTypesToTest(assembly).Where(t => t.IsClass); foreach (var c in classes) { @@ -567,7 +568,7 @@ private static IEnumerable GetInvalidInterfaceNames(Assembly assembly) { var result = new List(); - var interfaces = assembly.GetTypes().Where(t => t.IsInterface); + var interfaces = GetTypesToTest(assembly).Where(t => t.IsInterface); foreach (var i in interfaces) { @@ -584,7 +585,7 @@ private static IEnumerable GetInvalidClassNames(Assembly assembly) { var result = new List(); - var classes = assembly.GetTypes().Where(t => t.IsClass); + var classes = GetTypesToTest(assembly).Where(t => t.IsClass); foreach (var c in classes) { @@ -611,7 +612,7 @@ private static IEnumerable GetPropertiesWithNoGetter(Assembly assembly) { var result = new List(); - var classes = assembly.GetTypes().Where(t => t.IsClass); + var classes = GetTypesToTest(assembly).Where(t => t.IsClass); foreach (var c in classes) { @@ -633,7 +634,7 @@ private static IEnumerable GetPropertiesThatReturnArray(Assembly assembl { var result = new List(); - var classes = assembly.GetTypes().Where(t => t.IsClass); + var classes = GetTypesToTest(assembly).Where(t => t.IsClass); foreach (var c in classes) { @@ -667,7 +668,7 @@ private static IEnumerable GetProtectedFieldsContainingComparer(Assembly { var result = new List(); - var classes = assembly.GetTypes().Where(t => t.IsClass); + var classes = GetTypesToTest(assembly).Where(t => t.IsClass); foreach (var c in classes) { @@ -699,7 +700,7 @@ private static IEnumerable GetMembersContainingComparer(Assembly assembl { var result = new List(); - var types = assembly.GetTypes(); + var types = GetTypesToTest(assembly); foreach (var t in types) { @@ -737,7 +738,7 @@ private static IEnumerable GetMembersNamedSize(Assembly assembly) { var result = new List(); - var types = assembly.GetTypes(); + var types = GetTypesToTest(assembly); foreach (var t in types) { @@ -772,7 +773,7 @@ private static IEnumerable GetMembersContainingNonNetNumeric(Assembly as { var result = new List(); - var types = assembly.GetTypes(); + var types = GetTypesToTest(assembly); foreach (var t in types) { @@ -816,7 +817,7 @@ private static IEnumerable GetTypesContainingNonNetNumeric(Assembly asse { var result = new List(); - var types = assembly.GetTypes(); + var types = GetTypesToTest(assembly); foreach (var t in types) { @@ -838,7 +839,7 @@ private static IEnumerable GetMethodsThatReturnWritableArray(Assembly as { var result = new List(); - var classes = assembly.GetTypes().Where(t => t.IsClass); + var classes = GetTypesToTest(assembly).Where(t => t.IsClass); foreach (var c in classes) { @@ -892,7 +893,7 @@ private static IEnumerable GetPublicNullableEnumMembers(Assembly assembl { var result = new List(); - var types = assembly.GetTypes(); + var types = GetTypesToTest(assembly); foreach (var t in types) { @@ -1004,7 +1005,7 @@ private static IEnumerable GetMembersAcceptingOrReturningType(Type lookF { var result = new List(); - var types = assembly.GetTypes(); + var types = GetTypesToTest(assembly); foreach (var t in types) { @@ -1105,5 +1106,10 @@ private static IEnumerable GetMembersAcceptingOrReturningType(Type lookF return result.ToArray(); } + + private static IEnumerable GetTypesToTest(Assembly assembly) => + assembly.GetTypes() + .Where(t => !t.HasAttribute(inherit: false) + && !t.HasAttribute(inherit: false)); } }