Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ jobs:
- 6000.0.43f1 # Latest version that does not pin the test framework package.
- 6000.0.44f1 # pin test-framework v1.5.1
- 6000.0.59f2 # pin test-framework v1.6.0
- 6000.0.78f1
- 6000.3.18f1
- 6000.0.85f1
- 6000.3.28f1
- &latest_unity_version 6000.5.1f1 # pin test-framework v1.7.0
testMode:
- All # run tests in editor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ public class EditModeTestYieldInstructionExample
private static bool s_wasUnitySetUpCalled;
private static bool s_wasSetUpCalled;
private static bool s_wasSetUpAsyncCalled;
private static bool s_isDomainReloadPending;

private const string CsPath = "Assets/CreateFileExample.cs";
private const string RspPath = "Assets/csc.rsp";
private const string CsPath = "Assets/APIExamples/Scripts/Runtime/CreateFileExample.cs";
private const string RspPath = "Assets/APIExamples/Scripts/Runtime/csc.rsp";
private const string DLLSrcPath = "TestData/NativePluginExample.dll";
private const string DLLDstPath = "Assets/NativePluginExample.dll";

Expand Down Expand Up @@ -119,7 +120,18 @@ public IEnumerator ExitPlayModeで編集モードに切り替える例()
Assert.That(EditorApplication.isPlaying, Is.False);
}

private static IEnumerator WaitForPendingDomainReload()
{
// Note: RecompileScriptsはコンパイル完了までしか待たず、ドメインリロードが遅れて実行されることがあるため待機する。
// WaitForDomainReloadを使わないのは、ドメインリロードがRecompileScripts中に完了していると例外をスローするため
while (s_isDomainReloadPending)
{
yield return null;
}
}

[UnityTest]
[Timeout(60000)]
public IEnumerator RecompileScriptsでリコンパイルを実行する例_リコンパイルされたクラスのメソッドを呼び出せる()
{
Assume.That(Path.GetFullPath(CsPath), Does.Not.Exist,
Expand All @@ -130,11 +142,14 @@ public IEnumerator RecompileScriptsでリコンパイルを実行する例_リ
file.Write("public class Foo { public bool Bar(string msg) { return true; } }");
}

s_isDomainReloadPending = true;

// ここでAssetDatabase.Refresh()は不要
yield return new RecompileScripts();
yield return WaitForPendingDomainReload();

// リフレクションでメソッド呼び出し
var assemblyName = new AssemblyName("Assembly-CSharp");
var assemblyName = new AssemblyName("APIExamples");
var assembly = Assembly.Load(assemblyName);
var fooType = assembly.GetType("Foo");
dynamic foo = Activator.CreateInstance(fooType);
Expand All @@ -144,6 +159,7 @@ public IEnumerator RecompileScriptsでリコンパイルを実行する例_リ
}

[UnityTest]
[Timeout(60000)]
public IEnumerator RecompileScriptsでリコンパイルを実行する例_csc_rspで追加したスクリプティングシンボルが有効になる()
{
Assume.That(Path.GetFullPath(RspPath), Does.Not.Exist,
Expand All @@ -161,9 +177,14 @@ public IEnumerator RecompileScriptsでリコンパイルを実行する例_csc_r
"#endif\n" +
"} }");

s_isDomainReloadPending = true;

// ここでAssetDatabase.Refresh()は不要
yield return new RecompileScripts();
yield return WaitForPendingDomainReload();

var assembly = Assembly.Load(new AssemblyName("Assembly-CSharp"));
// リフレクションでメソッド呼び出し
var assembly = Assembly.Load(new AssemblyName("APIExamples"));
var fooType = assembly.GetType("Foo");
var actual = (bool)fooType.GetMethod("IsDefined")!.Invoke(null, null);

Expand Down
Loading