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.

This commit is contained in:
Dawid Weiss 2019-12-07 14:53:13 +01:00
parent c3bb81f032
commit 1021f04d1a
3 changed files with 58 additions and 18 deletions

View File

@ -1,8 +1,12 @@
import org.apache.tools.ant.taskdefs.condition.Os
import 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 {
if (verboseMode) {
maxParallelForks = 1
} else {
maxParallelForks = propertyOrDefault("tests.jvms", (int) Math.max(1, Math.min(Runtime.runtime.availableProcessors() / 2.0, 4.0)))
}
workingDir testsWorkDir
useJUnit()
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 {

View File

@ -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 = 0
testTasks.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?")
}
}

View File

@ -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"