update libs
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
using AssetStoreTools.Validator.Data;
|
||||
using AssetStoreTools.Validator.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AssetStoreTools.Validator.TestDefinitions
|
||||
@@ -9,39 +12,110 @@ namespace AssetStoreTools.Validator.TestDefinitions
|
||||
{
|
||||
public AutomatedTest(ValidationTestScriptableObject source) : base(source) { }
|
||||
|
||||
public override void Run(ValidationTestConfig config)
|
||||
public override void Run(ITestConfig config)
|
||||
{
|
||||
Type testClass;
|
||||
if (TestScript == null || (testClass = TestScript.GetClass()) == null)
|
||||
Type testClass = null;
|
||||
MethodInfo testMethod = null;
|
||||
|
||||
try
|
||||
{
|
||||
Debug.LogError($"Cannot run test {Title} - Test Script class was not found");
|
||||
ValidateTestMethod(ref testClass, ref testMethod);
|
||||
ValidateConfig(config);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!testClass.GetInterfaces().Contains(typeof(ITestScript)))
|
||||
object testClassInstance;
|
||||
try
|
||||
{
|
||||
Debug.LogError($"Cannot run test {Title} - Test Script class is not derived from {nameof(ITestScript)}");
|
||||
return;
|
||||
testClassInstance = CreateInstance(testClass, config);
|
||||
}
|
||||
|
||||
var testMethod = testClass.GetMethod("Run");
|
||||
if (testMethod == null)
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError($"Cannot run test {Title} - Run() method was not found");
|
||||
Debug.LogError($"Could not create an instance of class {testClass}:\n{e}");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Result = (TestResult)testMethod.Invoke(Activator.CreateInstance(testClass), new[] { config });
|
||||
Result = (TestResult)testMethod.Invoke(testClassInstance, new object[0]);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
var result = new TestResult() { Result = TestResult.ResultStatus.Undefined };
|
||||
var result = new TestResult() { Status = TestResultStatus.Undefined };
|
||||
result.AddMessage("An exception was caught when running this test case. See Console for more details");
|
||||
Debug.LogError($"An exception was caught when running validation for test case '{Title}'\n{e.InnerException}");
|
||||
Debug.LogError($"An exception was caught when running validation for test case '{Title}'\n{e}");
|
||||
Result = result;
|
||||
}
|
||||
}
|
||||
|
||||
private void ValidateTestMethod(ref Type testClass, ref MethodInfo testMethod)
|
||||
{
|
||||
if (TestScript == null || (testClass = TestScript.GetClass()) == null)
|
||||
throw new Exception($"Cannot run test {Title} - Test Script class was not found");
|
||||
|
||||
var interfaces = testClass.GetInterfaces();
|
||||
if (!interfaces.Contains(typeof(ITestScript)))
|
||||
throw new Exception($"Cannot run test {Title} - Test Script class is not derived from {nameof(ITestScript)}");
|
||||
|
||||
testMethod = testClass.GetMethod("Run");
|
||||
if (testMethod == null)
|
||||
throw new Exception($"Cannot run test {Title} - Run() method was not found");
|
||||
}
|
||||
|
||||
private void ValidateConfig(ITestConfig config)
|
||||
{
|
||||
switch (ValidationType)
|
||||
{
|
||||
case ValidationType.Generic:
|
||||
case ValidationType.UnityPackage:
|
||||
if (config is GenericTestConfig)
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException("Undefined validation type");
|
||||
}
|
||||
|
||||
throw new Exception("Config does not match the validation type");
|
||||
}
|
||||
|
||||
private object CreateInstance(Type testClass, ITestConfig testConfig)
|
||||
{
|
||||
var constructors = testClass.GetConstructors();
|
||||
if (constructors.Length != 1)
|
||||
throw new Exception($"Test class {testClass} should only contain a single constructor");
|
||||
|
||||
var constructor = constructors[0];
|
||||
var expectedParameters = constructor.GetParameters();
|
||||
var parametersToUse = new List<object>();
|
||||
foreach (var expectedParam in expectedParameters)
|
||||
{
|
||||
var paramType = expectedParam.ParameterType;
|
||||
|
||||
if (paramType == testConfig.GetType())
|
||||
{
|
||||
parametersToUse.Add(testConfig);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (typeof(IValidatorService).IsAssignableFrom(paramType))
|
||||
{
|
||||
var matchingService = ValidatorServiceProvider.Instance.GetService(paramType);
|
||||
if (matchingService == null)
|
||||
throw new Exception($"Service {paramType} is not registered and could not be retrieved");
|
||||
|
||||
parametersToUse.Add(matchingService);
|
||||
continue;
|
||||
}
|
||||
|
||||
throw new Exception($"Invalid parameter type: {paramType}");
|
||||
}
|
||||
|
||||
var instance = constructor.Invoke(parametersToUse.ToArray());
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,6 @@ AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 11.4.4
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Validator/Scripts/Test Definitions/AutomatedTest.cs
|
||||
uploadId: 712972
|
||||
uploadId: 724584
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace AssetStoreTools.Validator.TestDefinitions
|
||||
{
|
||||
internal class GenericTestConfig : ITestConfig
|
||||
{
|
||||
public string[] ValidationPaths { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 42aa5ee716f3fc340a5055b4c42a0b55
|
||||
guid: ba1ae4e7b45a6c84ca8ad0eb391bf95d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -13,6 +13,6 @@ AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 11.4.4
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Validator/Scripts/Test Definitions/ValidationTestConfig.cs
|
||||
uploadId: 712972
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Validator/Scripts/Test Definitions/GenericTestConfig.cs
|
||||
uploadId: 724584
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace AssetStoreTools.Validator.TestDefinitions
|
||||
{
|
||||
internal interface ITestConfig { }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c7e57766d04022c4dac58caf8ebe339a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Validator/Scripts/Test Definitions/ITestConfig.cs
|
||||
uploadId: 724584
|
||||
@@ -4,6 +4,6 @@ namespace AssetStoreTools.Validator.TestDefinitions
|
||||
{
|
||||
internal interface ITestScript
|
||||
{
|
||||
TestResult Run(ValidationTestConfig config);
|
||||
TestResult Run();
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,6 @@ AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 11.4.4
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Validator/Scripts/Test Definitions/ITestScript.cs
|
||||
uploadId: 712972
|
||||
uploadId: 724584
|
||||
|
||||
@@ -13,7 +13,7 @@ AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 11.4.4
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Validator/Scripts/Test Definitions/Scriptable
|
||||
Objects/AutomatedTestScriptableObject.cs
|
||||
uploadId: 712972
|
||||
uploadId: 724584
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
using AssetStoreTools.Validator.Data;
|
||||
using AssetStoreTools.Validator.Utility;
|
||||
using AssetStoreTools.Validator.Data;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AssetStoreTools.Validator.TestDefinitions
|
||||
{
|
||||
@@ -23,8 +23,9 @@ namespace AssetStoreTools.Validator.TestDefinitions
|
||||
|
||||
private ValidationTestScriptableObject _data;
|
||||
private ValidationTestScriptableObject[] _allObjects;
|
||||
|
||||
|
||||
private SerializedProperty _script;
|
||||
private SerializedProperty _validationType;
|
||||
|
||||
private SerializedProperty _testScript;
|
||||
private SerializedProperty _category;
|
||||
@@ -38,11 +39,13 @@ namespace AssetStoreTools.Validator.TestDefinitions
|
||||
private void OnEnable()
|
||||
{
|
||||
if (target == null) return;
|
||||
|
||||
|
||||
_data = target as ValidationTestScriptableObject;
|
||||
|
||||
_script = serializedObject.FindProperty("m_Script");
|
||||
|
||||
_validationType = serializedObject.FindProperty(nameof(ValidationTestScriptableObject.ValidationType));
|
||||
|
||||
_testScript = serializedObject.FindProperty(nameof(ValidationTestScriptableObject.TestScript));
|
||||
_category = serializedObject.FindProperty(nameof(ValidationTestScriptableObject.CategoryInfo));
|
||||
_failFilterProperty = _category.FindPropertyRelative(nameof(ValidationTestScriptableObject.CategoryInfo.IsFailFilter));
|
||||
@@ -58,7 +61,7 @@ namespace AssetStoreTools.Validator.TestDefinitions
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
EditorGUILayout.LabelField(GetInspectorTitle(), new GUIStyle(EditorStyles.centeredGreyMiniLabel) {fontSize = 24}, GUILayout.MinHeight(50));
|
||||
EditorGUILayout.LabelField(GetInspectorTitle(), new GUIStyle(EditorStyles.centeredGreyMiniLabel) { fontSize = 24 }, GUILayout.MinHeight(50));
|
||||
|
||||
EditorGUI.BeginDisabledGroup(true);
|
||||
EditorGUILayout.PropertyField(_script);
|
||||
@@ -70,15 +73,26 @@ namespace AssetStoreTools.Validator.TestDefinitions
|
||||
EditorGUILayout.HelpBox("ID is already in use", MessageType.Warning);
|
||||
EditorGUI.EndDisabledGroup();
|
||||
|
||||
EditorGUILayout.Space(8);
|
||||
EditorGUILayout.LabelField("Test Data", new GUIStyle(EditorStyles.centeredGreyMiniLabel) { alignment = TextAnchor.MiddleLeft, fontSize = 14, padding = new RectOffset(0, 0, 0, 0) });
|
||||
|
||||
// Validation Type
|
||||
var validationType = (ValidationType)EditorGUILayout.EnumPopup("Validation Type", (ValidationType)_validationType.enumValueIndex);
|
||||
_validationType.enumValueIndex = (int)validationType;
|
||||
|
||||
// Other fields
|
||||
_data.Title = EditorGUILayout.TextField("Title", _data.Title);
|
||||
if (string.IsNullOrEmpty(_data.Title))
|
||||
EditorGUILayout.HelpBox("Title cannot be empty", MessageType.Warning);
|
||||
|
||||
|
||||
EditorGUILayout.LabelField("Description");
|
||||
GUIStyle myTextAreaStyle = new GUIStyle(EditorStyles.textArea) { wordWrap = true };
|
||||
_data.Description = EditorGUILayout.TextArea(_data.Description, myTextAreaStyle);
|
||||
|
||||
// Test script
|
||||
EditorGUILayout.Space(8);
|
||||
EditorGUILayout.LabelField("Test Script", new GUIStyle(EditorStyles.centeredGreyMiniLabel) { alignment = TextAnchor.MiddleLeft, fontSize = 14, padding = new RectOffset(0, 0, 0, 0) });
|
||||
|
||||
EditorGUILayout.PropertyField(_testScript);
|
||||
if (_testScript.objectReferenceValue != null)
|
||||
{
|
||||
@@ -95,14 +109,15 @@ namespace AssetStoreTools.Validator.TestDefinitions
|
||||
GUILayout.FlexibleSpace();
|
||||
if (GUILayout.Button("Generate Test Method Script", GUILayout.MaxWidth(200f)))
|
||||
{
|
||||
var generatedScript = ValidatorUtility.GenerateTestScript(generatedScriptName);
|
||||
var generatedScript = ValidatorUtility.GenerateTestScript(generatedScriptName, (ValidationType)_validationType.enumValueIndex);
|
||||
_testScript.objectReferenceValue = generatedScript;
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
// Category Filter Options
|
||||
EditorGUILayout.Space(30);
|
||||
// Variable Sevetity Options
|
||||
EditorGUILayout.Space(8);
|
||||
EditorGUILayout.LabelField("Variable Severity Status Filtering", new GUIStyle(EditorStyles.centeredGreyMiniLabel) { alignment = TextAnchor.MiddleLeft, fontSize = 14, padding = new RectOffset(0, 0, 0, 0) });
|
||||
|
||||
var filterSeverity = (FilterSeverity)EditorGUILayout.EnumPopup("Fail Type", _failFilterProperty.boolValue ? FilterSeverity.Fail : FilterSeverity.Warning);
|
||||
_failFilterProperty.boolValue = filterSeverity == FilterSeverity.Fail ? true : false;
|
||||
@@ -129,7 +144,7 @@ namespace AssetStoreTools.Validator.TestDefinitions
|
||||
|
||||
_hadChanges = serializedObject.ApplyModifiedProperties() || _hadChanges;
|
||||
}
|
||||
|
||||
|
||||
private string GetInspectorTitle()
|
||||
{
|
||||
switch (_data)
|
||||
@@ -149,10 +164,10 @@ namespace AssetStoreTools.Validator.TestDefinitions
|
||||
|
||||
private string GetFilterDescription(bool isFailFilter, bool isInclusive)
|
||||
{
|
||||
string text = $"When a <i>{TestResult.ResultStatus.VariableSeverityIssue}</i> result type is returned from the test method:\n\n";
|
||||
if(isFailFilter)
|
||||
string text = $"When a <i>{TestResultStatus.VariableSeverityIssue}</i> result type is returned from the test method:\n\n";
|
||||
if (isFailFilter)
|
||||
{
|
||||
if(isInclusive)
|
||||
if (isInclusive)
|
||||
return text + "• <b>Categories IN the filter</b> will result in a <color=red>FAIL</color>.\n• <b>Categories NOT in the filter</b> will result in a <color=yellow>WARNING</color>";
|
||||
else
|
||||
return text + "• <b>Categories NOT in the filter</b> will result in a <color=red>FAIL</color>.\n• <b>Categories IN the filter</b> will result in a <color=yellow>WARNING</color>";
|
||||
|
||||
@@ -13,7 +13,7 @@ AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 11.4.4
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Validator/Scripts/Test Definitions/Scriptable
|
||||
Objects/Editor/ValidationTestScriptableObjectInspector.cs
|
||||
uploadId: 712972
|
||||
uploadId: 724584
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using AssetStoreTools.Validator.Categories;
|
||||
using AssetStoreTools.Validator.Data;
|
||||
using AssetStoreTools.Validator.Utility;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
@@ -14,6 +15,7 @@ namespace AssetStoreTools.Validator.TestDefinitions
|
||||
public string Title;
|
||||
public string Description;
|
||||
public ValidatorCategory CategoryInfo;
|
||||
public ValidationType ValidationType;
|
||||
public MonoScript TestScript;
|
||||
|
||||
private void OnEnable()
|
||||
|
||||
@@ -13,7 +13,7 @@ AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 11.4.4
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Validator/Scripts/Test Definitions/Scriptable
|
||||
Objects/ValidationTestScriptableObject.cs
|
||||
uploadId: 712972
|
||||
uploadId: 724584
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace AssetStoreTools.Validator.TestDefinitions
|
||||
public string Description;
|
||||
public MonoScript TestScript;
|
||||
|
||||
public ValidationType ValidationType;
|
||||
public ValidatorCategory CategoryInfo;
|
||||
|
||||
public TestResult Result;
|
||||
@@ -22,11 +23,12 @@ namespace AssetStoreTools.Validator.TestDefinitions
|
||||
Description = source.Description;
|
||||
TestScript = source.TestScript;
|
||||
CategoryInfo = source.CategoryInfo;
|
||||
ValidationType = source.ValidationType;
|
||||
Result = new TestResult();
|
||||
}
|
||||
|
||||
public abstract void Run(ValidationTestConfig config);
|
||||
|
||||
public abstract void Run(ITestConfig config);
|
||||
|
||||
public string Slugify(string value)
|
||||
{
|
||||
string newValue = value.Replace(' ', '-').ToLower();
|
||||
|
||||
@@ -13,6 +13,6 @@ AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 115
|
||||
packageName: Asset Store Publishing Tools
|
||||
packageVersion: 11.4.4
|
||||
packageVersion: 12.0.1
|
||||
assetPath: Packages/com.unity.asset-store-tools/Editor/Validator/Scripts/Test Definitions/ValidationTest.cs
|
||||
uploadId: 712972
|
||||
uploadId: 724584
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace AssetStoreTools.Validator.TestDefinitions
|
||||
{
|
||||
public class ValidationTestConfig
|
||||
{
|
||||
public string[] ValidationPaths;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user