This commit is contained in:
2021-06-13 10:28:03 +02:00
parent eb70603c85
commit df2d24cbd3
7487 changed files with 943244 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
using System.Reflection;
namespace UnityEngine.TestTools.Utils
{
internal class AssemblyLoadProxy : IAssemblyLoadProxy
{
public IAssemblyWrapper Load(string assemblyString)
{
return new AssemblyWrapper(Assembly.Load(assemblyString));
}
}
}

View File

@@ -0,0 +1,33 @@
using System;
using System.Reflection;
namespace UnityEngine.TestTools.Utils
{
internal class AssemblyWrapper : IAssemblyWrapper
{
public AssemblyWrapper(Assembly assembly)
{
Assembly = assembly;
Name = assembly.GetName();
}
public Assembly Assembly { get; }
public AssemblyName Name { get; }
public virtual string Location
{
get
{
//Some platforms dont support this
throw new NotImplementedException();
}
}
public virtual AssemblyName[] GetReferencedAssemblies()
{
//Some platforms dont support this
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,7 @@
namespace UnityEngine.TestTools.Utils
{
internal interface IAssemblyLoadProxy
{
IAssemblyWrapper Load(string assemblyString);
}
}

View File

@@ -0,0 +1,12 @@
using System.Reflection;
namespace UnityEngine.TestTools.Utils
{
internal interface IAssemblyWrapper
{
Assembly Assembly { get; }
AssemblyName Name { get; }
string Location { get; }
AssemblyName[] GetReferencedAssemblies();
}
}

View File

@@ -0,0 +1,7 @@
namespace UnityEngine.TestTools.Utils
{
internal interface IScriptingRuntimeProxy
{
string[] GetAllUserAssemblies();
}
}

View File

@@ -0,0 +1,10 @@
using NUnit.Framework.Interfaces;
namespace UnityEngine.TestTools.Utils
{
internal interface ITestAssemblyProvider
{
ITest GetTestsWithNUnit();
IAssemblyWrapper[] GetUserAssemblies();
}
}

View File

@@ -0,0 +1,66 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NUnit.Framework.Interfaces;
using UnityEngine.TestTools.NUnitExtensions;
namespace UnityEngine.TestTools.Utils
{
internal class PlayerTestAssemblyProvider
{
private IAssemblyLoadProxy m_AssemblyLoadProxy;
private readonly List<string> m_AssembliesToLoad;
//Cached until domain reload
private static List<IAssemblyWrapper> m_LoadedAssemblies;
internal PlayerTestAssemblyProvider(IAssemblyLoadProxy assemblyLoadProxy, List<string> assembliesToLoad)
{
m_AssemblyLoadProxy = assemblyLoadProxy;
m_AssembliesToLoad = assembliesToLoad;
LoadAssemblies();
}
public ITest GetTestsWithNUnit()
{
return BuildTests(TestPlatform.PlayMode, m_LoadedAssemblies.ToArray());
}
public List<IAssemblyWrapper> GetUserAssemblies()
{
return m_LoadedAssemblies;
}
protected static ITest BuildTests(TestPlatform testPlatform, IAssemblyWrapper[] assemblies)
{
var settings = UnityTestAssemblyBuilder.GetNUnitTestBuilderSettings(testPlatform);
var builder = new UnityTestAssemblyBuilder();
return builder.Build(assemblies.Select(a => a.Assembly).ToArray(), Enumerable.Repeat(testPlatform, assemblies.Length).ToArray(), settings);
}
private void LoadAssemblies()
{
if (m_LoadedAssemblies != null)
{
return;
}
m_LoadedAssemblies = new List<IAssemblyWrapper>();
foreach (var userAssembly in m_AssembliesToLoad)
{
IAssemblyWrapper a;
try
{
a = m_AssemblyLoadProxy.Load(userAssembly);
}
catch (FileNotFoundException)
{
continue;
}
if (a != null)
m_LoadedAssemblies.Add(a);
}
}
}
}

View File

@@ -0,0 +1,10 @@
namespace UnityEngine.TestTools.Utils
{
internal class ScriptingRuntimeProxy : IScriptingRuntimeProxy
{
public string[] GetAllUserAssemblies()
{
return ScriptingRuntime.GetAllUserAssemblies();
}
}
}