Skip to content

Commit

Permalink
Exclude generated code from ApiScanTestBase tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirwin committed Nov 5, 2024
1 parent cda4c6b commit 905caaf
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/Lucene.Net.TestFramework/Support/ApiScanTestBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Lucene.Net.Support;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -407,7 +408,7 @@ private static IEnumerable<string> GetInvalidPrivateFields(Assembly assembly, st
{
var result = new List<string>();

var classes = assembly.GetTypes().Where(t => t.IsClass);
var classes = GetTypesToTest(assembly).Where(t => t.IsClass);

foreach (var c in classes)
{
Expand Down Expand Up @@ -443,7 +444,7 @@ private static IEnumerable<string> GetInvalidProtectedFields(Assembly assembly)
{
var result = new List<string>();

var classes = assembly.GetTypes().Where(t => t.IsClass);
var classes = GetTypesToTest(assembly).Where(t => t.IsClass);

foreach (var c in classes)
{
Expand Down Expand Up @@ -489,7 +490,7 @@ private static IEnumerable<string> GetInvalidPublicFields(Assembly assembly, str
{
var result = new List<string>();

var classes = assembly.GetTypes().Where(t => t.IsClass && !t.HasAttribute<CompilerGeneratedAttribute>(inherit: false));
var classes = GetTypesToTest(assembly).Where(t => t.IsClass);

foreach (var c in classes)
{
Expand Down Expand Up @@ -535,7 +536,7 @@ private static IEnumerable<string> GetInvalidMethodParameterNames(Assembly assem
{
var result = new List<string>();

var classes = assembly.GetTypes().Where(t => t.IsClass);
var classes = GetTypesToTest(assembly).Where(t => t.IsClass);

foreach (var c in classes)
{
Expand Down Expand Up @@ -567,7 +568,7 @@ private static IEnumerable<string> GetInvalidInterfaceNames(Assembly assembly)
{
var result = new List<string>();

var interfaces = assembly.GetTypes().Where(t => t.IsInterface);
var interfaces = GetTypesToTest(assembly).Where(t => t.IsInterface);

foreach (var i in interfaces)
{
Expand All @@ -584,7 +585,7 @@ private static IEnumerable<string> GetInvalidClassNames(Assembly assembly)
{
var result = new List<string>();

var classes = assembly.GetTypes().Where(t => t.IsClass);
var classes = GetTypesToTest(assembly).Where(t => t.IsClass);

foreach (var c in classes)
{
Expand All @@ -611,7 +612,7 @@ private static IEnumerable<string> GetPropertiesWithNoGetter(Assembly assembly)
{
var result = new List<string>();

var classes = assembly.GetTypes().Where(t => t.IsClass);
var classes = GetTypesToTest(assembly).Where(t => t.IsClass);

foreach (var c in classes)
{
Expand All @@ -633,7 +634,7 @@ private static IEnumerable<string> GetPropertiesThatReturnArray(Assembly assembl
{
var result = new List<string>();

var classes = assembly.GetTypes().Where(t => t.IsClass);
var classes = GetTypesToTest(assembly).Where(t => t.IsClass);

foreach (var c in classes)
{
Expand Down Expand Up @@ -667,7 +668,7 @@ private static IEnumerable<string> GetProtectedFieldsContainingComparer(Assembly
{
var result = new List<string>();

var classes = assembly.GetTypes().Where(t => t.IsClass);
var classes = GetTypesToTest(assembly).Where(t => t.IsClass);

foreach (var c in classes)
{
Expand Down Expand Up @@ -699,7 +700,7 @@ private static IEnumerable<string> GetMembersContainingComparer(Assembly assembl
{
var result = new List<string>();

var types = assembly.GetTypes();
var types = GetTypesToTest(assembly);

foreach (var t in types)
{
Expand Down Expand Up @@ -737,7 +738,7 @@ private static IEnumerable<string> GetMembersNamedSize(Assembly assembly)
{
var result = new List<string>();

var types = assembly.GetTypes();
var types = GetTypesToTest(assembly);

foreach (var t in types)
{
Expand Down Expand Up @@ -772,7 +773,7 @@ private static IEnumerable<string> GetMembersContainingNonNetNumeric(Assembly as
{
var result = new List<string>();

var types = assembly.GetTypes();
var types = GetTypesToTest(assembly);

foreach (var t in types)
{
Expand Down Expand Up @@ -816,7 +817,7 @@ private static IEnumerable<string> GetTypesContainingNonNetNumeric(Assembly asse
{
var result = new List<string>();

var types = assembly.GetTypes();
var types = GetTypesToTest(assembly);

foreach (var t in types)
{
Expand All @@ -838,7 +839,7 @@ private static IEnumerable<string> GetMethodsThatReturnWritableArray(Assembly as
{
var result = new List<string>();

var classes = assembly.GetTypes().Where(t => t.IsClass);
var classes = GetTypesToTest(assembly).Where(t => t.IsClass);

foreach (var c in classes)
{
Expand Down Expand Up @@ -892,7 +893,7 @@ private static IEnumerable<string> GetPublicNullableEnumMembers(Assembly assembl
{
var result = new List<string>();

var types = assembly.GetTypes();
var types = GetTypesToTest(assembly);

foreach (var t in types)
{
Expand Down Expand Up @@ -1004,7 +1005,7 @@ private static IEnumerable<string> GetMembersAcceptingOrReturningType(Type lookF
{
var result = new List<string>();

var types = assembly.GetTypes();
var types = GetTypesToTest(assembly);

foreach (var t in types)
{
Expand Down Expand Up @@ -1105,5 +1106,10 @@ private static IEnumerable<string> GetMembersAcceptingOrReturningType(Type lookF

return result.ToArray();
}

private static IEnumerable<Type> GetTypesToTest(Assembly assembly) =>
assembly.GetTypes()
.Where(t => !t.HasAttribute<GeneratedCodeAttribute>(inherit: false)
&& !t.HasAttribute<CompilerGeneratedAttribute>(inherit: false));
}
}

0 comments on commit 905caaf

Please sign in to comment.