Commit af571a61 authored by BlackAngle233's avatar BlackAngle233
Browse files

212

parent 1d9b5391
using System;
using System.Linq;
using UnityEditor.Compilation;
using UnityEditor.TestTools.TestRunner.Api;
using UnityEngine;
using UnityEngine.TestTools;
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
{
[InitializeOnLoad]
internal static class UnityTestProtocolStarter
{
static UnityTestProtocolStarter()
{
var commandLineArgs = Environment.GetCommandLineArgs();
if (commandLineArgs.Contains("-automated") && commandLineArgs.Contains("-runTests")) // wanna have it only for utr run
{
var api = ScriptableObject.CreateInstance<TestRunnerApi>();
var listener = ScriptableObject.CreateInstance<UnityTestProtocolListener>();
api.RegisterCallbacks(listener);
CompilationPipeline.assemblyCompilationFinished += OnAssemblyCompilationFinished;
}
}
public static void OnAssemblyCompilationFinished(string assembly, CompilerMessage[] messages)
{
bool checkCompileErrors = RecompileScripts.Current == null || RecompileScripts.Current.ExpectScriptCompilationSuccess;
if (checkCompileErrors && messages.Any(x => x.type == CompilerMessageType.Error))
{
var compilerErrorMessages = messages.Where(x => x.type == CompilerMessageType.Error);
var utpMessageReporter = new UtpMessageReporter(new UtpDebugLogger());
utpMessageReporter.ReportAssemblyCompilationErrors(assembly, compilerErrorMessages);
}
}
}
}
using System;
using System.Linq;
using UnityEditor.Compilation;
using UnityEditor.TestTools.TestRunner.Api;
using UnityEngine;
using UnityEngine.TestTools;
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
{
[InitializeOnLoad]
internal static class UnityTestProtocolStarter
{
static UnityTestProtocolStarter()
{
var commandLineArgs = Environment.GetCommandLineArgs();
if (commandLineArgs.Contains("-automated") && commandLineArgs.Contains("-runTests")) // wanna have it only for utr run
{
var api = ScriptableObject.CreateInstance<TestRunnerApi>();
var listener = ScriptableObject.CreateInstance<UnityTestProtocolListener>();
api.RegisterCallbacks(listener);
CompilationPipeline.assemblyCompilationFinished += OnAssemblyCompilationFinished;
}
}
public static void OnAssemblyCompilationFinished(string assembly, CompilerMessage[] messages)
{
bool checkCompileErrors = RecompileScripts.Current == null || RecompileScripts.Current.ExpectScriptCompilationSuccess;
if (checkCompileErrors && messages.Any(x => x.type == CompilerMessageType.Error))
{
var compilerErrorMessages = messages.Where(x => x.type == CompilerMessageType.Error);
var utpMessageReporter = new UtpMessageReporter(new UtpDebugLogger());
utpMessageReporter.ReportAssemblyCompilationErrors(assembly, compilerErrorMessages);
}
}
}
}
fileFormatVersion: 2
guid: 1ac58cb55fc8daf4abd3945a2bbbb0c5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 1ac58cb55fc8daf4abd3945a2bbbb0c5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
{
class UtpDebugLogger : IUtpLogger
{
public void Log(Message msg)
{
var msgJson = JsonUtility.ToJson(msg);
Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, "\n##utp:{0}", msgJson);
}
}
}
using UnityEngine;
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
{
class UtpDebugLogger : IUtpLogger
{
public void Log(Message msg)
{
var msgJson = JsonUtility.ToJson(msg);
Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, "\n##utp:{0}", msgJson);
}
}
}
fileFormatVersion: 2
guid: d0abdd8cb6b29a24c8ee19626ef741b9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: d0abdd8cb6b29a24c8ee19626ef741b9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Compilation;
using UnityEditor.TestTools.TestRunner.Api;
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
{
internal class UtpMessageReporter : IUtpMessageReporter
{
public ITestRunnerApiMapper TestRunnerApiMapper;
public IUtpLogger Logger;
public UtpMessageReporter(IUtpLogger utpLogger)
{
TestRunnerApiMapper = new TestRunnerApiMapper();
Logger = utpLogger;
}
public void ReportAssemblyCompilationErrors(string assembly, IEnumerable<CompilerMessage> errorCompilerMessages)
{
var compilationErrorMessage = new AssemblyCompilationErrorsMessage
{
assembly = assembly,
errors = errorCompilerMessages.Select(x => x.message).ToArray()
};
Logger.Log(compilationErrorMessage);
}
public void ReportTestRunStarted(ITestAdaptor testsToRun)
{
var msg = TestRunnerApiMapper.MapTestToTestPlanMessage(testsToRun);
Logger.Log(msg);
}
public void ReportTestStarted(ITestAdaptor test)
{
if (test.IsSuite)
return;
var msg = TestRunnerApiMapper.MapTestToTestStartedMessage(test);
Logger.Log(msg);
}
public void ReportTestFinished(ITestResultAdaptor result)
{
if (result.Test.IsSuite)
return;
var msg = TestRunnerApiMapper.TestResultToTestFinishedMessage(result);
Logger.Log(msg);
}
}
}
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Compilation;
using UnityEditor.TestTools.TestRunner.Api;
namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
{
internal class UtpMessageReporter : IUtpMessageReporter
{
public ITestRunnerApiMapper TestRunnerApiMapper;
public IUtpLogger Logger;
public UtpMessageReporter(IUtpLogger utpLogger)
{
TestRunnerApiMapper = new TestRunnerApiMapper();
Logger = utpLogger;
}
public void ReportAssemblyCompilationErrors(string assembly, IEnumerable<CompilerMessage> errorCompilerMessages)
{
var compilationErrorMessage = new AssemblyCompilationErrorsMessage
{
assembly = assembly,
errors = errorCompilerMessages.Select(x => x.message).ToArray()
};
Logger.Log(compilationErrorMessage);
}
public void ReportTestRunStarted(ITestAdaptor testsToRun)
{
var msg = TestRunnerApiMapper.MapTestToTestPlanMessage(testsToRun);
Logger.Log(msg);
}
public void ReportTestStarted(ITestAdaptor test)
{
if (test.IsSuite)
return;
var msg = TestRunnerApiMapper.MapTestToTestStartedMessage(test);
Logger.Log(msg);
}
public void ReportTestFinished(ITestResultAdaptor result)
{
if (result.Test.IsSuite)
return;
var msg = TestRunnerApiMapper.TestResultToTestFinishedMessage(result);
Logger.Log(msg);
}
}
}
fileFormatVersion: 2
guid: ebcc5f899d9277642868aeda9a17cbaf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: ebcc5f899d9277642868aeda9a17cbaf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 950890083f4907541a6ed06d70959e49
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 950890083f4907541a6ed06d70959e49
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Reflection;
using System.Runtime.CompilerServices;
[assembly: AssemblyTitle("UnityEngine.TestRunner")]
[assembly: InternalsVisibleTo("UnityEditor.TestRunner")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
[assembly: InternalsVisibleTo("Unity.PerformanceTesting")]
[assembly: InternalsVisibleTo("Unity.PerformanceTesting.Editor")]
[assembly: InternalsVisibleTo("Assembly-CSharp-testable")]
[assembly: InternalsVisibleTo("Assembly-CSharp-Editor-testable")]
[assembly: InternalsVisibleTo("UnityEngine.TestRunner.Tests")]
[assembly: InternalsVisibleTo("UnityEditor.TestRunner.Tests")]
[assembly: InternalsVisibleTo("Unity.PackageManagerUI.Editor")]
[assembly: AssemblyVersion("1.0.0")]
using System.Reflection;
using System.Runtime.CompilerServices;
[assembly: AssemblyTitle("UnityEngine.TestRunner")]
[assembly: InternalsVisibleTo("UnityEditor.TestRunner")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
[assembly: InternalsVisibleTo("Unity.PerformanceTesting")]
[assembly: InternalsVisibleTo("Unity.PerformanceTesting.Editor")]
[assembly: InternalsVisibleTo("Assembly-CSharp-testable")]
[assembly: InternalsVisibleTo("Assembly-CSharp-Editor-testable")]
[assembly: InternalsVisibleTo("UnityEngine.TestRunner.Tests")]
[assembly: InternalsVisibleTo("UnityEditor.TestRunner.Tests")]
[assembly: InternalsVisibleTo("Unity.PackageManagerUI.Editor")]
[assembly: AssemblyVersion("1.0.0")]
fileFormatVersion: 2
guid: cc22cc13b69c1094c85e176c008b9ef8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: cc22cc13b69c1094c85e176c008b9ef8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 1ad55f5ad04d1d045a1f287409c650dd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 1ad55f5ad04d1d045a1f287409c650dd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System;
using NUnit.Framework;
using NUnit.Framework.Constraints;
using UnityEngine.Profiling;
namespace UnityEngine.TestTools.Constraints
{
public class AllocatingGCMemoryConstraint : Constraint
{
private class AllocatingGCMemoryResult : ConstraintResult
{
private readonly int diff;
public AllocatingGCMemoryResult(IConstraint constraint, object actualValue, int diff) : base(constraint, actualValue, diff > 0)
{
this.diff = diff;
}
public override void WriteMessageTo(MessageWriter writer)
{
if (diff == 0)
writer.WriteMessageLine("The provided delegate did not make any GC allocations.");
else
writer.WriteMessageLine("The provided delegate made {0} GC allocation(s).", diff);
}
}
private ConstraintResult ApplyTo(Action action, object original)
{
var recorder = Recorder.Get("GC.Alloc");
// The recorder was created enabled, which means it captured the creation of the Recorder object itself, etc.
// Disabling it flushes its data, so that we can retrieve the sample block count and have it correctly account
// for these initial allocations.
recorder.enabled = false;
#if !UNITY_WEBGL
recorder.FilterToCurrentThread();
#endif
recorder.enabled = true;
try
{
action();
}
finally
{
recorder.enabled = false;
#if !UNITY_WEBGL
recorder.CollectFromAllThreads();
#endif
}
return new AllocatingGCMemoryResult(this, original, recorder.sampleBlockCount);
}
public override ConstraintResult ApplyTo(object obj)
{
if (obj == null)
throw new ArgumentNullException();
TestDelegate d = obj as TestDelegate;
if (d == null)
throw new ArgumentException(string.Format("The actual value must be a TestDelegate but was {0}",
obj.GetType()));
return ApplyTo(() => d.Invoke(), obj);
}
public override ConstraintResult ApplyTo<TActual>(ActualValueDelegate<TActual> del)
{
if (del == null)
throw new ArgumentNullException();
return ApplyTo(() => del.Invoke(), del);
}
public override string Description
{
get { return "allocates GC memory"; }
}
}
}
using System;
using NUnit.Framework;
using NUnit.Framework.Constraints;
using UnityEngine.Profiling;
namespace UnityEngine.TestTools.Constraints
{
public class AllocatingGCMemoryConstraint : Constraint
{
private class AllocatingGCMemoryResult : ConstraintResult
{
private readonly int diff;
public AllocatingGCMemoryResult(IConstraint constraint, object actualValue, int diff) : base(constraint, actualValue, diff > 0)
{
this.diff = diff;
}
public override void WriteMessageTo(MessageWriter writer)
{
if (diff == 0)
writer.WriteMessageLine("The provided delegate did not make any GC allocations.");
else
writer.WriteMessageLine("The provided delegate made {0} GC allocation(s).", diff);
}
}
private ConstraintResult ApplyTo(Action action, object original)
{
var recorder = Recorder.Get("GC.Alloc");
// The recorder was created enabled, which means it captured the creation of the Recorder object itself, etc.
// Disabling it flushes its data, so that we can retrieve the sample block count and have it correctly account
// for these initial allocations.
recorder.enabled = false;
#if !UNITY_WEBGL
recorder.FilterToCurrentThread();
#endif
recorder.enabled = true;
try
{
action();
}
finally
{
recorder.enabled = false;
#if !UNITY_WEBGL
recorder.CollectFromAllThreads();
#endif
}
return new AllocatingGCMemoryResult(this, original, recorder.sampleBlockCount);
}
public override ConstraintResult ApplyTo(object obj)
{
if (obj == null)
throw new ArgumentNullException();
TestDelegate d = obj as TestDelegate;
if (d == null)
throw new ArgumentException(string.Format("The actual value must be a TestDelegate but was {0}",
obj.GetType()));
return ApplyTo(() => d.Invoke(), obj);
}
public override ConstraintResult ApplyTo<TActual>(ActualValueDelegate<TActual> del)
{
if (del == null)
throw new ArgumentNullException();
return ApplyTo(() => del.Invoke(), del);
}
public override string Description
{
get { return "allocates GC memory"; }
}
}
}
fileFormatVersion: 2
guid: d09858396dd7adb4bbdb22ea0c8c3a37
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: d09858396dd7adb4bbdb22ea0c8c3a37
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using NUnit.Framework.Constraints;
namespace UnityEngine.TestTools.Constraints
{
public static class ConstraintExtensions
{
public static AllocatingGCMemoryConstraint AllocatingGCMemory(this ConstraintExpression chain)
{
var constraint = new AllocatingGCMemoryConstraint();
chain.Append(constraint);
return constraint;
}
}
}
using NUnit.Framework.Constraints;
namespace UnityEngine.TestTools.Constraints
{
public static class ConstraintExtensions
{
public static AllocatingGCMemoryConstraint AllocatingGCMemory(this ConstraintExpression chain)
{
var constraint = new AllocatingGCMemoryConstraint();
chain.Append(constraint);
return constraint;
}
}
}
fileFormatVersion: 2
guid: 68a48d1900320ed458e118415857faf6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 68a48d1900320ed458e118415857faf6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using NUnit.Framework;
using NUnit.Framework.Interfaces;
namespace UnityEngine.TestTools.TestRunner
{
internal class InvalidSignatureException : ResultStateException
{
public InvalidSignatureException(string message)
: base(message)
{
}
public override ResultState ResultState
{
get { return ResultState.NotRunnable; }
}
}
}
using NUnit.Framework;
using NUnit.Framework.Interfaces;
namespace UnityEngine.TestTools.TestRunner
{
internal class InvalidSignatureException : ResultStateException
{
public InvalidSignatureException(string message)
: base(message)
{
}
public override ResultState ResultState
{
get { return ResultState.NotRunnable; }
}
}
}
fileFormatVersion: 2
guid: 9650d910fcaefb34cb45f121c1993892
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 9650d910fcaefb34cb45f121c1993892
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
namespace UnityEngine.TestTools.Constraints
{
public class Is : NUnit.Framework.Is
{
public static AllocatingGCMemoryConstraint AllocatingGCMemory()
{
return new AllocatingGCMemoryConstraint();
}
}
}
namespace UnityEngine.TestTools.Constraints
{
public class Is : NUnit.Framework.Is
{
public static AllocatingGCMemoryConstraint AllocatingGCMemory()
{
return new AllocatingGCMemoryConstraint();
}
}
}
fileFormatVersion: 2
guid: 6d5833966abeadb429de247e4316eef4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 6d5833966abeadb429de247e4316eef4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Text.RegularExpressions;
using UnityEngine.TestTools.Logging;
namespace UnityEngine.TestTools
{
public static class LogAssert
{
public static void Expect(LogType type, string message)
{
LogScope.Current.ExpectedLogs.Enqueue(new LogMatch() { LogType = type, Message = message });
}
public static void Expect(LogType type, Regex message)
{
LogScope.Current.ExpectedLogs.Enqueue(new LogMatch() { LogType = type, MessageRegex = message });
}
public static void NoUnexpectedReceived()
{
LogScope.Current.NoUnexpectedReceived();
}
public static bool ignoreFailingMessages
{
get
{
return LogScope.Current.IgnoreFailingMessages;
}
set
{
if (value != LogScope.Current.IgnoreFailingMessages)
{
Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, "\nIgnoreFailingMessages:" + (value? "true":"false"));
}
LogScope.Current.IgnoreFailingMessages = value;
}
}
}
}
using System.Text.RegularExpressions;
using UnityEngine.TestTools.Logging;
namespace UnityEngine.TestTools
{
public static class LogAssert
{
public static void Expect(LogType type, string message)
{
LogScope.Current.ExpectedLogs.Enqueue(new LogMatch() { LogType = type, Message = message });
}
public static void Expect(LogType type, Regex message)
{
LogScope.Current.ExpectedLogs.Enqueue(new LogMatch() { LogType = type, MessageRegex = message });
}
public static void NoUnexpectedReceived()
{
LogScope.Current.NoUnexpectedReceived();
}
public static bool ignoreFailingMessages
{
get
{
return LogScope.Current.IgnoreFailingMessages;
}
set
{
if (value != LogScope.Current.IgnoreFailingMessages)
{
Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, "\nIgnoreFailingMessages:" + (value? "true":"false"));
}
LogScope.Current.IgnoreFailingMessages = value;
}
}
}
}
fileFormatVersion: 2
guid: c97b794b51780d349a16826a4c7898d7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: c97b794b51780d349a16826a4c7898d7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
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