SynchronousFilter.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Collections;
  2. using System.Linq;
  3. using System.Reflection;
  4. using NUnit.Framework.Interfaces;
  5. using NUnit.Framework.Internal;
  6. namespace UnityEngine.TestTools.TestRunner.GUI
  7. {
  8. class SynchronousFilter : ITestFilter
  9. {
  10. public TNode ToXml(bool recursive)
  11. {
  12. return new TNode("synchronousOnly");
  13. }
  14. public TNode AddToXml(TNode parentNode, bool recursive)
  15. {
  16. return parentNode.AddElement("synchronousOnly");
  17. }
  18. public bool Pass(ITest test)
  19. {
  20. if (test.Method == null)
  21. return true;
  22. if (test.Method.ReturnType.Type == typeof(IEnumerator))
  23. return false;
  24. if (test.Method.GetCustomAttributes<IOuterUnityTestAction>(true).Any())
  25. return false;
  26. if (test.TypeInfo?.Type != null)
  27. {
  28. if (Reflect.GetMethodsWithAttribute(test.TypeInfo.Type, typeof(UnitySetUpAttribute), true)
  29. .Any(mi => mi.ReturnType == typeof(System.Collections.IEnumerator)))
  30. return false;
  31. if (Reflect.GetMethodsWithAttribute(test.TypeInfo.Type, typeof(UnityTearDownAttribute), true)
  32. .Any(mi => mi.ReturnType == typeof(System.Collections.IEnumerator)))
  33. return false;
  34. }
  35. return true;
  36. }
  37. public bool IsExplicitMatch(ITest test)
  38. {
  39. return Pass(test);
  40. }
  41. }
  42. }