A game about forced loneliness, made by TACStudios
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using UnityEditor.TestTools.TestRunner.Api;
5using UnityEngine;
6
7namespace UnityEditor.TestTools.TestRunner.UnityTestProtocol
8{
9 [InitializeOnLoad]
10 internal static class UnityTestProtocolStarter
11 {
12 static UnityTestProtocolStarter()
13 {
14 var commandLineArgs = Environment.GetCommandLineArgs();
15 //Ensuring that it is used only when tests are run using UTR.
16 if (IsEnabled())
17 {
18 var api = ScriptableObject.CreateInstance<TestRunnerApi>();
19 var listener = new UnityTestProtocolListener(GetRepositoryPath(commandLineArgs));
20 api.RegisterCallbacks(listener);
21 }
22 }
23
24 internal static bool IsEnabled()
25 {
26 var commandLineArgs = Environment.GetCommandLineArgs();
27 return commandLineArgs.Contains("-automated") && commandLineArgs.Contains("-runTests");
28 }
29
30 private static string GetRepositoryPath(IReadOnlyList<string> commandLineArgs)
31 {
32 for (var i = 0; i < commandLineArgs.Count; i++)
33 {
34 if (commandLineArgs[i].Equals("-projectRepositoryPath"))
35 {
36 return commandLineArgs[i + 1];
37 }
38 }
39 return string.Empty;
40 }
41 }
42}