ExitCallbacks.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using UnityEditor.TestTools.TestRunner.Api;
  3. using UnityEngine;
  4. namespace UnityEditor.TestTools.TestRunner.CommandLineTest
  5. {
  6. [Serializable]
  7. internal class ExitCallbacks : ScriptableObject, IErrorCallbacks
  8. {
  9. private bool m_AnyTestsExecuted;
  10. private bool m_RunFailed;
  11. internal static bool preventExit;
  12. public void RunFinished(ITestResultAdaptor testResults)
  13. {
  14. if (preventExit)
  15. {
  16. return;
  17. }
  18. if (!m_AnyTestsExecuted)
  19. {
  20. Debug.LogFormat(LogType.Warning, LogOption.NoStacktrace, null, "No tests were executed");
  21. }
  22. EditorApplication.Exit(m_RunFailed ? (int)Executer.ReturnCodes.Failed : (int)Executer.ReturnCodes.Ok);
  23. }
  24. public void TestStarted(ITestAdaptor test)
  25. {
  26. if (!test.IsSuite)
  27. {
  28. m_AnyTestsExecuted = true;
  29. }
  30. }
  31. public void TestFinished(ITestResultAdaptor result)
  32. {
  33. if (!result.Test.IsSuite && (result.TestStatus == TestStatus.Failed || result.TestStatus == TestStatus.Inconclusive))
  34. {
  35. m_RunFailed = true;
  36. }
  37. }
  38. public void RunStarted(ITestAdaptor testsToRun)
  39. {
  40. }
  41. public void OnError(string message)
  42. {
  43. EditorApplication.Exit((int)Executer.ReturnCodes.RunError);
  44. }
  45. }
  46. }