Increase unit test coverage for easier refactoring (#33)

Add unit tests, using MOQ when needed, to ensure we have unit tests around all the important areas of the package include CLI option mapping, decision statements, etc.
This commit is contained in:
Sean Stolberg 2023-05-19 17:52:32 -07:00 коммит произвёл GitHub Enterprise
Родитель f5857cf611
Коммит fb0d89a887
24 изменённых файлов: 1493 добавлений и 187 удалений

15
.github/pr-commenter.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,15 @@
comment:
on-update: edit
snippets:
- id: URP
files:
- **/*
body: |
### **Regression Tests to Run for CLI Project Setup**
You should always run the following job when you change code in this package. When you create a new run, use the CLI_PROJECT_SETUP_VERSION variable input field to enter a github url path to your dev branch changeset like this: `com.unity.cli-project-setup@"ssh://git@github.cds.internal.unity3d.com/unity/com.unity.cli-project-setup.git#e04468fd4be965e4da3635d4ce0cf90e866bd326"`
This will enable you to run the tests with your dev branch to gain more confidence that a regression hasn't been introduced.
- [URP PR](https://unity-ci.cds.internal.unity3d.com/project/3/branch/{{branchName}}/jobDefinition/.yamato%2Fsrp%2Furp.yml%23urp_pr) from the unity/unity repository
- [Pack and test all packages](https://unity-ci.cds.internal.unity3d.com/project/1166/branch/{{branchName}}/jobDefinition/.yamato%2Fupm-ci.yml%23all_package_ci) for this repository

28
.github/pull_request_template.md поставляемый Normal file
Просмотреть файл

@ -0,0 +1,28 @@
## Purpose of this PR
*[Description of feature/change. Links to screenshots, design docs, user docs, etc. Link to Jira if applicable. Remember reviewers may be outside your team, and not know your feature/area that should be explained more.]*
## Release Notes
*[Any release notes for the user including jira case IDs. Non-user facing changes or package updates should be marked internal. Use "None" if there are no release notes.]*
## Functional Testing status
*[Explanation of what's tested, how tested and existing or new automation tests. Can include manual testing by self and/or QA. Specify test plans. Rarely acceptable to have no testing.]*
## Performance Testing Status
*[Could this PR affect performance? If so, what has been done to measure time taken / memory used etc? Can include new or existing performance tests. Docs [here](https://confluence.hq.unity3d.com/display/DEV/Ensuring+Performance+by+Default)*
## Overall Product Risks
*What risks to the product do these changes pose? Docs [here](https://confluence.unity3d.com/display/RM/Testing+Status%2C+Complexity+and+Halo+Effect+for+your+PR) for more info*
Technical Risk: ?
*[ Score: 0 - 3, 0 is a simple one liner -> 3 is extreme impact to product ]*
Halo Effect: ?
*[ Score: 0 - 3, 0 isolated to a specific area/platform -> 3 ripples out to everything ]*
## Comments to reviewers
*[Info per person for what to focus on, or historical info to understand who have previously reviewed and coverage. Help them get context.]*

31
.github/workflows/pr-commenter.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,31 @@
# When a graphics (SRP packages) PR is opened, this workflow lists the recommeded builders
# to run on Yamato. It provides a link to the corresponding ant-graphics-ci branch.
name: "Graphics PR Commenter"
on:
pull_request:
paths:
- "*/**"
jobs:
pr-comment:
runs-on: self-hosted
steps:
- run: echo ${{ github.head_ref }}
- name: URLify Branch Name
id: urlifiedBranchName
run: |
BRANCH_URL=$(echo ${{ github.head_ref }} | sed 's:\/:%2F:g')
echo ::set-output name=short_ref::$BRANCH_URL
- run: echo ${{ steps.urlifiedBranchName.outputs.short_ref }}
- uses: actions/pr-commenter-action@v1.3.0
with:
github-token: "${{ github.token }}"
config-file: ".github/graphics-pr-commenter.yml"
template-variables: |
{
"branchName": "${{ steps.urlifiedBranchName.outputs.short_ref }}"
}

Просмотреть файл

@ -1,9 +1,8 @@
editors:
- version: trunk
- version: 2023.1
- version: 2022.2
- version: 2022.1
- version: 2021.3
- version: 2020.3
platforms:
- name: Windows64
os: windows

Просмотреть файл

@ -1,14 +1,12 @@
editors:
- version: trunk
cmd: -u trunk
- version: 2023.1
cmd: -u 2023.1/staging
- version: 2022.2
cmd: -u 2022.2/staging
- version: 2022.1
cmd: -u 2022.1/staging
- version: 2021.3
cmd: -u 2021.3/staging
- version: 2020.3
cmd: -u 2020.3/staging
platforms:
# Exhaustive list of operating systems and editor components used by all jobs so the preparation jobs
# can make sure all editors are cached on cheap vms before starting the heavy duty machines for running tests

Просмотреть файл

@ -4,6 +4,9 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [1.2.0-preview] - 2023-05-19
Adding unit test coverage and updated developer documentation
## [1.1.0-preview] - 2023-05-08
Revert breaking removal of XR setups; URP relies on these.

7
CODEOWNERS.meta Normal file
Просмотреть файл

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 61eb3413343f74e45984a70e80f7dee2
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -3,11 +3,6 @@ using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using NDesk.Options;
/* TODO: Revisit burst logic when we're using it
#if ENABLE_BURST_AOT
using Unity.Burst;
#endif
*/
using UnityEngine;
using UnityEngine.Rendering;
using UnityEditor;
@ -18,111 +13,167 @@ namespace com.unity.cliprojectsetup
{
public class CliProjectSetup
{
public List<string> ScenesToAddToBuild = new List<string>();
public readonly List<string> ScriptDefines = new List<string>();
private readonly string[] commandLineArgs;
public readonly List<string> ScenesToAddToBuild = new List<string>();
private readonly Regex customArgRegex = new Regex("-([^=]*)=", RegexOptions.Compiled);
private readonly PlatformSettings platformSettings = new PlatformSettings();
public PlatformSettings PlatformSettings = new PlatformSettings();
private List<EditorBuildSettingsScene> editorBuildSettingsScenes = new List<EditorBuildSettingsScene>();
public string[] CliArgs;
public CliProjectSetup(string[] args = null, PlatformSettings platformSettings = null)
{
if (args != null)
{
commandLineArgs = args;
}
if (platformSettings != null)
{
PlatformSettings = platformSettings;
}
}
public void ConfigureFromCmdlineArgs()
{
ParseCommandLineArgs();
ConfigureSettings();
AddTestScenesToBuild(ScenesToAddToBuild);
platformSettings.SerializeToAsset();
AddTestScenesToBuild();
PlatformSettings.SerializeToAsset();
}
public static void AddTestScenesToBuild(List<string> scenesToAddToBuild)
public virtual void AddTestScenesToBuild()
{
List<EditorBuildSettingsScene> editorBuildSettingsScenes = new List<EditorBuildSettingsScene>();
foreach (var sceneToAddToBuild in scenesToAddToBuild)
foreach (var sceneToAddToBuild in ScenesToAddToBuild)
{
editorBuildSettingsScenes.Add(new EditorBuildSettingsScene(sceneToAddToBuild, true));
}
// Note, this completely replaces the list of scenes currently in the project with only our tests scenes.
// Note, this completely replaces the list of buildSettingScenes currently in the project with only our tests buildSettingScenes.
if (editorBuildSettingsScenes.Count != 0)
{
EditorBuildSettings.scenes = editorBuildSettingsScenes.ToArray();
SetEditorBuildSettingsScenes(editorBuildSettingsScenes.ToArray());
}
}
public void ParseCommandLineArgs()
protected virtual void SetEditorBuildSettingsScenes(EditorBuildSettingsScene[] buildSettingScenes)
{
var args = Environment.GetCommandLineArgs();
EnsureOptionsLowerCased(args);
var optionSet = DefineOptionSet();
var unParsedArgs = optionSet.Parse(args);
EditorBuildSettings.scenes = buildSettingScenes;
}
private void EnsureOptionsLowerCased(string[] args)
public virtual void ParseCommandLineArgs()
{
for (var i = 0; i < args.Length; i++)
CliArgs = commandLineArgs ?? Environment.GetCommandLineArgs();
EnsureOptionsLowerCased();
var optionSet = DefineOptionSet();
var unParsedArgs = optionSet.Parse(CliArgs);
}
public void EnsureOptionsLowerCased()
{
for (var i = 0; i < CliArgs.Length; i++)
{
if (customArgRegex.IsMatch(args[i]))
if (customArgRegex.IsMatch(CliArgs[i]))
{
args[i] = customArgRegex.Replace(args[i], customArgRegex.Matches(args[i])[0].ToString().ToLower());
CliArgs[i] = customArgRegex.Replace(CliArgs[i], customArgRegex.Matches(CliArgs[i])[0].ToString().ToLower());
}
}
}
private void ConfigureSettings()
public virtual void ConfigureSettings()
{
ConfigureCrossplatformSettings();
// If Android, setup Android player settings
if (platformSettings.BuildTarget == BuildTarget.Android)
if (PlatformSettings.BuildTarget == BuildTarget.Android)
{
ConfigureAndroidSettings();
}
// If iOS, setup iOS player settings
if (platformSettings.BuildTarget == BuildTarget.iOS)
if (PlatformSettings.BuildTarget == BuildTarget.iOS)
{
ConfigureIosSettings();
}
if (!string.IsNullOrEmpty(platformSettings.XrTarget))
if (!string.IsNullOrEmpty(PlatformSettings.XrTarget))
{
XRPlatformSettings<PlatformSettings>.Configure(platformSettings);
ConfigureXrSettings();
}
}
private void ConfigureIosSettings()
public virtual void ConfigureXrSettings()
{
#if XR_SDK
XRPlatformSettings<PlatformSettings>.Configure(PlatformSettings);
#endif
}
public virtual void ConfigureIosSettings()
{
PlayerSettings.SetApplicationIdentifier(NamedBuildTarget.iOS, string.Format("com.unity3d.{0}", PlayerSettings.productName));
PlayerSettings.iOS.appleEnableAutomaticSigning = false;
PlayerSettings.iOS.iOSManualProvisioningProfileType = ProvisioningProfileType.Development;
}
private void ConfigureAndroidSettings()
public virtual void ConfigureAndroidSettings()
{
// If the user has specified AndroidArchitecture.ARMv7, but not specified ScriptingImplementation.Mono2x, or has incorrectly specified ScriptingImplementation.IL2CPP (not supported
// with mono), then set to AndroidArchitecture.ARMv7 so we're in a compatible configuration state.
if (platformSettings.AndroidTargetArchitecture == AndroidArchitecture.ARMv7 &&
platformSettings.ScriptingImplementation != ScriptingImplementation.Mono2x)
// AndroidTargetArchitecture has a default value of ARM64 and ScriptingImplementation is nullable. Further ARMv7 is only compatible with Mono2x.
// Given baseline assumption and constraints, we want to help the user avoid issues as much as we can here
// If AndroidTargetArchitecture is ARMv7, it's because the user passed it in on the CLI (ARM64 is the default in PlatformSettings). Further,
// if ScriptingImplementation is IL2CPP, it's also because the user passed it in on the CLI, but these are incompatible, but most likely the
// user didn't know that, so let's help them out but setting ScriptingImplementation to Mono2x.
if (PlatformSettings.AndroidTargetArchitecture == AndroidArchitecture.ARMv7 &&
PlatformSettings.ScriptingImplementation != ScriptingImplementation.Mono2x)
{
platformSettings.ScriptingImplementation = ScriptingImplementation.Mono2x;
PlayerSettings.SetScriptingBackend(NamedBuildTarget.FromBuildTargetGroup(EditorUserBuildSettings.selectedBuildTargetGroup), (ScriptingImplementation) platformSettings.ScriptingImplementation);
SetScriptingImplementationToMono2x();
SetPlayerSettingsAndroidScriptingBackend();
}
// If the user has specified mono scripting backend, but not specified AndroidArchitecture.ARMv7, or has incorrectly specified AndroidArchitecture.ARM64 (not supported
// with mono), then set to AndroidArchitecture.ARMv7 so we're in a compatible configuration state.
if (platformSettings.ScriptingImplementation == ScriptingImplementation.Mono2x &&
platformSettings.AndroidTargetArchitecture != AndroidArchitecture.ARMv7)
// If ScriptingImplementation is Mono, it's because the user passed it in on the CLI. Further,
// if AndroidArchitecture is NOT ARMv7, it's most likely because they didn't specify an AndroidArchitecture and it took it's default value of ARM64,
// but these are incompatible, so let's help them out but setting AndroidArchitecture to ARMv7.
if (PlatformSettings.ScriptingImplementation == ScriptingImplementation.Mono2x &&
PlatformSettings.AndroidTargetArchitecture != AndroidArchitecture.ARMv7)
{
platformSettings.AndroidTargetArchitecture = AndroidArchitecture.ARMv7;
SetAndroidTargetArchitectureToARMv7();
}
PlayerSettings.Android.targetArchitectures = platformSettings.AndroidTargetArchitecture;
SetPlayerSettingsAndroidTargetArchitectures();
}
private void ConfigureCrossplatformSettings()
public virtual void SetAndroidTargetArchitectureToARMv7()
{
if (platformSettings.PlayerGraphicsApi != GraphicsDeviceType.Null)
PlatformSettings.AndroidTargetArchitecture = AndroidArchitecture.ARMv7;
}
public virtual void SetScriptingImplementationToMono2x()
{
PlatformSettings.ScriptingImplementation = ScriptingImplementation.Mono2x;
}
public virtual void SetPlayerSettingsAndroidScriptingBackend()
{
PlayerSettings.SetScriptingBackend(
NamedBuildTarget.FromBuildTargetGroup(EditorUserBuildSettings.selectedBuildTargetGroup),
(ScriptingImplementation)PlatformSettings.ScriptingImplementation);
}
public virtual void SetPlayerSettingsAndroidTargetArchitectures()
{
PlayerSettings.Android.targetArchitectures = PlatformSettings.AndroidTargetArchitecture;
}
public virtual void ConfigureCrossplatformSettings()
{
if (PlatformSettings.PlayerGraphicsApi != GraphicsDeviceType.Null)
{
PlayerSettings.SetUseDefaultGraphicsAPIs(platformSettings.BuildTarget, false);
PlayerSettings.SetGraphicsAPIs(platformSettings.BuildTarget,
new[] {platformSettings.PlayerGraphicsApi});
PlayerSettings.SetUseDefaultGraphicsAPIs(PlatformSettings.BuildTarget, false);
PlayerSettings.SetGraphicsAPIs(PlatformSettings.BuildTarget,
new[] {PlatformSettings.PlayerGraphicsApi});
}
// Default to no vsync for performance tests
@ -130,159 +181,165 @@ namespace com.unity.cliprojectsetup
for (int i = 0; i < QualitySettings.names.Length; i++)
{
QualitySettings.SetQualityLevel(i);
QualitySettings.vSyncCount = !string.IsNullOrEmpty(platformSettings.Vsync) ? Convert.ToInt32(platformSettings.Vsync) : 0;
QualitySettings.vSyncCount = !string.IsNullOrEmpty(PlatformSettings.Vsync) ? Convert.ToInt32(PlatformSettings.Vsync) : 0;
}
PlayerSettings.graphicsJobs = platformSettings.GraphicsJobs;
PlayerSettings.MTRendering = platformSettings.MtRendering;
PlayerSettings.colorSpace = platformSettings.ColorSpace;
if (platformSettings.ScriptingImplementation != null)
{
PlayerSettings.SetScriptingBackend(
NamedBuildTarget.FromBuildTargetGroup(EditorUserBuildSettings.selectedBuildTargetGroup),
(ScriptingImplementation)platformSettings.ScriptingImplementation);
}
if (platformSettings.ApiCompatibilityLevel != null)
{
PlayerSettings.SetApiCompatibilityLevel(NamedBuildTarget.FromBuildTargetGroup(EditorUserBuildSettings.selectedBuildTargetGroup), (ApiCompatibilityLevel) platformSettings.ApiCompatibilityLevel);
}
PlayerSettings.stripEngineCode = platformSettings.StringEngineCode;
PlayerSettings.SetManagedStrippingLevel(NamedBuildTarget.FromBuildTargetGroup(EditorUserBuildSettings.selectedBuildTargetGroup), platformSettings.ManagedStrippingLevel);
EditorUserBuildSettings.allowDebugging = platformSettings.ScriptDebugging;
/* TODO: Revisit burst logic when we're using it
#if ENABLE_BURST_AOT
BurstCompiler.Options.EnableBurstCompilation = platformSettings.EnableBurst;
#endif
*/
if (platformSettings.JobWorkerCount >= 0)
{
try
{
Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobWorkerCount = platformSettings.JobWorkerCount;
}
catch (Exception e)
{
// If we try to set the JobWorkerCount to more than the number of cores - 1 for a given machine,
// an exception is thrown. In this case, catch the exception and just use the default JobWorkerCount,
// then save this as the value used in our platformSettings.
Debug.Log($"Exception caught while trying to set JobWorkerCount to {platformSettings.JobWorkerCount}. Exception: {e.Message}");
platformSettings.JobWorkerCount = Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobWorkerCount;
}
PlayerSettings.graphicsJobs = PlatformSettings.GraphicsJobs;
PlayerSettings.MTRendering = PlatformSettings.MtRendering;
PlayerSettings.colorSpace = PlatformSettings.ColorSpace;
TrySetScriptingBackend();
TrySetApiCompatabilityLevel();
PlayerSettings.stripEngineCode = PlatformSettings.StripEngineCode;
PlayerSettings.SetManagedStrippingLevel(NamedBuildTarget.FromBuildTargetGroup(EditorUserBuildSettings.selectedBuildTargetGroup), PlatformSettings.ManagedStrippingLevel);
EditorUserBuildSettings.allowDebugging = PlatformSettings.ScriptDebugging;
if (PlatformSettings.JobWorkerCount >= 0)
{
SetJobWorkerCount();
}
}
public virtual void SetJobWorkerCount()
{
Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobWorkerCount = PlatformSettings.JobWorkerCount;
}
public virtual void TrySetApiCompatabilityLevel()
{
if (PlatformSettings.ApiCompatibilityLevel != null)
{
SetApiCompatabilityLevel();
}
}
public virtual void SetApiCompatabilityLevel()
{
PlayerSettings.SetApiCompatibilityLevel(
NamedBuildTarget.FromBuildTargetGroup(EditorUserBuildSettings.selectedBuildTargetGroup),
(ApiCompatibilityLevel)PlatformSettings.ApiCompatibilityLevel);
}
public virtual void TrySetScriptingBackend()
{
if (PlatformSettings.ScriptingImplementation != null)
{
SetScriptingBackend();
}
}
public virtual void SetScriptingBackend()
{
PlayerSettings.SetScriptingBackend(
NamedBuildTarget.FromBuildTargetGroup(EditorUserBuildSettings.selectedBuildTargetGroup),
(ScriptingImplementation)PlatformSettings.ScriptingImplementation);
}
private OptionSet DefineOptionSet()
{
var optionsSet = new OptionSet();
optionsSet.Add("scripting-backend|scriptingbackend=",
"Scripting backend to use. IL2CPP is default. Values: IL2CPP, Mono", ParseScriptingBackend);
"Scripting backend to use. Values: IL2CPP, Mono", ParseScriptingBackend);
optionsSet.Add("playergraphicsapi=", "Graphics API based on GraphicsDeviceType.",
graphicsDeviceType =>
platformSettings.PlayerGraphicsApi = TryParse<GraphicsDeviceType>(graphicsDeviceType));
PlatformSettings.PlayerGraphicsApi = ParseEnum<GraphicsDeviceType>(graphicsDeviceType));
optionsSet.Add("colorspace=", "Linear or Gamma color space.",
colorSpace => platformSettings.ColorSpace = TryParse<ColorSpace>(colorSpace));
colorSpace => PlatformSettings.ColorSpace = ParseEnum<ColorSpace>(colorSpace));
optionsSet.Add("mtRendering",
"Enable or disable multithreaded rendering. Enabled is default. Use option to enable, or use option and append '-' to disable.",
option => platformSettings.MtRendering = option != null);
option => PlatformSettings.MtRendering = option != null);
optionsSet.Add("graphicsJobs",
"Enable graphics jobs rendering. Disabled is default. Use option to enable, or use option and append '-' to disable.",
option => platformSettings.GraphicsJobs = option != null);
option => PlatformSettings.GraphicsJobs = option != null);
optionsSet.Add("testsrev=",
"revision id of the tests being used.",
testsrev => platformSettings.TestsRevision = testsrev);
testsrev => PlatformSettings.TestsRevision = testsrev);
optionsSet.Add("testsrevdate=",
"revision date of the tests being used.",
revDate => platformSettings.TestsRevisionDate = revDate);
revDate => PlatformSettings.TestsRevisionDate = revDate);
optionsSet.Add("testsbranch=",
"branch of the tests repo being used.",
testsbranch => platformSettings.TestsBranch = testsbranch);
testsbranch => PlatformSettings.TestsBranch = testsbranch);
optionsSet.Add("enableburst",
"Enable burst. Enabled is default. Use option to disable: -enableburst",
option => platformSettings.EnableBurst = option != null);
option => PlatformSettings.EnableBurst = option != null);
optionsSet.Add("packageundertestname=",
"package under test commit revision id",
packageundertestname => platformSettings.PackageUnderTestName = packageundertestname);
packageundertestname => PlatformSettings.PackageUnderTestName = packageundertestname);
optionsSet.Add("packageundertestversion=",
"package under test version",
packageundertestrev => platformSettings.PackageUnderTestVersion = packageundertestrev);
packageundertestrev => PlatformSettings.PackageUnderTestVersion = packageundertestrev);
optionsSet.Add("packageundertestrev=",
"package under test commit revision id",
packageundertestrev => platformSettings.PackageUnderTestRevision = packageundertestrev);
packageundertestrev => PlatformSettings.PackageUnderTestRevision = packageundertestrev);
optionsSet.Add("packageundertestrevdate=",
"package under test commit revision date",
packageundertestrevdate => platformSettings.PackageUnderTestRevisionDate = packageundertestrevdate);
packageundertestrevdate => PlatformSettings.PackageUnderTestRevisionDate = packageundertestrevdate);
optionsSet.Add("packageundertestbranch=",
"branch of the package under test repo being used.",
packageundertestbranch => platformSettings.PackageUnderTestBranch = packageundertestbranch);
packageundertestbranch => PlatformSettings.PackageUnderTestBranch = packageundertestbranch);
optionsSet.Add("testprojectname=",
"test project commit revision id",
testprojectname => platformSettings.TestProjectName = testprojectname);
testprojectname => PlatformSettings.TestProjectName = testprojectname);
optionsSet.Add("testprojectrevision=",
"test project commit revision id",
testprojectrevision => platformSettings.TestProjectRevision = testprojectrevision);
testprojectrevision => PlatformSettings.TestProjectRevision = testprojectrevision);
optionsSet.Add("testprojectrevdate=",
"test project commit revision date",
testprojectrevdate => platformSettings.TestProjectRevisionDate = testprojectrevdate);
testprojectrevdate => PlatformSettings.TestProjectRevisionDate = testprojectrevdate);
optionsSet.Add("testprojectbranch=",
"branch of the test project repo being used.",
testprojectbranch => platformSettings.TestProjectBranch = testprojectbranch);
testprojectbranch => PlatformSettings.TestProjectBranch = testprojectbranch);
optionsSet.Add("joblink=",
"Hyperlink to test job.",
joblink => platformSettings.JobLink = joblink);
joblink => PlatformSettings.JobLink = joblink);
optionsSet.Add("jobworkercount=",
"Number of job workers to use. Range is 0 - number of cores minus 1.",
jobworkercount =>
{
if (jobworkercount != null)
if (int.TryParse(jobworkercount, out var count))
{
platformSettings.JobWorkerCount = Convert.ToInt32(jobworkercount);
PlatformSettings.JobWorkerCount = count;
}
});
optionsSet.Add("apicompatibilitylevel=", "API compatibility to use. Default is NET_2_0",
apicompatibilitylevel => platformSettings.ApiCompatibilityLevel =
TryParse<ApiCompatibilityLevel>(apicompatibilitylevel));
apicompatibilitylevel => PlatformSettings.ApiCompatibilityLevel =
ParseEnum<ApiCompatibilityLevel>(apicompatibilitylevel));
optionsSet.Add("stripenginecode",
"Enable Engine code stripping. Disabled is default. Use option to enable, or use option and append '-' to disable.",
option => platformSettings.StringEngineCode = option != null);
optionsSet.Add("managedstrippinglevel=", "Managed stripping level to use. Default is low",
managedstrippinglevel => platformSettings.ManagedStrippingLevel =
TryParse<ManagedStrippingLevel>(managedstrippinglevel));
option => PlatformSettings.StripEngineCode = option != null);
optionsSet.Add("managedstrippinglevel=", "Managed stripping level to use. Default is Disabled",
managedstrippinglevel => PlatformSettings.ManagedStrippingLevel =
ParseEnum<ManagedStrippingLevel>(managedstrippinglevel));
optionsSet.Add("scriptdebugging",
"Enable scriptdebugging. Disabled is default. Use option to enable, or use option and append '-' to disable.",
scriptdebugging => platformSettings.ScriptDebugging = scriptdebugging != null);
scriptdebugging => PlatformSettings.ScriptDebugging = scriptdebugging != null);
optionsSet.Add("addscenetobuild=",
"Specify path to scene to add to the build, Path is relative to Assets folder.",
AddSceneToBuildList);
optionsSet.Add("openxrfeatures=",
"Add array of feature names to enable for openxr. ex [r:MockRuntime,OculusQuestFeature] should be name of feature class. Add r: before the feature name to make it required. Required features will fail the job if not found",
features => platformSettings.OpenXRFeatures = features);
features => PlatformSettings.OpenXRFeatures = features);
optionsSet.Add("enabledxrtarget|enabledxrtargets=",
"XR target to enable in player settings. Values: " +
"\r\n\"Oculus\"\r\n\"OpenVR\"\r\n\"cardboard\"\r\n\"daydream\"\r\n\"MockHMD\"\r\n\"OculusXRSDK\"\r\n\"MockHMDXRSDK\"\r\n\"MagicLeapXRSDK\"\r\n\"WindowsMRXRSDK\"\r\n\"PSVR2\"",
xrTarget => platformSettings.XrTarget = xrTarget);
xrTarget => PlatformSettings.XrTarget = xrTarget);
optionsSet.Add("stereorenderingmode|stereorenderingpath=", "Stereo rendering mode to enable. SinglePass is default.",
srm => platformSettings.StereoRenderingMode = srm);
srm => PlatformSettings.StereoRenderingMode = srm);
optionsSet.Add("simulationmode=",
"Enable Simulation modes for Windows MR in Editor. Values: \r\n\"HoloLens\"\r\n\"WindowsMR\"\r\n\"Remoting\"",
simMode => platformSettings.SimulationMode = simMode);
simMode => PlatformSettings.SimulationMode = simMode);
optionsSet.Add("deviceruntimeversion=",
"runtime version of the device we're running on.",
deviceruntime => platformSettings.DeviceRuntimeVersion = string.Format("deviceruntimeversion|{0}", deviceruntime));
deviceruntime => PlatformSettings.DeviceRuntimeVersion = string.Format("deviceruntimeversion|{0}", deviceruntime));
optionsSet.Add("ffrlevel=",
"ffr level we're running at",
ffrlevel => platformSettings.FfrLevel = string.Format("ffrlevel|{0}", ffrlevel));
optionsSet.Add("enablefoveatedrendering", "enable foveated rendering", foveatedrendering => platformSettings.FoveatedRendering = foveatedrendering != null);
ffrlevel => PlatformSettings.FfrLevel = string.Format("ffrlevel|{0}", ffrlevel));
optionsSet.Add("enablefoveatedrendering", "enable foveated rendering", foveatedrendering => PlatformSettings.FoveatedRendering = foveatedrendering != null);
optionsSet.Add("androidtargetarchitecture=",
"Android Target Architecture to use.",
androidtargetarchitecture => platformSettings.AndroidTargetArchitecture = TryParse<AndroidArchitecture>(androidtargetarchitecture));
optionsSet.Add("scriptdefine=",
"String to add to the player setting script defines.",
scriptDefine => ScriptDefines.AddRange(scriptDefine.Split(';')));
androidtargetarchitecture => PlatformSettings.AndroidTargetArchitecture = ParseEnum<AndroidArchitecture>(androidtargetarchitecture));
optionsSet.Add("vsync=",
"test project commit revision id", vsync => platformSettings.Vsync = vsync);
"test project commit revision id", vsync => PlatformSettings.Vsync = vsync);
return optionsSet;
}
@ -300,7 +357,7 @@ namespace com.unity.cliprojectsetup
}
}
public static T TryParse<T>(string stringToParse)
public static T ParseEnum<T>(string stringToParse)
{
T thisType;
try
@ -317,8 +374,10 @@ namespace com.unity.cliprojectsetup
private void ParseScriptingBackend(string scriptingBackend)
{
platformSettings.ScriptingImplementation =
scriptingBackend.ToLower().StartsWith("mono") ? ScriptingImplementation.Mono2x : ScriptingImplementation.IL2CPP;
if (scriptingBackend.ToLower().StartsWith("mono"))
PlatformSettings.ScriptingImplementation = ScriptingImplementation.Mono2x;
else
PlatformSettings.ScriptingImplementation = ScriptingImplementation.IL2CPP;
}
}
}

Просмотреть файл

@ -20,13 +20,13 @@ namespace com.unity.cliprojectsetup
{
#if UNITY_EDITOR
public BuildTargetGroup BuildTargetGroup => EditorUserBuildSettings.selectedBuildTargetGroup;
public BuildTarget BuildTarget => EditorUserBuildSettings.activeBuildTarget;
public ScriptingImplementation? ScriptingImplementation;
public ApiCompatibilityLevel? ApiCompatibilityLevel;
public AndroidArchitecture AndroidTargetArchitecture = AndroidArchitecture.ARM64;
public virtual BuildTarget BuildTarget => EditorUserBuildSettings.activeBuildTarget;
public virtual ScriptingImplementation? ScriptingImplementation { get; set; }
public virtual ApiCompatibilityLevel? ApiCompatibilityLevel { get; set; }
public virtual AndroidArchitecture AndroidTargetArchitecture { get; set; } = AndroidArchitecture.ARM64;
public ManagedStrippingLevel ManagedStrippingLevel;
#endif
private readonly string UnavailableMsg = "unavailable";
private readonly string unavailableMsg = "unavailable";
public GraphicsDeviceType PlayerGraphicsApi;
public string PackageUnderTestName;
public string PackageUnderTestVersion;
@ -44,18 +44,20 @@ namespace com.unity.cliprojectsetup
public string Username;
public string JobLink;
public int JobWorkerCount = -1; // sentinel value indicating we don't want to set the JobWorkerCount
public bool StringEngineCode;
public bool StripEngineCode;
public bool ScriptDebugging;
public string TestProjectName;
public string TestProjectRevision;
public string TestProjectRevisionDate;
public string TestProjectBranch;
public string StereoRenderingMode;
public virtual string StereoRenderingMode { get; set; }
public string StereoRenderingModeDesktop;
public string StereoRenderingModeAndroid;
public string SimulationMode;
public string PluginVersion;
public string XrTarget;
public virtual string XrTarget { get; set; }
public string OpenXRFeatures;
public string DeviceRuntimeVersion;
public bool FoveatedRendering;
@ -66,7 +68,7 @@ namespace com.unity.cliprojectsetup
private readonly Regex majorMinorVersionValueRegex = new Regex("([0-9]*\\.[0-9]*\\.)",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
public void SerializeToAsset()
public virtual void SerializeToAsset()
{
var settings = CustomMetadataManager.Instance;
var pathParts = Application.dataPath.Split('/');
@ -75,7 +77,7 @@ namespace com.unity.cliprojectsetup
settings.MtRendering = MtRendering;
settings.GraphicsJobs = GraphicsJobs;
settings.EnableBurst = EnableBurst;
settings.ScriptingBackend = ScriptingImplementation.ToString();
settings.ScriptingBackend = ScriptingImplementation?.ToString();
settings.ColorSpace = ColorSpace.ToString();
settings.Username = Username = Environment.UserName;
settings.PackageUnderTestName = PackageUnderTestName;
@ -89,7 +91,7 @@ namespace com.unity.cliprojectsetup
settings.JobLink = JobLink;
settings.JobWorkerCount = Unity.Jobs.LowLevel.Unsafe.JobsUtility.JobWorkerCount;
settings.ApiCompatibilityLevel = ApiCompatibilityLevel.ToString();
settings.StripEngineCode = StringEngineCode;
settings.StripEngineCode = StripEngineCode;
settings.ManagedStrippingLevel = ManagedStrippingLevel.ToString();
settings.ScriptDebugging = ScriptDebugging;
settings.TestProjectName = TestProjectName;
@ -168,7 +170,7 @@ namespace com.unity.cliprojectsetup
settings.PackageUnderTestRevision =
!string.IsNullOrEmpty(PackageUnderTestRevision) ? PackageUnderTestRevision :
!string.IsNullOrEmpty(TryGetRevisionFromPackageJson(PackageUnderTestName)) ? TryGetRevisionFromPackageJson(PackageUnderTestName) :
UnavailableMsg;
unavailableMsg;
// if PackageUnderTestRevisionDate is empty, then it wasn't passed in on the command line (which is
// usually going to be the case if we're running in tests at the PR level for the package).
@ -177,7 +179,7 @@ namespace com.unity.cliprojectsetup
settings.PackageUnderTestRevisionDate =
!string.IsNullOrEmpty(PackageUnderTestRevisionDate) ? PackageUnderTestRevisionDate :
packageUnderTestInfo.datePublished != null ? GetPackageUnderTestRevisionDate(packageUnderTestInfo.datePublished) :
UnavailableMsg;
unavailableMsg;
// if PackageUnderTestBranch is empty, then it wasn't passed in on the command line (which is
// usually going to be the case if we're running in tests at the PR level for the package).
@ -186,14 +188,14 @@ namespace com.unity.cliprojectsetup
settings.PackageUnderTestBranch =
!string.IsNullOrEmpty(PackageUnderTestBranch) ? PackageUnderTestBranch :
!string.IsNullOrEmpty(packageUnderTestInfo.version) ? GetPackageUnderTestBranch(packageUnderTestInfo.version) :
UnavailableMsg;
unavailableMsg;
}
else
{
settings.PackageUnderTestRevision = UnavailableMsg;
settings.PackageUnderTestVersion = UnavailableMsg;
settings.PackageUnderTestRevisionDate = UnavailableMsg;
settings.PackageUnderTestBranch = UnavailableMsg;
settings.PackageUnderTestRevision = unavailableMsg;
settings.PackageUnderTestVersion = unavailableMsg;
settings.PackageUnderTestRevisionDate = unavailableMsg;
settings.PackageUnderTestBranch = unavailableMsg;
}
}
@ -206,7 +208,7 @@ namespace com.unity.cliprojectsetup
public string GetPackageUnderTestRevisionDate(DateTime? datePublished)
{
return datePublished != null ?
((DateTime)datePublished).ToString("s", DateTimeFormatInfo.InvariantInfo) : UnavailableMsg;
((DateTime)datePublished).ToString("s", DateTimeFormatInfo.InvariantInfo) : unavailableMsg;
}
public string TryGetRevisionFromPackageJson(string packageName)

Просмотреть файл

@ -36,7 +36,12 @@
"name": "com.unity.xr.windowsmr",
"expression": "0.0.1",
"define": "XR_SDK;WMR_SDK"
}
},
{
"name": "com.unity.render-pipelines.universal",
"expression": "0.0.1",
"define": "URP"
}
],
"noEngineReferences": false
}

