@@ -221,6 +221,16 @@ project.ext {
221
221
interactiveModeTestsEnabled =
222
222
findProperty(" INTERACTIVE_MODE_TESTS_ENABLED" , " 1" ) == " 1"
223
223
224
+ // Whether to continue to the next test if one fails.
225
+ continueOnFailForTestsEnabled =
226
+ findProperty(" CONTINUE_ON_FAIL_FOR_TESTS_ENABLED" , " 0" ) == " 1"
227
+
228
+ // List of failed tests
229
+ failedTests = []
230
+
231
+ // List of passed tests
232
+ passedTests = []
233
+
224
234
// Directory for intermediate and final build outputs.
225
235
buildDir = new File (scriptDirectory, " build" )
226
236
// Directory for external tools.
@@ -922,6 +932,9 @@ Task createNUnitTask(String name, String description, File testDll,
922
932
args ([sprintf (" -output:%s" , logFile. absolutePath),
923
933
sprintf (" -xml:%s" , xmlLogFile. absolutePath),
924
934
testDll. absolutePath])
935
+ // TODO: Support continueOnFailForTestsEnabled
936
+ // NUnit test is currently broken. Need to fix it before implementing
937
+ // continueOnFailForTestsEnabled
925
938
}
926
939
}
927
940
}
@@ -935,19 +948,21 @@ Task createNUnitTask(String name, String description, File testDll,
935
948
* @param dependsOn Tasks this depends upon.
936
949
* @param executable Executable to run.
937
950
* @param arguments Arguments for the executable.
951
+ * @param continueOnFail Whether to ignore non-zero return code and continue.
938
952
*
939
953
* @returns Task which runs the specified executable.
940
954
*/
941
955
Task createExecTask (String name , String description ,
942
956
Iterable<Task > dependsOn , File executableToRun ,
943
- Iterable<String > arguments ) {
957
+ Iterable<String > arguments , Boolean continueOnFail = false ) {
944
958
Task execTask = tasks. create(name : name,
945
959
description : description,
946
960
type : Exec ,
947
961
dependsOn : dependsOn)
948
962
execTask. with {
949
963
executable executableToRun
950
964
args arguments
965
+ ignoreExitValue continueOnFail
951
966
}
952
967
return execTask
953
968
}
@@ -989,6 +1004,7 @@ Task createEmptyTask(String taskName, String summary,
989
1004
* @param batchMode Whether to run Unity in batch mode.
990
1005
* @param createTaskClosure Optional task used to start Unity, this must
991
1006
* conform to createExecTask()
1007
+ * @param continueOnFail Whether to ignore non-zero return code and continue.
992
1008
*
993
1009
* @returns Task which executes Unity.
994
1010
* The following extended properties are set on the task:
@@ -1000,7 +1016,8 @@ Task createEmptyTask(String taskName, String summary,
1000
1016
Task createUnityTask (String taskName , String summary ,
1001
1017
Iterable<Task > dependsOn , String projectName ,
1002
1018
File projectContainerDir , Iterable<String > arguments ,
1003
- Boolean batchMode , createTaskClosure ) {
1019
+ Boolean batchMode , createTaskClosure ,
1020
+ Boolean continueOnFail = false ) {
1004
1021
Boolean createProject = summary == " create"
1005
1022
File logFile = new File (projectContainerDir,
1006
1023
sprintf (" %s_%s.log" , projectName, summary))
@@ -1021,8 +1038,13 @@ Task createUnityTask(String taskName, String summary,
1021
1038
if (! createTaskClosure) {
1022
1039
createTaskClosure = {
1023
1040
String name, String description, Iterable<Task > depends,
1024
- File executable, Iterable<String > args ->
1025
- return createExecTask(name, description, depends, executable, args)
1041
+ File executable, Iterable<String > args, Boolean contOnFail->
1042
+ return createExecTask(name,
1043
+ description,
1044
+ depends,
1045
+ executable,
1046
+ args,
1047
+ contOnFail)
1026
1048
}
1027
1049
}
1028
1050
@@ -1036,7 +1058,8 @@ Task createUnityTask(String taskName, String summary,
1036
1058
summary, projectName),
1037
1059
dependsOn,
1038
1060
project. ext. unityExe,
1039
- executeArguments)
1061
+ executeArguments,
1062
+ continueOnFail)
1040
1063
}
1041
1064
unityTask. with {
1042
1065
outputs. files files(logFile)
@@ -1173,8 +1196,15 @@ Task createUnityTestTask(String taskName, String description,
1173
1196
setupTestProject. ext. projectDir. name,
1174
1197
setupTestProject. ext. containerDir,
1175
1198
additionalArguments, batchMode,
1176
- createTaskClosure)
1199
+ createTaskClosure,
1200
+ true )
1177
1201
testTask. description = description
1202
+ testTask. with {
1203
+ finalizedBy reportAllTestsResult
1204
+ doLast {
1205
+ EvaluateTestResult (testTask)
1206
+ }
1207
+ }
1178
1208
1179
1209
// Create a clean task
1180
1210
Task cleanTestTask = tasks. create(name : sprintf (" clean%s" , taskName),
@@ -1267,13 +1297,15 @@ Task createInstallPythonPackageTask(String taskName, String description,
1267
1297
* @param script Python script to run.
1268
1298
* @param arguments Command line arguments to pass to the Python script.
1269
1299
* @param packages Optional Python packages to install.
1300
+ * @param continueOnFail Whether to ignore non-zero return code and continue.
1270
1301
*
1271
1302
* @returns Task which executes Python.
1272
1303
*/
1273
1304
Task createPythonTask (String taskName , String description ,
1274
1305
Iterable<Task > dependsOn ,
1275
1306
File script , Iterable<String > arguments ,
1276
- Iterable<String > packages ) {
1307
+ Iterable<String > packages ,
1308
+ Boolean continueOnFail = false ) {
1277
1309
List<Task > installPackagesTask = []
1278
1310
if (packages) {
1279
1311
installPackagesTask = [
@@ -1289,6 +1321,7 @@ Task createPythonTask(String taskName, String description,
1289
1321
description : sprintf (" Run Python to %s" , description),
1290
1322
type : Exec ,
1291
1323
dependsOn : (dependsOn + installPackagesTask + [" build_envs" ])). with {
1324
+ ignoreExitValue continueOnFail
1292
1325
executable project. ext. pythonExe
1293
1326
args ([script. absolutePath] + arguments)
1294
1327
}
@@ -1389,37 +1422,103 @@ task testDownloadArtifacts(type: GradleBuild) {
1389
1422
dir " source/AndroidResolver/scripts"
1390
1423
}
1391
1424
1392
- createPythonTask(
1425
+ /*
1426
+ * Evaluate previously-ran test result
1427
+ *
1428
+ * @param testTask Task for previously-ran test
1429
+ */
1430
+ void EvaluateTestResult (Task testTask ) {
1431
+ if (testTask. class. simpleName. startsWith(" Exec" )) {
1432
+ if (testTask. execResult. exitValue != 0 ) {
1433
+ String errorMsg = sprintf (" Test %s FAILED" , testTask. name)
1434
+ println sprintf (" ::error::%s" , errorMsg)
1435
+ project. ext. failedTests. add(testTask. name)
1436
+ if (! project. ext. continueOnFailForTestsEnabled) {
1437
+ throw new GradleException (errorMsg)
1438
+ }
1439
+ } else {
1440
+ println sprintf (" ::debug::Test %s PASSED" , testTask. name, testTask. execResult. exitValue)
1441
+ project. ext. passedTests. add(testTask. name)
1442
+ }
1443
+ }
1444
+ }
1445
+
1446
+ Task reportAllTestsResult = tasks. create (
1447
+ name : " reportAllTestsResult" ,
1448
+ description : " Report the result all every test that has been run" ,
1449
+ type : Task
1450
+ ). with {
1451
+ doLast {
1452
+ project. ext. passedTests. each {
1453
+ println sprintf (" Test %s PASSED" , it)
1454
+ }
1455
+ project. ext. failedTests. each {
1456
+ println sprintf (" Test %s FAILED" , it)
1457
+ }
1458
+ if (project. ext. failedTests. size > 0 ) {
1459
+ throw new GradleException (
1460
+ sprintf (" %d out of %d tests failed" ,
1461
+ project. ext. failedTests. size,
1462
+ project. ext. failedTests. size + project. ext. passedTests. size))
1463
+ }
1464
+ }
1465
+ }
1466
+
1467
+ Task testPackageUploader = createPythonTask(
1393
1468
" testPackageUploader" ,
1394
1469
" Test the unity_asset_uploader.py application." ,
1395
1470
[],
1396
1471
new File (project. ext. unityAssetUploaderDir, " unity_asset_uploader_test.py" ),
1397
1472
[],
1398
- [])
1473
+ [],
1474
+ true ). with {
1475
+ finalizedBy reportAllTestsResult
1476
+ doLast {
1477
+ EvaluateTestResult (testPackageUploader)
1478
+ }
1479
+ }
1399
1480
1400
- createPythonTask(
1481
+ Task testExportUnityPackage = createPythonTask(
1401
1482
" testExportUnityPackage" ,
1402
1483
" Test the export_unity_package.py application" ,
1403
1484
[],
1404
1485
new File (project. ext. exportUnityPackageDir, " export_unity_package_test.py" ),
1405
1486
[],
1406
- exportUnityPackageRequirements)
1487
+ exportUnityPackageRequirements,
1488
+ true ). with {
1489
+ finalizedBy reportAllTestsResult
1490
+ doLast {
1491
+ EvaluateTestResult (testExportUnityPackage)
1492
+ }
1493
+ }
1407
1494
1408
- createPythonTask(
1495
+ Task testGenGuids = createPythonTask(
1409
1496
" testGenGuids" ,
1410
1497
" Test the gen_guids.py application" ,
1411
1498
[],
1412
1499
new File (project. ext. exportUnityPackageDir, " gen_guids_test.py" ),
1413
1500
[],
1414
- [" absl-py" ])
1501
+ [" absl-py" ],
1502
+ true ). with {
1503
+ finalizedBy reportAllTestsResult
1504
+ doLast {
1505
+ EvaluateTestResult (testGenGuids)
1506
+ }
1507
+ }
1415
1508
1416
- createPythonTask(
1509
+ Task testImportUnityPackage = createPythonTask(
1417
1510
" testImportUnityPackage" ,
1418
1511
" Test the import_unity_package.py application" ,
1419
1512
[],
1420
1513
new File (project. ext. importUnityPackageDir, " import_unity_package_test.py" ),
1421
1514
[],
1422
- [" absl-py" ])
1515
+ [" absl-py" ],
1516
+ true ). with {
1517
+ finalizedBy reportAllTestsResult
1518
+ doLast {
1519
+ EvaluateTestResult (testImportUnityPackage)
1520
+ }
1521
+ }
1423
1522
1424
1523
task updateEmbeddedGradleWrapper (type : Zip ) {
1425
1524
description " Update the gradle wrapper in gradle-template.zip"
@@ -1841,7 +1940,7 @@ createUnityTestBatchAndNonBatch(
1841
1940
" source/VersionHandlerImpl/test/webrequest" ),
1842
1941
[], [],
1843
1942
{ String name, String description, Iterable<Task > depends,
1844
- File executable, Iterable<String > args ->
1943
+ File executable, Iterable<String > args, Boolean continueOnFail ->
1845
1944
Iterable<String > runnerArgs = [executable. absolutePath] + args
1846
1945
return createPythonTask(
1847
1946
name, description, depends,
@@ -1852,7 +1951,7 @@ createUnityTestBatchAndNonBatch(
1852
1951
" test" ),
1853
1952
" webrequest_launcher.py" ),
1854
1953
runnerArgs,
1855
- [])
1954
+ [], continueOnFail )
1856
1955
})
1857
1956
1858
1957
createUnityTestBatchAndNonBatch(
0 commit comments