From c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sun, 19 Apr 2020 17:19:32 -0400 Subject: Inital commit --- .../Assertions/AllocatingGCMemoryConstraint.cs | 83 ++++++++ .../AllocatingGCMemoryConstraint.cs.meta | 11 + .../Assertions/ConstraintsExtensions.cs | 14 ++ .../Assertions/ConstraintsExtensions.cs.meta | 11 + .../Assertions/InvalidSignatureException.cs | 18 ++ .../Assertions/InvalidSignatureException.cs.meta | 11 + .../UnityEngine.TestRunner/Assertions/Is.cs | 10 + .../UnityEngine.TestRunner/Assertions/Is.cs.meta | 11 + .../UnityEngine.TestRunner/Assertions/LogAssert.cs | 39 ++++ .../Assertions/LogAssert.cs.meta | 11 + .../Assertions/LogScope.meta | 8 + .../Assertions/LogScope/ILogScope.cs | 22 ++ .../Assertions/LogScope/ILogScope.cs.meta | 11 + .../Assertions/LogScope/LogEvent.cs | 18 ++ .../Assertions/LogScope/LogEvent.cs.meta | 11 + .../Assertions/LogScope/LogMatch.cs | 103 ++++++++++ .../Assertions/LogScope/LogMatch.cs.meta | 11 + .../Assertions/LogScope/LogScope.cs | 223 +++++++++++++++++++++ .../Assertions/LogScope/LogScope.cs.meta | 11 + .../Assertions/UnexpectedLogMessageException.cs | 29 +++ .../UnexpectedLogMessageException.cs.meta | 11 + .../Assertions/UnhandledLogMessageException.cs | 35 ++++ .../UnhandledLogMessageException.cs.meta | 11 + .../Assertions/UnityTestTimeoutException.cs | 28 +++ .../Assertions/UnityTestTimeoutException.cs.meta | 11 + 25 files changed, 762 insertions(+) create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/AllocatingGCMemoryConstraint.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/AllocatingGCMemoryConstraint.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/ConstraintsExtensions.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/ConstraintsExtensions.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/InvalidSignatureException.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/InvalidSignatureException.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/Is.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/Is.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogAssert.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogAssert.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/ILogScope.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/ILogScope.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogEvent.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogEvent.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogMatch.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogMatch.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogScope.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogScope.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnexpectedLogMessageException.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnexpectedLogMessageException.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnhandledLogMessageException.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnhandledLogMessageException.cs.meta create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnityTestTimeoutException.cs create mode 100644 Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnityTestTimeoutException.cs.meta (limited to 'Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions') diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/AllocatingGCMemoryConstraint.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/AllocatingGCMemoryConstraint.cs new file mode 100644 index 0000000..d765cdb --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/AllocatingGCMemoryConstraint.cs @@ -0,0 +1,83 @@ +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(ActualValueDelegate del) + { + if (del == null) + throw new ArgumentNullException(); + + return ApplyTo(() => del.Invoke(), del); + } + + public override string Description + { + get { return "allocates GC memory"; } + } + } +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/AllocatingGCMemoryConstraint.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/AllocatingGCMemoryConstraint.cs.meta new file mode 100644 index 0000000..e38d0b4 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/AllocatingGCMemoryConstraint.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d09858396dd7adb4bbdb22ea0c8c3a37 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/ConstraintsExtensions.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/ConstraintsExtensions.cs new file mode 100644 index 0000000..54b8e64 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/ConstraintsExtensions.cs @@ -0,0 +1,14 @@ +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; + } + } +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/ConstraintsExtensions.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/ConstraintsExtensions.cs.meta new file mode 100644 index 0000000..b0fc061 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/ConstraintsExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 68a48d1900320ed458e118415857faf6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/InvalidSignatureException.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/InvalidSignatureException.cs new file mode 100644 index 0000000..b9c132b --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/InvalidSignatureException.cs @@ -0,0 +1,18 @@ +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; } + } + } +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/InvalidSignatureException.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/InvalidSignatureException.cs.meta new file mode 100644 index 0000000..a995fcf --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/InvalidSignatureException.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9650d910fcaefb34cb45f121c1993892 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/Is.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/Is.cs new file mode 100644 index 0000000..4cdc715 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/Is.cs @@ -0,0 +1,10 @@ +namespace UnityEngine.TestTools.Constraints +{ + public class Is : NUnit.Framework.Is + { + public static AllocatingGCMemoryConstraint AllocatingGCMemory() + { + return new AllocatingGCMemoryConstraint(); + } + } +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/Is.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/Is.cs.meta new file mode 100644 index 0000000..636110b --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/Is.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6d5833966abeadb429de247e4316eef4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogAssert.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogAssert.cs new file mode 100644 index 0000000..32900eb --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogAssert.cs @@ -0,0 +1,39 @@ +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; + } + } + } +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogAssert.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogAssert.cs.meta new file mode 100644 index 0000000..222bb52 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogAssert.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c97b794b51780d349a16826a4c7898d7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope.meta new file mode 100644 index 0000000..a225ac0 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b1d8465ba1376b148bdab58965101f47 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/ILogScope.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/ILogScope.cs new file mode 100644 index 0000000..efd00f7 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/ILogScope.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; + +namespace UnityEngine.TestTools.Logging +{ + internal interface ILogScope : IDisposable + { + Queue ExpectedLogs { get; set; } + List AllLogs { get; } + List FailingLogs { get; } + bool IgnoreFailingMessages { get; set; } + bool IsNUnitException { get; } + bool IsNUnitSuccessException { get; } + bool IsNUnitInconclusiveException { get; } + bool IsNUnitIgnoreException { get; } + string NUnitExceptionMessage { get; } + void AddLog(string message, string stacktrace, LogType type); + bool AnyFailingLogs(); + void ProcessExpectedLogs(); + void NoUnexpectedReceived(); + } +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/ILogScope.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/ILogScope.cs.meta new file mode 100644 index 0000000..97b0e2c --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/ILogScope.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3504aa04cda851b44a65973f9aead6f7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogEvent.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogEvent.cs new file mode 100644 index 0000000..49f58cb --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogEvent.cs @@ -0,0 +1,18 @@ +namespace UnityEngine.TestTools.Logging +{ + internal class LogEvent + { + public string Message { get; set; } + + public string StackTrace { get; set; } + + public LogType LogType { get; set; } + + public bool IsHandled { get; set; } + + public override string ToString() + { + return string.Format("[{0}] {1}", LogType, Message); + } + } +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogEvent.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogEvent.cs.meta new file mode 100644 index 0000000..1609325 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogEvent.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0c56471f08a0f6846afc792f0b4205b9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogMatch.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogMatch.cs new file mode 100644 index 0000000..05df048 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogMatch.cs @@ -0,0 +1,103 @@ +using System; +using System.Text.RegularExpressions; + +namespace UnityEngine.TestTools.Logging +{ + [Serializable] + internal class LogMatch + { + [SerializeField] + private bool m_UseRegex; + [SerializeField] + private string m_Message; + [SerializeField] + private string m_MessageRegex; + [SerializeField] + private string m_LogType; + + public string Message + { + get { return m_Message; } + set + { + m_Message = value; + m_UseRegex = false; + } + } + + public Regex MessageRegex + { + get + { + if (!m_UseRegex) + { + return null; + } + + return new Regex(m_MessageRegex); + } + set + { + if (value != null) + { + m_MessageRegex = value.ToString(); + m_UseRegex = true; + } + else + { + m_MessageRegex = null; + m_UseRegex = false; + } + } + } + + public LogType? LogType + { + get + { + if (!string.IsNullOrEmpty(m_LogType)) + { + return Enum.Parse(typeof(LogType), m_LogType) as LogType ? ; + } + + return null; + } + set + { + if (value != null) + { + m_LogType = value.Value.ToString(); + } + else + { + m_LogType = null; + } + } + } + + public bool Matches(LogEvent log) + { + if (LogType != null && LogType != log.LogType) + { + return false; + } + + if (m_UseRegex) + { + return MessageRegex.IsMatch(log.Message); + } + else + { + return Message.Equals(log.Message); + } + } + + public override string ToString() + { + if (m_UseRegex) + return string.Format("[{0}] Regex: {1}", LogType, MessageRegex); + else + return string.Format("[{0}] {1}", LogType, Message); + } + } +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogMatch.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogMatch.cs.meta new file mode 100644 index 0000000..12f2cf8 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogMatch.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9945ffed4692c6044b6d3acf81efd694 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogScope.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogScope.cs new file mode 100644 index 0000000..6f429c9 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogScope.cs @@ -0,0 +1,223 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine.TestTools.TestRunner; + +namespace UnityEngine.TestTools.Logging +{ + sealed class LogScope : ILogScope + { + static List s_ActiveScopes = new List(); + + readonly object m_Lock = new object(); + bool m_Disposed; + bool m_NeedToProcessLogs; + + public Queue ExpectedLogs { get; set; } + public List AllLogs { get; } + public List FailingLogs { get; } + public bool IgnoreFailingMessages { get; set; } + public bool IsNUnitException { get; private set; } + public bool IsNUnitSuccessException { get; private set; } + public bool IsNUnitInconclusiveException { get; private set; } + public bool IsNUnitIgnoreException { get; private set; } + public string NUnitExceptionMessage { get; private set; } + + public static LogScope Current + { + get + { + if (s_ActiveScopes.Count == 0) + throw new InvalidOperationException("No log scope is available"); + return s_ActiveScopes[0]; + } + } + + public static bool HasCurrentLogScope() + { + return s_ActiveScopes.Count > 0; + } + + public LogScope() + { + AllLogs = new List(); + FailingLogs = new List(); + ExpectedLogs = new Queue(); + IgnoreFailingMessages = false; + Activate(); + } + + void Activate() + { + s_ActiveScopes.Insert(0, this); + RegisterScope(this); + Application.logMessageReceivedThreaded -= AddLog; + Application.logMessageReceivedThreaded += AddLog; + } + + void Deactivate() + { + Application.logMessageReceivedThreaded -= AddLog; + s_ActiveScopes.Remove(this); + UnregisterScope(this); + } + + static void RegisterScope(LogScope logScope) + { + Application.logMessageReceivedThreaded += logScope.AddLog; + } + + static void UnregisterScope(LogScope logScope) + { + Application.logMessageReceivedThreaded -= logScope.AddLog; + } + + public void AddLog(string message, string stacktrace, LogType type) + { + lock (m_Lock) + { + m_NeedToProcessLogs = true; + var log = new LogEvent + { + LogType = type, + Message = message, + StackTrace = stacktrace, + }; + + AllLogs.Add(log); + + if (IsNUnitResultStateException(stacktrace, type)) + { + if (message.StartsWith("SuccessException")) + { + IsNUnitException = true; + IsNUnitSuccessException = true; + if (message.StartsWith("SuccessException: ")) + { + NUnitExceptionMessage = message.Substring("SuccessException: ".Length); + return; + } + } + else if (message.StartsWith("InconclusiveException")) + { + IsNUnitException = true; + IsNUnitInconclusiveException = true; + if (message.StartsWith("InconclusiveException: ")) + { + NUnitExceptionMessage = message.Substring("InconclusiveException: ".Length); + return; + } + } + else if (message.StartsWith("IgnoreException")) + { + IsNUnitException = true; + IsNUnitIgnoreException = true; + if (message.StartsWith("IgnoreException: ")) + { + NUnitExceptionMessage = message.Substring("IgnoreException: ".Length); + return; + } + } + } + + if (IsFailingLog(type) && !IgnoreFailingMessages) + { + FailingLogs.Add(log); + } + } + } + + static bool IsNUnitResultStateException(string stacktrace, LogType logType) + { + if (logType != LogType.Exception) + return false; + + return string.IsNullOrEmpty(stacktrace) || stacktrace.StartsWith("NUnit.Framework.Assert."); + } + + static bool IsFailingLog(LogType type) + { + switch (type) + { + case LogType.Assert: + case LogType.Error: + case LogType.Exception: + return true; + default: + return false; + } + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + void Dispose(bool disposing) + { + if (m_Disposed) + { + return; + } + + m_Disposed = true; + + if (disposing) + { + Deactivate(); + } + } + + public bool AnyFailingLogs() + { + ProcessExpectedLogs(); + return FailingLogs.Any(); + } + + public void ProcessExpectedLogs() + { + lock (m_Lock) + { + if (!m_NeedToProcessLogs || !ExpectedLogs.Any()) + return; + + LogMatch expectedLog = null; + foreach (var logEvent in AllLogs) + { + if (!ExpectedLogs.Any()) + break; + if (expectedLog == null && ExpectedLogs.Any()) + expectedLog = ExpectedLogs.Peek(); + + if (expectedLog != null && expectedLog.Matches(logEvent)) + { + ExpectedLogs.Dequeue(); + logEvent.IsHandled = true; + if (FailingLogs.Any(expectedLog.Matches)) + { + var failingLog = FailingLogs.First(expectedLog.Matches); + FailingLogs.Remove(failingLog); + } + expectedLog = null; + } + } + m_NeedToProcessLogs = false; + } + } + + public void NoUnexpectedReceived() + { + lock (m_Lock) + { + ProcessExpectedLogs(); + + var unhandledLog = AllLogs.FirstOrDefault(x => !x.IsHandled); + if (unhandledLog != null) + { + throw new UnhandledLogMessageException(unhandledLog); + } + } + } + } +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogScope.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogScope.cs.meta new file mode 100644 index 0000000..876c080 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/LogScope/LogScope.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4bbc17b35884fdf468e4b52ae4222882 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnexpectedLogMessageException.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnexpectedLogMessageException.cs new file mode 100644 index 0000000..4a491be --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnexpectedLogMessageException.cs @@ -0,0 +1,29 @@ +using NUnit.Framework; +using NUnit.Framework.Interfaces; +using UnityEngine.TestTools.Logging; + +namespace UnityEngine.TestTools.TestRunner +{ + internal class UnexpectedLogMessageException : ResultStateException + { + public LogMatch LogEvent; + + public UnexpectedLogMessageException(LogMatch log) + : base(BuildMessage(log)) + { + LogEvent = log; + } + + private static string BuildMessage(LogMatch log) + { + return string.Format("Expected log did not appear: {0}", log); + } + + public override ResultState ResultState + { + get { return ResultState.Failure; } + } + + public override string StackTrace { get { return null; } } + } +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnexpectedLogMessageException.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnexpectedLogMessageException.cs.meta new file mode 100644 index 0000000..57673e2 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnexpectedLogMessageException.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5b2eeca598284bd4abb4a15c30df1576 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnhandledLogMessageException.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnhandledLogMessageException.cs new file mode 100644 index 0000000..5a7ab33 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnhandledLogMessageException.cs @@ -0,0 +1,35 @@ +using NUnit.Framework; +using NUnit.Framework.Interfaces; +using UnityEngine.TestTools.Logging; +using UnityEngine.TestTools.Utils; + +namespace UnityEngine.TestTools.TestRunner +{ + internal class UnhandledLogMessageException : ResultStateException + { + public LogEvent LogEvent; + private readonly string m_CustomStackTrace; + + public UnhandledLogMessageException(LogEvent log) + : base(BuildMessage(log)) + { + LogEvent = log; + m_CustomStackTrace = StackTraceFilter.Filter(log.StackTrace); + } + + private static string BuildMessage(LogEvent log) + { + return string.Format("Unhandled log message: '{0}'. Use UnityEngine.TestTools.LogAssert.Expect", log); + } + + public override ResultState ResultState + { + get { return ResultState.Failure; } + } + + public override string StackTrace + { + get { return m_CustomStackTrace; } + } + } +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnhandledLogMessageException.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnhandledLogMessageException.cs.meta new file mode 100644 index 0000000..6394a8d --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnhandledLogMessageException.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a8ed4063f2beecd41a234a582202f3c4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnityTestTimeoutException.cs b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnityTestTimeoutException.cs new file mode 100644 index 0000000..56566d7 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnityTestTimeoutException.cs @@ -0,0 +1,28 @@ +using NUnit.Framework; +using NUnit.Framework.Interfaces; + +namespace UnityEngine.TestTools.TestRunner +{ + internal class UnityTestTimeoutException : ResultStateException + { + public UnityTestTimeoutException(int timeout) + : base(BuildMessage(timeout)) + { + } + + private static string BuildMessage(int timeout) + { + return string.Format("UnityTest exceeded Timeout value of {0}ms", timeout); + } + + public override ResultState ResultState + { + get { return ResultState.Failure; } + } + + public override string StackTrace + { + get { return ""; } + } + } +} diff --git a/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnityTestTimeoutException.cs.meta b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnityTestTimeoutException.cs.meta new file mode 100644 index 0000000..188de19 --- /dev/null +++ b/Library/PackageCache/com.unity.test-framework@1.1.11/UnityEngine.TestRunner/Assertions/UnityTestTimeoutException.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ffb335140c799c4408411d81789fb05c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: -- cgit v1.2.3