Initial
test
This commit is contained in:
		@@ -0,0 +1,8 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: 61e236e8570a95e4eb754fb291e102e0
 | 
			
		||||
folderAsset: yes
 | 
			
		||||
DefaultImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
@@ -0,0 +1,47 @@
 | 
			
		||||
using NUnit.Framework;
 | 
			
		||||
using NUnit.Framework.Interfaces;
 | 
			
		||||
 | 
			
		||||
namespace UnityEngine.TestTools.TestRunner.Callbacks
 | 
			
		||||
{
 | 
			
		||||
    [AddComponentMenu("")]
 | 
			
		||||
    internal class PlayModeRunnerCallback : MonoBehaviour, ITestRunnerListener
 | 
			
		||||
    {
 | 
			
		||||
        private TestResultRenderer m_ResultRenderer;
 | 
			
		||||
 | 
			
		||||
        public void RunFinished(ITestResult testResults)
 | 
			
		||||
        {
 | 
			
		||||
            Application.logMessageReceivedThreaded -= LogRecieved;
 | 
			
		||||
            if (Camera.main == null)
 | 
			
		||||
            {
 | 
			
		||||
                gameObject.AddComponent<Camera>();
 | 
			
		||||
            }
 | 
			
		||||
            m_ResultRenderer = new TestResultRenderer(testResults);
 | 
			
		||||
            m_ResultRenderer.ShowResults();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void TestFinished(ITestResult result)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void OnGUI()
 | 
			
		||||
        {
 | 
			
		||||
            if (m_ResultRenderer != null)
 | 
			
		||||
                m_ResultRenderer.Draw();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void RunStarted(ITest testsToRun)
 | 
			
		||||
        {
 | 
			
		||||
            Application.logMessageReceivedThreaded += LogRecieved;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void TestStarted(ITest test)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void LogRecieved(string message, string stacktrace, LogType type)
 | 
			
		||||
        {
 | 
			
		||||
            if (TestContext.Out != null)
 | 
			
		||||
                TestContext.Out.WriteLine(message);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: 3cf5cb9e1ef590c48b1f919f2a7bd895
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
@@ -0,0 +1,151 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using NUnit.Framework.Interfaces;
 | 
			
		||||
using UnityEngine.Networking.PlayerConnection;
 | 
			
		||||
using UnityEngine.TestRunner.TestLaunchers;
 | 
			
		||||
 | 
			
		||||
namespace UnityEngine.TestTools.TestRunner.Callbacks
 | 
			
		||||
{
 | 
			
		||||
    [AddComponentMenu("")]
 | 
			
		||||
    internal class RemoteTestResultSender : MonoBehaviour, ITestRunnerListener
 | 
			
		||||
    {
 | 
			
		||||
        private class QueueData
 | 
			
		||||
        {
 | 
			
		||||
            public Guid id { get; set; }
 | 
			
		||||
            public byte[] data { get; set; }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private const int k_aliveMessageFrequency = 120;
 | 
			
		||||
        private float m_NextliveMessage = k_aliveMessageFrequency;
 | 
			
		||||
        private readonly Queue<QueueData> m_SendQueue = new Queue<QueueData>();
 | 
			
		||||
        private readonly object m_LockQueue = new object();
 | 
			
		||||
        private readonly IRemoteTestResultDataFactory m_TestResultDataFactory = new RemoteTestResultDataFactory();
 | 
			
		||||
 | 
			
		||||
        public void Start()
 | 
			
		||||
        {
 | 
			
		||||
            PlayerConnection.instance.Register(PlayerConnectionMessageIds.quitPlayerMessageId, EditorProccessedTheResult);
 | 
			
		||||
            StartCoroutine(SendDataRoutine());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void EditorProccessedTheResult(MessageEventArgs arg0)
 | 
			
		||||
        {
 | 
			
		||||
            if (arg0.data != null)
 | 
			
		||||
            {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            //Some platforms don't quit, so we need to disconnect to make sure they will not connect to another editor instance automatically.
 | 
			
		||||
            PlayerConnection.instance.DisconnectAll();
 | 
			
		||||
 | 
			
		||||
            //XBOX has an error when quitting
 | 
			
		||||
            if (Application.platform == RuntimePlatform.XboxOne)
 | 
			
		||||
            {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            Application.Quit();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private byte[] SerializeObject(object objectToSerialize)
 | 
			
		||||
        {
 | 
			
		||||
            return Encoding.UTF8.GetBytes(JsonUtility.ToJson(objectToSerialize));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void RunStarted(ITest testsToRun)
 | 
			
		||||
        {
 | 
			
		||||
            var data = SerializeObject(m_TestResultDataFactory.CreateFromTest(testsToRun));
 | 
			
		||||
            lock (m_LockQueue)
 | 
			
		||||
            {
 | 
			
		||||
                m_SendQueue.Enqueue(new QueueData
 | 
			
		||||
                {
 | 
			
		||||
                    id = PlayerConnectionMessageIds.runStartedMessageId,
 | 
			
		||||
                    data = data
 | 
			
		||||
                });
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void RunFinished(ITestResult testResults)
 | 
			
		||||
        {
 | 
			
		||||
            var data = SerializeObject(m_TestResultDataFactory.CreateFromTestResult(testResults));
 | 
			
		||||
            lock (m_LockQueue)
 | 
			
		||||
            {
 | 
			
		||||
                m_SendQueue.Enqueue(new QueueData { id = PlayerConnectionMessageIds.runFinishedMessageId, data = data, });
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void TestStarted(ITest test)
 | 
			
		||||
        {
 | 
			
		||||
            var data = SerializeObject(m_TestResultDataFactory.CreateFromTest(test));
 | 
			
		||||
            lock (m_LockQueue)
 | 
			
		||||
            {
 | 
			
		||||
                m_SendQueue.Enqueue(new QueueData
 | 
			
		||||
                {
 | 
			
		||||
                    id = PlayerConnectionMessageIds.testStartedMessageId,
 | 
			
		||||
                    data = data
 | 
			
		||||
                });
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void TestFinished(ITestResult result)
 | 
			
		||||
        {
 | 
			
		||||
            var testRunnerResultForApi = m_TestResultDataFactory.CreateFromTestResult(result);
 | 
			
		||||
            var resultData = SerializeObject(testRunnerResultForApi);
 | 
			
		||||
            lock (m_LockQueue)
 | 
			
		||||
            {
 | 
			
		||||
                m_SendQueue.Enqueue(new QueueData
 | 
			
		||||
                {
 | 
			
		||||
                    id = PlayerConnectionMessageIds.testFinishedMessageId,
 | 
			
		||||
                    data = resultData,
 | 
			
		||||
                });
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public IEnumerator SendDataRoutine()
 | 
			
		||||
        {
 | 
			
		||||
            while (!PlayerConnection.instance.isConnected)
 | 
			
		||||
            {
 | 
			
		||||
                yield return new WaitForSeconds(1);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            while (true)
 | 
			
		||||
            {
 | 
			
		||||
                lock (m_LockQueue)
 | 
			
		||||
                {
 | 
			
		||||
                    if (PlayerConnection.instance.isConnected && m_SendQueue.Count > 0)
 | 
			
		||||
                    {
 | 
			
		||||
                        ResetNextPlayerAliveMessageTime();
 | 
			
		||||
                        var queueData = m_SendQueue.Dequeue();
 | 
			
		||||
                        PlayerConnection.instance.Send(queueData.id, queueData.data);
 | 
			
		||||
                        yield return null;
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    //This is needed so we dont stall the player totally
 | 
			
		||||
                    if (!m_SendQueue.Any())
 | 
			
		||||
                    {
 | 
			
		||||
                        SendAliveMessageIfNeeded();
 | 
			
		||||
                        yield return new WaitForSeconds(0.02f);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void SendAliveMessageIfNeeded()
 | 
			
		||||
        {
 | 
			
		||||
            if (Time.timeSinceLevelLoad < m_NextliveMessage)
 | 
			
		||||
            {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Debug.Log("Sending player alive message back to editor.");
 | 
			
		||||
            ResetNextPlayerAliveMessageTime();
 | 
			
		||||
            PlayerConnection.instance.Send(PlayerConnectionMessageIds.playerAliveHeartbeat, new byte[0]);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ResetNextPlayerAliveMessageTime()
 | 
			
		||||
        {
 | 
			
		||||
            m_NextliveMessage = Time.timeSinceLevelLoad + k_aliveMessageFrequency;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: 20793418366caf14293b29c55df5e9ec
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
@@ -0,0 +1,97 @@
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using NUnit.Framework.Interfaces;
 | 
			
		||||
using NUnit.Framework.Internal;
 | 
			
		||||
 | 
			
		||||
namespace UnityEngine.TestTools.TestRunner.Callbacks
 | 
			
		||||
{
 | 
			
		||||
    internal class TestResultRenderer
 | 
			
		||||
    {
 | 
			
		||||
        private static class Styles
 | 
			
		||||
        {
 | 
			
		||||
            public static readonly GUIStyle SucceedLabelStyle;
 | 
			
		||||
            public static readonly GUIStyle FailedLabelStyle;
 | 
			
		||||
            public static readonly GUIStyle FailedMessagesStyle;
 | 
			
		||||
 | 
			
		||||
            static Styles()
 | 
			
		||||
            {
 | 
			
		||||
                SucceedLabelStyle = new GUIStyle("label");
 | 
			
		||||
                SucceedLabelStyle.normal.textColor = Color.green;
 | 
			
		||||
                SucceedLabelStyle.fontSize = 48;
 | 
			
		||||
 | 
			
		||||
                FailedLabelStyle = new GUIStyle("label");
 | 
			
		||||
                FailedLabelStyle.normal.textColor = Color.red;
 | 
			
		||||
                FailedLabelStyle.fontSize = 32;
 | 
			
		||||
 | 
			
		||||
                FailedMessagesStyle = new GUIStyle("label");
 | 
			
		||||
                FailedMessagesStyle.wordWrap = false;
 | 
			
		||||
                FailedMessagesStyle.richText = true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private readonly List<ITestResult> m_FailedTestCollection;
 | 
			
		||||
 | 
			
		||||
        private bool m_ShowResults;
 | 
			
		||||
        private Vector2 m_ScrollPosition;
 | 
			
		||||
 | 
			
		||||
        public TestResultRenderer(ITestResult testResults)
 | 
			
		||||
        {
 | 
			
		||||
            m_FailedTestCollection = new List<ITestResult>();
 | 
			
		||||
            GetFailedTests(testResults);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GetFailedTests(ITestResult testResults)
 | 
			
		||||
        {
 | 
			
		||||
            if (testResults is TestCaseResult)
 | 
			
		||||
            {
 | 
			
		||||
                if (testResults.ResultState.Status == TestStatus.Failed)
 | 
			
		||||
                    m_FailedTestCollection.Add(testResults);
 | 
			
		||||
            }
 | 
			
		||||
            else if (testResults.HasChildren)
 | 
			
		||||
            {
 | 
			
		||||
                foreach (var testResultsChild in testResults.Children)
 | 
			
		||||
                {
 | 
			
		||||
                    GetFailedTests(testResultsChild);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private const int k_MaxStringLength = 15000;
 | 
			
		||||
 | 
			
		||||
        public void ShowResults()
 | 
			
		||||
        {
 | 
			
		||||
            m_ShowResults = true;
 | 
			
		||||
            Cursor.visible = true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void Draw()
 | 
			
		||||
        {
 | 
			
		||||
            if (!m_ShowResults) return;
 | 
			
		||||
            if (m_FailedTestCollection.Count == 0)
 | 
			
		||||
            {
 | 
			
		||||
                GUILayout.Label("All test(s) succeeded", Styles.SucceedLabelStyle, GUILayout.Width(600));
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                int count = m_FailedTestCollection.Count;
 | 
			
		||||
                GUILayout.Label(count + " tests failed!", Styles.FailedLabelStyle);
 | 
			
		||||
 | 
			
		||||
                m_ScrollPosition = GUILayout.BeginScrollView(m_ScrollPosition, GUILayout.ExpandWidth(true));
 | 
			
		||||
                var text = "";
 | 
			
		||||
 | 
			
		||||
                text += "<b><size=18>Code-based tests</size></b>\n";
 | 
			
		||||
                text += string.Join("\n", m_FailedTestCollection
 | 
			
		||||
                    .Select(result => result.Name + " " + result.ResultState + "\n" + result.Message)
 | 
			
		||||
                    .ToArray());
 | 
			
		||||
 | 
			
		||||
                if (text.Length > k_MaxStringLength)
 | 
			
		||||
                    text = text.Substring(0, k_MaxStringLength);
 | 
			
		||||
 | 
			
		||||
                GUILayout.TextArea(text, Styles.FailedMessagesStyle);
 | 
			
		||||
                GUILayout.EndScrollView();
 | 
			
		||||
            }
 | 
			
		||||
            if (GUILayout.Button("Close"))
 | 
			
		||||
                Application.Quit();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: 5ebb87899ca30b743bb4274bc00c02b4
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
@@ -0,0 +1,36 @@
 | 
			
		||||
using NUnit.Framework.Interfaces;
 | 
			
		||||
 | 
			
		||||
namespace UnityEngine.TestTools.TestRunner.Callbacks
 | 
			
		||||
{
 | 
			
		||||
    internal class TestResultRendererCallback : MonoBehaviour, ITestRunnerListener
 | 
			
		||||
    {
 | 
			
		||||
        private TestResultRenderer m_ResultRenderer;
 | 
			
		||||
        public void RunStarted(ITest testsToRun)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void RunFinished(ITestResult testResults)
 | 
			
		||||
        {
 | 
			
		||||
            if (Camera.main == null)
 | 
			
		||||
            {
 | 
			
		||||
                gameObject.AddComponent<Camera>();
 | 
			
		||||
            }
 | 
			
		||||
            m_ResultRenderer = new TestResultRenderer(testResults);
 | 
			
		||||
            m_ResultRenderer.ShowResults();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void OnGUI()
 | 
			
		||||
        {
 | 
			
		||||
            if (m_ResultRenderer != null)
 | 
			
		||||
                m_ResultRenderer.Draw();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void TestStarted(ITest test)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void TestFinished(ITestResult result)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: dfc336f10b83bd74eaded16a658275c7
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
@@ -0,0 +1,26 @@
 | 
			
		||||
using System;
 | 
			
		||||
using NUnit.Framework.Interfaces;
 | 
			
		||||
using UnityEngine.Events;
 | 
			
		||||
 | 
			
		||||
namespace UnityEngine.TestTools.TestRunner
 | 
			
		||||
{
 | 
			
		||||
    internal interface ITestRunnerListener
 | 
			
		||||
    {
 | 
			
		||||
        void RunStarted(ITest testsToRun);
 | 
			
		||||
        void RunFinished(ITestResult testResults);
 | 
			
		||||
        void TestStarted(ITest test);
 | 
			
		||||
        void TestFinished(ITestResult result);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [Serializable]
 | 
			
		||||
    internal class TestFinishedEvent : UnityEvent<ITestResult> {}
 | 
			
		||||
 | 
			
		||||
    [Serializable]
 | 
			
		||||
    internal class TestStartedEvent : UnityEvent<ITest> {}
 | 
			
		||||
 | 
			
		||||
    [Serializable]
 | 
			
		||||
    internal class RunFinishedEvent : UnityEvent<ITestResult> {}
 | 
			
		||||
 | 
			
		||||
    [Serializable]
 | 
			
		||||
    internal class RunStartedEvent : UnityEvent<ITest> {}
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: d1b534518943030499685344fd1d476d
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
@@ -0,0 +1,8 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: 256a0ca37fa972840bce7fca446e75e7
 | 
			
		||||
folderAsset: yes
 | 
			
		||||
DefaultImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
@@ -0,0 +1,12 @@
 | 
			
		||||
using System.Collections;
 | 
			
		||||
 | 
			
		||||
namespace UnityEngine.TestTools
 | 
			
		||||
{
 | 
			
		||||
    public interface IEditModeTestYieldInstruction
 | 
			
		||||
    {
 | 
			
		||||
        bool ExpectDomainReload { get; }
 | 
			
		||||
        bool ExpectedPlaymodeState { get; }
 | 
			
		||||
 | 
			
		||||
        IEnumerator Perform();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: 898bc38486fc899428fbe5bd6adfe473
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
@@ -0,0 +1,129 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using UnityEngine.SceneManagement;
 | 
			
		||||
using UnityEngine.TestRunner.NUnitExtensions;
 | 
			
		||||
using UnityEngine.TestRunner.NUnitExtensions.Runner;
 | 
			
		||||
using UnityEngine.TestTools.NUnitExtensions;
 | 
			
		||||
using UnityEngine.TestTools.Utils;
 | 
			
		||||
 | 
			
		||||
namespace UnityEngine.TestTools.TestRunner
 | 
			
		||||
{
 | 
			
		||||
    [Serializable]
 | 
			
		||||
    [AddComponentMenu("")]
 | 
			
		||||
    internal class PlaymodeTestsController : MonoBehaviour
 | 
			
		||||
    {
 | 
			
		||||
        private IEnumerator m_TestSteps;
 | 
			
		||||
 | 
			
		||||
        [SerializeField]
 | 
			
		||||
        private List<string> m_AssembliesWithTests;
 | 
			
		||||
        public List<string> AssembliesWithTests
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return m_AssembliesWithTests;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                m_AssembliesWithTests = value;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [SerializeField]
 | 
			
		||||
        internal TestStartedEvent testStartedEvent = new TestStartedEvent();
 | 
			
		||||
        [SerializeField]
 | 
			
		||||
        internal TestFinishedEvent testFinishedEvent = new TestFinishedEvent();
 | 
			
		||||
        [SerializeField]
 | 
			
		||||
        internal RunStartedEvent runStartedEvent = new RunStartedEvent();
 | 
			
		||||
        [SerializeField]
 | 
			
		||||
        internal RunFinishedEvent runFinishedEvent = new RunFinishedEvent();
 | 
			
		||||
 | 
			
		||||
        internal const string kPlaymodeTestControllerName = "Code-based tests runner";
 | 
			
		||||
 | 
			
		||||
        [SerializeField]
 | 
			
		||||
        public PlaymodeTestsControllerSettings settings = new PlaymodeTestsControllerSettings();
 | 
			
		||||
 | 
			
		||||
        internal UnityTestAssemblyRunner m_Runner;
 | 
			
		||||
 | 
			
		||||
        public IEnumerator Start()
 | 
			
		||||
        {
 | 
			
		||||
            //Skip 2 frame because Unity.
 | 
			
		||||
            yield return null;
 | 
			
		||||
            yield return null;
 | 
			
		||||
            StartCoroutine(Run());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal static bool IsControllerOnScene()
 | 
			
		||||
        {
 | 
			
		||||
            return GameObject.Find(kPlaymodeTestControllerName) != null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal static PlaymodeTestsController GetController()
 | 
			
		||||
        {
 | 
			
		||||
            return GameObject.Find(kPlaymodeTestControllerName).GetComponent<PlaymodeTestsController>();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public IEnumerator TestRunnerCoroutine()
 | 
			
		||||
        {
 | 
			
		||||
            while (m_TestSteps.MoveNext())
 | 
			
		||||
            {
 | 
			
		||||
                yield return m_TestSteps.Current;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (m_Runner.IsTestComplete)
 | 
			
		||||
            {
 | 
			
		||||
                runFinishedEvent.Invoke(m_Runner.Result);
 | 
			
		||||
                Cleanup();
 | 
			
		||||
 | 
			
		||||
                yield return null;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public IEnumerator Run()
 | 
			
		||||
        {
 | 
			
		||||
            CoroutineTestWorkItem.monoBehaviourCoroutineRunner = this;
 | 
			
		||||
            gameObject.hideFlags |= HideFlags.DontSave;
 | 
			
		||||
 | 
			
		||||
            if (settings.sceneBased)
 | 
			
		||||
            {
 | 
			
		||||
                SceneManager.LoadScene(1, LoadSceneMode.Additive);
 | 
			
		||||
                yield return null;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            var testListUtil = new PlayerTestAssemblyProvider(new AssemblyLoadProxy(), m_AssembliesWithTests);
 | 
			
		||||
            m_Runner = new UnityTestAssemblyRunner(new UnityTestAssemblyBuilder(), new PlaymodeWorkItemFactory());
 | 
			
		||||
 | 
			
		||||
            var loadedTests = m_Runner.Load(testListUtil.GetUserAssemblies().Select(a => a.Assembly).ToArray(), TestPlatform.PlayMode, UnityTestAssemblyBuilder.GetNUnitTestBuilderSettings(TestPlatform.PlayMode));
 | 
			
		||||
            loadedTests.ParseForNameDuplicates();
 | 
			
		||||
            runStartedEvent.Invoke(m_Runner.LoadedTest);
 | 
			
		||||
 | 
			
		||||
            var testListenerWrapper = new TestListenerWrapper(testStartedEvent, testFinishedEvent);
 | 
			
		||||
            m_TestSteps = m_Runner.Run(testListenerWrapper, settings.BuildNUnitFilter()).GetEnumerator();
 | 
			
		||||
 | 
			
		||||
            yield return TestRunnerCoroutine();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void Cleanup()
 | 
			
		||||
        {
 | 
			
		||||
            if (m_Runner != null)
 | 
			
		||||
            {
 | 
			
		||||
                m_Runner.StopRun();
 | 
			
		||||
                m_Runner = null;
 | 
			
		||||
            }
 | 
			
		||||
            if (Application.isEditor)
 | 
			
		||||
            {
 | 
			
		||||
                Destroy(gameObject);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static void TryCleanup()
 | 
			
		||||
        {
 | 
			
		||||
            var controller = GetController();
 | 
			
		||||
            if (controller != null)
 | 
			
		||||
            {
 | 
			
		||||
                controller.Cleanup();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: 102e512f651ee834f951a2516c1ea3b8
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
@@ -0,0 +1,36 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using NUnit.Framework.Interfaces;
 | 
			
		||||
using NUnit.Framework.Internal.Filters;
 | 
			
		||||
using UnityEngine.SceneManagement;
 | 
			
		||||
using UnityEngine.TestTools.TestRunner.GUI;
 | 
			
		||||
 | 
			
		||||
namespace UnityEngine.TestTools.TestRunner
 | 
			
		||||
{
 | 
			
		||||
    [Serializable]
 | 
			
		||||
    internal class PlaymodeTestsControllerSettings
 | 
			
		||||
    {
 | 
			
		||||
        [SerializeField]
 | 
			
		||||
        public TestRunnerFilter[] filters;
 | 
			
		||||
        public bool sceneBased;
 | 
			
		||||
        public string originalScene;
 | 
			
		||||
        public string bootstrapScene;
 | 
			
		||||
 | 
			
		||||
        public static PlaymodeTestsControllerSettings CreateRunnerSettings(TestRunnerFilter[] filters)
 | 
			
		||||
        {
 | 
			
		||||
            var settings = new PlaymodeTestsControllerSettings
 | 
			
		||||
            {
 | 
			
		||||
                filters = filters,
 | 
			
		||||
                sceneBased = false,
 | 
			
		||||
                originalScene = SceneManager.GetActiveScene().path,
 | 
			
		||||
                bootstrapScene = null
 | 
			
		||||
            };
 | 
			
		||||
            return settings;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal ITestFilter BuildNUnitFilter()
 | 
			
		||||
        {
 | 
			
		||||
            return new OrFilter(filters.Select(f => f.BuildNUnitFilter()).ToArray());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: 2799eb4c84e72e54092a292cf626936b
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
@@ -0,0 +1,8 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: 91c20d2c22b8b3a4cb6c816bd225591a
 | 
			
		||||
folderAsset: yes
 | 
			
		||||
DefaultImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
using System;
 | 
			
		||||
using NUnit.Framework.Interfaces;
 | 
			
		||||
 | 
			
		||||
namespace UnityEngine.TestRunner.TestLaunchers
 | 
			
		||||
{
 | 
			
		||||
    internal interface IRemoteTestResultDataFactory
 | 
			
		||||
    {
 | 
			
		||||
        RemoteTestResultDataWithTestData CreateFromTestResult(ITestResult result);
 | 
			
		||||
        RemoteTestResultDataWithTestData CreateFromTest(ITest test);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: 874c0713cdc44f549b0161750b48d2c2
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
@@ -0,0 +1,14 @@
 | 
			
		||||
using System;
 | 
			
		||||
 | 
			
		||||
namespace UnityEngine.TestRunner.TestLaunchers
 | 
			
		||||
{
 | 
			
		||||
    internal static class PlayerConnectionMessageIds
 | 
			
		||||
    {
 | 
			
		||||
        public static Guid runStartedMessageId { get { return new Guid("6a7f53dd-4672-461d-a7b5-9467e9393fd3"); } }
 | 
			
		||||
        public static Guid runFinishedMessageId { get { return new Guid("ffb622fc-34ad-4901-8d7b-47fb04b0bdd4"); } }
 | 
			
		||||
        public static Guid testStartedMessageId { get { return new Guid("b54d241e-d88d-4dba-8c8f-ee415d11c030"); } }
 | 
			
		||||
        public static Guid testFinishedMessageId { get { return new Guid("72f7b7f4-6829-4cd1-afde-78872b9d5adc"); } }
 | 
			
		||||
        public static Guid quitPlayerMessageId { get { return new Guid("ab44bfe0-bb50-4ee6-9977-69d2ea6bb3a0"); } }
 | 
			
		||||
        public static Guid playerAliveHeartbeat { get { return new Guid("8c0c307b-f7fd-4216-8623-35b4b3f55fb6"); } }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: 41d60936b62cc6d4ca7fe628b22b0e40
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
@@ -0,0 +1,56 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using NUnit.Framework.Interfaces;
 | 
			
		||||
using NUnit.Framework.Internal;
 | 
			
		||||
using UnityEngine.TestRunner.NUnitExtensions;
 | 
			
		||||
 | 
			
		||||
namespace UnityEngine.TestRunner.TestLaunchers
 | 
			
		||||
{
 | 
			
		||||
    [Serializable]
 | 
			
		||||
    internal class RemoteTestData
 | 
			
		||||
    {
 | 
			
		||||
        public string id;
 | 
			
		||||
        public string name;
 | 
			
		||||
        public string fullName;
 | 
			
		||||
        public int testCaseCount;
 | 
			
		||||
        public int ChildIndex;
 | 
			
		||||
        public bool hasChildren;
 | 
			
		||||
        public bool isSuite;
 | 
			
		||||
        public string[] childrenIds;
 | 
			
		||||
        public int testCaseTimeout;
 | 
			
		||||
        public string[] Categories;
 | 
			
		||||
        public bool IsTestAssembly;
 | 
			
		||||
        public RunState RunState;
 | 
			
		||||
        public string Description;
 | 
			
		||||
        public string SkipReason;
 | 
			
		||||
        public string ParentId;
 | 
			
		||||
        public string UniqueName;
 | 
			
		||||
        public string ParentUniqueName;
 | 
			
		||||
        public string ParentFullName;
 | 
			
		||||
 | 
			
		||||
        internal RemoteTestData(ITest test)
 | 
			
		||||
        {
 | 
			
		||||
            id = test.Id;
 | 
			
		||||
            name = test.Name;
 | 
			
		||||
            fullName = test.FullName;
 | 
			
		||||
            testCaseCount = test.TestCaseCount;
 | 
			
		||||
            ChildIndex = -1;
 | 
			
		||||
            if (test.Properties["childIndex"].Count > 0)
 | 
			
		||||
            {
 | 
			
		||||
                ChildIndex = (int)test.Properties["childIndex"][0];
 | 
			
		||||
            }
 | 
			
		||||
            hasChildren = test.HasChildren;
 | 
			
		||||
            isSuite = test.IsSuite;
 | 
			
		||||
            childrenIds = test.Tests.Select(t => t.Id).ToArray();
 | 
			
		||||
            Categories = test.GetAllCategoriesFromTest().ToArray();
 | 
			
		||||
            IsTestAssembly = test is TestAssembly;
 | 
			
		||||
            RunState = (RunState)Enum.Parse(typeof(RunState), test.RunState.ToString());
 | 
			
		||||
            Description = (string)test.Properties.Get(PropertyNames.Description);
 | 
			
		||||
            SkipReason = test.GetSkipReason();
 | 
			
		||||
            ParentId = test.GetParentId();
 | 
			
		||||
            UniqueName = test.GetUniqueName();
 | 
			
		||||
            ParentUniqueName = test.GetParentUniqueName();
 | 
			
		||||
            ParentFullName = test.GetParentFullName();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: b135ec222fdcd11468014c90d11d6821
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
@@ -0,0 +1,54 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using NUnit.Framework.Interfaces;
 | 
			
		||||
 | 
			
		||||
namespace UnityEngine.TestRunner.TestLaunchers
 | 
			
		||||
{
 | 
			
		||||
    [Serializable]
 | 
			
		||||
    internal class RemoteTestResultData
 | 
			
		||||
    {
 | 
			
		||||
        public string testId;
 | 
			
		||||
        public string name;
 | 
			
		||||
        public string fullName;
 | 
			
		||||
        public string resultState;
 | 
			
		||||
        public TestStatus testStatus;
 | 
			
		||||
        public double duration;
 | 
			
		||||
        public DateTime startTime;
 | 
			
		||||
        public DateTime endTime;
 | 
			
		||||
        public string message;
 | 
			
		||||
        public string stackTrace;
 | 
			
		||||
        public int assertCount;
 | 
			
		||||
        public int failCount;
 | 
			
		||||
        public int passCount;
 | 
			
		||||
        public int skipCount;
 | 
			
		||||
        public int inconclusiveCount;
 | 
			
		||||
        public bool hasChildren;
 | 
			
		||||
        public string output;
 | 
			
		||||
        public string xml;
 | 
			
		||||
        public string[] childrenIds;
 | 
			
		||||
 | 
			
		||||
        internal RemoteTestResultData(ITestResult result)
 | 
			
		||||
        {
 | 
			
		||||
            testId = result.Test.Id;
 | 
			
		||||
            name = result.Name;
 | 
			
		||||
            fullName = result.FullName;
 | 
			
		||||
            resultState = result.ResultState.ToString();
 | 
			
		||||
            testStatus = result.ResultState.Status;
 | 
			
		||||
            duration = result.Duration;
 | 
			
		||||
            startTime = result.StartTime;
 | 
			
		||||
            endTime = result.EndTime;
 | 
			
		||||
            message = result.Message;
 | 
			
		||||
            stackTrace = result.StackTrace;
 | 
			
		||||
            assertCount = result.AssertCount;
 | 
			
		||||
            failCount = result.FailCount;
 | 
			
		||||
            passCount = result.PassCount;
 | 
			
		||||
            skipCount = result.SkipCount;
 | 
			
		||||
            inconclusiveCount = result.InconclusiveCount;
 | 
			
		||||
            hasChildren = result.HasChildren;
 | 
			
		||||
            output = result.Output;
 | 
			
		||||
            xml = result.ToXml(true).OuterXml;
 | 
			
		||||
            childrenIds = result.Children.Select(child => child.Test.Id).ToArray();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: 03e4d63665d06f04c8a6cf68133c1592
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
@@ -0,0 +1,51 @@
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using NUnit.Framework.Interfaces;
 | 
			
		||||
using UnityEngine.TestRunner.NUnitExtensions.Runner;
 | 
			
		||||
 | 
			
		||||
namespace UnityEngine.TestRunner.TestLaunchers
 | 
			
		||||
{
 | 
			
		||||
    internal class RemoteTestResultDataFactory : IRemoteTestResultDataFactory
 | 
			
		||||
    {
 | 
			
		||||
        public RemoteTestResultDataWithTestData CreateFromTestResult(ITestResult result)
 | 
			
		||||
        {
 | 
			
		||||
            var tests = CreateTestDataList(result.Test);
 | 
			
		||||
            tests.First().testCaseTimeout = UnityTestExecutionContext.CurrentContext.TestCaseTimeout;
 | 
			
		||||
            return new RemoteTestResultDataWithTestData()
 | 
			
		||||
            {
 | 
			
		||||
                results = CreateTestResultDataList(result),
 | 
			
		||||
                tests = tests
 | 
			
		||||
            };
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public RemoteTestResultDataWithTestData CreateFromTest(ITest test)
 | 
			
		||||
        {
 | 
			
		||||
            var tests = CreateTestDataList(test);
 | 
			
		||||
            if (UnityTestExecutionContext.CurrentContext != null)
 | 
			
		||||
            {
 | 
			
		||||
                tests.First().testCaseTimeout = UnityTestExecutionContext.CurrentContext.TestCaseTimeout;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return new RemoteTestResultDataWithTestData()
 | 
			
		||||
            {
 | 
			
		||||
                tests = tests
 | 
			
		||||
            };
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private RemoteTestData[] CreateTestDataList(ITest test)
 | 
			
		||||
        {
 | 
			
		||||
            var list = new List<RemoteTestData>();
 | 
			
		||||
            list.Add(new RemoteTestData(test));
 | 
			
		||||
            list.AddRange(test.Tests.SelectMany(CreateTestDataList));
 | 
			
		||||
            return list.ToArray();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static RemoteTestResultData[] CreateTestResultDataList(ITestResult result)
 | 
			
		||||
        {
 | 
			
		||||
            var list = new List<RemoteTestResultData>();
 | 
			
		||||
            list.Add(new RemoteTestResultData(result));
 | 
			
		||||
            list.AddRange(result.Children.SelectMany(CreateTestResultDataList));
 | 
			
		||||
            return list.ToArray();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: 826b6becaef90fb458eedebe4c2f3664
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
@@ -0,0 +1,15 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using NUnit.Framework.Interfaces;
 | 
			
		||||
using UnityEngine.TestRunner.NUnitExtensions.Runner;
 | 
			
		||||
 | 
			
		||||
namespace UnityEngine.TestRunner.TestLaunchers
 | 
			
		||||
{
 | 
			
		||||
    [Serializable]
 | 
			
		||||
    internal class RemoteTestResultDataWithTestData
 | 
			
		||||
    {
 | 
			
		||||
        public RemoteTestResultData[] results;
 | 
			
		||||
        public RemoteTestData[] tests;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: 475e3699f219c854f8581a9838135002
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
@@ -0,0 +1,51 @@
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
using NUnit.Framework.Interfaces;
 | 
			
		||||
using NUnit.Framework.Internal;
 | 
			
		||||
 | 
			
		||||
namespace UnityEngine.TestTools.TestRunner.GUI
 | 
			
		||||
{
 | 
			
		||||
    class SynchronousFilter : ITestFilter
 | 
			
		||||
    {
 | 
			
		||||
        public TNode ToXml(bool recursive)
 | 
			
		||||
        {
 | 
			
		||||
            return new TNode("synchronousOnly");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public TNode AddToXml(TNode parentNode, bool recursive)
 | 
			
		||||
        {
 | 
			
		||||
            return parentNode.AddElement("synchronousOnly");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool Pass(ITest test)
 | 
			
		||||
        {
 | 
			
		||||
            if (test.Method == null)
 | 
			
		||||
                return true;
 | 
			
		||||
            
 | 
			
		||||
            if (test.Method.ReturnType.Type == typeof(IEnumerator))
 | 
			
		||||
                return false;
 | 
			
		||||
 | 
			
		||||
            if (test.Method.GetCustomAttributes<IOuterUnityTestAction>(true).Any())
 | 
			
		||||
                return false;
 | 
			
		||||
 | 
			
		||||
            if (test.TypeInfo?.Type != null)
 | 
			
		||||
            {
 | 
			
		||||
                if (Reflect.GetMethodsWithAttribute(test.TypeInfo.Type, typeof(UnitySetUpAttribute), true)
 | 
			
		||||
                    .Any(mi => mi.ReturnType == typeof(System.Collections.IEnumerator)))
 | 
			
		||||
                    return false;
 | 
			
		||||
 | 
			
		||||
                if (Reflect.GetMethodsWithAttribute(test.TypeInfo.Type, typeof(UnityTearDownAttribute), true)
 | 
			
		||||
                    .Any(mi => mi.ReturnType == typeof(System.Collections.IEnumerator)))
 | 
			
		||||
                    return false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool IsExplicitMatch(ITest test)
 | 
			
		||||
        {
 | 
			
		||||
            return Pass(test);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: b9aec9d3b0a86466ab4647d01e8fc87d
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
@@ -0,0 +1,51 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
using NUnit.Framework;
 | 
			
		||||
using NUnit.Framework.Interfaces;
 | 
			
		||||
using NUnit.Framework.Internal;
 | 
			
		||||
 | 
			
		||||
namespace UnityEngine.TestTools.TestRunner
 | 
			
		||||
{
 | 
			
		||||
    internal class TestEnumeratorWrapper
 | 
			
		||||
    {
 | 
			
		||||
        private readonly TestMethod m_TestMethod;
 | 
			
		||||
 | 
			
		||||
        public TestEnumeratorWrapper(TestMethod testMethod)
 | 
			
		||||
        {
 | 
			
		||||
            m_TestMethod = testMethod;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public IEnumerator GetEnumerator(ITestExecutionContext context)
 | 
			
		||||
        {
 | 
			
		||||
            if (m_TestMethod.Method.ReturnType.Type == typeof(IEnumerator))
 | 
			
		||||
            {
 | 
			
		||||
                return HandleEnumerableTest(context);
 | 
			
		||||
            }
 | 
			
		||||
            var message = string.Format("Return type {0} of {1} in {2} is not supported.",
 | 
			
		||||
                m_TestMethod.Method.ReturnType, m_TestMethod.Method.Name, m_TestMethod.Method.TypeInfo.FullName);
 | 
			
		||||
            if (m_TestMethod.Method.ReturnType.Type == typeof(IEnumerable))
 | 
			
		||||
            {
 | 
			
		||||
                message += "\nDid you mean IEnumerator?";
 | 
			
		||||
            }
 | 
			
		||||
            throw new InvalidSignatureException(message);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private IEnumerator HandleEnumerableTest(ITestExecutionContext context)
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                return m_TestMethod.Method.MethodInfo.Invoke(context.TestObject, m_TestMethod.parms != null ? m_TestMethod.parms.OriginalArguments : null) as IEnumerator;
 | 
			
		||||
            }
 | 
			
		||||
            catch (TargetInvocationException e)
 | 
			
		||||
            {
 | 
			
		||||
                if (e.InnerException is IgnoreException)
 | 
			
		||||
                {
 | 
			
		||||
                    context.CurrentResult.SetResult(ResultState.Ignored, e.InnerException.Message);
 | 
			
		||||
                    return null;
 | 
			
		||||
                }
 | 
			
		||||
                throw;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: 9ad0b0c865b01af4ca1b414689e71259
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
@@ -0,0 +1,30 @@
 | 
			
		||||
using NUnit.Framework.Interfaces;
 | 
			
		||||
 | 
			
		||||
namespace UnityEngine.TestTools.TestRunner
 | 
			
		||||
{
 | 
			
		||||
    internal class TestListenerWrapper : ITestListener
 | 
			
		||||
    {
 | 
			
		||||
        private readonly TestFinishedEvent m_TestFinishedEvent;
 | 
			
		||||
        private readonly TestStartedEvent m_TestStartedEvent;
 | 
			
		||||
 | 
			
		||||
        public TestListenerWrapper(TestStartedEvent testStartedEvent, TestFinishedEvent testFinishedEvent)
 | 
			
		||||
        {
 | 
			
		||||
            m_TestStartedEvent = testStartedEvent;
 | 
			
		||||
            m_TestFinishedEvent = testFinishedEvent;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void TestStarted(ITest test)
 | 
			
		||||
        {
 | 
			
		||||
            m_TestStartedEvent.Invoke(test);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void TestFinished(ITestResult result)
 | 
			
		||||
        {
 | 
			
		||||
            m_TestFinishedEvent.Invoke(result);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void TestOutput(TestOutput output)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: 73deb9b8722aa284eab27c4dc90956c6
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
@@ -0,0 +1,21 @@
 | 
			
		||||
using System;
 | 
			
		||||
 | 
			
		||||
namespace UnityEngine.TestTools
 | 
			
		||||
{
 | 
			
		||||
    [Flags]
 | 
			
		||||
    [Serializable]
 | 
			
		||||
    public enum TestPlatform : byte
 | 
			
		||||
    {
 | 
			
		||||
        All = 0xFF,
 | 
			
		||||
        EditMode = 1 << 1,
 | 
			
		||||
        PlayMode = 1 << 2
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    internal static class TestPlatformEnumExtensions
 | 
			
		||||
    {
 | 
			
		||||
        public static bool IsFlagIncluded(this TestPlatform flags, TestPlatform flag)
 | 
			
		||||
        {
 | 
			
		||||
            return (flags & flag) == flag;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: 743879b4db4bc1a4b829aae4386f4acf
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
@@ -0,0 +1,203 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text.RegularExpressions;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using NUnit.Framework.Interfaces;
 | 
			
		||||
using NUnit.Framework.Internal;
 | 
			
		||||
using NUnit.Framework.Internal.Filters;
 | 
			
		||||
using UnityEngine.TestRunner.NUnitExtensions.Filters;
 | 
			
		||||
 | 
			
		||||
namespace UnityEngine.TestTools.TestRunner.GUI
 | 
			
		||||
{
 | 
			
		||||
    [Serializable]
 | 
			
		||||
    internal class TestRunnerFilter
 | 
			
		||||
    {
 | 
			
		||||
#pragma warning disable 649
 | 
			
		||||
        public string[] assemblyNames;
 | 
			
		||||
        public string[] groupNames;
 | 
			
		||||
        public string[] categoryNames;
 | 
			
		||||
        public static TestRunnerFilter empty = new TestRunnerFilter();
 | 
			
		||||
        public string[] testNames;
 | 
			
		||||
        public int testRepetitions = 1;
 | 
			
		||||
        public bool synchronousOnly = false;
 | 
			
		||||
 | 
			
		||||
        public static string AssemblyNameFromPath(string path)
 | 
			
		||||
        {
 | 
			
		||||
            string output = Path.GetFileName(path);
 | 
			
		||||
            if (output != null && output.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
 | 
			
		||||
                return output.Substring(0, output.Length - 4);
 | 
			
		||||
            return output;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private bool CategoryMatches(IEnumerable<string> categories)
 | 
			
		||||
        {
 | 
			
		||||
            if (categoryNames == null || categoryNames.Length == 0)
 | 
			
		||||
                return true;
 | 
			
		||||
 | 
			
		||||
            foreach (string category in categories)
 | 
			
		||||
            {
 | 
			
		||||
                if (categoryNames.Contains(category))
 | 
			
		||||
                    return true;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private bool IDMatchesAssembly(string id)
 | 
			
		||||
        {
 | 
			
		||||
            if (AreOptionalFiltersEmpty())
 | 
			
		||||
                return true;
 | 
			
		||||
 | 
			
		||||
            if (assemblyNames == null)
 | 
			
		||||
                return false;
 | 
			
		||||
 | 
			
		||||
            int openingBracket = id.IndexOf('[');
 | 
			
		||||
            int closingBracket = id.IndexOf(']');
 | 
			
		||||
            if (openingBracket >= 0 && openingBracket < id.Length && closingBracket > openingBracket && openingBracket < id.Length)
 | 
			
		||||
            {
 | 
			
		||||
                //Some assemblies are absolute and explicitly part of the test ID e.g.
 | 
			
		||||
                //"[/path/to/assembly-name.dll][rest of ID ...]"
 | 
			
		||||
                //While some are minimal assembly names e.g.
 | 
			
		||||
                //"[assembly-name][rest of ID ...]"
 | 
			
		||||
                //Strip them down to just the assembly name
 | 
			
		||||
                string assemblyNameFromID = AssemblyNameFromPath(id.Substring(openingBracket + 1, closingBracket - openingBracket - 1));
 | 
			
		||||
                foreach (string assemblyName in assemblyNames)
 | 
			
		||||
                {
 | 
			
		||||
                    if (assemblyName.Equals(assemblyNameFromID, StringComparison.OrdinalIgnoreCase))
 | 
			
		||||
                        return true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private bool NameMatches(string name)
 | 
			
		||||
        {
 | 
			
		||||
            if (AreOptionalFiltersEmpty())
 | 
			
		||||
                return true;
 | 
			
		||||
 | 
			
		||||
            if (groupNames == null)
 | 
			
		||||
                return false;
 | 
			
		||||
 | 
			
		||||
            foreach (var nameFromFilter in groupNames)
 | 
			
		||||
            {
 | 
			
		||||
                //Strict regex match for test group name on its own
 | 
			
		||||
                if (Regex.IsMatch(name, nameFromFilter))
 | 
			
		||||
                    return true;
 | 
			
		||||
                //Match test names that end with parametrized test values and full nunit generated test names that have . separators
 | 
			
		||||
                var regex = nameFromFilter.TrimEnd('$') + @"[\.|\(.*\)]";
 | 
			
		||||
                if (Regex.IsMatch(name, regex))
 | 
			
		||||
                    return true;
 | 
			
		||||
            }
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private bool AreOptionalFiltersEmpty()
 | 
			
		||||
        {
 | 
			
		||||
            if (assemblyNames != null && assemblyNames.Length != 0)
 | 
			
		||||
                return false;
 | 
			
		||||
            if (groupNames != null && groupNames.Length != 0)
 | 
			
		||||
                return false;
 | 
			
		||||
            if (testNames != null && testNames.Length != 0)
 | 
			
		||||
                return false;
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private bool NameMatchesExactly(string name)
 | 
			
		||||
        {
 | 
			
		||||
            if (AreOptionalFiltersEmpty())
 | 
			
		||||
                return true;
 | 
			
		||||
 | 
			
		||||
            if (testNames == null)
 | 
			
		||||
                return false;
 | 
			
		||||
 | 
			
		||||
            foreach (var exactName in testNames)
 | 
			
		||||
            {
 | 
			
		||||
                if (name == exactName)
 | 
			
		||||
                    return true;
 | 
			
		||||
            }
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static void ClearAncestors(IEnumerable<IClearableResult> newResultList, string parentID)
 | 
			
		||||
        {
 | 
			
		||||
            if (string.IsNullOrEmpty(parentID))
 | 
			
		||||
                return;
 | 
			
		||||
            foreach (var result in newResultList)
 | 
			
		||||
            {
 | 
			
		||||
                if (result.Id == parentID)
 | 
			
		||||
                {
 | 
			
		||||
                    result.Clear();
 | 
			
		||||
                    ClearAncestors(newResultList, result.ParentId);
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void ClearResults(List<IClearableResult> newResultList)
 | 
			
		||||
        {
 | 
			
		||||
            foreach (var result in newResultList)
 | 
			
		||||
            {
 | 
			
		||||
                if (!result.IsSuite && CategoryMatches(result.Categories))
 | 
			
		||||
                {
 | 
			
		||||
                    if (IDMatchesAssembly(result.Id) || NameMatches(result.FullName) || NameMatchesExactly(result.FullName))
 | 
			
		||||
                    {
 | 
			
		||||
                        result.Clear();
 | 
			
		||||
                        ClearAncestors(newResultList, result.ParentId);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public ITestFilter BuildNUnitFilter()
 | 
			
		||||
        {
 | 
			
		||||
            var filters = new List<ITestFilter>();
 | 
			
		||||
 | 
			
		||||
            if (testNames != null && testNames.Length != 0)
 | 
			
		||||
            {
 | 
			
		||||
                var nameFilter = new OrFilter(testNames.Select(n => new FullNameFilter(n)).ToArray());
 | 
			
		||||
                filters.Add(nameFilter);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (groupNames != null && groupNames.Length != 0)
 | 
			
		||||
            {
 | 
			
		||||
                var exactNamesFilter = new OrFilter(groupNames.Select(n =>
 | 
			
		||||
                {
 | 
			
		||||
                    var f = new FullNameFilter(n);
 | 
			
		||||
                    f.IsRegex = true;
 | 
			
		||||
                    return f;
 | 
			
		||||
                }).ToArray());
 | 
			
		||||
                filters.Add(exactNamesFilter);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (assemblyNames != null && assemblyNames.Length != 0)
 | 
			
		||||
            {
 | 
			
		||||
                var assemblyFilter = new OrFilter(assemblyNames.Select(c => new AssemblyNameFilter(c)).ToArray());
 | 
			
		||||
                filters.Add(assemblyFilter);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (categoryNames != null && categoryNames.Length != 0)
 | 
			
		||||
            {
 | 
			
		||||
                var categoryFilter = new OrFilter(categoryNames.Select(c => new CategoryFilterExtended(c) {IsRegex = true}).ToArray());
 | 
			
		||||
                filters.Add(categoryFilter);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (synchronousOnly)
 | 
			
		||||
            {
 | 
			
		||||
                filters.Add(new SynchronousFilter());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return filters.Count == 0 ? TestFilter.Empty : new AndFilter(filters.ToArray());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        internal interface IClearableResult
 | 
			
		||||
        {
 | 
			
		||||
            string Id { get; }
 | 
			
		||||
            string FullName { get; }
 | 
			
		||||
            string ParentId { get; }
 | 
			
		||||
            bool IsSuite { get; }
 | 
			
		||||
            List<string> Categories { get; }
 | 
			
		||||
            void Clear();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: a025ba7ee40d0104db8d08b1d9eabb0d
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
		Reference in New Issue
	
	Block a user