Skip to content
Snippets Groups Projects
Commit af571a61 authored by BlackAngle233's avatar BlackAngle233
Browse files

212

parent 1d9b5391
Branches
No related merge requests found
Showing
with 369 additions and 369 deletions
using System.Collections.Generic; using System.Collections.Generic;
using UnityEditor.TestTools.TestRunner.Api; using UnityEditor.TestTools.TestRunner.Api;
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
{ {
interface ITestRunnerApiMapper interface ITestRunnerApiMapper
{ {
string GetRunStateFromResultNunitXml(ITestResultAdaptor result); string GetRunStateFromResultNunitXml(ITestResultAdaptor result);
TestState GetTestStateFromResult(ITestResultAdaptor result); TestState GetTestStateFromResult(ITestResultAdaptor result);
List<string> FlattenTestNames(ITestAdaptor testsToRun); List<string> FlattenTestNames(ITestAdaptor testsToRun);
TestPlanMessage MapTestToTestPlanMessage(ITestAdaptor testsToRun); TestPlanMessage MapTestToTestPlanMessage(ITestAdaptor testsToRun);
TestStartedMessage MapTestToTestStartedMessage(ITestAdaptor test); TestStartedMessage MapTestToTestStartedMessage(ITestAdaptor test);
TestFinishedMessage TestResultToTestFinishedMessage(ITestResultAdaptor result); TestFinishedMessage TestResultToTestFinishedMessage(ITestResultAdaptor result);
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: 6de79ae237e51554da96fd28f68b66a6 guid: 6de79ae237e51554da96fd28f68b66a6
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
{ {
interface IUtpLogger interface IUtpLogger
{ {
void Log(Message msg); void Log(Message msg);
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: 9014630255533ed42915965b4065cde8 guid: 9014630255533ed42915965b4065cde8
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
using System.Collections.Generic; using System.Collections.Generic;
using UnityEditor.Compilation; using UnityEditor.Compilation;
using UnityEditor.TestTools.TestRunner.Api; using UnityEditor.TestTools.TestRunner.Api;
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
{ {
internal interface IUtpMessageReporter internal interface IUtpMessageReporter
{ {
void ReportAssemblyCompilationErrors(string assembly, IEnumerable<CompilerMessage> errorCompilerMessages); void ReportAssemblyCompilationErrors(string assembly, IEnumerable<CompilerMessage> errorCompilerMessages);
void ReportTestFinished(ITestResultAdaptor result); void ReportTestFinished(ITestResultAdaptor result);
void ReportTestRunStarted(ITestAdaptor testsToRun); void ReportTestRunStarted(ITestAdaptor testsToRun);
void ReportTestStarted(ITestAdaptor test); void ReportTestStarted(ITestAdaptor test);
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: 952b3dc7b47846947b37c8d3ae46579a guid: 952b3dc7b47846947b37c8d3ae46579a
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
using System; using System;
using System.Diagnostics; using System.Diagnostics;
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
{ {
[Serializable] [Serializable]
internal abstract class Message internal abstract class Message
{ {
public string type; public string type;
// Milliseconds since unix epoch // Milliseconds since unix epoch
public ulong time; public ulong time;
public int version; public int version;
public string phase; public string phase;
public int processId; public int processId;
protected Message() protected Message()
{ {
version = 2; version = 2;
phase = "Immediate"; phase = "Immediate";
processId = Process.GetCurrentProcess().Id; processId = Process.GetCurrentProcess().Id;
AddTimeStamp(); AddTimeStamp();
} }
public void AddTimeStamp() public void AddTimeStamp()
{ {
time = Convert.ToUInt64((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds); time = Convert.ToUInt64((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds);
} }
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: 321dc2c0720f8dd4f9396ecdc12b8746 guid: 321dc2c0720f8dd4f9396ecdc12b8746
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
{ {
internal class TestFinishedMessage : Message internal class TestFinishedMessage : Message
{ {
public string name; public string name;
public TestState state; public TestState state;
public string message; public string message;
public ulong duration; // milliseconds public ulong duration; // milliseconds
public ulong durationMicroseconds; public ulong durationMicroseconds;
public string stackTrace; public string stackTrace;
public TestFinishedMessage() public TestFinishedMessage()
{ {
type = "TestStatus"; type = "TestStatus";
phase = "End"; phase = "End";
} }
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: 423fe2ef878fa1140a7e1f7f9e365815 guid: 423fe2ef878fa1140a7e1f7f9e365815
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
using System.Collections.Generic; using System.Collections.Generic;
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
{ {
internal class TestPlanMessage : Message internal class TestPlanMessage : Message
{ {
public List<string> tests; public List<string> tests;
public TestPlanMessage() public TestPlanMessage()
{ {
type = "TestPlan"; type = "TestPlan";
} }
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: 28f79a0d7e64c2345bc46f8c4cf788f8 guid: 28f79a0d7e64c2345bc46f8c4cf788f8
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Xml; using System.Xml;
using UnityEditor.TestTools.TestRunner.Api; using UnityEditor.TestTools.TestRunner.Api;
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
{ {
internal class TestRunnerApiMapper : ITestRunnerApiMapper internal class TestRunnerApiMapper : ITestRunnerApiMapper
{ {
public TestPlanMessage MapTestToTestPlanMessage(ITestAdaptor testsToRun) public TestPlanMessage MapTestToTestPlanMessage(ITestAdaptor testsToRun)
{ {
var testsNames = testsToRun != null ? FlattenTestNames(testsToRun) : new List<string>(); var testsNames = testsToRun != null ? FlattenTestNames(testsToRun) : new List<string>();
var msg = new TestPlanMessage var msg = new TestPlanMessage
{ {
tests = testsNames tests = testsNames
}; };
return msg; return msg;
} }
public TestStartedMessage MapTestToTestStartedMessage(ITestAdaptor test) public TestStartedMessage MapTestToTestStartedMessage(ITestAdaptor test)
{ {
return new TestStartedMessage return new TestStartedMessage
{ {
name = test.FullName name = test.FullName
}; };
} }
public TestFinishedMessage TestResultToTestFinishedMessage(ITestResultAdaptor result) public TestFinishedMessage TestResultToTestFinishedMessage(ITestResultAdaptor result)
{ {
return new TestFinishedMessage return new TestFinishedMessage
{ {
name = result.Test.FullName, name = result.Test.FullName,
duration = Convert.ToUInt64(result.Duration * 1000), duration = Convert.ToUInt64(result.Duration * 1000),
durationMicroseconds = Convert.ToUInt64(result.Duration * 1000000), durationMicroseconds = Convert.ToUInt64(result.Duration * 1000000),
message = result.Message, message = result.Message,
state = GetTestStateFromResult(result), state = GetTestStateFromResult(result),
stackTrace = result.StackTrace stackTrace = result.StackTrace
}; };
} }
public string GetRunStateFromResultNunitXml(ITestResultAdaptor result) public string GetRunStateFromResultNunitXml(ITestResultAdaptor result)
{ {
var doc = new XmlDocument(); var doc = new XmlDocument();
doc.LoadXml(result.ToXml().OuterXml); doc.LoadXml(result.ToXml().OuterXml);
return doc.FirstChild.Attributes["runstate"].Value; return doc.FirstChild.Attributes["runstate"].Value;
} }
public TestState GetTestStateFromResult(ITestResultAdaptor result) public TestState GetTestStateFromResult(ITestResultAdaptor result)
{ {
var state = TestState.Failure; var state = TestState.Failure;
if (result.TestStatus == TestStatus.Passed) if (result.TestStatus == TestStatus.Passed)
{ {
state = TestState.Success; state = TestState.Success;
var runstate = GetRunStateFromResultNunitXml(result); var runstate = GetRunStateFromResultNunitXml(result);
runstate = runstate ?? String.Empty; runstate = runstate ?? String.Empty;
if (runstate.ToLowerInvariant().Equals("explicit")) if (runstate.ToLowerInvariant().Equals("explicit"))
state = TestState.Skipped; state = TestState.Skipped;
} }
else if (result.TestStatus == TestStatus.Skipped) else if (result.TestStatus == TestStatus.Skipped)
{ {
state = TestState.Skipped; state = TestState.Skipped;
if (result.ResultState.ToLowerInvariant().EndsWith("ignored")) if (result.ResultState.ToLowerInvariant().EndsWith("ignored"))
state = TestState.Ignored; state = TestState.Ignored;
} }
else else
{ {
if (result.ResultState.ToLowerInvariant().Equals("inconclusive")) if (result.ResultState.ToLowerInvariant().Equals("inconclusive"))
state = TestState.Inconclusive; state = TestState.Inconclusive;
if (result.ResultState.ToLowerInvariant().EndsWith("cancelled") || if (result.ResultState.ToLowerInvariant().EndsWith("cancelled") ||
result.ResultState.ToLowerInvariant().EndsWith("error")) result.ResultState.ToLowerInvariant().EndsWith("error"))
state = TestState.Error; state = TestState.Error;
} }
return state; return state;
} }
public List<string> FlattenTestNames(ITestAdaptor test) public List<string> FlattenTestNames(ITestAdaptor test)
{ {
var results = new List<string>(); var results = new List<string>();
if (!test.IsSuite) if (!test.IsSuite)
results.Add(test.FullName); results.Add(test.FullName);
if (test.Children != null && test.Children.Any()) if (test.Children != null && test.Children.Any())
foreach (var child in test.Children) foreach (var child in test.Children)
results.AddRange(FlattenTestNames(child)); results.AddRange(FlattenTestNames(child));
return results; return results;
} }
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: 2011a59d3f76b3d4a85cb53f945fceee guid: 2011a59d3f76b3d4a85cb53f945fceee
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
{ {
internal class TestStartedMessage : Message internal class TestStartedMessage : Message
{ {
public string name; public string name;
public TestState state; public TestState state;
public TestStartedMessage() public TestStartedMessage()
{ {
type = "TestStatus"; type = "TestStatus";
phase = "Begin"; phase = "Begin";
state = TestState.Inconclusive; state = TestState.Inconclusive;
} }
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: bd3e81baa10021f4d877fa36382bab16 guid: bd3e81baa10021f4d877fa36382bab16
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
{ {
// This matches the state definitions expected by the Perl code, which in turn matches the NUnit 2 values... // This matches the state definitions expected by the Perl code, which in turn matches the NUnit 2 values...
internal enum TestState internal enum TestState
{ {
Inconclusive = 0, Inconclusive = 0,
Skipped = 2, Skipped = 2,
Ignored = 3, Ignored = 3,
Success = 4, Success = 4,
Failure = 5, Failure = 5,
Error = 6 Error = 6
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: 77f432980bb30084299a138e15c6f571 guid: 77f432980bb30084299a138e15c6f571
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
using UnityEditor.TestTools.TestRunner.Api; using UnityEditor.TestTools.TestRunner.Api;
using UnityEngine; using UnityEngine;
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
{ {
internal class UnityTestProtocolListener : ScriptableObject, ICallbacks internal class UnityTestProtocolListener : ScriptableObject, ICallbacks
{ {
private IUtpMessageReporter m_UtpMessageReporter; private IUtpMessageReporter m_UtpMessageReporter;
public UnityTestProtocolListener() public UnityTestProtocolListener()
{ {
m_UtpMessageReporter = new UtpMessageReporter(new UtpDebugLogger()); m_UtpMessageReporter = new UtpMessageReporter(new UtpDebugLogger());
} }
public void RunStarted(ITestAdaptor testsToRun) public void RunStarted(ITestAdaptor testsToRun)
{ {
m_UtpMessageReporter.ReportTestRunStarted(testsToRun); m_UtpMessageReporter.ReportTestRunStarted(testsToRun);
} }
public void RunFinished(ITestResultAdaptor testResults) public void RunFinished(ITestResultAdaptor testResults)
{ {
// Apparently does nothing :) // Apparently does nothing :)
} }
public void TestStarted(ITestAdaptor test) public void TestStarted(ITestAdaptor test)
{ {
m_UtpMessageReporter.ReportTestStarted(test); m_UtpMessageReporter.ReportTestStarted(test);
} }
public void TestFinished(ITestResultAdaptor result) public void TestFinished(ITestResultAdaptor result)
{ {
m_UtpMessageReporter.ReportTestFinished(result); m_UtpMessageReporter.ReportTestFinished(result);
} }
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: 900aac3710bc14542a8d164e3f0ff820 guid: 900aac3710bc14542a8d164e3f0ff820
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment