No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StrictCheckCommand.cs 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections;
  3. using NUnit.Framework.Interfaces;
  4. using NUnit.Framework.Internal;
  5. using NUnit.Framework.Internal.Commands;
  6. using UnityEditor;
  7. using UnityEngine.TestRunner.NUnitExtensions.Runner;
  8. #if UNITY_EDITOR
  9. using UnityEditorInternal;
  10. #endif
  11. namespace UnityEngine.TestTools
  12. {
  13. internal class StrictCheckCommand : DelegatingTestCommand, IEnumerableTestMethodCommand
  14. {
  15. public StrictCheckCommand(TestCommand innerCommand) : base(innerCommand)
  16. {
  17. }
  18. public override TestResult Execute(ITestExecutionContext context)
  19. {
  20. throw new NotImplementedException();
  21. }
  22. public IEnumerable ExecuteEnumerable(ITestExecutionContext context)
  23. {
  24. var unityContext = UnityTestExecutionContext.CurrentContext;
  25. var executeEnumerable = ((IEnumerableTestMethodCommand)innerCommand).ExecuteEnumerable(context);
  26. foreach (var iterator in executeEnumerable)
  27. {
  28. yield return iterator;
  29. }
  30. if (!unityContext.FeatureFlags.strictDomainReload)
  31. {
  32. yield break;
  33. }
  34. // Refreshing the asset database before the check, to ensure that
  35. // no potential pending domain reloads propagate to the following test
  36. // (due to ex. creation or deletion of asset files in the TearDown of a test).
  37. #if UNITY_EDITOR
  38. AssetDatabase.Refresh();
  39. #endif
  40. if (isDomainReloadPending())
  41. {
  42. context.CurrentResult.SetResult(ResultState.Failure, "A pending domain reload was detected.");
  43. }
  44. }
  45. private static bool isDomainReloadPending()
  46. {
  47. #if UNITY_EDITOR
  48. return (InternalEditorUtility.IsScriptReloadRequested() || EditorApplication.isCompiling);
  49. #else
  50. return false;
  51. #endif
  52. }
  53. }
  54. }