From: Ben Soares Date: Wed, 26 Apr 2023 01:32:55 +0000 (+0100) Subject: JAL-629 JAL-4167 Added args to tests. Fixed potential --headless arg bug. Added testT... X-Git-Tag: Release_2_11_4_0~375 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=98abc3db2b1699262f7de567d865393b4aa91a4c;p=jalview.git JAL-629 JAL-4167 Added args to tests. Fixed potential --headless arg bug. Added testTaskN tasks for separated tests, and code to make summary report when running normal test task. --- diff --git a/build.gradle b/build.gradle index 7c08c2b..6c5c7a5 100644 --- a/build.gradle +++ b/build.gradle @@ -1732,50 +1732,161 @@ task prepare { compileJava.dependsOn prepare run.dependsOn compileJava -//run.dependsOn prepare +compileTestJava.dependsOn compileJava -//testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir -test { - dependsOn prepare - - if (useClover) { - dependsOn cloverClasses - } else { //? - dependsOn compileJava //? +ext.testsFailed = false +/* testTask0 is the main test task */ +task testTask0(type: Test) { + useTestNG() { + includeGroups testng_groups.split(",") + excludeGroups testng_excluded_groups.split(",") + tasks.withType(Test).matching {it.name.startsWith("testTask") && it.name != name}.all {t -> excludeGroups t.name} + preserveOrder true + useDefaultListeners=true } +} +/* separated tests */ +task testTask1(type: Test) { useTestNG() { - includeGroups testng_groups - excludeGroups testng_excluded_groups + includeGroups name + excludeGroups testng_excluded_groups.split(",") + tasks.withType(Test).matching {it.name.startsWith("testTask") && it.name != name}.all {t -> excludeGroups t.name} preserveOrder true useDefaultListeners=true } +} - maxHeapSize = "1024m" +/* + * adapted from https://medium.com/@wasyl/pretty-tests-summary-in-gradle-744804dd676c + * to summarise test results from all Test tasks + */ +/* START of test tasks results summary */ +import groovy.time.TimeCategory +import org.gradle.api.tasks.testing.logging.TestExceptionFormat +import org.gradle.api.tasks.testing.logging.TestLogEvent + +rootProject.ext.testsResults = [] // Container for tests summaries + +allprojects { project -> + tasks.withType(Test).matching {t -> t.getName().startsWith("testTask")}.all { testTask -> + + // run main tests first +// if (!testTask.name.equals("testTask0")) +// testTask.mustRunAfter testTask0 + + testTask.testLogging { logging -> + events TestLogEvent.FAILED, + TestLogEvent.SKIPPED, + TestLogEvent.STANDARD_OUT, + TestLogEvent.STANDARD_ERROR + + exceptionFormat TestExceptionFormat.FULL + showExceptions true + showCauses true + showStackTraces true + } - workingDir = jalviewDir - def testLaf = project.findProperty("test_laf") - if (testLaf != null) { - println("Setting Test LaF to '${testLaf}'") - systemProperty "laf", testLaf - } - def testHiDPIScale = project.findProperty("test_HiDPIScale") - if (testHiDPIScale != null) { - println("Setting Test HiDPI Scale to '${testHiDPIScale}'") - systemProperty "sun.java2d.uiScale", testHiDPIScale - } - sourceCompatibility = compile_source_compatibility - targetCompatibility = compile_target_compatibility - jvmArgs += additional_compiler_args + ignoreFailures = true // Always try to run all tests for all modules - doFirst { + afterSuite { desc, result -> + + if (desc.parent) return // Only summarize results for whole modules + + String summary = "${testTask.project.name}:${testTask.name} results: ${result.resultType} " + + "(" + + "${result.testCount} tests, " + + "${result.successfulTestCount} successes, " + + "${result.failedTestCount} failures, " + + "${result.skippedTestCount} skipped" + + ") " + + "in ${TimeCategory.minus(new Date(result.endTime), new Date(result.startTime))}" + + "\n" + + "Report file: ${testTask.reports.html.entryPoint}" + + // Add reports in `testsResults`, keep failed suites at the end + if (result.resultType == TestResult.ResultType.SUCCESS) { + rootProject.ext.testsResults.add(0, summary) + } else { + rootProject.ext.testsResults += summary + } + if (result.resultType == TestResult.ResultType.FAILURE) { + testsFailed = true + } + } + + // from original test task if (useClover) { - println("Running tests " + (useClover?"WITH":"WITHOUT") + " clover") + dependsOn cloverClasses + } else { //? + dependsOn compileJava //? + } + maxHeapSize = "1024m" + + workingDir = jalviewDir + def testLaf = project.findProperty("test_laf") + if (testLaf != null) { + println("Setting Test LaF to '${testLaf}'") + systemProperty "laf", testLaf } + def testHiDPIScale = project.findProperty("test_HiDPIScale") + if (testHiDPIScale != null) { + println("Setting Test HiDPI Scale to '${testHiDPIScale}'") + systemProperty "sun.java2d.uiScale", testHiDPIScale + } + sourceCompatibility = compile_source_compatibility + targetCompatibility = compile_target_compatibility + jvmArgs += additional_compiler_args + + doFirst { + if (useClover) { + println("Running tests " + (useClover?"WITH":"WITHOUT") + " clover") + } + } + } } +gradle.buildFinished { + def allResults = rootProject.ext.testsResults + + if (!allResults.isEmpty()) { + printResults allResults + } +} + +private static void printResults(allResults) { + def maxLength = allResults*.readLines().flatten().collect { it.length() }.max() + + println "┌${"${"─" * maxLength}"}┐" + + println allResults.collect { + it.readLines().collect { + "│" + it + " " * (maxLength - it.length()) + "│" + }.join("\n") + }.join("\n├${"${"─" * maxLength}"}┤\n") + + println "└${"${"─" * maxLength}"}┘" +} +/* END of test tasks results summary */ + +task verifyTestStatus { + doLast { + if (testsFailed) { + throw new GradleException("There were failing tests!") + } + } +} + +test { + dependsOn tasks.withType(Test).matching {t -> t.getName().startsWith("testTask")} + finalizedBy verifyTestStatus + + // not running tests in this task + exclude "**/*" +} + task compileLinkCheck(type: JavaCompile) { options.fork = true diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index e384a0b..6c04be7 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -466,7 +466,7 @@ public class Jalview { System.setProperty("java.awt.headless", "true"); // new - headlessArg = argparser.getBool(Arg.HEADLESS); + headlessArg = bootstrapArgs.getBoolean(Arg.HEADLESS); } if (aparser.contains("nodisplay") || aparser.contains("nogui") || aparser.contains("headless")) diff --git a/test/jalview/bin/CommandsTest2.java b/test/jalview/bin/CommandsTest2.java index 535eb78..29fbc86 100644 --- a/test/jalview/bin/CommandsTest2.java +++ b/test/jalview/bin/CommandsTest2.java @@ -57,7 +57,7 @@ public class CommandsTest2 @Test( groups = - { "Functional" }, + { "Functional", "testTask1" }, dataProvider = "structureOpeningArgsParams", singleThreaded = true) public void structureOpeningArgsTest(String cmdLine, int seqNum, @@ -101,9 +101,6 @@ public class CommandsTest2 int dcount = 0; for (AlignmentAnnotation aa : aas) { - System.err.println("##### DIAGNOSIS: annotation " + ++dcount - + " is labelled '" + aa.label + "'"); - System.err.println("# " + aa.annotationId + ": " + aa.toString()); if (aa.visible) visibleAnn++; } @@ -181,9 +178,9 @@ public class CommandsTest2 + "--noannotations " + "--nossannotations " + "--props=test/jalview/bin/commandsTest2.jvprops1 ", 15, 0, 1 }, - { "--props=test/jalview/bin/commandsTest.jvprops --argfile=test/jalview/bin/commandsTest2.argfile1 ", + { "--nonews --nosplash --debug --nowebservicediscovery --props=test/jalview/bin/commandsTest.jvprops --argfile=test/jalview/bin/commandsTest2.argfile1 ", 16, 19, 3 }, - { "--props=test/jalview/bin/commandsTest.jvprops --argfile=test/jalview/bin/commandsTest2.argfile2 ", + { "--nonews --nosplash --debug --nowebservicediscovery --props=test/jalview/bin/commandsTest.jvprops --argfile=test/jalview/bin/commandsTest2.argfile2 ", 16, 0, 2 }, // }; diff --git a/test/jalview/bin/commandsTest2.argfile1 b/test/jalview/bin/commandsTest2.argfile1 index e46b746..1dc9e30 100644 --- a/test/jalview/bin/commandsTest2.argfile1 +++ b/test/jalview/bin/commandsTest2.argfile1 @@ -1,6 +1,3 @@ ---debug ---nonews ---nosplash --substitutions --append=examples/test_fab41.result/sample.a2m --annotations