Skip to content

Commit de35169

Browse files
authored
test: show ShaderCompileTest in TestRunner (#589)
* give error message when a shader fails to compile * change indent * declare variable internally * delete duplicate CompileTests * add ToonConstants * add shaders path constant * open runtime assembly to tests * add references to the runtime inside the EditorTests assembly
1 parent dacbf58 commit de35169

File tree

6 files changed

+33
-72
lines changed

6 files changed

+33
-72
lines changed

com.unity.toonshader/Editor/CompileTest.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

com.unity.toonshader/Editor/CompileTest.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

com.unity.toonshader/Runtime/AssemblyInfo.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System.Runtime.CompilerServices;
22
[assembly: InternalsVisibleTo("Unity.ToonShader.Editor")]
3+
[assembly: InternalsVisibleTo("Unity.ToonShader.EditorTests")]
4+
5+
36
[assembly: InternalsVisibleTo("Unity.VisualCompositor")]
47
[assembly: InternalsVisibleTo("Unity.VisualCompositor.Tests")]
58
[assembly: InternalsVisibleTo("Unity.VisualCompositor.Editor")]

com.unity.toonshader/Runtime/ToonConstants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ namespace Unity.Rendering.Toon {
55

66
internal static class ToonConstants {
77

8+
internal const string PACKAGE_NAME = "com.unity.toonshader";
9+
810
internal const string SHADER_KEYWORD_IS_CLIPPING_MATTE = "_IS_CLIPPING_MATTE";
911

1012
internal static readonly int SHADER_PROPERTY_CLIPPING_MATTE_MODE = Shader.PropertyToID("_ClippingMatteMode");
Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
1+
using System.IO;
12
using NUnit.Framework;
23
using UnityEditor;
34
using UnityEngine;
4-
using System.Collections.Generic;
5-
using System.Reflection;
6-
using UnityEngine.TestTools;
5+
using Unity.Rendering.Toon;
6+
7+
namespace Unity.ToonShader.EditorTests {
8+
internal class ShaderCompileTest
9+
{
10+
[Test]
11+
public void CompileToonShaders() {
12+
string[] guids = AssetDatabase.FindAssets("t:Shader", new[] { SHADERS_PATH});
13+
int numShaders = guids.Length;
14+
Assert.Greater(numShaders,0);
15+
for (int i=0;i<numShaders;++i) {
16+
string curAssetPath = AssetDatabase.GUIDToAssetPath(guids[i]);
17+
Shader shader = AssetDatabase.LoadAssetAtPath<Shader>(curAssetPath);
18+
AssetDatabase.ImportAsset(curAssetPath); //Recompile the shader to make sure there are no compile errors
19+
20+
Assert.True(shader.isSupported);
21+
bool shaderHasError = ShaderUtil.ShaderHasError(shader);
22+
Assert.False(shaderHasError, "[UTS] Shader Compile Error: " + shader.name);
723

8-
namespace Unity.Rendering.ToonShader.Tests {
9-
internal class ShaderCompileTest
10-
{
11-
12-
[Test]
13-
public void CompileLegacyToonShadersDefault() {
14-
string[] guids = AssetDatabase.FindAssets("t:Shader", new[] { LEGACY_SHADERS_PATH});
15-
int numShaders = guids.Length;
16-
Assert.Greater(numShaders,0);
17-
bool shaderHasError = false;
18-
for (int i=0;i<numShaders && !shaderHasError;++i) {
19-
string curAssetPath = AssetDatabase.GUIDToAssetPath(guids[i]);
20-
Shader shader = AssetDatabase.LoadAssetAtPath<Shader>(curAssetPath);
21-
AssetDatabase.ImportAsset(curAssetPath); //Recompile the shader to make sure there are no compile errors
22-
23-
// Assert.True(shader.isSupported);
24-
shaderHasError = ShaderUtil.ShaderHasError(shader);
25-
Assert.False(shaderHasError);
26-
27-
}
2824
}
25+
}
2926

27+
//----------------------------------------------------------------------------------------------------------------------
3028

29+
private static readonly string SHADERS_PATH = Path.Combine("Packages", ToonConstants.PACKAGE_NAME,"Runtime/Integrated/Shaders");
3130

32-
private const string LEGACY_SHADERS_PATH = "Packages/com.unity.toonshader/Runtime/Integrated/Shaders";
31+
}
3332

34-
}
3533
} //end namespace

com.unity.toonshader/Tests/Editor/Unity.ToonShader.EditorTests.asmdef

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"name": "Unity.Toonshader.EditorTests",
3+
"rootNamespace": "",
34
"references": [
45
"UnityEngine.TestRunner",
5-
"UnityEditor.TestRunner"
6+
"UnityEditor.TestRunner",
7+
"Unity.Toonshader"
68
],
79
"includePlatforms": [
810
"Editor"
@@ -17,5 +19,6 @@
1719
"defineConstraints": [
1820
"UNITY_INCLUDE_TESTS"
1921
],
20-
"versionDefines": []
22+
"versionDefines": [],
23+
"noEngineReferences": false
2124
}

0 commit comments

Comments
 (0)