Skip to content

Commit

Permalink
Add compile check test utility
Browse files Browse the repository at this point in the history
  • Loading branch information
kochounoyume committed Nov 24, 2024
1 parent 66ccf0d commit 0ea5430
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Packages/MinimalUtility/Editor/Test.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions Packages/MinimalUtility/Editor/TestUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.IO;
using System.Runtime.CompilerServices;
using UnityEditor;
using UnityEditor.Build.Player;

namespace MinimalUtility.Editor
{
/// <summary>
/// テスト関連のユーティリティ.
/// </summary>
public static class TestUtils
{
/// <summary>
/// 指定したビルドターゲットでスクリプトをコンパイルし、成功したかどうかを返す.
/// </summary>
/// <param name="buildTarget">テスト対象環境.</param>
/// <param name="outputPath">出力先パス.</param>
/// <param name="scriptingDefines">スクリプト条件コンパイル定義があれば登録.</param>
/// <returns>成功したかどうか.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool SuccessCompile(BuildTarget buildTarget, string outputPath = "Temp/TestOutput", params string[] scriptingDefines)
{
ScriptCompilationSettings settings = new ()
{
extraScriptingDefines = scriptingDefines,
group = BuildPipeline.GetBuildTargetGroup(buildTarget),
target = buildTarget,
};
try
{
ScriptCompilationResult result = PlayerBuildInterface.CompilePlayerScripts(settings, outputPath);
return result is { assemblies: { Count: > 0 }, typeDB: not null };
}
catch
{
throw;
}
finally
{
if (Directory.Exists(outputPath))
{
Directory.Delete(outputPath, true);
}
}
}
}
}
3 changes: 3 additions & 0 deletions Packages/MinimalUtility/Editor/TestUtils.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0ea5430

Please sign in to comment.