From 7c1e566113d59699af1624186c64eca67f063fc6 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Mon, 20 Apr 2020 19:09:33 -0400 Subject: Upgraded Unity --- .../TestLaunchers/AttributeFinderBase.cs | 104 --------------------- 1 file changed, 104 deletions(-) delete mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/TestLaunchers/AttributeFinderBase.cs (limited to 'Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/TestLaunchers/AttributeFinderBase.cs') diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/TestLaunchers/AttributeFinderBase.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/TestLaunchers/AttributeFinderBase.cs deleted file mode 100644 index c1690a2..0000000 --- a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEditor.TestRunner/TestLaunchers/AttributeFinderBase.cs +++ /dev/null @@ -1,104 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using NUnit.Framework.Interfaces; -using UnityEngine; -using UnityEngine.TestTools; - -namespace UnityEditor.TestTools.TestRunner -{ - internal abstract class AttributeFinderBase : IAttributeFinder - { - public abstract IEnumerable Search(ITest tests, ITestFilter filter, RuntimePlatform testTargetPlatform); - } - - internal interface IAttributeFinder - { - IEnumerable Search(ITest tests, ITestFilter filter, RuntimePlatform testTargetPlatform); - } - - internal abstract class AttributeFinderBase : AttributeFinderBase where T2 : Attribute - { - private readonly Func m_TypeSelector; - protected AttributeFinderBase(Func typeSelector) - { - m_TypeSelector = typeSelector; - } - - public override IEnumerable Search(ITest tests, ITestFilter filter, RuntimePlatform testTargetPlatform) - { - var selectedTests = new List(); - GetMatchingTests(tests, filter, ref selectedTests, testTargetPlatform); - - var result = new List(); - result.AddRange(GetTypesFromPrebuildAttributes(selectedTests)); - result.AddRange(GetTypesFromInterface(selectedTests, testTargetPlatform)); - - return result.Distinct(); - } - - private static void GetMatchingTests(ITest tests, ITestFilter filter, ref List resultList, RuntimePlatform testTargetPlatform) - { - foreach (var test in tests.Tests) - { - if (IsTestEnabledOnPlatform(test, testTargetPlatform)) - { - if (test.IsSuite) - { - GetMatchingTests(test, filter, ref resultList, testTargetPlatform); - } - else - { - if (filter.Pass(test)) - resultList.Add(test); - } - } - } - } - - private static bool IsTestEnabledOnPlatform(ITest test, RuntimePlatform testTargetPlatform) - { - if (test.Method == null) - { - return true; - } - - var attributesFromMethods = test.Method.GetCustomAttributes(true).Select(attribute => attribute); - var attributesFromTypes = test.Method.TypeInfo.GetCustomAttributes(true).Select(attribute => attribute); - - if (!attributesFromMethods.All(a => a.IsPlatformSupported(testTargetPlatform))) - { - return false; - } - - if (!attributesFromTypes.All(a => a.IsPlatformSupported(testTargetPlatform))) - { - return false; - } - - return true; - } - - private IEnumerable GetTypesFromPrebuildAttributes(IEnumerable tests) - { - var allAssemblies = AppDomain.CurrentDomain.GetAssemblies(); - allAssemblies = allAssemblies.Where(x => x.GetReferencedAssemblies().Any(z => z.Name == "UnityEditor.TestRunner")).ToArray(); - var attributesFromAssemblies = allAssemblies.SelectMany(assembly => assembly.GetCustomAttributes(typeof(T2), true).OfType()); - var attributesFromMethods = tests.SelectMany(t => t.Method.GetCustomAttributes(true).Select(attribute => attribute)); - var attributesFromTypes = tests.SelectMany(t => t.Method.TypeInfo.GetCustomAttributes(true).Select(attribute => attribute)); - - var result = new List(); - result.AddRange(attributesFromAssemblies); - result.AddRange(attributesFromMethods); - result.AddRange(attributesFromTypes); - - return result.Select(m_TypeSelector).Where(type => type != null); - } - - private static IEnumerable GetTypesFromInterface(IEnumerable selectedTests, RuntimePlatform testTargetPlatform) - { - var typesWithInterfaces = selectedTests.Where(t => typeof(T1).IsAssignableFrom(t.Method.TypeInfo.Type) && IsTestEnabledOnPlatform(t, testTargetPlatform)); - return typesWithInterfaces.Select(t => t.Method.TypeInfo.Type); - } - } -} -- cgit v1.2.3