Initial Commit
This commit is contained in:
parent
53eb92e9af
commit
270ab7d11f
15341 changed files with 700234 additions and 0 deletions
|
@ -0,0 +1,86 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework.Interfaces;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools.Logging;
|
||||
using UnityEngine.TestTools.TestRunner;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
|
||||
{
|
||||
internal abstract class BuildActionTaskBase<T> : TestTaskBase
|
||||
{
|
||||
private string typeName;
|
||||
internal IAttributeFinder attributeFinder;
|
||||
internal RuntimePlatform targetPlatform = Application.platform;
|
||||
internal Action<string> logAction = Debug.Log;
|
||||
internal Func<ILogScope> logScopeProvider = () => new LogScope();
|
||||
internal Func<Type, object> createInstance = Activator.CreateInstance;
|
||||
|
||||
protected BuildActionTaskBase(IAttributeFinder attributeFinder)
|
||||
{
|
||||
this.attributeFinder = attributeFinder;
|
||||
typeName = typeof(T).Name;
|
||||
}
|
||||
|
||||
protected abstract void Action(T target);
|
||||
|
||||
public override IEnumerator Execute(TestJobData testJobData)
|
||||
{
|
||||
if (testJobData.testTree == null)
|
||||
{
|
||||
throw new Exception($"Test tree is not available for {GetType().Name}.");
|
||||
}
|
||||
|
||||
var enumerator = ExecuteMethods(testJobData.testTree, testJobData.executionSettings.BuildNUnitFilter());
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected IEnumerator ExecuteMethods(ITest testTree, ITestFilter testRunnerFilter)
|
||||
{
|
||||
var exceptions = new List<Exception>();
|
||||
|
||||
foreach (var targetClassType in attributeFinder.Search(testTree, testRunnerFilter, targetPlatform))
|
||||
{
|
||||
try
|
||||
{
|
||||
var targetClass = (T) createInstance(targetClassType);
|
||||
|
||||
logAction($"Executing {typeName} for: {targetClassType.FullName}.");
|
||||
|
||||
using (var logScope = logScopeProvider())
|
||||
{
|
||||
Action(targetClass);
|
||||
|
||||
if (logScope.AnyFailingLogs())
|
||||
{
|
||||
var failingLog = logScope.FailingLogs.First();
|
||||
throw new UnhandledLogMessageException(failingLog);
|
||||
}
|
||||
|
||||
if (logScope.ExpectedLogs.Any())
|
||||
{
|
||||
var expectedLogs = logScope.ExpectedLogs.First();
|
||||
throw new UnexpectedLogMessageException(expectedLogs);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exceptions.Add(ex);
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
if (exceptions.Count > 0)
|
||||
{
|
||||
throw new AggregateException($"One or more exceptions when executing {typeName}.", exceptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c2441d353f9c42a44af6e224e4901b52
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,61 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using UnityEditor.TestTools.TestRunner.Api;
|
||||
using UnityEngine.TestRunner.NUnitExtensions;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.TestTools.NUnitExtensions;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
|
||||
{
|
||||
internal class BuildTestTreeTask : TestTaskBase
|
||||
{
|
||||
private TestPlatform m_TestPlatform;
|
||||
|
||||
public BuildTestTreeTask(TestPlatform testPlatform)
|
||||
{
|
||||
m_TestPlatform = testPlatform;
|
||||
}
|
||||
|
||||
internal IEditorLoadedTestAssemblyProvider m_testAssemblyProvider = new EditorLoadedTestAssemblyProvider(new EditorCompilationInterfaceProxy(), new EditorAssembliesProxy());
|
||||
internal IAsyncTestAssemblyBuilder m_testAssemblyBuilder = new UnityTestAssemblyBuilder();
|
||||
internal ICallbacksDelegator m_CallbacksDelegator = CallbacksDelegator.instance;
|
||||
|
||||
public override IEnumerator Execute(TestJobData testJobData)
|
||||
{
|
||||
if (testJobData.testTree != null)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
var assembliesEnumerator = m_testAssemblyProvider.GetAssembliesGroupedByTypeAsync(m_TestPlatform);
|
||||
while (assembliesEnumerator.MoveNext())
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
if (assembliesEnumerator.Current == null)
|
||||
{
|
||||
throw new Exception("Assemblies not retrieved.");
|
||||
}
|
||||
|
||||
var assemblies = assembliesEnumerator.Current.Where(pair => m_TestPlatform.IsFlagIncluded(pair.Key)).SelectMany(pair => pair.Value).Select(x => x.Assembly).ToArray();
|
||||
var buildSettings = UnityTestAssemblyBuilder.GetNUnitTestBuilderSettings(m_TestPlatform);
|
||||
var enumerator = m_testAssemblyBuilder.BuildAsync(assemblies, Enumerable.Repeat(m_TestPlatform, assemblies.Length).ToArray(), buildSettings);
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
var testList = enumerator.Current;
|
||||
if (testList== null)
|
||||
{
|
||||
throw new Exception("Test list not retrieved.");
|
||||
}
|
||||
|
||||
testList.ParseForNameDuplicates();
|
||||
testJobData.testTree = testList;
|
||||
m_CallbacksDelegator.TestTreeRebuild(testList);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a0288e1c9324e824bab7e2044a72a434
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
|
||||
{
|
||||
internal class CleanupVerificationTask : FileCleanupVerifierTaskBase
|
||||
{
|
||||
private const string k_Indent = " ";
|
||||
|
||||
internal Action<object> logAction = Debug.LogWarning;
|
||||
|
||||
public override IEnumerator Execute(TestJobData testJobData)
|
||||
{
|
||||
var currentFiles = GetAllFilesInAssetsDirectory();
|
||||
var existingFiles = testJobData.existingFiles;
|
||||
|
||||
if (currentFiles.Length != existingFiles.Length)
|
||||
{
|
||||
var existingFilesHashSet = new HashSet<string>(existingFiles);
|
||||
var newFiles = currentFiles.Where(file => !existingFilesHashSet.Contains(file)).ToArray();
|
||||
LogWarningForFilesIfAny(newFiles);
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
private void LogWarningForFilesIfAny(string[] filePaths)
|
||||
{
|
||||
if (filePaths.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var stringWriter = new StringWriter();
|
||||
stringWriter.WriteLine("Files generated by test without cleanup.");
|
||||
stringWriter.WriteLine(k_Indent + "Found {0} new files.", filePaths.Length);
|
||||
|
||||
foreach (var filePath in filePaths)
|
||||
{
|
||||
stringWriter.WriteLine(k_Indent + filePath);
|
||||
}
|
||||
|
||||
logAction(stringWriter.ToString());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 93eb6389f4fb6924987867ce0bc339ee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
|
||||
{
|
||||
internal abstract class FileCleanupVerifierTaskBase : TestTaskBase
|
||||
{
|
||||
internal Func<string[]> GetAllAssetPathsAction = AssetDatabase.GetAllAssetPaths;
|
||||
|
||||
protected string[] GetAllFilesInAssetsDirectory()
|
||||
{
|
||||
return GetAllAssetPathsAction();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ad7bb166069f8414e9ad26606b305e66
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,26 @@
|
|||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
|
||||
{
|
||||
internal class LegacyEditModeRunTask : TestTaskBase
|
||||
{
|
||||
public LegacyEditModeRunTask() : base(true)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override IEnumerator Execute(TestJobData testJobData)
|
||||
{
|
||||
var testLauncher = new EditModeLauncher(testJobData.executionSettings.filters, TestPlatform.EditMode, testJobData.executionSettings.runSynchronously);
|
||||
testJobData.editModeRunner = testLauncher.m_EditModeRunner;
|
||||
testLauncher.Run();
|
||||
|
||||
while (testJobData.editModeRunner != null && !testJobData.editModeRunner.RunFinished)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b4246555189b5ee43b4857220f9fd29b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,26 @@
|
|||
using System.Collections;
|
||||
using System.Linq;
|
||||
using UnityEngine.TestTools.TestRunner;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
|
||||
{
|
||||
internal class LegacyPlayModeRunTask : TestTaskBase
|
||||
{
|
||||
public LegacyPlayModeRunTask() : base(true)
|
||||
{
|
||||
|
||||
}
|
||||
public override IEnumerator Execute(TestJobData testJobData)
|
||||
{
|
||||
var settings = PlaymodeTestsControllerSettings.CreateRunnerSettings(testJobData.executionSettings.filters.Select(filter => filter.ToRuntimeTestRunnerFilter(testJobData.executionSettings.runSynchronously)).ToArray());
|
||||
var launcher = new PlaymodeLauncher(settings);
|
||||
|
||||
launcher.Run();
|
||||
|
||||
while (PlaymodeLauncher.IsRunning)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4769fe1e7475c8843b092338acbcad25
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,18 @@
|
|||
using System.Collections;
|
||||
using System.Linq;
|
||||
using UnityEngine.TestTools.TestRunner;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
|
||||
{
|
||||
internal class LegacyPlayerRunTask : TestTaskBase
|
||||
{
|
||||
public override IEnumerator Execute(TestJobData testJobData)
|
||||
{
|
||||
var executionSettings = testJobData.executionSettings;
|
||||
var settings = PlaymodeTestsControllerSettings.CreateRunnerSettings(executionSettings.filters.Select(filter => filter.ToRuntimeTestRunnerFilter(executionSettings.runSynchronously)).ToArray());
|
||||
var launcher = new PlayerLauncher(settings, executionSettings.targetPlatform, executionSettings.overloadTestRunSettings, executionSettings.playerHeartbeatTimeout);
|
||||
launcher.Run();
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b93fe5bbea454ae438fcec241c5fa85b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
|
||||
{
|
||||
internal class PerformUndoTask : TestTaskBase
|
||||
{
|
||||
private const double warningThreshold = 1000;
|
||||
|
||||
internal Action<int> RevertAllDownToGroup = Undo.RevertAllDownToGroup;
|
||||
internal Action<string> LogWarning = Debug.LogWarning;
|
||||
internal Action<string, string, float> DisplayProgressBar = EditorUtility.DisplayProgressBar;
|
||||
internal Action ClearProgressBar = EditorUtility.ClearProgressBar;
|
||||
internal Func<DateTime> TimeNow = () => DateTime.Now;
|
||||
|
||||
public override IEnumerator Execute(TestJobData testJobData)
|
||||
{
|
||||
if (testJobData.undoGroup < 0)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
DisplayProgressBar("Undo", "Reverting changes to the scene", 0);
|
||||
|
||||
var undoStartTime = TimeNow();
|
||||
|
||||
RevertAllDownToGroup(testJobData.undoGroup);
|
||||
|
||||
var timeDelta = TimeNow() - undoStartTime;
|
||||
if (timeDelta.TotalMilliseconds >= warningThreshold)
|
||||
{
|
||||
LogWarning($"Undo after editor test run took {timeDelta.Seconds} second{(timeDelta.Seconds == 1 ? "" : "s")}.");
|
||||
}
|
||||
|
||||
ClearProgressBar();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fb1abebffd37bd4458c84e15a5d7ab04
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using NUnit.Framework.Interfaces;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
|
||||
{
|
||||
internal class PrebuildSetupTask : BuildActionTaskBase<IPrebuildSetup>
|
||||
{
|
||||
public PrebuildSetupTask() : base(new PrebuildSetupAttributeFinder())
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Action(IPrebuildSetup target)
|
||||
{
|
||||
target.Setup();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fc039194235714f48a39bd364885e744
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,13 @@
|
|||
using System.Collections;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
|
||||
{
|
||||
internal class RegisterFilesForCleanupVerificationTask : FileCleanupVerifierTaskBase
|
||||
{
|
||||
public override IEnumerator Execute(TestJobData testJobData)
|
||||
{
|
||||
testJobData.existingFiles = GetAllFilesInAssetsDirectory();
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a398fde47a0349a40a9bdf8988c392c9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using UnityEditor.SceneManagement;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
|
||||
{
|
||||
internal class SaveModiedSceneTask : TestTaskBase
|
||||
{
|
||||
internal Func<bool> SaveCurrentModifiedScenesIfUserWantsTo =
|
||||
EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo;
|
||||
public override IEnumerator Execute(TestJobData testJobData)
|
||||
{
|
||||
var cancelled = !SaveCurrentModifiedScenesIfUserWantsTo();
|
||||
if (cancelled)
|
||||
{
|
||||
throw new TestRunCanceledException();
|
||||
}
|
||||
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c321246872d389b469bd0cb86d3701ed
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
|
||||
{
|
||||
internal class SaveUndoIndexTask : TestTaskBase
|
||||
{
|
||||
internal Func<int> GetUndoGroup = Undo.GetCurrentGroup;
|
||||
public override IEnumerator Execute(TestJobData testJobData)
|
||||
{
|
||||
testJobData.undoGroup = GetUndoGroup();
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cc0ce06a7515c044bb8db4c75db84114
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,16 @@
|
|||
using System.Collections;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner.TestRun.Tasks
|
||||
{
|
||||
internal abstract class TestTaskBase
|
||||
{
|
||||
public bool SupportsResumingEnumerator;
|
||||
|
||||
protected TestTaskBase(bool supportsResumingEnumerator = false)
|
||||
{
|
||||
SupportsResumingEnumerator = supportsResumingEnumerator;
|
||||
}
|
||||
|
||||
public abstract IEnumerator Execute(TestJobData testJobData);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 342d9ef4da0a19b49877f576c2deec14
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue