TestStarter.cs
2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.IO;
using UnityEditor.TestRunner.CommandLineParser;
using UnityEditor.TestTools.TestRunner.Api;
using UnityEngine;
using UnityEditor.Compilation;
using System.Linq;
using UnityEngine.TestTools;
namespace UnityEditor.TestTools.TestRunner.CommandLineTest
{
[InitializeOnLoad]
static class TestStarter
{
static TestStarter()
{
if (!ShouldRunTests())
{
return;
}
if (EditorApplication.isCompiling)
{
return;
}
if (RunData.instance.isRunning)
{
executer.ExitOnCompileErrors();
executer.SetUpCallbacks(RunData.instance.executionSettings);
return;
}
EditorApplication.update += UpdateWatch;
}
static void UpdateWatch()
{
EditorApplication.update -= UpdateWatch;
if (RunData.instance.isRunning)
{
return;
}
RunData.instance.isRunning = true;
var commandLineArgs = Environment.GetCommandLineArgs();
RunData.instance.executionSettings = executer.BuildExecutionSettings(commandLineArgs);
executer.SetUpCallbacks(RunData.instance.executionSettings);
executer.InitializeAndExecuteRun(commandLineArgs);
}
static bool ShouldRunTests()
{
var shouldRunTests = false;
var optionSet = new CommandLineOptionSet(
new CommandLineOption("runTests", () => { shouldRunTests = true; }),
new CommandLineOption("runEditorTests", () => { shouldRunTests = true; })
);
optionSet.Parse(Environment.GetCommandLineArgs());
return shouldRunTests;
}
static Executer s_Executer;
static Executer executer
{
get
{
if (s_Executer == null)
{
Func<bool> compilationCheck = () => EditorUtility.scriptCompilationFailed;
Action<string> actionLogger = (string msg) => { Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, msg); };
var apiSettingsBuilder = new SettingsBuilder(new TestSettingsDeserializer(() => new TestSettings()), actionLogger, Debug.LogWarning, File.Exists, compilationCheck);
s_Executer = new Executer(ScriptableObject.CreateInstance<TestRunnerApi>(), apiSettingsBuilder, Debug.LogErrorFormat, Debug.LogException, EditorApplication.Exit, compilationCheck);
}
return s_Executer;
}
}
}
}