Apache Solr open-source search software
Add some support for -Ptests.verbose mode when streams are dumped to the console. This is constrained by gradle's runner but is better than nothing.
Dawid Weiss1021f04d1a7c
diff --git a/gradle/testing/defaults-tests.gradle b/gradle/testing/defaults-tests.gradleindex c454b5c52a7..3dcf76cc0c6 100644--- a/gradle/testing/defaults-tests.gradle+++ b/gradle/testing/defaults-tests.gradle@@ -1,8 +1,12 @@import org.apache.tools.ant.taskdefs.condition.Osimport org.gradle.api.tasks.testing.logging.*+def verboseModeHookInstalled = false+allprojects {plugins.withType(JavaPlugin) {+ def verboseMode = propertyOrDefault("tests.verbose", "false")+project.ext {testsWorkDir = file("${buildDir}/tmp/tests-cwd")testsTmpDir = file("${buildDir}/tmp/tests-tmp")@@ -10,13 +14,33 @@ allprojects {commonSolrDir = project(":solr").projectDir}+ // If we're running in verbose mode and:+ // 1) worker count > 1+ // 2) number of 'test' tasks in the build is > 1+ // then the output would very likely be mangled on the+ // console. Fail and let the user know what to do.+ if (verboseMode && !verboseModeHookInstalled) {+ verboseModeHookInstalled = true+ if (gradle.startParameter.maxWorkerCount > 1) {+ gradle.taskGraph.whenReady { graph ->+ def testTasks = graph.allTasks.findAll { task -> task instanceof Test }+ if (testTasks.size() > 1) {+ throw new GradleException("Run your tests in verbose mode only with --max-workers=1 option passed to gradle.")+ }+ }+ }+ }+test {- workingDir testsWorkDir+ if (verboseMode) {+ maxParallelForks = 1+ } else {+ maxParallelForks = propertyOrDefault("tests.jvms", (int) Math.max(1, Math.min(Runtime.runtime.availableProcessors() / 2.0, 4.0)))+ }+ workingDir testsWorkDiruseJUnit()- maxParallelForks = propertyOrDefault("tests.jvms", (int) Math.max(1, Math.min(Runtime.runtime.availableProcessors() / 2.0, 4.0)))-minHeapSize = "256m"maxHeapSize = "512m"@@ -44,12 +68,26 @@ allprojects {}// Set up logging.- testLogging {- events TestLogEvent.FAILED- exceptionFormat TestExceptionFormat.FULL- showExceptions true- showCauses true- showStackTraces true+ if (verboseMode) {+ testLogging {+ events TestLogEvent.FAILED+ exceptionFormat TestExceptionFormat.FULL+ showExceptions true+ showCauses true+ showStackTraces true+ showStandardStreams = false+ }+ onOutput { td, event ->+ print event.message+ }+ } else {+ testLogging {+ events TestLogEvent.FAILED+ exceptionFormat TestExceptionFormat.FULL+ showExceptions true+ showCauses true+ showStackTraces true+ }}doFirst {diff --git a/gradle/testing/fail-on-no-tests.gradle b/gradle/testing/fail-on-no-tests.gradleindex dd148d1d7ce..f0377254d0c 100644--- a/gradle/testing/fail-on-no-tests.gradle+++ b/gradle/testing/fail-on-no-tests.gradle@@ -22,8 +22,12 @@ gradle.taskGraph.whenReady { graph ->// ... and there are some test tasks in the execution graph.if (!testTasks.isEmpty()) {def executedTests = 0+ def executedTasks = 0testTasks.each { task ->+ task.doFirst {+ executedTasks+++ }task.afterSuite { desc, result ->executedTests += result.testCount}@@ -31,7 +35,7 @@ gradle.taskGraph.whenReady { graph ->// After the build is finished, check the test count.gradle.buildFinished {- if (executedTests == 0) {+ if (executedTests == 0 && executedTasks > 0) {throw new GradleException("No tests found for the given filters?")}}diff --git a/help/tests.txt b/help/tests.txtindex 686113e24c5..09d8c35464e 100644--- a/help/tests.txt+++ b/help/tests.txt@@ -94,13 +94,11 @@ cleanTest task:gradlew -p lucene/core cleanTest test -Ptests.seed=deadbeef+Verbose mode and debugging+--------------------------+The "tests.verbose" mode switch enables standard streams from tests+to be dumped directly to the console. Run your verbose tests explicitly+specifying the project and test task or a fully qualified task path. Example:--------+gradlew -p lucene/core test -Ptests.verbose=true --tests "TestDemo"