Просмотреть файл

@ -1,6 +1,63 @@
# com.unity.cli-project-setup
Provides a command line parser and options to set editor, build, player, and other Unity settings when running Unity from the command line
## Developer Guide
In order to contribute to the com.unity.cli-project-setup package, do the following
1. Clone this git repository to your local machine
2. Choose a test project to include the com.unity.cli-project-setup package in while developing and debugging it.
1. Add the package to the dependencies section of the project manifest, using a local reference syntax like this but using the location that is specific to your machine
```
"com.unity.cli-project-setup": "file:D:/com.unity.cli-project-setup"
```
2. The com.unity.cli-project-setup package requires the com.unity.test.metadata-manager package as a dependency, so you'll need to include this in one of three ways:
1. Add a local reference: Clone the com.unity.test.metadata-manager locally like you did for this package in the first step, and add a local dependency reference to it.
```
"com.unity.test.metadata-manager": "file:D:/com.unity.test.metadata-manager"
```
2. Add a scoped registry section to your project manifest: The com.unity.test.metadata-manager is published to the internal, upm-candidates package registry. If your project needs to use the production (non-internal) Unity package registry, you'll need to add a scopedRegistry section to your project manifest in order to access it
```
"scopedRegistries": [
{
"name": "Internal Candidate Registry",
"url": "https://artifactory.prd.it.unity3d.com/artifactory/api/npm/upm-candidates",
"scopes": [
"com.unity.test.metadata-manager"
]
}
],
```
3. Update the project manifest to use the internal package registry exlusively: If using the internal, upm-candidates, registry is acceptable for your project, just ensure you have this entry in the project manifest.
```
"registry": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
```
4. Add the MOQ mocking framework package to your project manifest.
```
"nuget.moq": "2.0.0-pre.2"
```
3. Add com.unity.cli-project-setup to the project manifest's "testables" section. This will ensure the unit tests can be seen and run from the editor's test runner tab
```
"testables": [
"com.unity.cli-project-setup"
]
```
If you've setup up everything correctly, you should now see the tests from the EditMode tab of the Unity editor test runner tab.
## Testing changes
This package is used broadly across Graphics and XR testing. Following is a procedure for verifying changes and keeping broader support in mind.
- Verify your own use cases.

