Last active
November 13, 2024 16:26
-
-
Save serpro69/c987a4016fb59f6ca2ff9f8d8464561d to your computer and use it in GitHub Desktop.
Revisions
-
serpro69 revised this gist
Nov 4, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent tasks.test { useJUnitPlatform() maxParallelForks = 1 testLogging { // credits: https://stackoverflow.com/a/36130467/5917497 // set options for log level LIFECYCLE events = setOf( TestLogEvent.FAILED, -
serpro69 created this gist
Nov 4, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,82 @@ import org.gradle.api.tasks.testing.TestResult.ResultType import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.gradle.api.tasks.testing.logging.TestLogEvent //... tasks.test { useJUnitPlatform() maxParallelForks = 1 testLogging { // set options for log level LIFECYCLE events = setOf( TestLogEvent.FAILED, TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.STANDARD_OUT ) exceptionFormat = TestExceptionFormat.FULL showExceptions = true showCauses = true showStackTraces = true // set options for log level DEBUG and INFO debug { events = setOf( TestLogEvent.STARTED, TestLogEvent.FAILED, TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.STANDARD_ERROR, TestLogEvent.STANDARD_OUT ) exceptionFormat = TestExceptionFormat.FULL } info.events = debug.events info.exceptionFormat = debug.exceptionFormat afterSuite(KotlinClosure2({ desc: TestDescriptor, result: TestResult -> if (desc.parent == null) { // will match the outermost suite val pass = "${Color.GREEN}${result.successfulTestCount} passed${Color.NONE}" val fail = "${Color.RED}${result.failedTestCount} failed${Color.NONE}" val skip = "${Color.YELLOW}${result.skippedTestCount} skipped${Color.NONE}" val type = when (val r = result.resultType) { ResultType.SUCCESS -> "${Color.GREEN}$r${Color.NONE}" ResultType.FAILURE -> "${Color.RED}$r${Color.NONE}" ResultType.SKIPPED -> "${Color.YELLOW}$r${Color.NONE}" } val output = "Results: $type (${result.testCount} tests, $pass, $fail, $skip)" val startItem = "| " val endItem = " |" val repeatLength = startItem.length + output.length + endItem.length - 36 println("") println("\n" + ("-" * repeatLength) + "\n" + startItem + output + endItem + "\n" + ("-" * repeatLength)) } })) } onOutput(KotlinClosure2({ _: TestDescriptor, event: TestOutputEvent -> if (event.destination == TestOutputEvent.Destination.StdOut) { logger.lifecycle(event.message.replace(Regex("""\s+$"""), "")) } })) } operator fun String.times(x: Int): String { return List(x) { this }.joinToString("") } internal enum class Color(ansiCode: Int) { NONE(0), BLACK(30), RED(31), GREEN(32), YELLOW(33), BLUE(34), PURPLE(35), CYAN(36), WHITE(37); private val ansiString: String = "\u001B[${ansiCode}m" override fun toString(): String { return ansiString } }