-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathIntegrationTestHelper.cs
83 lines (74 loc) · 2.65 KB
/
IntegrationTestHelper.cs
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
83
using System;
using System.IO;
using JetBrains.Annotations;
using Packages.Rider.Editor.Util;
using Unity.CodeEditor;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using Object = UnityEngine.Object;
namespace Editor
{
[UsedImplicitly]
[InitializeOnLoad]
public static class IntegrationTestHelper
{
static IntegrationTestHelper()
{
Console.WriteLine("IntegrationTestHelper.ctor");
}
private static bool myChanged;
private static object myLockObject = new Object();
public static void Start()
{
EditorPrefs.SetInt("Rider_SelectedLoggingLevel", 6); // trace
var commandlineParser = new CommandLineParser(Environment.GetCommandLineArgs());
if (commandlineParser.Options.ContainsKey("-riderPath"))
{
var originRiderPath = commandlineParser.Options["-riderPath"];
Console.WriteLine($"originRiderPath file exists {File.Exists(originRiderPath)}");
Console.WriteLine($"originRiderPath directory exists {Directory.Exists(originRiderPath)}");
Debug.Log($"CodeEditor.SetExternalScriptEditor({originRiderPath});");
CodeEditor.SetExternalScriptEditor(originRiderPath);
}
File.WriteAllText(".start", string.Empty);
EditorSceneManager.OpenScene("Assets/Scenes/SampleScene.unity", OpenSceneMode.Single);
EditorUtility.RequestScriptReload(); // EditorPlugin would get loaded // todo: it must be reloaded itself, but for some reason it doesn't make it during te test
}
public static void ResetAndStart()
{
EditorPrefs.DeleteAll();
Start();
}
private static bool isReported = false;
public static void WriteToLog()
{
EditorApplication.update += () =>
{
if (!isReported)
{
Debug.Log("#Test#");
isReported = true;
}
};
}
public static void DumpExternalEditor()
{
var path = Path.Combine(Application.dataPath, "ExternalEditor.txt");
File.WriteAllText(path, EditorPrefs.GetString("kScriptsDefaultApp", null) ?? "Unknown");
}
private static void Update()
{
var localChange = myChanged;
lock (myLockObject)
{
myChanged = false;
}
if (localChange)
{
Debug.Log("Recompile for plugin load");
AssetDatabase.Refresh();
}
}
}
}