Просмотреть файл

@ -1,6 +1,6 @@
{
"createSeparatePackage": true,
"dependencies": {
"nuget.moq": "1.0.0"
"nuget.moq": "2.0.0-pre.2"
}
}

Просмотреть файл

@ -0,0 +1,18 @@
using com.unity.cliprojectsetup;
using UnityEditor;
public class CliProjectSetupMock : CliProjectSetup
{
public CliProjectSetupMock(string[] args = null)
: base(args)
{
}
public EditorBuildSettingsScene[] Scenes;
protected override void SetEditorBuildSettingsScenes(EditorBuildSettingsScene[] buildSettingScenes)
{
Scenes = buildSettingScenes;
}
}

Просмотреть файл

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b68590a75c5b55c44b35f878dc8b63ff
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,789 @@
using com.unity.cliprojectsetup;
#if NUGET_MOQ_AVAILABLE
using Moq;
#endif
using NUnit.Framework;
using UnityEditor;
using UnityEngine.Rendering;
public class CliProjectSetupOptions
{
[Test]
public void VerifyOptionsLowerCased_NoMatch_NoChange()
{
// Arrange
var expArgs = new[] { "-a=Arg1", "-b=arg2", "-c=ARG3" };
var cliProjectSetup = new CliProjectSetup(expArgs);
cliProjectSetup.ParseCommandLineArgs();
// Act
cliProjectSetup.EnsureOptionsLowerCased();
// Assert
Assert.AreEqual(new[] { "-a=Arg1", "-b=arg2", "-c=ARG3" }, cliProjectSetup.CliArgs);
}
[Test]
public void VerifyOptionsLowerCased_SingleMatch_ChangeToLowercase()
{
// Arrange
var inputArgs = new[] { "-a=Arg1", "-B=arg2", "-c=arg3" };
var expTransformedArgs = new[] { "-a=Arg1", "-b=arg2", "-c=arg3" };
var cliProjectSetup = new CliProjectSetup(inputArgs);
cliProjectSetup.ParseCommandLineArgs();
// Act
cliProjectSetup.EnsureOptionsLowerCased();
// Assert
Assert.AreEqual(expTransformedArgs, cliProjectSetup.CliArgs);
}
[Test]
public void VerifyOptionsLowerCased_MultipleMatches_ChangeToLowercase()
{
// Arrange
var inputArgs = new[] { "-A=Arg1", "-B=arg2", "-c=ARG3", "-d=Arg4" };
var expTransformedArgs = new[] { "-a=Arg1", "-b=arg2", "-c=ARG3", "-d=Arg4" };
var cliProjectSetup = new CliProjectSetup(inputArgs);
cliProjectSetup.ParseCommandLineArgs();
// Act
cliProjectSetup.EnsureOptionsLowerCased();
// Assert
Assert.AreEqual(expTransformedArgs, cliProjectSetup.CliArgs);
}
[Test]
public void VerifyOption_SetScriptingBackend()
{
// Arrange
var testScenePath1 = "Assets/Scenes/Scene1.unity";
var args = new[] { $"-addscenetobuild={testScenePath1}" };
var mockPlatformSettings = new Mock<PlatformSettings>()
{
CallBase = true
};
mockPlatformSettings.Setup(m => m.ScriptingImplementation).Returns(ScriptingImplementation.IL2CPP);
var mockCliProjectSetup = new Mock<CliProjectSetup>(args, mockPlatformSettings.Object)
{
CallBase = true
};
// Act
mockCliProjectSetup.Object.ConfigureCrossplatformSettings();
// Assert
mockCliProjectSetup.Verify(m => m.TrySetScriptingBackend(), Times.Once);
}
[Test]
public void VerifyOption_DoNotSetScriptingBackend()
{
// Arrange
var testScenePath1 = "Assets/Scenes/Scene1.unity";
var args = new[] { $"-addscenetobuild={testScenePath1}" };
var mockPlatformSettings = new Mock<PlatformSettings>()
{
CallBase = true
};
var mockCliProjectSetup = new Mock<CliProjectSetup>(args, mockPlatformSettings.Object)
{
CallBase = true
};
// Act
mockCliProjectSetup.Object.ConfigureCrossplatformSettings();
// Assert
mockCliProjectSetup.Verify(m => m.SetScriptingBackend(), Times.Never);
}
[Test]
public void VerifyOption_SetApiCompatabilityLevel()
{
// Arrange
var testScenePath1 = "Assets/Scenes/Scene1.unity";
var args = new[] { $"-addscenetobuild={testScenePath1}" };
var mockPlatformSettings = new Mock<PlatformSettings>()
{
CallBase = true
};
mockPlatformSettings.Setup(m => m.ApiCompatibilityLevel).Returns(ApiCompatibilityLevel.NET_4_6);
var mockCliProjectSetup = new Mock<CliProjectSetup>(args, mockPlatformSettings.Object)
{
CallBase = true
};
// Act
mockCliProjectSetup.Object.ConfigureCrossplatformSettings();
// Assert
mockCliProjectSetup.Verify(m => m.SetApiCompatabilityLevel(), Times.Once);
}
[Test]
public void VerifyOption_DoNotSetApiCompatabilityLevel()
{
// Arrange
var testScenePath1 = "Assets/Scenes/Scene1.unity";
var args = new[] { $"-addscenetobuild={testScenePath1}" };
var mockPlatformSettings = new Mock<PlatformSettings>()
{
CallBase = true
};
var mockCliProjectSetup = new Mock<CliProjectSetup>(args, mockPlatformSettings.Object)
{
CallBase = true
};
// Act
mockCliProjectSetup.Object.ConfigureCrossplatformSettings();
// Assert
mockCliProjectSetup.Verify(m => m.SetApiCompatabilityLevel(), Times.Never);
}
[Test]
public void VerifyOption_MtRenderingIsTrueByDefault()
{
// Arrange
var cliProjectSetup = new CliProjectSetup(new string[] { });
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.IsTrue(cliProjectSetup.PlatformSettings.MtRendering);
}
[Test]
public void VerifyOption_MtRenderingSetToFalse()
{
// Arrange
var args = new[] { $"-mtRendering-" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.IsFalse(cliProjectSetup.PlatformSettings.MtRendering);
}
[Test]
public void VerifyOption_GraphicsJobsIsFalseByDefault()
{
// Arrange
var cliProjectSetup = new CliProjectSetup(new string[] { });
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.IsFalse(cliProjectSetup.PlatformSettings.GraphicsJobs);
}
[Test]
public void VerifyOption_GraphicsJobsSetToTrue()
{
// Arrange
var args = new[] { $"-graphicsJobs" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.IsTrue(cliProjectSetup.PlatformSettings.GraphicsJobs);
}
[Test]
public void VerifyOption_ScriptingBackend_Il2Cpp()
{
// Arrange
var args = new[] { $"-scripting-backend=il2cpp" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("IL2CPP", cliProjectSetup.PlatformSettings.ScriptingImplementation.ToString());
}
[Test]
public void VerifyOption_ScriptingBackend_Il2Cpp_AlternateCliOption()
{
// Arrange
var args = new[] { $"-scriptingbackend=il2cpp" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("IL2CPP", cliProjectSetup.PlatformSettings.ScriptingImplementation.ToString());
}
[Test]
public void VerifyOption_ScriptingBackend_Mono()
{
// Arrange
var args = new[] { $"-scripting-backend=mono" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("Mono2x", cliProjectSetup.PlatformSettings.ScriptingImplementation.ToString());
}
[Test]
public void VerifyOption_ScriptingBackend_NotSet()
{
// Arrange
var cliProjectSetup = new CliProjectSetup(new string[] { });
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual(string.Empty, cliProjectSetup.PlatformSettings.ScriptingImplementation.ToString());
}
[Test]
public void VerifyOption_PlayerGraphicsApi_Metal()
{
// Arrange
var args = new[] { $"-playergraphicsapi=Metal" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("Metal", cliProjectSetup.PlatformSettings.PlayerGraphicsApi.ToString());
}
[Test]
public void VerifyOption_PlayerGraphicsApi_Default()
{
// Arrange
var cliProjectSetup = new CliProjectSetup(new string[] { });
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual((GraphicsDeviceType)0, cliProjectSetup.PlatformSettings.PlayerGraphicsApi);
}
[Test]
public void VerifyOption_Colorspace_Linear()
{
// Arrange
var args = new[] { $"-colorspace=Linear" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("Linear", cliProjectSetup.PlatformSettings.ColorSpace.ToString());
}
[Test]
public void VerifyOption_Colorspace_Gamma()
{
// Arrange
var args = new[] { $"-colorspace=Gamma" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("Gamma", cliProjectSetup.PlatformSettings.ColorSpace.ToString());
}
[Test]
public void VerifyOption_TestsRev()
{
// Arrange
var args = new[] { $"-testsrev=1" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("1", cliProjectSetup.PlatformSettings.TestsRevision);
}
[Test]
public void VerifyOption_TestsRevDate()
{
// Arrange
var args = new[] { $"-testsrevdate=12345" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("12345", cliProjectSetup.PlatformSettings.TestsRevisionDate);
}
[Test]
public void VerifyOption_TestsBranch()
{
// Arrange
var args = new[] { $"-testsbranch=myDevBranch" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("myDevBranch", cliProjectSetup.PlatformSettings.TestsBranch);
}
[Test]
public void VerifyOption_EnableBurstByDefault()
{
// Arrange
var cliProjectSetup = new CliProjectSetup(new string[] { });
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.IsTrue(cliProjectSetup.PlatformSettings.EnableBurst);
}
[Test]
public void VerifyOption_DisableBurst()
{
// Arrange
var args = new[] { $"-enableburst-" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.IsFalse(cliProjectSetup.PlatformSettings.EnableBurst);
}
[Test]
public void VerifyOption_PackageUnderTestName()
{
// Arrange
var args = new[] { $"-packageundertestname=myPackageName" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("myPackageName", cliProjectSetup.PlatformSettings.PackageUnderTestName);
}
[Test]
public void VerifyOption_PackageUnderTestVersion()
{
// Arrange
var args = new[] { $"-packageundertestversion=12.0.3" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("12.0.3", cliProjectSetup.PlatformSettings.PackageUnderTestVersion);
}
[Test]
public void VerifyOption_PackageUnderTestRevision()
{
// Arrange
var args = new[] { $"-packageundertestrev=45890" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("45890", cliProjectSetup.PlatformSettings.PackageUnderTestRevision);
}
[Test]
public void VerifyOption_PackageUnderTestRevisionDate()
{
// Arrange
var args = new[] { $"-packageundertestrevdate=45890" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("45890", cliProjectSetup.PlatformSettings.PackageUnderTestRevisionDate);
}
[Test]
public void VerifyOption_PackageUnderTestBranch()
{
// Arrange
var args = new[] { $"-packageundertestbranch=myPackageBranch" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("myPackageBranch", cliProjectSetup.PlatformSettings.PackageUnderTestBranch);
}
[Test]
public void VerifyOption_TestProjectName()
{
// Arrange
var args = new[] { $"-testprojectname=myTestProjectName" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("myTestProjectName", cliProjectSetup.PlatformSettings.TestProjectName);
}
[Test]
public void VerifyOption_TestProjectRevision()
{
// Arrange
var args = new[] { $"-testprojectrevision=1.2.3" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("1.2.3", cliProjectSetup.PlatformSettings.TestProjectRevision);
}
[Test]
public void VerifyOption_TestProjectRevisionDate()
{
// Arrange
var args = new[] { $"-testprojectrevdate=45891" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("45891", cliProjectSetup.PlatformSettings.TestProjectRevisionDate);
}
[Test]
public void VerifyOption_TestProjectBranch()
{
// Arrange
var args = new[] { $"-testprojectbranch=myTestProjectBranch" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("myTestProjectBranch", cliProjectSetup.PlatformSettings.TestProjectBranch);
}
[Test]
public void VerifyOption_JobLink()
{
// Arrange
var args = new[] { $"-joblink=http://myjoblink" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("http://myjoblink", cliProjectSetup.PlatformSettings.JobLink);
}
[Test]
public void VerifyOption_JobWorkerCount()
{
// Arrange
var args = new[] { $"-jobworkercount=4" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual(4, cliProjectSetup.PlatformSettings.JobWorkerCount);
}
[Test]
public void VerifyOption_JobWorkerCount_HandleEmptyStringValue()
{
// Arrange
var args = new[] { $"-jobworkercount=" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual(-1, cliProjectSetup.PlatformSettings.JobWorkerCount);
}
[Test]
public void VerifyOption_ApiCompatibilityLevel()
{
// Arrange
var args = new[] { $"-apicompatibilitylevel=NET_2_0_Subset" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("NET_2_0_Subset", cliProjectSetup.PlatformSettings.ApiCompatibilityLevel.ToString());
}
[Test]
public void VerifyOption_StripEngineCodeDisabledByDefault()
{
// Arrange
var cliProjectSetup = new CliProjectSetup(new string[] { });
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.IsFalse(cliProjectSetup.PlatformSettings.StripEngineCode);
}
[Test]
public void VerifyOption_StripEngineCode()
{
// Arrange
var args = new[] { $"-stripenginecode" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.IsTrue(cliProjectSetup.PlatformSettings.StripEngineCode);
}
[Test]
public void VerifyOption_ManagedStrippingLevelDefault()
{
// Arrange
var cliProjectSetup = new CliProjectSetup(new string[] { });
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("Disabled", cliProjectSetup.PlatformSettings.ManagedStrippingLevel.ToString());
}
[Test]
public void VerifyOption_ManagedStrippingLevel()
{
// Arrange
var args = new[] { $"-managedstrippinglevel=High" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("High", cliProjectSetup.PlatformSettings.ManagedStrippingLevel.ToString());
}
[Test]
public void VerifyOption_ScriptDebuggingDisabledByDefault()
{
// Arrange
var cliProjectSetup = new CliProjectSetup(new string[] { });
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.IsFalse(cliProjectSetup.PlatformSettings.ScriptDebugging);
}
[Test]
public void VerifyOption_ScriptDebugging()
{
// Arrange
var args = new[] { $"-scriptdebugging" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.IsTrue(cliProjectSetup.PlatformSettings.ScriptDebugging);
}
[Test]
public void VerifyOption_AddSceneToBuild()
{
// Arrange
var testScenePath1 = "Assets/Scenes/Scene1.unity";
var args = new[] { $"-addscenetobuild={testScenePath1}" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.True(cliProjectSetup.ScenesToAddToBuild.Contains(testScenePath1));
}
[Test]
public void VerifyOption_AddMutlipleScenesToBuild()
{
// Arrange
var testScenePath1 = "Assets/Scenes/Scene1.unity";
var testScenePath2 = "Assets/Scenes/Scene2.unity";
var args = new[] { $"-addscenetobuild={testScenePath1}", $"-addscenetobuild={testScenePath2}" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.True(cliProjectSetup.ScenesToAddToBuild.Contains(testScenePath1));
Assert.True(cliProjectSetup.ScenesToAddToBuild.Contains(testScenePath2));
}
[Test]
public void VerifyOption_OpenXRFeatures()
{
// Arrange
var args = new[] { $"-openxrfeatures=r:MockRuntime,OculusQuestFeature" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("r:MockRuntime,OculusQuestFeature", cliProjectSetup.PlatformSettings.OpenXRFeatures);
}
[Test]
public void VerifyOption_XrTarget()
{
// Arrange
var args = new[] { $"-enabledxrtarget=OculusXRSDK" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("OculusXRSDK", cliProjectSetup.PlatformSettings.XrTarget);
}
[Test]
public void VerifyOption_XrTarget_Alternate()
{
// Arrange
var args = new[] { $"-enabledxrtargets=OculusXRSDK" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("OculusXRSDK", cliProjectSetup.PlatformSettings.XrTarget);
}
[Test]
public void VerifyOption_SimulationMode()
{
// Arrange
var args = new[] { $"-simulationmode=HoloLens" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("HoloLens", cliProjectSetup.PlatformSettings.SimulationMode);
}
[Test]
public void VerifyOption_DeviceRuntimeVersion()
{
// Arrange
var args = new[] { $"-deviceruntimeversion=2.8.9" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("deviceruntimeversion|2.8.9", cliProjectSetup.PlatformSettings.DeviceRuntimeVersion);
}
[Test]
public void VerifyOption_FfrLevel()
{
// Arrange
var args = new[] { $"-ffrlevel=2" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("ffrlevel|2", cliProjectSetup.PlatformSettings.FfrLevel);
}
[Test]
public void VerifyOption_AndroidTargetArchitecture()
{
// Arrange
var args = new[] { $"-androidtargetarchitecture=ARMv7" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("ARMv7", cliProjectSetup.PlatformSettings.AndroidTargetArchitecture.ToString());
}
[Test]
public void VerifyOption_Vsync()
{
// Arrange
var args = new[] { $"-vsync=2" };
var cliProjectSetup = new CliProjectSetup(args);
// Act
cliProjectSetup.ParseCommandLineArgs();
// Assert
Assert.AreEqual("2", cliProjectSetup.PlatformSettings.Vsync);
}
}

Просмотреть файл

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 855f6adfa6849294e83697d805e4db50
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,268 @@
using System;
using System.Linq;
using com.unity.cliprojectsetup;
#if NUGET_MOQ_AVAILABLE
using Moq;
#endif
using NUnit.Framework;
using UnityEditor;
using UnityEngine;
public class CliProjectSetupTests
{
[Test]
public void VerifyAddTestScenesToBuild_OneScene()
{
// Arrange
var testScenePath = "Assets/Scenes/Scene1.unity";
var args = new[] { $"-addscenetobuild={testScenePath}" };
var cliProjectSetupMock = new CliProjectSetupMock(args);
cliProjectSetupMock.ParseCommandLineArgs();
// Act
cliProjectSetupMock.AddTestScenesToBuild();
// Assert
Assert.AreEqual(testScenePath, cliProjectSetupMock.Scenes[0].path);
}
[Test]
public void VerifyAddTestScenesToBuild_MultipleScene()
{
// Arrange
var testScenePath1 = "Assets/Scenes/Scene1.unity";
var testScenePath2 = "Assets/Scenes/Scene2.unity";
var args = new[] { $"-addscenetobuild={testScenePath1}", $"-addscenetobuild={testScenePath2}" };
var cliProjectSetupMock = new CliProjectSetupMock(args);
cliProjectSetupMock.ParseCommandLineArgs();
// Act
cliProjectSetupMock.AddTestScenesToBuild();
// Assert
Assert.AreEqual(2, cliProjectSetupMock.Scenes.Length);
Assert.True(cliProjectSetupMock.Scenes.Select(s => s.path).Contains(testScenePath1));
Assert.True(cliProjectSetupMock.Scenes.Select(s => s.path).Contains(testScenePath2));
}
[Test]
public void VerifyAddTestScenesToBuild_NoScenePassedInCliArgs()
{
// Arrange
var cliProjectSetupMock = new CliProjectSetupMock();
cliProjectSetupMock.ParseCommandLineArgs();
// Act
cliProjectSetupMock.AddTestScenesToBuild();
// Assert
Assert.IsNull(cliProjectSetupMock.Scenes);
}
[Test]
public void VerifyParseEnumThrowsExecptionForInvalidValue()
{
// Assert
Assert.Throws<ArgumentException>(() => CliProjectSetup.ParseEnum<AndroidArchitecture>("notAnAdroidArchitectureValue"));
}
#if NUGET_MOQ_AVAILABLE
[Test]
public void VerifyConfigureFromCmdlineArgsSubMethodCalls()
{
// Arrange
var testScenePath1 = "Assets/Scenes/Scene1.unity";
var testScenePath2 = "Assets/Scenes/Scene2.unity";
var args = new[] { $"-addscenetobuild={testScenePath1}", $"-addscenetobuild={testScenePath2}" };
var mockPlatformSettings = new Mock<PlatformSettings>();
var mockCliProjectSetup = new Mock<CliProjectSetup>(args, mockPlatformSettings.Object);
// Act
mockCliProjectSetup.Object.ConfigureFromCmdlineArgs();
// Assert
mockCliProjectSetup.Verify(m => m.ParseCommandLineArgs(), Times.Once);
mockCliProjectSetup.Verify(m => m.ConfigureSettings(), Times.Once);
mockCliProjectSetup.Verify(m => m.AddTestScenesToBuild(), Times.Once);
mockPlatformSettings.Verify(m => m.SerializeToAsset(), Times.Once);
}
[Test]
public void VerifyAndroid_NoXR_BuildTargetSubMethodCalls()
{
// Arrange
var testScenePath1 = "Assets/Scenes/Scene1.unity";
var args = new[] { $"-addscenetobuild={testScenePath1}" };
var mockPlatformSettings = new Mock<PlatformSettings>();
mockPlatformSettings.Setup(m => m.BuildTarget).Returns(BuildTarget.Android);
var mockCliProjectSetup = new Mock<CliProjectSetup>(args, mockPlatformSettings.Object)
{
CallBase = true
};
// Act
mockCliProjectSetup.Object.ConfigureSettings();
// Assert
mockCliProjectSetup.Verify(m => m.ConfigureCrossplatformSettings(), Times.Once);
mockCliProjectSetup.Verify(m => m.ConfigureAndroidSettings(), Times.Once);
mockCliProjectSetup.Verify(m => m.ConfigureIosSettings(), Times.Never);
mockCliProjectSetup.Verify(m => m.ConfigureXrSettings(), Times.Never);
}
[Test]
public void VerifyAndroid_WithXR_BuildTargetSubMethodCalls()
{
// Arrange
var testScenePath1 = "Assets/Scenes/Scene1.unity";
var args = new[] { $"-addscenetobuild={testScenePath1}"};
var mockPlatformSettings = new Mock<PlatformSettings>();
mockPlatformSettings.Setup(m => m.BuildTarget).Returns(BuildTarget.Android);
mockPlatformSettings.Setup(m => m.XrTarget).Returns("OculusXRSDK");
mockPlatformSettings.Setup(m => m.StereoRenderingMode).Returns("Multiview");
var mockCliProjectSetup = new Mock<CliProjectSetup>(args, mockPlatformSettings.Object)
{
CallBase = true
};
// Act
mockCliProjectSetup.Object.ConfigureSettings();
// Assert
mockCliProjectSetup.Verify(m => m.ConfigureCrossplatformSettings(), Times.Once);
mockCliProjectSetup.Verify(m => m.ConfigureAndroidSettings(), Times.Once);
mockCliProjectSetup.Verify(m => m.ConfigureIosSettings(), Times.Never);
mockCliProjectSetup.Verify(m => m.ConfigureXrSettings(), Times.Once);
}
[Test]
public void VerifyiOS_NoXR_BuildTargetSubMethodCalls()
{
// Arrange
var testScenePath1 = "Assets/Scenes/Scene1.unity";
var args = new[] { $"-addscenetobuild={testScenePath1}" };
var mockPlatformSettings = new Mock<PlatformSettings>();
mockPlatformSettings.Setup(m => m.BuildTarget).Returns(BuildTarget.iOS);
var mockCliProjectSetup = new Mock<CliProjectSetup>(args, mockPlatformSettings.Object)
{
CallBase = true
};
// Act
mockCliProjectSetup.Object.ConfigureSettings();
// Assert
mockCliProjectSetup.Verify(m => m.ConfigureCrossplatformSettings(), Times.Once);
mockCliProjectSetup.Verify(m => m.ConfigureAndroidSettings(), Times.Never);
mockCliProjectSetup.Verify(m => m.ConfigureIosSettings(), Times.Once);
mockCliProjectSetup.Verify(m => m.ConfigureXrSettings(), Times.Never);
}
[Test]
public void VerifyAndroid_InvalidCombo_ARMv7_without_Mono2x()
{
// Arrange
var testScenePath1 = "Assets/Scenes/Scene1.unity";
var args = new[] { $"-addscenetobuild={testScenePath1}" };
var mockPlatformSettings = new Mock<PlatformSettings>()
{
CallBase = true
};
mockPlatformSettings.Setup(m => m.BuildTarget).Returns(BuildTarget.Android);
mockPlatformSettings.Setup(m => m.AndroidTargetArchitecture).Returns(AndroidArchitecture.ARMv7);
mockPlatformSettings.Setup(m => m.ScriptingImplementation).Returns(ScriptingImplementation.IL2CPP);
var mockCliProjectSetup = new Mock<CliProjectSetup>(args, mockPlatformSettings.Object)
{
CallBase = true
};
// Act
mockCliProjectSetup.Object.ConfigureAndroidSettings();
// Assert
mockCliProjectSetup.Verify(m => m.SetScriptingImplementationToMono2x(), Times.Once);
mockCliProjectSetup.Verify(m => m.SetPlayerSettingsAndroidScriptingBackend(), Times.Once);
mockCliProjectSetup.Verify(m => m.SetPlayerSettingsAndroidTargetArchitectures(), Times.Once);
}
[Test]
public void VerifyAndroid_InvalidCombo_Mono2x_without_ARMv7()
{
// Arrange
var testScenePath1 = "Assets/Scenes/Scene1.unity";
var args = new[] { $"-addscenetobuild={testScenePath1}" };
var mockPlatformSettings = new Mock<PlatformSettings>()
{
CallBase = true
};
mockPlatformSettings.Setup(m => m.BuildTarget).Returns(BuildTarget.Android);
mockPlatformSettings.Setup(m => m.AndroidTargetArchitecture).Returns(AndroidArchitecture.X86_64);
mockPlatformSettings.Setup(m => m.ScriptingImplementation).Returns(ScriptingImplementation.Mono2x);
var mockCliProjectSetup = new Mock<CliProjectSetup>(args, mockPlatformSettings.Object)
{
CallBase = true
};
// Act
mockCliProjectSetup.Object.ConfigureAndroidSettings();
// Assert
mockCliProjectSetup.Verify(m => m.SetAndroidTargetArchitectureToARMv7(), Times.Once);
mockCliProjectSetup.Verify(m => m.SetPlayerSettingsAndroidTargetArchitectures(), Times.Once);
}
[Test]
public void VerifySetJobWorkerCount_ValidValue()
{
// Arrange
var args = new[] { $"-jobworkercount=1" };
var mockPlatformSettings = new Mock<PlatformSettings>();
var mockCliProjectSetup = new Mock<CliProjectSetup>(args, mockPlatformSettings.Object)
{
CallBase = true
};
mockCliProjectSetup.Object.ParseCommandLineArgs();
// Act
mockCliProjectSetup.Object.ConfigureCrossplatformSettings();
// Assert
mockCliProjectSetup.Verify(m => m.SetJobWorkerCount(), Times.Once);
}
[Test]
public void VerifySetJobWorkerCount_InvalidValue()
{
// Arrange
var args = new[] { $"-jobworkercount=1000" };
var mockPlatformSettings = new PlatformSettings();
var mockCliProjectSetup = new CliProjectSetup(args, mockPlatformSettings);
mockCliProjectSetup.ParseCommandLineArgs();
// Act/Assert
Assert.Throws<ArgumentOutOfRangeException>(() => mockCliProjectSetup.SetJobWorkerCount());
}
[Test]
public void VerifySetJobWorkerCount_NotCalled()
{
// Arrange
var args = new[] { $"-jobworkercount=-1" };
var mockPlatformSettings = new Mock<PlatformSettings>();
var mockCliProjectSetup = new Mock<CliProjectSetup>(args, mockPlatformSettings.Object)
{
CallBase = true
};
mockCliProjectSetup.Object.ParseCommandLineArgs();
// Act
mockCliProjectSetup.Object.ConfigureCrossplatformSettings();
// Assert
mockCliProjectSetup.Verify(m => m.SetJobWorkerCount(), Times.Never);
}
#endif
}

Просмотреть файл

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7816e62605bb5c947b596da83c00ae86
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -1,17 +1,12 @@
using System.Collections;
using System.Collections.Generic;
using com.unity.cliprojectsetup;
#if NUGET_MOQ_AVAILABLE
using Moq;
#endif
using NUnit.Framework;
using UnityEditor.PackageManager.Requests;
using UnityEngine;
using UnityEngine.TestTools;
public class CliProjectSetupEditorTests
public class PlaformSettingsTests
{
private readonly string UnavailableMsg = "unavailable";
private readonly string unavailableMsg = "unavailable";
private CurrentSettings currentSettings;
private PlatformSettings platformSettings;
@ -26,15 +21,14 @@ public class CliProjectSetupEditorTests
public void VerifyGetPackageUnderTestVersionInfo_PackageUnderTestRevision_NotEmpty()
{
// Arrange
platformSettings.PackageUnderTestName = @"com.unity.test-framework";
platformSettings.PackageUnderTestName = @"com.unity.cli-project-setup";
// Act
platformSettings.GetPackageUnderTestVersionInfo(currentSettings);
// Assert
Assert.AreNotEqual(UnavailableMsg, currentSettings.PackageUnderTestName, nameof(currentSettings.PackageUnderTestName));
Assert.AreNotEqual(UnavailableMsg, currentSettings.PackageUnderTestRevision, nameof(currentSettings.PackageUnderTestRevision));
Assert.AreNotEqual(UnavailableMsg, currentSettings.PackageUnderTestVersion, nameof(currentSettings.PackageUnderTestVersion));
Assert.AreNotEqual(unavailableMsg, currentSettings.PackageUnderTestName, nameof(currentSettings.PackageUnderTestName));
Assert.AreNotEqual(unavailableMsg, currentSettings.PackageUnderTestVersion, nameof(currentSettings.PackageUnderTestVersion));
}
[Test]
@ -48,10 +42,10 @@ public class CliProjectSetupEditorTests
platformSettings.GetPackageUnderTestVersionInfo(currentSettings);
// Assert
Assert.AreEqual(UnavailableMsg, currentSettings.PackageUnderTestRevision, nameof(currentSettings.PackageUnderTestRevision));
Assert.AreEqual(UnavailableMsg, currentSettings.PackageUnderTestVersion, nameof(currentSettings.PackageUnderTestVersion));
Assert.AreEqual(UnavailableMsg, currentSettings.PackageUnderTestRevisionDate, nameof(currentSettings.PackageUnderTestRevisionDate));
Assert.AreEqual(UnavailableMsg, currentSettings.PackageUnderTestBranch, nameof(currentSettings.PackageUnderTestBranch));
Assert.AreEqual(unavailableMsg, currentSettings.PackageUnderTestRevision, nameof(currentSettings.PackageUnderTestRevision));
Assert.AreEqual(unavailableMsg, currentSettings.PackageUnderTestVersion, nameof(currentSettings.PackageUnderTestVersion));
Assert.AreEqual(unavailableMsg, currentSettings.PackageUnderTestRevisionDate, nameof(currentSettings.PackageUnderTestRevisionDate));
Assert.AreEqual(unavailableMsg, currentSettings.PackageUnderTestBranch, nameof(currentSettings.PackageUnderTestBranch));
}
#if NUGET_MOQ_AVAILABLE
@ -62,7 +56,7 @@ public class CliProjectSetupEditorTests
platformSettings.PackageUnderTestName = string.Empty;
var testPackageName = "testPackage";
platformSettings.PackageUnderTestName = testPackageName;
platformSettings.PackageUnderTestRevision = UnavailableMsg;
platformSettings.PackageUnderTestRevision = unavailableMsg;
var mockPackageManagerClient = new Mock<IPackageManagerClient>();
mockPackageManagerClient.Setup(pmc => pmc.PackageUnderTestPresentInProject(testPackageName)).Returns(true);
@ -72,7 +66,7 @@ public class CliProjectSetupEditorTests
platformSettings.GetPackageUnderTestVersionInfo(currentSettings);
// Assert
Assert.AreEqual(UnavailableMsg, currentSettings.PackageUnderTestRevision, nameof(currentSettings.PackageUnderTestRevision));
Assert.AreEqual(unavailableMsg, currentSettings.PackageUnderTestRevision, nameof(currentSettings.PackageUnderTestRevision));
}
[Test]
@ -82,7 +76,7 @@ public class CliProjectSetupEditorTests
platformSettings.PackageUnderTestRevisionDate = string.Empty;
var testPackageName = "testPackage";
platformSettings.PackageUnderTestName = testPackageName;
platformSettings.PackageUnderTestRevision = UnavailableMsg;
platformSettings.PackageUnderTestRevision = unavailableMsg;
var mockPackageManagerClient = new Mock<IPackageManagerClient>();
mockPackageManagerClient.Setup(pmc => pmc.PackageUnderTestPresentInProject(testPackageName)).Returns(true);
@ -92,7 +86,7 @@ public class CliProjectSetupEditorTests
platformSettings.GetPackageUnderTestVersionInfo(currentSettings);
// Assert
Assert.AreEqual(UnavailableMsg, currentSettings.PackageUnderTestRevisionDate, nameof(currentSettings.PackageUnderTestRevisionDate));
Assert.AreEqual(unavailableMsg, currentSettings.PackageUnderTestRevisionDate, nameof(currentSettings.PackageUnderTestRevisionDate));
}
[Test]
@ -102,7 +96,7 @@ public class CliProjectSetupEditorTests
platformSettings.PackageUnderTestBranch = string.Empty;
var testPackageName = "testPackage";
platformSettings.PackageUnderTestName = testPackageName;
platformSettings.PackageUnderTestRevision = UnavailableMsg;
platformSettings.PackageUnderTestRevision = unavailableMsg;
var mockPackageManagerClient = new Mock<IPackageManagerClient>();
mockPackageManagerClient.Setup(pmc => pmc.PackageUnderTestPresentInProject(testPackageName)).Returns(true);
@ -112,7 +106,7 @@ public class CliProjectSetupEditorTests
platformSettings.GetPackageUnderTestVersionInfo(currentSettings);
// Assert
Assert.AreEqual(UnavailableMsg, currentSettings.PackageUnderTestBranch, nameof(currentSettings.PackageUnderTestBranch));
Assert.AreEqual(unavailableMsg, currentSettings.PackageUnderTestBranch, nameof(currentSettings.PackageUnderTestBranch));
}
#endif
}

Просмотреть файл

@ -1,5 +1,5 @@
{
"name": "com.unity.cliprojectsetup.tests",
"name": "com.unity.cliprojectsetup.editor.tests",
"rootNamespace": "",
"references": [
"UnityEngine.TestRunner",
@ -21,12 +21,12 @@
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [
{
"name": "nuget.moq",
"expression": "1.0.0",
"define": "NUGET_MOQ_AVAILABLE"
}
],
"versionDefines": [
{
"name": "nuget.moq",
"expression": "1.0.0",
"define": "NUGET_MOQ_AVAILABLE"
}
],
"noEngineReferences": false
}

Просмотреть файл

@ -1,8 +1,8 @@
{
"name": "com.unity.cli-project-setup",
"displayName": "Unity CLI Project Setup",
"version": "1.1.0-preview",
"unity": "2020.3",
"version": "1.2.0-preview",
"unity": "2021.3",
"description": "Provides a command line parser and options to set build, player, and other Unity settings when running Unity from the command line.",
"dependencies": {
"com.unity.test.metadata-manager": "0.3.0-preview"