Skip to content

Commit d20d6f2

Browse files
author
Stewart Miles
committed
Restored interactive mode testing.
At some point I disabled interactive mode testing likely due to dialogs popping up and prompting the user. This change re-enables interactive mode testing and moves all dialog pop ups to a class that can be disabled via a command line flag. In addition, dialog behavior can be mocked in unit tests removing duplicate code from the measurement unit test. Interactive tests can be disabled from the command line by using the INTERACTIVE_MODE_TESTS_ENABLED property... ./gradlew -PINTERACTIVE_MODE_TESTS_ENABLED=0 test Change-Id: I9446359cd38d0b833aa8a020f017c864e4d70e60
1 parent 4b00594 commit d20d6f2

14 files changed

+305
-256
lines changed

build.gradle

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ project.ext {
172172
// Whether debug symbols should be included.
173173
debugEnabled = findProperty("NDEBUG") == null
174174

175+
// Whether interactive mode tests are enabled.
176+
interactiveModeTestsEnabled =
177+
findProperty("INTERACTIVE_MODE_TESTS_ENABLED", "1") == "1"
178+
175179
// Directory for intermediate and final build outputs.
176180
buildDir = new File(scriptDirectory, "build")
177181
// Directory for testing.
@@ -223,6 +227,8 @@ project.ext {
223227

224228
// Common arguments used to execute Unity in batch mode.
225229
unityBatchModeArguments = ["-batchmode", "-nographics"]
230+
// Common arguments used to execute Unity in interactive mode.
231+
unityInteractiveModeArguments = ["-gvh_noninteractive"]
226232
// Extension for Unity asset metadata files.
227233
unityMetadataExtension = ".meta"
228234
// Extension for debug files.
@@ -848,6 +854,28 @@ Task createExecTask(String name, String description,
848854
return execTask
849855
}
850856

857+
/*
858+
* Create a task that does nothing.
859+
*
860+
* @param taskName Name of the task to create.
861+
* @param summary Description of the task.
862+
* @param dependsOn Dependencies of the new task.
863+
*
864+
* @returns Task that does nothing.
865+
*/
866+
Task createEmptyTask(String taskName, String summary,
867+
Iterable<Task> dependsOn) {
868+
Task emptyTask = tasks.create(name: taskName,
869+
description: sprintf("(disabled) %s", summary),
870+
dependsOn: dependsOn)
871+
emptyTask.with {
872+
doLast {
873+
logger.info(sprintf("%s disabled", taskName))
874+
}
875+
}
876+
return emptyTask
877+
}
878+
851879
/*
852880
* Create a task to execute Unity.
853881
*
@@ -881,7 +909,11 @@ Task createUnityTask(String taskName, String summary,
881909
File projectDir = new File(projectContainerDir, projectName)
882910
List<String> executeArguments = []
883911

884-
if (batchMode) executeArguments += unityBatchModeArguments
912+
if (batchMode) {
913+
executeArguments += project.ext.unityBatchModeArguments
914+
} else {
915+
executeArguments += project.ext.unityInteractiveModeArguments
916+
}
885917
executeArguments += [
886918
"-logFile", logFile.absolutePath,
887919
createProject ? "-createProject" : "-projectPath", projectDir.absolutePath]
@@ -896,13 +928,18 @@ Task createUnityTask(String taskName, String summary,
896928
}
897929
}
898930

899-
Task unityTask = createTaskClosure(taskName,
900-
sprintf(
901-
"Run Unity to %s (project: %s)",
902-
summary, projectName),
903-
dependsOn,
904-
project.ext.unityExe,
905-
executeArguments)
931+
Task unityTask
932+
if (!batchMode && !project.ext.interactiveModeTestsEnabled) {
933+
unityTask = createEmptyTask(taskName, summary, dependsOn)
934+
} else {
935+
unityTask = createTaskClosure(taskName,
936+
sprintf(
937+
"Run Unity to %s (project: %s)",
938+
summary, projectName),
939+
dependsOn,
940+
project.ext.unityExe,
941+
executeArguments)
942+
}
906943
unityTask.with {
907944
inputs.files fileTree(projectDir)
908945
outputs.files files(logFile)
@@ -1055,8 +1092,8 @@ Task createUnityTestBatchAndNonBatch(String taskName, String description,
10551092
createUnityTestTask(
10561093
sprintf("%sInteractiveMode", taskName),
10571094
sprintf("%s (Interactive Mode)", description),
1058-
dependsOn, testScriptsDir, additionalArguments,
1059-
true, createTaskClosure)])
1095+
dependsOn, testScriptsDir, additionalArguments, false,
1096+
createTaskClosure)])
10601097
}
10611098

10621099
Task compileResolverLibTests = createXbuildTask(

source/AndroidResolver/AndroidResolver.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
<Folder Include="Properties\" />
5454
</ItemGroup>
5555
<ItemGroup>
56-
<Compile Include="src\AlertModal.cs" />
5756
<Compile Include="src\AndroidAbis.cs" />
5857
<Compile Include="src\AndroidSdkManager.cs" />
5958
<Compile Include="src\AndroidXmlDependencies.cs" />

source/AndroidResolver/src/AlertModal.cs

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

source/AndroidResolver/src/AndroidSdkManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ public void InstallPackages(HashSet<AndroidSdkPackageNameVersion> packages,
937937
var packagesString = AndroidSdkPackageNameVersion.ListToString(packages);
938938
// TODO: Remove this dialog when the package manager provides feedback while
939939
// downloading.
940-
bool installPackage = UnityEditor.EditorUtility.DisplayDialog(
940+
var installPackage = Dialog.Display(
941941
"Missing Android SDK packages",
942942
String.Format(
943943
"Android SDK packages need to be installed:\n" +
@@ -947,8 +947,8 @@ public void InstallPackages(HashSet<AndroidSdkPackageNameVersion> packages,
947947
"which may lead you to think Unity has hung / crashed. Would you like " +
948948
"to wait for these package to be installed?",
949949
packagesString),
950-
"Yes", cancel: "No");
951-
if (!installPackage) {
950+
Dialog.Option.Selected0, "Yes", "No");
951+
if (installPackage == Dialog.Option.Selected0) {
952952
PlayServicesResolver.Log(
953953
"User cancelled installation of Android SDK tools package.",
954954
level: LogLevel.Warning);

source/AndroidResolver/src/GradleResolver.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,14 +702,14 @@ private void FindAndResolveConflicts() {
702702
// possibly clean up the old versions automatically.
703703
if (Dependency.versionComparer.Compare(conflictingVersions[0],
704704
currentVersion) >= 0) {
705-
if (EditorUtility.DisplayDialog(
705+
if (Dialog.Display(
706706
"Resolve Conflict?",
707707
warningMessage +
708708
"\n" +
709709
"The conflicting libraries are older than the library managed by " +
710710
"the Android Resolver. Would you like to remove the old libraries " +
711711
"to resolve the conflict?",
712-
"Yes", "No")) {
712+
Dialog.Option.Selected0, "Yes", "No") == Dialog.Option.Selected0) {
713713
var deleteFailures = new List<string>();
714714
foreach (var filename in conflict.Value) {
715715
deleteFailures.AddRange(

source/AndroidResolver/src/JavaUtilities.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,12 @@ private static string FindJavaTool(string javaTool)
142142
if (!String.IsNullOrEmpty(javaHome)) {
143143
toolPath = JavaHomeBinaryPath(javaTool);
144144
if (String.IsNullOrEmpty(toolPath)) {
145-
EditorUtility.DisplayDialog(
145+
Dialog.Display(
146146
"Android Resolver",
147147
String.Format("{0} environment references a directory ({1}) that does " +
148148
"not contain {2} which is required to process Android " +
149149
"libraries.", JAVA_HOME, javaHome, javaTool),
150-
"OK");
150+
Dialog.Option.Selected0, "OK");
151151
throw new ToolNotFoundException(
152152
String.Format("{0} not found, {1} references incomplete Java distribution.",
153153
javaTool, javaHome));
@@ -156,14 +156,14 @@ private static string FindJavaTool(string javaTool)
156156
} else {
157157
toolPath = CommandLine.FindExecutable(javaTool);
158158
if (!File.Exists(toolPath)) {
159-
EditorUtility.DisplayDialog(
159+
Dialog.Display(
160160
"Android Resolver",
161161
String.Format("Unable to find {0} in the system path. This tool is " +
162162
"required to process Android libraries. Please configure " +
163163
"your JDK location under the " +
164164
"'Unity Preferences > External Tools' menu.",
165165
javaTool),
166-
"OK");
166+
Dialog.Option.Selected0, "OK");
167167
throw new ToolNotFoundException(javaTool + " not found.");
168168
}
169169
}

0 commit comments

Comments
 (0)