update libs
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
using AssetStoreTools.Validator.TestDefinitions;
|
||||
using AssetStoreTools.Validator.Data;
|
||||
using AssetStoreTools.Validator.Services;
|
||||
using AssetStoreTools.Validator.TestDefinitions;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using static AssetStoreTools.Constants;
|
||||
using ValidatorConstants = AssetStoreTools.Constants.Validator;
|
||||
|
||||
namespace AssetStoreTools.Validator.Utility
|
||||
{
|
||||
internal static class ValidatorUtility
|
||||
{
|
||||
private const string TestsPath = "Packages/com.unity.asset-store-tools/Editor/Validator/Scripts/Tests";
|
||||
private const string TestMethodsPath = "Packages/com.unity.asset-store-tools/Editor/Validator/Scripts/Tests/Test Methods";
|
||||
|
||||
public enum SortType
|
||||
{
|
||||
Id,
|
||||
@@ -21,7 +23,7 @@ namespace AssetStoreTools.Validator.Utility
|
||||
|
||||
public static ValidationTestScriptableObject[] GetAutomatedTestCases(SortType sortType)
|
||||
{
|
||||
string[] guids = AssetDatabase.FindAssets("t:AutomatedTestScriptableObject", new[] { TestsPath });
|
||||
string[] guids = AssetDatabase.FindAssets("t:AutomatedTestScriptableObject", new[] { ValidatorConstants.Tests.TestDefinitionsPath });
|
||||
ValidationTestScriptableObject[] tests = new ValidationTestScriptableObject[guids.Length];
|
||||
for (int i = 0; i < tests.Length; i++)
|
||||
{
|
||||
@@ -35,19 +37,36 @@ namespace AssetStoreTools.Validator.Utility
|
||||
{
|
||||
default:
|
||||
case SortType.Id:
|
||||
tests = tests.OrderBy(x => x.Id).ToArray();
|
||||
tests = tests.Where(x => x != null).OrderBy(x => x.Id).ToArray();
|
||||
break;
|
||||
case SortType.Alphabetical:
|
||||
tests = tests.OrderBy(x => x.Title).ToArray();
|
||||
tests = tests.Where(x => x != null).OrderBy(x => x.Title).ToArray();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return tests;
|
||||
}
|
||||
|
||||
public static MonoScript GenerateTestScript(string testName)
|
||||
public static MonoScript GenerateTestScript(string testName, ValidationType validationType)
|
||||
{
|
||||
var newScriptPath = $"{TestMethodsPath}/{testName}";
|
||||
var derivedType = nameof(ITestScript);
|
||||
var configType = string.Empty;
|
||||
var scriptPath = string.Empty;
|
||||
switch (validationType)
|
||||
{
|
||||
case ValidationType.Generic:
|
||||
configType = nameof(GenericTestConfig);
|
||||
scriptPath = ValidatorConstants.Tests.GenericTestMethodsPath;
|
||||
break;
|
||||
case ValidationType.UnityPackage:
|
||||
configType = nameof(GenericTestConfig);
|
||||
scriptPath = ValidatorConstants.Tests.UnityPackageTestMethodsPath;
|
||||
break;
|
||||
default:
|
||||
throw new System.Exception("Undefined validation type");
|
||||
}
|
||||
|
||||
var newScriptPath = $"{scriptPath}/{testName}";
|
||||
if (!newScriptPath.EndsWith(".cs"))
|
||||
newScriptPath += ".cs";
|
||||
|
||||
@@ -57,19 +76,24 @@ namespace AssetStoreTools.Validator.Utility
|
||||
|
||||
var scriptContent =
|
||||
$"using AssetStoreTools.Validator.Data;\n" +
|
||||
$"using AssetStoreTools.Validator.TestDefinitions;\n" +
|
||||
$"using AssetStoreTools.Validator.TestMethods.Utility;\n\n" +
|
||||
$"using AssetStoreTools.Validator.TestDefinitions;\n\n" +
|
||||
$"namespace AssetStoreTools.Validator.TestMethods\n" +
|
||||
"{\n" +
|
||||
$" internal class {testName} : {nameof(ITestScript)}\n" +
|
||||
" {\n" +
|
||||
$" public TestResult Run({nameof(ValidationTestConfig)} config)\n" +
|
||||
" {\n" +
|
||||
" var result = new TestResult() { Result = TestResult.ResultStatus.Undefined };\n" +
|
||||
" return result;\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}\n";
|
||||
$"{{\n" +
|
||||
$" internal class {testName} : {derivedType}\n" +
|
||||
$" {{\n" +
|
||||
$" private {configType} _config;\n\n" +
|
||||
$" // Constructor also accepts dependency injection of registered {nameof(IValidatorService)} types\n" +
|
||||
$" public {testName}({configType} config)\n" +
|
||||
$" {{\n" +
|
||||
$" _config = config;\n" +
|
||||
$" }}\n\n" +
|
||||
$" public {nameof(TestResult)} {nameof(ITestScript.Run)}()\n" +
|
||||
$" {{\n" +
|
||||
$" var result = new {nameof(TestResult)}() {{ {nameof(TestResult.Status)} = {nameof(TestResultStatus)}.{nameof(TestResultStatus.Undefined)} }};\n" +
|
||||
$" return result;\n" +
|
||||
$" }}\n" +
|
||||
$" }}\n" +
|
||||
$"}}\n";
|
||||
|
||||
File.WriteAllText(newScriptPath, scriptContent);
|
||||
AssetDatabase.Refresh();
|
||||
@@ -87,7 +111,7 @@ namespace AssetStoreTools.Validator.Utility
|
||||
var longPaths = new List<string>();
|
||||
var guids = AssetDatabase.FindAssets("*", rootPaths);
|
||||
|
||||
foreach(var guid in guids)
|
||||
foreach (var guid in guids)
|
||||
{
|
||||
var path = AssetDatabase.GUIDToAssetPath(guid);
|
||||
longPaths.Add(path);
|
||||
@@ -95,5 +119,24 @@ namespace AssetStoreTools.Validator.Utility
|
||||
|
||||
return longPaths;
|
||||
}
|
||||
|
||||
public static Texture GetStatusTexture(TestResultStatus status)
|
||||
{
|
||||
var iconTheme = "";
|
||||
if (!EditorGUIUtility.isProSkin)
|
||||
iconTheme = "_d";
|
||||
|
||||
switch (status)
|
||||
{
|
||||
case TestResultStatus.Pass:
|
||||
return (Texture)EditorGUIUtility.Load($"{WindowStyles.ValidatorIconsPath}/success{iconTheme}.png");
|
||||
case TestResultStatus.Warning:
|
||||
return (Texture)EditorGUIUtility.Load($"{WindowStyles.ValidatorIconsPath}/warning{iconTheme}.png");
|
||||
case TestResultStatus.Fail:
|
||||
return (Texture)EditorGUIUtility.Load($"{WindowStyles.ValidatorIconsPath}/error{iconTheme}.png");
|
||||
default:
|
||||
return (Texture)EditorGUIUtility.Load($"{WindowStyles.ValidatorIconsPath}/undefined{iconTheme}.png");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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/Utility/ValidatorUtility.cs
|
||||
uploadId: 712972
|
||||
uploadId: 724584
|
||||
|
||||
Reference in New Issue
Block a user