test
This commit is contained in:
JonatanRek
2020-01-31 16:10:04 +01:00
commit bea2dce063
3837 changed files with 179123 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections;
using UnityEditor;
namespace UnityEngine.TestTools
{
public class EnterPlayMode : IEditModeTestYieldInstruction
{
public bool ExpectDomainReload { get; }
public bool ExpectedPlaymodeState { get; private set; }
public EnterPlayMode(bool expectDomainReload = true)
{
ExpectDomainReload = expectDomainReload;
}
public IEnumerator Perform()
{
if (EditorApplication.isPlaying)
{
throw new Exception("Editor is already in PlayMode");
}
if (EditorUtility.scriptCompilationFailed)
{
throw new Exception("Script compilation failed");
}
yield return null;
ExpectedPlaymodeState = true;
EditorApplication.UnlockReloadAssemblies();
EditorApplication.isPlaying = true;
while (!EditorApplication.isPlaying)
{
yield return null;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9bd5a110ed89025499ddee8c7e73778e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections;
using UnityEditor;
namespace UnityEngine.TestTools
{
public class ExitPlayMode : IEditModeTestYieldInstruction
{
public bool ExpectDomainReload { get; }
public bool ExpectedPlaymodeState { get; private set; }
public ExitPlayMode()
{
ExpectDomainReload = false;
ExpectedPlaymodeState = false;
}
public IEnumerator Perform()
{
if (!EditorApplication.isPlayingOrWillChangePlaymode)
{
throw new Exception("Editor is already in EditMode");
}
EditorApplication.isPlaying = false;
while (EditorApplication.isPlaying)
{
yield return null;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 408674d91d506a54aac9a7f07951c018
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,63 @@
using System;
using System.Collections;
using UnityEditor;
namespace UnityEngine.TestTools
{
public class RecompileScripts : IEditModeTestYieldInstruction
{
public RecompileScripts() : this(true)
{
}
public RecompileScripts(bool expectScriptCompilation) : this(expectScriptCompilation, true)
{
}
public RecompileScripts(bool expectScriptCompilation, bool expectScriptCompilationSuccess)
{
ExpectScriptCompilation = expectScriptCompilation;
ExpectScriptCompilationSuccess = expectScriptCompilationSuccess;
ExpectDomainReload = true;
}
public bool ExpectDomainReload { get; private set; }
public bool ExpectedPlaymodeState { get; }
public bool ExpectScriptCompilation { get; private set; }
public bool ExpectScriptCompilationSuccess { get; private set; }
public static RecompileScripts Current { get; private set; }
public IEnumerator Perform()
{
Current = this;
// We need to yield, to give the test runner a chance to prepare for the domain reload
// If the script compilation happens very fast, then EditModeRunner.MoveNextAndUpdateYieldObject will not have a chance to set m_CurrentYieldObject
// This really should be fixed in EditModeRunner.MoveNextAndUpdateYieldObject
yield return null;
AssetDatabase.Refresh();
if (ExpectScriptCompilation && !EditorApplication.isCompiling)
{
Current = null;
throw new Exception("Editor does not need to recompile scripts");
}
EditorApplication.UnlockReloadAssemblies();
while (EditorApplication.isCompiling)
{
yield return null;
}
Current = null;
if (ExpectScriptCompilationSuccess && EditorUtility.scriptCompilationFailed)
{
EditorApplication.LockReloadAssemblies();
throw new Exception("Script compilation failed");
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9202fbba95ea8294cb5e718f028f21b0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,44 @@
using System;
using System.Collections;
using UnityEditor;
namespace UnityEngine.TestTools
{
public class WaitForDomainReload : IEditModeTestYieldInstruction
{
public WaitForDomainReload()
{
ExpectDomainReload = true;
}
public bool ExpectDomainReload { get;  }
public bool ExpectedPlaymodeState { get; }
public IEnumerator Perform()
{
EditorApplication.UnlockReloadAssemblies();
// Detect if AssetDatabase.Refresh was called (true) or if it will be called on next tick
bool isAsync = EditorApplication.isCompiling;
yield return null;
if (!isAsync)
{
EditorApplication.LockReloadAssemblies();
throw new Exception("Expected domain reload, but it did not occur");
}
while (EditorApplication.isCompiling)
{
yield return null;
}
if (EditorUtility.scriptCompilationFailed)
{
EditorApplication.LockReloadAssemblies();
throw new Exception("Script compilation failed");
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5df3c21c5237c994db89660fbdfee07d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: