This commit is contained in:
Matt Schoen 2017-01-09 16:46:07 -08:00
Родитель 3c1ef4468c
Коммит 0af3a1d8b1
4 изменённых файлов: 131 добавлений и 0 удалений

9
Tests.meta Normal file
Просмотреть файл

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: e66b81717fd984a4198e4ef39ecc34f1
folderAsset: yes
timeCreated: 1483990449
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Tests/Editor.meta Normal file
Просмотреть файл

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: bad2284f6d38fab4ca76252a966fa0c3
folderAsset: yes
timeCreated: 1483990458
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

101
Tests/Editor/CCUTest.cs Normal file
Просмотреть файл

@ -0,0 +1,101 @@
using System;
using System.Reflection;
using NUnit.Framework;
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
public class CCUTest
{
const string kEditorPrefsKey = "EVR_TEST_CCU";
const string kOldDefinesKey = "EVR_TEST_CCU_OLD_DEFINES";
static bool compiled;
static FieldInfo s_RunnerWindowInstanceField;
static Type s_RunnerWindowType;
static string s_ErrorLog;
[Test]
public void TestCCU()
{
if (compiled)
{
Assert.IsFalse(CheckErrors(), s_ErrorLog);
if (EditorPrefs.HasKey(kOldDefinesKey))
{
PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, EditorPrefs.GetString(kOldDefinesKey));
EditorPrefs.DeleteKey(kOldDefinesKey);
}
}
else
{
Debug.ClearDeveloperConsole();
Application.logMessageReceived += Log;
EditorPrefs.SetString(kOldDefinesKey, PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone));
PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, "");
EditorPrefs.SetBool(kEditorPrefsKey, true);
Assert.Inconclusive("Waiting for compile");
}
}
static CCUTest()
{
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
s_RunnerWindowType = assembly.GetType("UnityEditor.EditorTestsRunner.EditorTestsRunnerWindow", false, true);
if (s_RunnerWindowType != null)
break;
}
s_RunnerWindowInstanceField = s_RunnerWindowType.GetField("s_Instance", BindingFlags.Static | BindingFlags.NonPublic);
EditorApplication.update -= Update;
EditorApplication.update += Update;
}
static void Update()
{
if (!EditorApplication.isCompiling)
{
var runnerWindowInstance = s_RunnerWindowInstanceField.GetValue(null);
if (runnerWindowInstance != null)
{
var test = EditorPrefs.GetBool(kEditorPrefsKey);
if (test)
{
compiled = true;
EditorPrefs.DeleteKey(kEditorPrefsKey);
Application.logMessageReceived -= Log;
s_RunnerWindowType.InvokeMember("RunTests", BindingFlags.InvokeMethod | BindingFlags.NonPublic, null, runnerWindowInstance, null);
}
}
if (CheckErrors() && EditorPrefs.HasKey(kOldDefinesKey))
{
Application.logMessageReceived -= Log;
PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, EditorPrefs.GetString(kOldDefinesKey));
EditorPrefs.DeleteKey(kOldDefinesKey);
}
}
}
static void Log(string logString, string stackTrace, LogType type)
{
s_ErrorLog += logString + '\n' + stackTrace + '\n';
}
static bool CheckErrors()
{
var assembly = Assembly.GetAssembly(typeof(SceneView));
var logEntries = assembly.GetType("UnityEditorInternal.LogEntries");
logEntries.GetMethod("Clear").Invoke (new object (), null);
var count = (int)logEntries.GetMethod("GetCount").Invoke(new object(), null);
return count > 0;
}
}

Просмотреть файл

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a453af7b8c5c6d849be47cc2da16236e
timeCreated: 1483990479
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: