From ceac524eddb3fc0e235dad77dea4c15cf7e2271f Mon Sep 17 00:00:00 2001 From: radarsh Date: Thu, 7 Feb 2019 21:35:00 +0000 Subject: [PATCH 1/8] Fix double escaping of brackets --- .../gradle/testlogger/theme/MochaTheme.groovy | 3 ++- .../gradle/testlogger/theme/PlainTheme.groovy | 3 ++- .../gradle/testlogger/theme/StandardTheme.groovy | 3 ++- .../gradle/testlogger/util/RendererUtils.groovy | 4 ++++ .../gradle/testlogger/theme/BaseThemeSpec.groovy | 2 +- .../testlogger/theme/MochaParallelThemeSpec.groovy | 4 ++-- .../gradle/testlogger/theme/MochaThemeSpec.groovy | 4 ++-- .../testlogger/theme/PlainParallelThemeSpec.groovy | 4 ++-- .../gradle/testlogger/theme/PlainThemeSpec.groovy | 4 ++-- .../theme/StandardParallelThemeSpec.groovy | 4 ++-- .../gradle/testlogger/theme/StandardThemeSpec.groovy | 4 ++-- .../gradle/testlogger/util/RendererUtilsSpec.groovy | 12 ++++++++++++ 12 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/main/groovy/com/adarshr/gradle/testlogger/theme/MochaTheme.groovy b/src/main/groovy/com/adarshr/gradle/testlogger/theme/MochaTheme.groovy index 60116e3..b2d375f 100644 --- a/src/main/groovy/com/adarshr/gradle/testlogger/theme/MochaTheme.groovy +++ b/src/main/groovy/com/adarshr/gradle/testlogger/theme/MochaTheme.groovy @@ -6,6 +6,7 @@ import groovy.transform.CompileStatic import groovy.transform.InheritConstructors import org.gradle.api.tasks.testing.TestResult.ResultType +import static com.adarshr.gradle.testlogger.util.RendererUtils.preserveAnsi import static java.lang.System.lineSeparator import static org.gradle.api.tasks.testing.TestResult.ResultType.* @@ -116,7 +117,7 @@ class MochaTheme extends AbstractTheme { return '' } - lines = lines.replace('[', '\\[') + lines = preserveAnsi(lines) def indentation = ' ' * indent def line = new StringBuilder("[grey]${lineSeparator()}") diff --git a/src/main/groovy/com/adarshr/gradle/testlogger/theme/PlainTheme.groovy b/src/main/groovy/com/adarshr/gradle/testlogger/theme/PlainTheme.groovy index b814a28..389f714 100644 --- a/src/main/groovy/com/adarshr/gradle/testlogger/theme/PlainTheme.groovy +++ b/src/main/groovy/com/adarshr/gradle/testlogger/theme/PlainTheme.groovy @@ -5,6 +5,7 @@ import com.adarshr.gradle.testlogger.TestResultWrapper import groovy.transform.CompileStatic import groovy.transform.InheritConstructors +import static com.adarshr.gradle.testlogger.util.RendererUtils.preserveAnsi import static java.lang.System.lineSeparator import static org.gradle.api.tasks.testing.TestResult.ResultType.* @@ -91,7 +92,7 @@ class PlainTheme extends AbstractTheme { return '' } - lines = lines.replace('[', '\\[') + lines = preserveAnsi(lines) def indentation = ' ' * indent def line = new StringBuilder(lineSeparator()) diff --git a/src/main/groovy/com/adarshr/gradle/testlogger/theme/StandardTheme.groovy b/src/main/groovy/com/adarshr/gradle/testlogger/theme/StandardTheme.groovy index f0d7fd3..5007b78 100644 --- a/src/main/groovy/com/adarshr/gradle/testlogger/theme/StandardTheme.groovy +++ b/src/main/groovy/com/adarshr/gradle/testlogger/theme/StandardTheme.groovy @@ -5,6 +5,7 @@ import com.adarshr.gradle.testlogger.TestResultWrapper import groovy.transform.CompileStatic import groovy.transform.InheritConstructors +import static com.adarshr.gradle.testlogger.util.RendererUtils.preserveAnsi import static java.lang.System.lineSeparator import static org.gradle.api.tasks.testing.TestResult.ResultType.* @@ -108,7 +109,7 @@ class StandardTheme extends AbstractTheme { return '' } - lines = lines.replace('[', '\\[') + lines = preserveAnsi(lines) def indentation = ' ' * indent def line = new StringBuilder("[default]${lineSeparator()}") diff --git a/src/main/groovy/com/adarshr/gradle/testlogger/util/RendererUtils.groovy b/src/main/groovy/com/adarshr/gradle/testlogger/util/RendererUtils.groovy index 2a859ba..8092b94 100644 --- a/src/main/groovy/com/adarshr/gradle/testlogger/util/RendererUtils.groovy +++ b/src/main/groovy/com/adarshr/gradle/testlogger/util/RendererUtils.groovy @@ -8,4 +8,8 @@ class RendererUtils { static String escape(String text) { text?.replace('\u001B', '')?.replace('[', '\\[')?.replace(']', '\\]') } + + static String preserveAnsi(String text) { + text?.replace('\u001B[', '\u001B\\[') + } } diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/theme/BaseThemeSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/theme/BaseThemeSpec.groovy index 79a9b6e..708c3b1 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/theme/BaseThemeSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/theme/BaseThemeSpec.groovy @@ -12,7 +12,7 @@ abstract class BaseThemeSpec extends Specification { protected def testLoggerExtensionMock = Mock(TestLoggerExtension) protected def testDescriptorMock = Mock(TestDescriptorWrapper) protected def testResultMock = Mock(TestResultWrapper) - protected def streamLines = "Hello${lineSeparator()}World" + protected def streamLines = "Hello${lineSeparator()}World [brackets] \u001B[0mANSI" def setup() { testResultMock.loggable >> true diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaParallelThemeSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaParallelThemeSpec.groovy index 3a66f1f..57eeeba 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaParallelThemeSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaParallelThemeSpec.groovy @@ -187,7 +187,7 @@ class MochaParallelThemeSpec extends BaseThemeSpec { theme.testStandardStreamText(streamLines, testResultMock) == '''|[grey] | Hello - | World[/] + | World [brackets] \u001B\\[0mANSI[/] |'''.stripMargin().replace('\n', lineSeparator()) } @@ -207,7 +207,7 @@ class MochaParallelThemeSpec extends BaseThemeSpec { theme.suiteStandardStreamText(streamLines, testResultMock) == '''|[grey] | Hello - | World[/] + | World [brackets] \u001B\\[0mANSI[/] |'''.stripMargin().replace('\n', lineSeparator()) } diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaThemeSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaThemeSpec.groovy index cdef6de..808e56d 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaThemeSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaThemeSpec.groovy @@ -188,7 +188,7 @@ class MochaThemeSpec extends BaseThemeSpec { theme.testStandardStreamText(streamLines, testResultMock) == '''|[grey] | Hello - | World[/] + | World [brackets] \u001B\\[0mANSI[/] |'''.stripMargin().replace('\n', lineSeparator()) } @@ -208,7 +208,7 @@ class MochaThemeSpec extends BaseThemeSpec { theme.suiteStandardStreamText(streamLines, testResultMock) == '''|[grey] | Hello - | World[/] + | World [brackets] \u001B\\[0mANSI[/] |'''.stripMargin().replace('\n', lineSeparator()) } diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainParallelThemeSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainParallelThemeSpec.groovy index 17f283e..5738657 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainParallelThemeSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainParallelThemeSpec.groovy @@ -141,7 +141,7 @@ class PlainParallelThemeSpec extends BaseThemeSpec { theme.testStandardStreamText(streamLines, testResultMock) == '''| | Hello - | World + | World [brackets] \u001B\\[0mANSI |'''.stripMargin().replace('\n', lineSeparator()) } @@ -163,7 +163,7 @@ class PlainParallelThemeSpec extends BaseThemeSpec { theme.suiteStandardStreamText(streamLines, testResultMock) == '''| | Hello - | World + | World [brackets] \u001B\\[0mANSI |'''.stripMargin().replace('\n', lineSeparator()) } diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainThemeSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainThemeSpec.groovy index 177504a..b1209c2 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainThemeSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainThemeSpec.groovy @@ -142,7 +142,7 @@ class PlainThemeSpec extends BaseThemeSpec { theme.testStandardStreamText(streamLines, testResultMock) == '''| | Hello - | World + | World [brackets] \u001B\\[0mANSI |'''.stripMargin().replace('\n', lineSeparator()) } @@ -162,7 +162,7 @@ class PlainThemeSpec extends BaseThemeSpec { theme.suiteStandardStreamText(streamLines, testResultMock) == '''| | Hello - | World + | World [brackets] \u001B\\[0mANSI |'''.stripMargin().replace('\n', lineSeparator()) } diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardParallelThemeSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardParallelThemeSpec.groovy index 28a5017..a8e6962 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardParallelThemeSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardParallelThemeSpec.groovy @@ -167,7 +167,7 @@ class StandardParallelThemeSpec extends BaseThemeSpec { theme.testStandardStreamText(streamLines, testResultMock) == '''|[default] | Hello - | World[/] + | World [brackets] \u001B\\[0mANSI[/] |'''.stripMargin().replace('\n', lineSeparator()) } @@ -187,7 +187,7 @@ class StandardParallelThemeSpec extends BaseThemeSpec { theme.suiteStandardStreamText(streamLines, testResultMock) == '''|[default] | Hello - | World[/] + | World [brackets] \u001B\\[0mANSI[/] |'''.stripMargin().replace('\n', lineSeparator()) } diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardThemeSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardThemeSpec.groovy index 3998c2f..beedc62 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardThemeSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardThemeSpec.groovy @@ -164,7 +164,7 @@ class StandardThemeSpec extends BaseThemeSpec { theme.testStandardStreamText(streamLines, testResultMock) == '''|[default] | Hello - | World[/] + | World [brackets] \u001B\\[0mANSI[/] |'''.stripMargin().replace('\n', lineSeparator()) } @@ -184,7 +184,7 @@ class StandardThemeSpec extends BaseThemeSpec { theme.suiteStandardStreamText(streamLines, testResultMock) == '''|[default] | Hello - | World[/] + | World [brackets] \u001B\\[0mANSI[/] |'''.stripMargin().replace('\n', lineSeparator()) } diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/util/RendererUtilsSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/util/RendererUtilsSpec.groovy index 87315d2..55e474f 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/util/RendererUtilsSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/util/RendererUtilsSpec.groovy @@ -17,4 +17,16 @@ class RendererUtilsSpec extends Specification { '[escape]' | '\\[escape\\]' '\u001Btext' | 'text' } + + @Unroll + def "preserve ansi #text"() { + expect: + RendererUtils.preserveAnsi(text) == expected + where: + text | expected + null | null + '' | '' + '[do not escape]' | '[do not escape]' + '\u001B[0mANSI' | '\u001B\\[0mANSI' + } } From 8e1bbf4bd50ff9b6118e9f1582c8a64820b673de Mon Sep 17 00:00:00 2001 From: radarsh Date: Wed, 13 Mar 2019 15:51:05 +0000 Subject: [PATCH 2/8] Show output from before System.exit(5) was called --- .../testlogger/TestResultWrapper.groovy | 4 +- .../functional/AbstractFunctionalSpec.groovy | 5 +- .../functional/TestLoggerPluginSpec.groovy | 80 ++++++++++++++++--- .../build.gradle | 14 ++++ .../groovy/com/adarshr/test/FirstSpec.groovy | 55 +++++++++++++ .../groovy/com/adarshr/test/SecondSpec.groovy | 55 +++++++++++++ .../resources/test-marker.gradle | 6 +- .../testlogger/TestResultWrapperSpec.groovy | 3 + 8 files changed, 207 insertions(+), 15 deletions(-) create mode 100644 src/test-functional/resources/sample-spock-tests-system-exit/build.gradle create mode 100644 src/test-functional/resources/sample-spock-tests-system-exit/src/test/groovy/com/adarshr/test/FirstSpec.groovy create mode 100644 src/test-functional/resources/sample-spock-tests-system-exit/src/test/groovy/com/adarshr/test/SecondSpec.groovy diff --git a/src/main/groovy/com/adarshr/gradle/testlogger/TestResultWrapper.groovy b/src/main/groovy/com/adarshr/gradle/testlogger/TestResultWrapper.groovy index 6da8d53..e14dafe 100644 --- a/src/main/groovy/com/adarshr/gradle/testlogger/TestResultWrapper.groovy +++ b/src/main/groovy/com/adarshr/gradle/testlogger/TestResultWrapper.groovy @@ -4,6 +4,8 @@ import com.adarshr.gradle.testlogger.util.TimeUtils import groovy.transform.CompileStatic import org.gradle.api.tasks.testing.TestResult +import static org.gradle.api.tasks.testing.TestResult.ResultType.SKIPPED + @CompileStatic class TestResultWrapper { @@ -18,7 +20,7 @@ class TestResultWrapper { boolean isLoggable() { testLoggerExtension.showPassed && testResult.successfulTestCount || - testLoggerExtension.showSkipped && testResult.skippedTestCount || + testLoggerExtension.showSkipped && (testResult.resultType == SKIPPED || testResult.skippedTestCount) || testLoggerExtension.showFailed && testResult.failedTestCount } diff --git a/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/AbstractFunctionalSpec.groovy b/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/AbstractFunctionalSpec.groovy index 28e9a45..82882ec 100644 --- a/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/AbstractFunctionalSpec.groovy +++ b/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/AbstractFunctionalSpec.groovy @@ -8,6 +8,7 @@ import org.junit.Rule import org.junit.rules.TemporaryFolder import spock.lang.Specification +import static java.lang.System.lineSeparator import static org.apache.commons.io.FileUtils.copyDirectoryToDirectory @SuppressWarnings('GrMethodMayBeStatic') @@ -28,10 +29,12 @@ abstract class AbstractFunctionalSpec extends Specification { private static final def SUITE_MARKER_REGEX = $/${SUITE_MARKER}(.*)__/$ private static final def TEST_MARKER_REGEX = $/${TEST_MARKER}(.*)__/$ + private static final def FILTER_PATTERN = $/(?ms)${lineSeparator()}Unexpected exception thrown.*> Task :test FAILED${lineSeparator()}/$ + private AnsiTextRenderer ansi = new AnsiTextRenderer() protected TestLoggerOutput getLoggerOutput(String text) { - def allLines = text.readLines() + def allLines = text.replaceAll(FILTER_PATTERN, '').readLines() def lines = allLines .subList(allLines.indexOf(START_MARKER) + 1, allLines.indexOf(SUMMARY_MARKER)) .findAll { !it.startsWith(TEST_MARKER) } diff --git a/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/TestLoggerPluginSpec.groovy b/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/TestLoggerPluginSpec.groovy index 7142674..34afaf7 100644 --- a/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/TestLoggerPluginSpec.groovy +++ b/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/TestLoggerPluginSpec.groovy @@ -161,19 +161,19 @@ class TestLoggerPluginSpec extends AbstractFunctionalSpec { and: lines.size() == 14 lines[0] == render('') - lines[1] == render('[erase-ahead,bold]com.adarshr.test.NestedTest$NestedTestsetOne[/]') + lines[1] == render('[erase-ahead,bold]com.adarshr.test.NestedTest$NestedTestsetThree[/]') lines[2] == render('') - lines[3] == render('[erase-ahead,bold] Test [bold-off]secondTestOfNestedTestsetOne()[green] PASSED[/]') - lines[4] == render('[erase-ahead,bold] Test [bold-off]firstTestOfNestedTestsetOne()[green] PASSED[/]') - lines[5] == render('') - lines[6] == render('[erase-ahead,bold]com.adarshr.test.NestedTest$NestedTestsetThree[/]') - lines[7] == render('') - lines[8] == render('[erase-ahead,bold] Test [bold-off]firstTestOfNestedTestsetThree()[green] PASSED[/]') + lines[3] == render('[erase-ahead,bold] Test [bold-off]firstTestOfNestedTestsetThree()[green] PASSED[/]') + lines[4] == render('') + lines[5] == render('[erase-ahead,bold]com.adarshr.test.NestedTest$NestedTestsetTwo[/]') + lines[6] == render('') + lines[7] == render('[erase-ahead,bold] Test [bold-off]secondTestOfNestedTestsetTwo()[green] PASSED[/]') + lines[8] == render('[erase-ahead,bold] Test [bold-off]firstTestOfNestedTestsetTwo()[green] PASSED[/]') lines[9] == render('') - lines[10] == render('[erase-ahead,bold]com.adarshr.test.NestedTest$NestedTestsetTwo[/]') + lines[10] == render('[erase-ahead,bold]com.adarshr.test.NestedTest$NestedTestsetOne[/]') lines[11] == render('') - lines[12] == render('[erase-ahead,bold] Test [bold-off]secondTestOfNestedTestsetTwo()[green] PASSED[/]') - lines[13] == render('[erase-ahead,bold] Test [bold-off]firstTestOfNestedTestsetTwo()[green] PASSED[/]') + lines[12] == render('[erase-ahead,bold] Test [bold-off]secondTestOfNestedTestsetOne()[green] PASSED[/]') + lines[13] == render('[erase-ahead,bold] Test [bold-off]firstTestOfNestedTestsetOne()[green] PASSED[/]') and: result.task(":test").outcome == SUCCESS } @@ -346,6 +346,66 @@ class TestLoggerPluginSpec extends AbstractFunctionalSpec { result.task(":test").outcome == SUCCESS } + def "show standard streams from before System exit was called from setupSpec"() { + when: + def result = run( + 'sample-spock-tests-system-exit', + ''' + testlogger { + showStandardStreams true + } + ''', + 'clean test --tests *SecondSpec' + ) + then: + def lines = getLoggerOutput(result.output).lines + and: + lines.size() == 4 + lines[0] == render('[default]') + lines[1] == render(' SecondSpec - stdout setupSpec') + lines[2] == render(' SecondSpec - stderr setupSpec[/]') + lines[3] == render('') + and: + result.task(":test").outcome == FAILED + } + + def "show standard streams from before System exit was called from setup"() { + when: + def result = run( + 'sample-spock-tests-system-exit', + ''' + testlogger { + showStandardStreams true + } + ''', + 'clean test --tests *FirstSpec' + ) + then: + def output = getLoggerOutput(result.output) + def lines = output.lines + def summary = output.summary + and: + lines.size() == 12 + lines[0] == render('[default]') + lines[1] == render(' FirstSpec - stdout setupSpec') + lines[2] == render(' FirstSpec - stderr setupSpec[/]') + lines[3] == render('') + lines[4] == render('') + lines[5] == render('[erase-ahead,bold]com.adarshr.test.FirstSpec[/]') + lines[6] == render('') + lines[7] == render('[erase-ahead,bold] Test [bold-off]this test should pass[yellow] SKIPPED[/]') + lines[8] == render('[default]') + lines[9] == render(' FirstSpec - this test should pass - stdout setup') + lines[10] == render(' FirstSpec - this test should pass - stderr setup[/]') + and: + summary[0] == render('') + summary[1].startsWith render('[erase-ahead,bold,green]SUCCESS: [default]Executed 1 tests in') + summary[1].endsWith render('(1 skipped)[/]') + summary[2] == render('') + and: + result.task(":test").outcome == FAILED + } + def "hide passed tests"() { when: def result = run( diff --git a/src/test-functional/resources/sample-spock-tests-system-exit/build.gradle b/src/test-functional/resources/sample-spock-tests-system-exit/build.gradle new file mode 100644 index 0000000..e19c32a --- /dev/null +++ b/src/test-functional/resources/sample-spock-tests-system-exit/build.gradle @@ -0,0 +1,14 @@ +plugins { + id 'groovy' + id 'com.adarshr.test-logger' +} + +repositories { + mavenLocal() + mavenCentral() +} + +dependencies { + testCompile 'org.codehaus.groovy:groovy-all:2.4.12' + testCompile 'org.spockframework:spock-core:1.1-groovy-2.4' +} diff --git a/src/test-functional/resources/sample-spock-tests-system-exit/src/test/groovy/com/adarshr/test/FirstSpec.groovy b/src/test-functional/resources/sample-spock-tests-system-exit/src/test/groovy/com/adarshr/test/FirstSpec.groovy new file mode 100644 index 0000000..bbac7d6 --- /dev/null +++ b/src/test-functional/resources/sample-spock-tests-system-exit/src/test/groovy/com/adarshr/test/FirstSpec.groovy @@ -0,0 +1,55 @@ +package com.adarshr.test + +import spock.lang.Ignore +import spock.lang.Narrative +import spock.lang.Specification +import spock.lang.Stepwise + +@Stepwise +@Narrative('Test that calls System.exit from setup method') +class FirstSpec extends Specification { + + def setupSpec() { + println "${getClass().simpleName} - stdout setupSpec" + System.err.println "${getClass().simpleName} - stderr setupSpec" + } + + def cleanupSpec() { + println "${getClass().simpleName} - stdout cleanupSpec" + System.err.println "${getClass().simpleName} - stderr cleanupSpec" + } + + def setup() { + println "${getClass().simpleName} - ${specificationContext.currentFeature.name} - stdout setup" + System.err.println "${getClass().simpleName} - ${specificationContext.currentFeature.name} - stderr setup" + + System.exit(5) + } + + def cleanup() { + println "${getClass().simpleName} - ${specificationContext.currentFeature.name} - stdout cleanup" + System.err.println "${getClass().simpleName} - ${specificationContext.currentFeature.name} - stderr cleanup" + } + + def "this test should pass"() { + expect: + println "${getClass().simpleName} - ${specificationContext.currentFeature.name} - stdout expect" + System.err.println "${getClass().simpleName} - ${specificationContext.currentFeature.name} - stderr expect" + 1 == 1 + } + + def "this test should fail"() { + expect: + println "${getClass().simpleName} - ${specificationContext.currentFeature.name} - stdout expect" + System.err.println "${getClass().simpleName} - ${specificationContext.currentFeature.name} - stderr expect" + 1 == 2 + } + + @Ignore + def "this test should be skipped"() { + expect: + println "${getClass().simpleName} - ${specificationContext.currentFeature.name} - stdout expect" + System.err.println "${getClass().simpleName} - ${specificationContext.currentFeature.name} - stderr expect" + 1 == 2 + } +} diff --git a/src/test-functional/resources/sample-spock-tests-system-exit/src/test/groovy/com/adarshr/test/SecondSpec.groovy b/src/test-functional/resources/sample-spock-tests-system-exit/src/test/groovy/com/adarshr/test/SecondSpec.groovy new file mode 100644 index 0000000..6837c84 --- /dev/null +++ b/src/test-functional/resources/sample-spock-tests-system-exit/src/test/groovy/com/adarshr/test/SecondSpec.groovy @@ -0,0 +1,55 @@ +package com.adarshr.test + +import spock.lang.Ignore +import spock.lang.Narrative +import spock.lang.Specification +import spock.lang.Stepwise + +@Stepwise +@Narrative('Test that calls System.exit from setupSpec method') +class SecondSpec extends Specification { + + def setupSpec() { + println "${getClass().simpleName} - stdout setupSpec" + System.err.println "${getClass().simpleName} - stderr setupSpec" + + System.exit(5) + } + + def cleanupSpec() { + println "${getClass().simpleName} - stdout cleanupSpec" + System.err.println "${getClass().simpleName} - stderr cleanupSpec" + } + + def setup() { + println "${getClass().simpleName} - ${specificationContext.currentFeature.name} - stdout setup" + System.err.println "${getClass().simpleName} - ${specificationContext.currentFeature.name} - stderr setup" + } + + def cleanup() { + println "${getClass().simpleName} - ${specificationContext.currentFeature.name} - stdout cleanup" + System.err.println "${getClass().simpleName} - ${specificationContext.currentFeature.name} - stderr cleanup" + } + + def "this test should pass"() { + expect: + println "${getClass().simpleName} - ${specificationContext.currentFeature.name} - stdout expect" + System.err.println "${getClass().simpleName} - ${specificationContext.currentFeature.name} - stderr expect" + 1 == 1 + } + + def "this test should fail"() { + expect: + println "${getClass().simpleName} - ${specificationContext.currentFeature.name} - stdout expect" + System.err.println "${getClass().simpleName} - ${specificationContext.currentFeature.name} - stderr expect" + 1 == 2 + } + + @Ignore + def "this test should be skipped"() { + expect: + println "${getClass().simpleName} - ${specificationContext.currentFeature.name} - stdout expect" + System.err.println "${getClass().simpleName} - ${specificationContext.currentFeature.name} - stderr expect" + 1 == 2 + } +} diff --git a/src/test-functional/resources/test-marker.gradle b/src/test-functional/resources/test-marker.gradle index 528197d..7260a62 100644 --- a/src/test-functional/resources/test-marker.gradle +++ b/src/test-functional/resources/test-marker.gradle @@ -14,12 +14,12 @@ tasks.withType(Test) { boolean started = false def suites = [] - beforeTest { suite -> - if (suite.className.startsWith('com.adarshr') && !started) { + beforeSuite { suite -> + if (suite.className?.startsWith('com.adarshr') && !started) { started = true logger.lifecycle '__START__' } - if (suite.className.startsWith('com.adarshr') && !suites.contains(suite.className)) { + if (suite.className?.startsWith('com.adarshr') && !suites.contains(suite.className)) { logger.lifecycle "__SUITE=${suite.className}__" suites << suite.className } diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/TestResultWrapperSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/TestResultWrapperSpec.groovy index 04bbf7a..9318884 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/TestResultWrapperSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/TestResultWrapperSpec.groovy @@ -18,6 +18,8 @@ class TestResultWrapperSpec extends Specification { testLoggerExtensionMock.showPassed >> showPassed testLoggerExtensionMock.showSkipped >> showSkipped testLoggerExtensionMock.showFailed >> showFailed + and: + testResultMock.resultType >> resultType testResultMock.testCount >> totalCount testResultMock.successfulTestCount >> successfulCount testResultMock.skippedTestCount >> skippedCount @@ -28,6 +30,7 @@ class TestResultWrapperSpec extends Specification { resultType | totalCount | successfulCount | skippedCount | failedCount | showPassed | showSkipped | showFailed SUCCESS | 1 | 1 | 0 | 0 | true | false | false SKIPPED | 1 | 0 | 1 | 0 | false | true | false + SKIPPED | 0 | 0 | 0 | 0 | false | true | false FAILURE | 1 | 0 | 0 | 1 | false | false | true } From 7c4c08436df38d8e3ede8cda6e163e74c2a24bbd Mon Sep 17 00:00:00 2001 From: aalmiray Date: Mon, 4 Mar 2019 14:01:46 +0100 Subject: [PATCH 3/8] Configure build-scan plugin --- .circleci/config.yml | 6 +++--- build.gradle | 6 ++++++ gradle.properties | 4 ++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 37670a8..003cd72 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -23,10 +23,10 @@ jobs: key: v1-dependencies-{{ checksum "build.gradle" }} - run: name: Run tests - command: GRADLE_OPTS="-Xms256m -Xmx2048m" ./gradlew build --no-daemon + command: GRADLE_OPTS="-Xms256m -Xmx2048m" ./gradlew build --no-daemon --scan - run: name: Code coverage - command: GRADLE_OPTS="-Xms256m -Xmx1024m" ./gradlew jacocoTestReport coveralls --no-daemon + command: GRADLE_OPTS="-Xms256m -Xmx1024m" ./gradlew jacocoTestReport coveralls --no-daemon --scan - run: name: Save reports command: | @@ -68,7 +68,7 @@ jobs: - run: name: Publish plugin command: - GRADLE_OPTS="-Xms256m -Xmx1024m" ./gradlew clean publishPlugins --no-daemon + GRADLE_OPTS="-Xms256m -Xmx1024m" ./gradlew clean publishPlugins --no-daemon --scan -Pgradle.publish.key=${GRADLE_PUBLISH_KEY} -Pgradle.publish.secret=${GRADLE_PUBLISH_SECRET} diff --git a/build.gradle b/build.gradle index 540ca10..c257834 100644 --- a/build.gradle +++ b/build.gradle @@ -5,6 +5,7 @@ buildscript { } plugins { + id 'com.gradle.build-scan' version '1.16' id 'groovy' id 'java-gradle-plugin' id 'maven-publish' @@ -14,6 +15,11 @@ plugins { id 'com.github.kt3k.coveralls' version '2.8.2' } +buildScan { + termsOfServiceUrl = 'https://gradle.com/terms-of-service' + termsOfServiceAgree = 'yes' +} + def thisPlugin = new GroovyScriptEngine(file('src/main/groovy').absolutePath, this.class.classLoader) .loadScriptByName('com/adarshr/gradle/testlogger/TestLoggerPlugin.groovy') diff --git a/gradle.properties b/gradle.properties index 89a0425..08cd650 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,6 @@ version=1.6.0 group=com.adarshr + +org.gradle.daemon = true +org.gradle.caching = true +org.gradle.parallel = true \ No newline at end of file From 9fe63ac75b3384654eb4c80225521fb89ba3f586 Mon Sep 17 00:00:00 2001 From: radarsh Date: Wed, 24 Apr 2019 20:27:30 +0100 Subject: [PATCH 4/8] Improve Windows build stability --- .../functional/AbstractFunctionalSpec.groovy | 11 +++++++++-- .../functional/ParallelExecutionSpec.groovy | 1 + .../testlogger/functional/TestLoggerPluginSpec.groovy | 1 + .../testlogger/functional/ThemeSwitchingSpec.groovy | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/AbstractFunctionalSpec.groovy b/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/AbstractFunctionalSpec.groovy index 82882ec..98a300c 100644 --- a/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/AbstractFunctionalSpec.groovy +++ b/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/AbstractFunctionalSpec.groovy @@ -29,12 +29,19 @@ abstract class AbstractFunctionalSpec extends Specification { private static final def SUITE_MARKER_REGEX = $/${SUITE_MARKER}(.*)__/$ private static final def TEST_MARKER_REGEX = $/${TEST_MARKER}(.*)__/$ - private static final def FILTER_PATTERN = $/(?ms)${lineSeparator()}Unexpected exception thrown.*> Task :test FAILED${lineSeparator()}/$ + private static final List> FILTER_PATTERNS = [ + [pattern: $/(?ms)${lineSeparator()}Unexpected exception thrown.*?${lineSeparator() * 2}/$, replacement: ''], + [pattern: $/(?ms)> Task .*?${lineSeparator()}/$, replacement: ''] + ] private AnsiTextRenderer ansi = new AnsiTextRenderer() protected TestLoggerOutput getLoggerOutput(String text) { - def allLines = text.replaceAll(FILTER_PATTERN, '').readLines() + FILTER_PATTERNS.each { it -> + text = text.replaceAll(it.pattern, it.replacement) + } + + def allLines = text.readLines() def lines = allLines .subList(allLines.indexOf(START_MARKER) + 1, allLines.indexOf(SUMMARY_MARKER)) .findAll { !it.startsWith(TEST_MARKER) } diff --git a/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/ParallelExecutionSpec.groovy b/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/ParallelExecutionSpec.groovy index c172bfc..45d8604 100644 --- a/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/ParallelExecutionSpec.groovy +++ b/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/ParallelExecutionSpec.groovy @@ -1,5 +1,6 @@ package com.adarshr.gradle.testlogger.functional + import static org.gradle.testkit.runner.TaskOutcome.FAILED import static org.gradle.testkit.runner.TaskOutcome.SUCCESS diff --git a/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/TestLoggerPluginSpec.groovy b/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/TestLoggerPluginSpec.groovy index 34afaf7..1d0b855 100644 --- a/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/TestLoggerPluginSpec.groovy +++ b/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/TestLoggerPluginSpec.groovy @@ -1,5 +1,6 @@ package com.adarshr.gradle.testlogger.functional + import static org.gradle.testkit.runner.TaskOutcome.FAILED import static org.gradle.testkit.runner.TaskOutcome.SUCCESS diff --git a/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/ThemeSwitchingSpec.groovy b/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/ThemeSwitchingSpec.groovy index 14af14c..cbd4731 100644 --- a/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/ThemeSwitchingSpec.groovy +++ b/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/ThemeSwitchingSpec.groovy @@ -1,5 +1,6 @@ package com.adarshr.gradle.testlogger.functional + import spock.util.environment.OperatingSystem import static org.gradle.testkit.runner.TaskOutcome.SUCCESS From 36d018c882b5edef622faaf5a5bc3a5f297d6745 Mon Sep 17 00:00:00 2001 From: radarsh Date: Fri, 8 Feb 2019 00:25:57 +0000 Subject: [PATCH 5/8] Use classDisplayName for friendlier suite names --- .../testlogger/TestDescriptorWrapper.groovy | 7 +++++- .../theme/MochaParallelTheme.groovy | 2 +- .../gradle/testlogger/theme/MochaTheme.groovy | 2 +- .../theme/PlainParallelTheme.groovy | 2 +- .../gradle/testlogger/theme/PlainTheme.groovy | 2 +- .../theme/StandardParallelTheme.groovy | 2 +- .../testlogger/theme/StandardTheme.groovy | 2 +- .../functional/TestLoggerPluginSpec.groovy | 22 +++++++++---------- .../java/com/adarshr/test/DeepNestedTest.java | 2 ++ .../TestDescriptorWrapperSpec.groovy | 16 ++++++++++++++ .../theme/MochaParallelThemeSpec.groovy | 7 +++--- .../testlogger/theme/MochaThemeSpec.groovy | 2 +- .../theme/PlainParallelThemeSpec.groovy | 5 +++-- .../testlogger/theme/PlainThemeSpec.groovy | 2 +- .../theme/StandardParallelThemeSpec.groovy | 7 +++--- .../testlogger/theme/StandardThemeSpec.groovy | 2 +- 16 files changed, 55 insertions(+), 29 deletions(-) diff --git a/src/main/groovy/com/adarshr/gradle/testlogger/TestDescriptorWrapper.groovy b/src/main/groovy/com/adarshr/gradle/testlogger/TestDescriptorWrapper.groovy index 71960b5..d7b7fb9 100644 --- a/src/main/groovy/com/adarshr/gradle/testlogger/TestDescriptorWrapper.groovy +++ b/src/main/groovy/com/adarshr/gradle/testlogger/TestDescriptorWrapper.groovy @@ -22,9 +22,14 @@ class TestDescriptorWrapper { escape(testDescriptor.className) } + @CompileDynamic + String getClassDisplayName() { + escape(testDescriptor.properties.classDisplayName ?: testDescriptor.className) + } + @CompileDynamic String getDisplayName() { - escape(testDescriptor.properties.displayName ?: name) + escape(testDescriptor.properties.displayName ?: testDescriptor.name) } String getSuiteKey() { diff --git a/src/main/groovy/com/adarshr/gradle/testlogger/theme/MochaParallelTheme.groovy b/src/main/groovy/com/adarshr/gradle/testlogger/theme/MochaParallelTheme.groovy index 4b65dfa..799618f 100644 --- a/src/main/groovy/com/adarshr/gradle/testlogger/theme/MochaParallelTheme.groovy +++ b/src/main/groovy/com/adarshr/gradle/testlogger/theme/MochaParallelTheme.groovy @@ -16,7 +16,7 @@ class MochaParallelTheme extends MochaTheme { @Override protected String testTextInternal(TestDescriptorWrapper descriptor, TestResultWrapper result) { - super.testTextInternal(" [erase-ahead,default]${descriptor.className} ", descriptor, result) + super.testTextInternal(" [erase-ahead,default]${descriptor.classDisplayName} ", descriptor, result) } @Override diff --git a/src/main/groovy/com/adarshr/gradle/testlogger/theme/MochaTheme.groovy b/src/main/groovy/com/adarshr/gradle/testlogger/theme/MochaTheme.groovy index b2d375f..f75d689 100644 --- a/src/main/groovy/com/adarshr/gradle/testlogger/theme/MochaTheme.groovy +++ b/src/main/groovy/com/adarshr/gradle/testlogger/theme/MochaTheme.groovy @@ -16,7 +16,7 @@ class MochaTheme extends AbstractTheme { @Override protected String suiteTextInternal(TestDescriptorWrapper descriptor) { - " [erase-ahead,default]${descriptor.className}[/]${lineSeparator()}" + " [erase-ahead,default]${descriptor.classDisplayName}[/]${lineSeparator()}" } @Override diff --git a/src/main/groovy/com/adarshr/gradle/testlogger/theme/PlainParallelTheme.groovy b/src/main/groovy/com/adarshr/gradle/testlogger/theme/PlainParallelTheme.groovy index 636fafb..83ec3ed 100644 --- a/src/main/groovy/com/adarshr/gradle/testlogger/theme/PlainParallelTheme.groovy +++ b/src/main/groovy/com/adarshr/gradle/testlogger/theme/PlainParallelTheme.groovy @@ -16,7 +16,7 @@ class PlainParallelTheme extends PlainTheme { @Override protected String testTextInternal(TestDescriptorWrapper descriptor, TestResultWrapper result) { - super.testTextInternal("${descriptor.className} ${descriptor.displayName} ${RESULT_TYPE_MAPPING[result.resultType]}", descriptor, result) + super.testTextInternal("${descriptor.classDisplayName} ${descriptor.displayName} ${RESULT_TYPE_MAPPING[result.resultType]}", descriptor, result) } @Override diff --git a/src/main/groovy/com/adarshr/gradle/testlogger/theme/PlainTheme.groovy b/src/main/groovy/com/adarshr/gradle/testlogger/theme/PlainTheme.groovy index 389f714..5e45ff9 100644 --- a/src/main/groovy/com/adarshr/gradle/testlogger/theme/PlainTheme.groovy +++ b/src/main/groovy/com/adarshr/gradle/testlogger/theme/PlainTheme.groovy @@ -21,7 +21,7 @@ class PlainTheme extends AbstractTheme { @Override protected String suiteTextInternal(TestDescriptorWrapper descriptor) { - "${descriptor.className}${lineSeparator()}" + "${descriptor.classDisplayName}${lineSeparator()}" } @Override diff --git a/src/main/groovy/com/adarshr/gradle/testlogger/theme/StandardParallelTheme.groovy b/src/main/groovy/com/adarshr/gradle/testlogger/theme/StandardParallelTheme.groovy index 654a6de..ccc6666 100644 --- a/src/main/groovy/com/adarshr/gradle/testlogger/theme/StandardParallelTheme.groovy +++ b/src/main/groovy/com/adarshr/gradle/testlogger/theme/StandardParallelTheme.groovy @@ -16,7 +16,7 @@ class StandardParallelTheme extends StandardTheme { @Override protected String testTextInternal(TestDescriptorWrapper descriptor, TestResultWrapper result) { - super.testTextInternal("[erase-ahead,bold]${descriptor.className}[bold-off] ${descriptor.displayName}", descriptor, result) + super.testTextInternal("[erase-ahead,bold]${descriptor.classDisplayName}[bold-off] ${descriptor.displayName}", descriptor, result) } @Override diff --git a/src/main/groovy/com/adarshr/gradle/testlogger/theme/StandardTheme.groovy b/src/main/groovy/com/adarshr/gradle/testlogger/theme/StandardTheme.groovy index 5007b78..658b900 100644 --- a/src/main/groovy/com/adarshr/gradle/testlogger/theme/StandardTheme.groovy +++ b/src/main/groovy/com/adarshr/gradle/testlogger/theme/StandardTheme.groovy @@ -15,7 +15,7 @@ class StandardTheme extends AbstractTheme { @Override protected String suiteTextInternal(TestDescriptorWrapper descriptor) { - "[erase-ahead,bold]${descriptor.className}[/]${lineSeparator()}" + "[erase-ahead,bold]${descriptor.classDisplayName}[/]${lineSeparator()}" } @Override diff --git a/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/TestLoggerPluginSpec.groovy b/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/TestLoggerPluginSpec.groovy index 1d0b855..48812eb 100644 --- a/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/TestLoggerPluginSpec.groovy +++ b/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/TestLoggerPluginSpec.groovy @@ -137,7 +137,7 @@ class TestLoggerPluginSpec extends AbstractFunctionalSpec { and: lines.size() == 10 lines[0] == render('') - lines[1] == render('[erase-ahead,bold]com.adarshr.test.FirstTest[/]') + lines[1] == render('[erase-ahead,bold]FirstTest[/]') lines[2] == render('') lines[3] == render('[erase-ahead,bold] Test [bold-off]thisTestShouldBeSkipped()[yellow] SKIPPED[/]') lines[4] == render('[erase-ahead,bold] Test [bold-off]this test should fail[red] FAILED[red]') @@ -162,16 +162,16 @@ class TestLoggerPluginSpec extends AbstractFunctionalSpec { and: lines.size() == 14 lines[0] == render('') - lines[1] == render('[erase-ahead,bold]com.adarshr.test.NestedTest$NestedTestsetThree[/]') + lines[1] == render('[erase-ahead,bold]NestedTestsetOne[/]') lines[2] == render('') - lines[3] == render('[erase-ahead,bold] Test [bold-off]firstTestOfNestedTestsetThree()[green] PASSED[/]') - lines[4] == render('') - lines[5] == render('[erase-ahead,bold]com.adarshr.test.NestedTest$NestedTestsetTwo[/]') - lines[6] == render('') - lines[7] == render('[erase-ahead,bold] Test [bold-off]secondTestOfNestedTestsetTwo()[green] PASSED[/]') - lines[8] == render('[erase-ahead,bold] Test [bold-off]firstTestOfNestedTestsetTwo()[green] PASSED[/]') + lines[3] == render('[erase-ahead,bold] Test [bold-off]secondTestOfNestedTestsetOne()[green] PASSED[/]') + lines[4] == render('[erase-ahead,bold] Test [bold-off]firstTestOfNestedTestsetOne()[green] PASSED[/]') + lines[5] == render('') + lines[6] == render('[erase-ahead,bold]NestedTestsetThree[/]') + lines[7] == render('') + lines[8] == render('[erase-ahead,bold] Test [bold-off]firstTestOfNestedTestsetThree()[green] PASSED[/]') lines[9] == render('') - lines[10] == render('[erase-ahead,bold]com.adarshr.test.NestedTest$NestedTestsetOne[/]') + lines[10] == render('[erase-ahead,bold]NestedTestsetTwo[/]') lines[11] == render('') lines[12] == render('[erase-ahead,bold] Test [bold-off]secondTestOfNestedTestsetOne()[green] PASSED[/]') lines[13] == render('[erase-ahead,bold] Test [bold-off]firstTestOfNestedTestsetOne()[green] PASSED[/]') @@ -190,11 +190,11 @@ class TestLoggerPluginSpec extends AbstractFunctionalSpec { and: lines.size() == 8 lines[0] == render('') - lines[1] == render('[erase-ahead,bold]com.adarshr.test.DeepNestedTest$NestedTestsetLevelOne[/]') + lines[1] == render('[erase-ahead,bold]NestedTestsetLevelOne[/]') lines[2] == render('') lines[3] == render('[erase-ahead,bold] Test [bold-off]nestedTestsetLevelOne()[green] PASSED[/]') lines[4] == render('') - lines[5] == render('[erase-ahead,bold]com.adarshr.test.DeepNestedTest$NestedTestsetLevelOne$NestedTestsetLevelTwo[/]') + lines[5] == render('[erase-ahead,bold]Nested test set level two[/]') lines[6] == render('') lines[7] == render('[erase-ahead,bold] Test [bold-off]nestedTestsetLevelTwo()[green] PASSED[/]') and: diff --git a/src/test-functional/resources/sample-junit5-jupiter-deep-nested-tests/src/test/java/com/adarshr/test/DeepNestedTest.java b/src/test-functional/resources/sample-junit5-jupiter-deep-nested-tests/src/test/java/com/adarshr/test/DeepNestedTest.java index e3e7c9b..5457640 100644 --- a/src/test-functional/resources/sample-junit5-jupiter-deep-nested-tests/src/test/java/com/adarshr/test/DeepNestedTest.java +++ b/src/test-functional/resources/sample-junit5-jupiter-deep-nested-tests/src/test/java/com/adarshr/test/DeepNestedTest.java @@ -4,6 +4,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.DisplayName; public class DeepNestedTest { @@ -16,6 +17,7 @@ public void nestedTestsetLevelOne() { } @Nested + @DisplayName("Nested test set level two") public class NestedTestsetLevelTwo { @Test diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/TestDescriptorWrapperSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/TestDescriptorWrapperSpec.groovy index f809e93..d2e5bab 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/TestDescriptorWrapperSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/TestDescriptorWrapperSpec.groovy @@ -17,6 +17,22 @@ class TestDescriptorWrapperSpec extends Specification { wrapper.className == 'ClassName \\[escaped\\]' } + def "classDisplayName delegates to classDisplayName property if present"() { + given: + testDescriptorMock.properties >> [classDisplayName: 'class display name [escaped]'] + testDescriptorMock.className >> 'ClassName [escaped]' + expect: + wrapper.classDisplayName == 'class display name \\[escaped\\]' + } + + def "classDisplayName falls back to className if classDisplayName property is missing"() { + given: + testDescriptorMock.properties >> [:] + testDescriptorMock.className >> 'ClassName [escaped]' + expect: + wrapper.classDisplayName == 'ClassName \\[escaped\\]' + } + def "displayName delegates to displayName property if present"() { given: testDescriptorMock.properties >> [displayName: 'display name [escaped]'] diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaParallelThemeSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaParallelThemeSpec.groovy index 57eeeba..3297cf7 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaParallelThemeSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaParallelThemeSpec.groovy @@ -37,7 +37,7 @@ class MochaParallelThemeSpec extends BaseThemeSpec { given: System.setProperty('os.name', os) testResultMock.resultType >> resultType - testDescriptorMock.className >> 'ClassName' + testDescriptorMock.classDisplayName >> 'ClassName' testDescriptorMock.displayName >> 'test name' when: def actual = theme.testText(testDescriptorMock, testResultMock) @@ -63,6 +63,7 @@ class MochaParallelThemeSpec extends BaseThemeSpec { testResultMock.exception >> exception testDescriptorMock.displayName >> 'floppy test' testDescriptorMock.className >> this.class.name + testDescriptorMock.classDisplayName >> this.class.name when: def actual = theme.testText(testDescriptorMock, testResultMock) then: @@ -107,7 +108,7 @@ class MochaParallelThemeSpec extends BaseThemeSpec { testResultMock.resultType >> resultType testResultMock.duration >> '10s' testResultMock.tooSlow >> true - testDescriptorMock.className >> 'ClassName' + testDescriptorMock.classDisplayName >> 'ClassName' testDescriptorMock.displayName >> 'test name' when: def actual = theme.testText(testDescriptorMock, testResultMock) @@ -125,7 +126,7 @@ class MochaParallelThemeSpec extends BaseThemeSpec { testResultMock.resultType >> resultType testResultMock.duration >> '1.5s' testResultMock.mediumSlow >> true - testDescriptorMock.className >> 'ClassName' + testDescriptorMock.classDisplayName >> 'ClassName' testDescriptorMock.displayName >> 'test name' when: def actual = theme.testText(testDescriptorMock, testResultMock) diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaThemeSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaThemeSpec.groovy index 808e56d..4259499 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaThemeSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaThemeSpec.groovy @@ -29,7 +29,7 @@ class MochaThemeSpec extends BaseThemeSpec { def "suite text"() { given: - testDescriptorMock.className >> 'ClassName' + testDescriptorMock.classDisplayName >> 'ClassName' when: def actual = theme.suiteText(testDescriptorMock, testResultMock) then: diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainParallelThemeSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainParallelThemeSpec.groovy index 5738657..0a80874 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainParallelThemeSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainParallelThemeSpec.groovy @@ -30,7 +30,7 @@ class PlainParallelThemeSpec extends BaseThemeSpec { def "after test with result type #resultType"() { given: testResultMock.resultType >> resultType - testDescriptorMock.className >> 'ClassName' + testDescriptorMock.classDisplayName >> 'ClassName' testDescriptorMock.displayName >> 'test name' when: def actual = theme.testText(testDescriptorMock, testResultMock) @@ -52,6 +52,7 @@ class PlainParallelThemeSpec extends BaseThemeSpec { testResultMock.exception >> exception testDescriptorMock.displayName >> 'floppy test' testDescriptorMock.className >> this.class.name + testDescriptorMock.classDisplayName >> this.class.name when: def actual = theme.testText(testDescriptorMock, testResultMock) then: @@ -95,7 +96,7 @@ class PlainParallelThemeSpec extends BaseThemeSpec { testResultMock.tooSlow >> true testResultMock.duration >> '10s' testResultMock.resultType >> SUCCESS - testDescriptorMock.className >> 'ClassName' + testDescriptorMock.classDisplayName >> 'ClassName' testDescriptorMock.displayName >> 'test name' when: def actual = theme.testText(testDescriptorMock, testResultMock) diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainThemeSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainThemeSpec.groovy index b1209c2..078d30f 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainThemeSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainThemeSpec.groovy @@ -23,7 +23,7 @@ class PlainThemeSpec extends BaseThemeSpec { def "suite text"() { given: - testDescriptorMock.className >> 'ClassName' + testDescriptorMock.classDisplayName >> 'ClassName' when: def actual = theme.suiteText(testDescriptorMock, testResultMock) then: diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardParallelThemeSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardParallelThemeSpec.groovy index a8e6962..5ee081d 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardParallelThemeSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardParallelThemeSpec.groovy @@ -30,7 +30,7 @@ class StandardParallelThemeSpec extends BaseThemeSpec { def "after test with result type #resultType"() { given: testResultMock.resultType >> resultType - testDescriptorMock.className >> 'ClassName' + testDescriptorMock.classDisplayName >> 'ClassName' testDescriptorMock.displayName >> 'test name' when: def actual = theme.testText(testDescriptorMock, testResultMock) @@ -52,6 +52,7 @@ class StandardParallelThemeSpec extends BaseThemeSpec { testResultMock.exception >> exception testDescriptorMock.displayName >> 'floppy test' testDescriptorMock.className >> this.class.name + testDescriptorMock.classDisplayName >> this.class.name when: def actual = theme.testText(testDescriptorMock, testResultMock) then: @@ -100,7 +101,7 @@ class StandardParallelThemeSpec extends BaseThemeSpec { testResultMock.resultType >> resultType testResultMock.tooSlow >> true testResultMock.duration >> '10s' - testDescriptorMock.className >> 'ClassName' + testDescriptorMock.classDisplayName >> 'ClassName' testDescriptorMock.displayName >> 'test name' when: def actual = theme.testText(testDescriptorMock, testResultMock) @@ -118,7 +119,7 @@ class StandardParallelThemeSpec extends BaseThemeSpec { testResultMock.resultType >> resultType testResultMock.duration >> '1.5s' testResultMock.mediumSlow >> true - testDescriptorMock.className >> 'ClassName' + testDescriptorMock.classDisplayName >> 'ClassName' testDescriptorMock.displayName >> 'test name' when: def actual = theme.testText(testDescriptorMock, testResultMock) diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardThemeSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardThemeSpec.groovy index beedc62..10bf587 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardThemeSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardThemeSpec.groovy @@ -23,7 +23,7 @@ class StandardThemeSpec extends BaseThemeSpec { def "suite text"() { given: - testDescriptorMock.className >> 'ClassName' + testDescriptorMock.classDisplayName >> 'ClassName' when: def actual = theme.suiteText(testDescriptorMock, testResultMock) then: From 8d5475752810641d9506a52a41733ad01ac2d99d Mon Sep 17 00:00:00 2001 From: radarsh Date: Thu, 18 Apr 2019 16:43:01 +0100 Subject: [PATCH 6/8] Add option to show simple names --- README.md | 12 ++++ .../testlogger/TestDescriptorWrapper.groovy | 13 +++- .../testlogger/TestLoggerExtension.groovy | 8 +++ .../functional/TestLoggerPluginSpec.groovy | 64 ++++++++++++++++--- .../TestDescriptorWrapperSpec.groovy | 26 ++++++++ 5 files changed, 112 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 08eab12..82fa7e3 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ testlogger { showExceptions true slowThreshold 2000 showSummary true + showSimpleNames false showPassed true showSkipped true showFailed true @@ -164,6 +165,17 @@ testlogger { } ``` +### Show simple names + +If you don't like seeing long, fully-qualified class names being used for displaying the test suite names, you can choose to +show only [simple names](https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getSimpleName--) by setting the below flag to true. + +```groovy +testlogger { + showSimpleNames true +} +``` + ### Show standard streams The display of standard output and error streams alongside the test logs can be controlled using the below configuration. diff --git a/src/main/groovy/com/adarshr/gradle/testlogger/TestDescriptorWrapper.groovy b/src/main/groovy/com/adarshr/gradle/testlogger/TestDescriptorWrapper.groovy index d7b7fb9..c1932bb 100644 --- a/src/main/groovy/com/adarshr/gradle/testlogger/TestDescriptorWrapper.groovy +++ b/src/main/groovy/com/adarshr/gradle/testlogger/TestDescriptorWrapper.groovy @@ -24,12 +24,21 @@ class TestDescriptorWrapper { @CompileDynamic String getClassDisplayName() { - escape(testDescriptor.properties.classDisplayName ?: testDescriptor.className) + def className = testDescriptor.className + def classDisplayName = testDescriptor.properties.classDisplayName as String + def useClassDisplayName = classDisplayName && classDisplayName != className && !className.endsWith(classDisplayName) + + if (testLoggerExtension.showSimpleNames) { + className = className.substring(className.lastIndexOf('.') + 1) + className = className.substring(className.lastIndexOf('$') + 1) + } + + escape(useClassDisplayName ? classDisplayName : className) } @CompileDynamic String getDisplayName() { - escape(testDescriptor.properties.displayName ?: testDescriptor.name) + escape(testDescriptor.properties.displayName ?: testDescriptor.name as String) } String getSuiteKey() { diff --git a/src/main/groovy/com/adarshr/gradle/testlogger/TestLoggerExtension.groovy b/src/main/groovy/com/adarshr/gradle/testlogger/TestLoggerExtension.groovy index e7eea05..456e001 100644 --- a/src/main/groovy/com/adarshr/gradle/testlogger/TestLoggerExtension.groovy +++ b/src/main/groovy/com/adarshr/gradle/testlogger/TestLoggerExtension.groovy @@ -25,6 +25,7 @@ class TestLoggerExtension { boolean showPassed = true boolean showSkipped = true boolean showFailed = true + boolean showSimpleNames = false private final ConsoleOutput consoleType private Set configuredProperties = [] @@ -46,6 +47,7 @@ class TestLoggerExtension { this.showPassed = source.showPassed this.showSkipped = source.showSkipped this.showFailed = source.showFailed + this.showSimpleNames = source.showSimpleNames this.consoleType = source.consoleType this.configuredProperties = source.configuredProperties } @@ -118,6 +120,11 @@ class TestLoggerExtension { this.configuredProperties << 'showFailed' } + void setShowSimpleNames(boolean showSimpleNames) { + this.showSimpleNames = showSimpleNames + this.configuredProperties << 'showSimpleNames' + } + TestLoggerExtension undecorate() { new TestLoggerExtension(this) } @@ -155,6 +162,7 @@ class TestLoggerExtension { override(overrides, 'showPassed', Boolean) override(overrides, 'showSkipped', Boolean) override(overrides, 'showFailed', Boolean) + override(overrides, 'showSimpleNames', Boolean) this } diff --git a/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/TestLoggerPluginSpec.groovy b/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/TestLoggerPluginSpec.groovy index 48812eb..37d859d 100644 --- a/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/TestLoggerPluginSpec.groovy +++ b/src/test-functional/groovy/com/adarshr/gradle/testlogger/functional/TestLoggerPluginSpec.groovy @@ -137,7 +137,7 @@ class TestLoggerPluginSpec extends AbstractFunctionalSpec { and: lines.size() == 10 lines[0] == render('') - lines[1] == render('[erase-ahead,bold]FirstTest[/]') + lines[1] == render('[erase-ahead,bold]com.adarshr.test.FirstTest[/]') lines[2] == render('') lines[3] == render('[erase-ahead,bold] Test [bold-off]thisTestShouldBeSkipped()[yellow] SKIPPED[/]') lines[4] == render('[erase-ahead,bold] Test [bold-off]this test should fail[red] FAILED[red]') @@ -162,16 +162,16 @@ class TestLoggerPluginSpec extends AbstractFunctionalSpec { and: lines.size() == 14 lines[0] == render('') - lines[1] == render('[erase-ahead,bold]NestedTestsetOne[/]') + lines[1] == render('[erase-ahead,bold]com.adarshr.test.NestedTest$NestedTestsetThree[/]') lines[2] == render('') - lines[3] == render('[erase-ahead,bold] Test [bold-off]secondTestOfNestedTestsetOne()[green] PASSED[/]') - lines[4] == render('[erase-ahead,bold] Test [bold-off]firstTestOfNestedTestsetOne()[green] PASSED[/]') - lines[5] == render('') - lines[6] == render('[erase-ahead,bold]NestedTestsetThree[/]') - lines[7] == render('') - lines[8] == render('[erase-ahead,bold] Test [bold-off]firstTestOfNestedTestsetThree()[green] PASSED[/]') + lines[3] == render('[erase-ahead,bold] Test [bold-off]firstTestOfNestedTestsetThree()[green] PASSED[/]') + lines[4] == render('') + lines[5] == render('[erase-ahead,bold]com.adarshr.test.NestedTest$NestedTestsetTwo[/]') + lines[6] == render('') + lines[7] == render('[erase-ahead,bold] Test [bold-off]secondTestOfNestedTestsetTwo()[green] PASSED[/]') + lines[8] == render('[erase-ahead,bold] Test [bold-off]firstTestOfNestedTestsetTwo()[green] PASSED[/]') lines[9] == render('') - lines[10] == render('[erase-ahead,bold]NestedTestsetTwo[/]') + lines[10] == render('[erase-ahead,bold]com.adarshr.test.NestedTest$NestedTestsetOne[/]') lines[11] == render('') lines[12] == render('[erase-ahead,bold] Test [bold-off]secondTestOfNestedTestsetOne()[green] PASSED[/]') lines[13] == render('[erase-ahead,bold] Test [bold-off]firstTestOfNestedTestsetOne()[green] PASSED[/]') @@ -187,6 +187,29 @@ class TestLoggerPluginSpec extends AbstractFunctionalSpec { ) then: def lines = getLoggerOutput(result.output).lines + and: + lines.size() == 8 + lines[0] == render('') + lines[1] == render('[erase-ahead,bold]com.adarshr.test.DeepNestedTest$NestedTestsetLevelOne[/]') + lines[2] == render('') + lines[3] == render('[erase-ahead,bold] Test [bold-off]nestedTestsetLevelOne()[green] PASSED[/]') + lines[4] == render('') + lines[5] == render('[erase-ahead,bold]Nested test set level two[/]') + lines[6] == render('') + lines[7] == render('[erase-ahead,bold] Test [bold-off]nestedTestsetLevelTwo()[green] PASSED[/]') + and: + result.task(":test").outcome == SUCCESS + } + + def "log junit5 jupiter engine deep-nested tests when showSimpleNames is true"() { + when: + def result = run( + 'sample-junit5-jupiter-deep-nested-tests', + 'testlogger { showSimpleNames true }', + 'clean test' + ) + then: + def lines = getLoggerOutput(result.output).lines and: lines.size() == 8 lines[0] == render('') @@ -226,6 +249,29 @@ class TestLoggerPluginSpec extends AbstractFunctionalSpec { result.task(":test").outcome == FAILED } + def "log spock tests when showSimpleNames is true"() { + when: + def result = run( + 'single-spock-test', + ''' + testlogger { + theme 'plain' + showSimpleNames true + } + ''', + 'clean test' + ) + def lines = getLoggerOutput(result.output).lines + then: + lines.size() == 4 + lines[0] == render('') + lines[1] == render('SingleSpec') + lines[2] == render('') + lines[3] == render(' Test this is a single test PASSED') + and: + result.task(':test').outcome == SUCCESS + } + def "do not print empty suites when filtering tests"() { when: def result = run( diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/TestDescriptorWrapperSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/TestDescriptorWrapperSpec.groovy index d2e5bab..351011a 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/TestDescriptorWrapperSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/TestDescriptorWrapperSpec.groovy @@ -2,6 +2,7 @@ package com.adarshr.gradle.testlogger import org.gradle.api.tasks.testing.TestDescriptor import spock.lang.Specification +import spock.lang.Unroll class TestDescriptorWrapperSpec extends Specification { @@ -25,6 +26,31 @@ class TestDescriptorWrapperSpec extends Specification { wrapper.classDisplayName == 'class display name \\[escaped\\]' } + @Unroll + def "classDisplayName is #expected when classDisplayName property = #classDisplayName, className = #className and showSimpleNames = #showSimpleNames"() { + given: + testDescriptorMock.properties >> [classDisplayName: classDisplayName] + testDescriptorMock.className >> className + and: + testLoggerExtensionMock.showSimpleNames >> showSimpleNames + expect: + wrapper.classDisplayName == expected + where: + classDisplayName | className | showSimpleNames | expected + 'Test' | 'com.adarshr.Test' | false | 'com.adarshr.Test' + 'A test' | 'com.adarshr.Test' | false | 'A test' + '' | 'com.adarshr.Test' | false | 'com.adarshr.Test' + null | 'com.adarshr.Test' | false | 'com.adarshr.Test' + 'Two' | 'com.adarshr.Test$One$Two' | false | 'com.adarshr.Test$One$Two' + 'com.adarshr.Test' | 'com.adarshr.Test' | false | 'com.adarshr.Test' + 'Test' | 'com.adarshr.Test' | true | 'Test' + 'A test' | 'com.adarshr.Test' | true | 'A test' + '' | 'com.adarshr.Test' | true | 'Test' + null | 'com.adarshr.Test' | true | 'Test' + 'Two' | 'com.adarshr.Test$One$Two' | true | 'Two' + 'com.adarshr.Test' | 'com.adarshr.Test' | true | 'Test' + } + def "classDisplayName falls back to className if classDisplayName property is missing"() { given: testDescriptorMock.properties >> [:] From 52fbd062655fcc3e605e7fced011864714cdcdd2 Mon Sep 17 00:00:00 2001 From: radarsh Date: Wed, 29 May 2019 22:48:20 +0100 Subject: [PATCH 7/8] Add more control over stacktrace display --- README.md | 41 ++++-- build.gradle | 4 + .../testlogger/TestLoggerExtension.groovy | 41 ++++++ .../testlogger/theme/AbstractTheme.groovy | 125 ++++++++++++---- .../gradle/testlogger/theme/MochaTheme.groovy | 4 +- .../gradle/testlogger/theme/PlainTheme.groovy | 4 +- .../testlogger/theme/StandardTheme.groovy | 4 +- .../testlogger/TestLoggerExtensionSpec.groovy | 48 +++++-- .../testlogger/theme/AbstractThemeSpec.groovy | 134 +++++++++++++++++- .../theme/MochaParallelThemeSpec.groovy | 4 + .../testlogger/theme/MochaThemeSpec.groovy | 4 + .../theme/PlainParallelThemeSpec.groovy | 4 + .../testlogger/theme/PlainThemeSpec.groovy | 4 + .../theme/StandardParallelThemeSpec.groovy | 4 + .../testlogger/theme/StandardThemeSpec.groovy | 4 + 15 files changed, 373 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 82fa7e3..58b009d 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,9 @@ The following shows the complete default configuration applied when you configur testlogger { theme 'standard' showExceptions true + showStackTraces true + showFullStackTraces false + showCauses true slowThreshold 2000 showSummary true showSimpleNames false @@ -224,6 +227,35 @@ testlogger { By default all the above three flags are turned on. If you have chosen to display standard streams by setting `showStandardStreams` flag to `true`, any output produced by filtered out tests will not be displayed. +### Relationship between `testlogger` and `Test.testLogging` + +Where possible, the plugin's `testlogger` extension tries to react to equivalent properties of Gradle's `Test.testLogging` +extension. However, if a value is explicitly configured under the `testlogger` extension, the plugin __does not__ react to the +corresponding property of `Test.testLogging`. The below table demonstrates this in more detail. + +| Property | `Test.testLogging` value | `testlogging` value | Effective value | +|---------------------------|---------------------------------------|------------------------|---------------- | +| `showStandardStreams` | `true` | not configured | `true` | +| `showStandardStreams` | `true` | `false` | `false` | +| `showStandardStreams` | `false` | `true` | `true` | +| `showExceptions` | `true` | not configured | `true` | +| `showExceptions` | `true` | `false` | `false` | +| `showExceptions` | `false` | `true` | `true` | +| `showStackTraces` | `true` | not configured | `true` | +| `showStackTraces` | `true` | `false` | `false` | +| `showStackTraces` | `false` | `true` | `true` | +| `showFullStackTraces` | `testLogging.exceptionFormat = FULL` | not configured | `true` | +| `showFullStackTraces` | `testLogging.exceptionFormat = SHORT` | not configured | `false` | +| `showFullStackTraces` | `testLogging.exceptionFormat = FULL` | `false` | `false` | +| `showFullStackTraces` | `testLogging.exceptionFormat = SHORT` | `true` | `true` | +| `showCauses` | `true` | not configured | `true` | +| `showCauses` | `true` | `false` | `false` | +| `showCauses` | `false` | `true` | `true` | + +In other words, an explicitly configured `testlogger` property, despite it being `false`, takes precedence over any +value of `Test.testLogging`. + + ## FAQ ### Does it work on Windows? @@ -245,15 +277,6 @@ Yes. You will need to switch to a suitable parallel theme though. This can be on [`maxParallelForks`](https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html#org.gradle.api.tasks.testing.Test:maxParallelForks) greater than 1. They achieve this by sacrificing the ability to group tests and thus some readability is lost. -### How are `testlogger` and `Test.testLogging` related? - -Until recently, they were unrelated. While this plugin's `testlogger` has many properties named identical to the ones in Gradle's -`Test.testLogging`, to a large extent, they are kept isolated by design. - -However, as of this writing `testlogger.showStandardStreams` property has been made to react to `testLogging.showStandardStreams` -property as long as one doesn't configure a value for `testlogger.showStandardStreams`. If a value is configured for -`testlogger.showStandardStreams` (even if it is `false`), the plugin ignores `testLogging.showStandardStreams` altogether. - ### Can this plugin co-exist with junit-platform-gradle-plugin? Due to certain unknown reasons, `junit-platform-gradle-plugin` is incompatible with `gradle-test-logger-plugin`. If you are still diff --git a/build.gradle b/build.gradle index c257834..c23be21 100644 --- a/build.gradle +++ b/build.gradle @@ -82,6 +82,10 @@ test { testClassesDirs += sourceSets.functionalTest.output.classesDirs classpath += sourceSets.functionalTest.runtimeClasspath systemProperty 'file.encoding', 'UTF-8' + +// testLogging { +// exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL +// } testlogger { theme 'mocha' diff --git a/src/main/groovy/com/adarshr/gradle/testlogger/TestLoggerExtension.groovy b/src/main/groovy/com/adarshr/gradle/testlogger/TestLoggerExtension.groovy index 456e001..90aeb0f 100644 --- a/src/main/groovy/com/adarshr/gradle/testlogger/TestLoggerExtension.groovy +++ b/src/main/groovy/com/adarshr/gradle/testlogger/TestLoggerExtension.groovy @@ -9,6 +9,7 @@ import org.gradle.api.tasks.testing.logging.TestLogging import static com.adarshr.gradle.testlogger.theme.ThemeType.PLAIN import static com.adarshr.gradle.testlogger.theme.ThemeType.STANDARD import static org.gradle.api.logging.configuration.ConsoleOutput.Plain +import static org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL @CompileStatic @SuppressWarnings("GroovyUnusedDeclaration") @@ -16,6 +17,9 @@ class TestLoggerExtension { ThemeType theme = STANDARD boolean showExceptions = true + boolean showCauses = true + boolean showStackTraces = true + boolean showFullStackTraces = false long slowThreshold = 2000 boolean showSummary = true boolean showStandardStreams = false @@ -38,6 +42,9 @@ class TestLoggerExtension { private TestLoggerExtension(TestLoggerExtension source) { this.theme = source.theme this.showExceptions = source.showExceptions + this.showCauses = source.showCauses + this.showStackTraces = source.showStackTraces + this.showFullStackTraces = source.showFullStackTraces this.slowThreshold = source.slowThreshold this.showSummary = source.showSummary this.showStandardStreams = source.showStandardStreams @@ -75,6 +82,21 @@ class TestLoggerExtension { this.configuredProperties << 'showExceptions' } + void setShowCauses(boolean showCauses) { + this.showCauses = showCauses + this.configuredProperties << 'showCauses' + } + + void setShowStackTraces(boolean showStackTraces) { + this.showStackTraces = showStackTraces + this.configuredProperties << 'showStackTraces' + } + + void setShowFullStackTraces(boolean showFullStackTraces) { + this.showFullStackTraces = showFullStackTraces + this.configuredProperties << 'showFullStackTraces' + } + void setSlowThreshold(long slowThreshold) { this.slowThreshold = slowThreshold this.configuredProperties << 'slowThreshold' @@ -134,6 +156,22 @@ class TestLoggerExtension { this.showStandardStreams = testLogging.showStandardStreams this.configuredProperties -= 'showStandardStreams' } + if (!this.configuredProperties.contains('showExceptions')) { + this.showExceptions = testLogging.showExceptions + this.configuredProperties -= 'showExceptions' + } + if (!this.configuredProperties.contains('showCauses')) { + this.showCauses = testLogging.showCauses + this.configuredProperties -= 'showCauses' + } + if (!this.configuredProperties.contains('showStackTraces')) { + this.showStackTraces = testLogging.showStackTraces + this.configuredProperties -= 'showStackTraces' + } + if (!this.configuredProperties.contains('showFullStackTraces')) { + this.showFullStackTraces = testLogging.showStackTraces && testLogging.exceptionFormat == FULL + this.configuredProperties -= 'showFullStackTraces' + } this } @@ -153,6 +191,9 @@ class TestLoggerExtension { TestLoggerExtension applyOverrides(Map overrides) { override(overrides, 'theme', ThemeType) override(overrides, 'showExceptions', Boolean) + override(overrides, 'showCauses', Boolean) + override(overrides, 'showStackTraces', Boolean) + override(overrides, 'showFullStackTraces', Boolean) override(overrides, 'slowThreshold', Long) override(overrides, 'showSummary', Boolean) override(overrides, 'showStandardStreams', Boolean) diff --git a/src/main/groovy/com/adarshr/gradle/testlogger/theme/AbstractTheme.groovy b/src/main/groovy/com/adarshr/gradle/testlogger/theme/AbstractTheme.groovy index db61bec..53c1303 100644 --- a/src/main/groovy/com/adarshr/gradle/testlogger/theme/AbstractTheme.groovy +++ b/src/main/groovy/com/adarshr/gradle/testlogger/theme/AbstractTheme.groovy @@ -5,32 +5,18 @@ import com.adarshr.gradle.testlogger.TestLoggerExtension import com.adarshr.gradle.testlogger.TestResultWrapper import groovy.transform.CompileStatic -import static com.adarshr.gradle.testlogger.util.RendererUtils.escape +import static com.adarshr.gradle.testlogger.util.RendererUtils.preserveAnsi import static java.lang.System.lineSeparator -@SuppressWarnings("GrMethodMayBeStatic") @CompileStatic abstract class AbstractTheme implements Theme { final ThemeType type - - protected final boolean showExceptions - protected final long slowThreshold - protected final boolean showSummary - protected final boolean showStandardStreams - protected final boolean showPassed - protected final boolean showSkipped - protected final boolean showFailed + protected final TestLoggerExtension extension AbstractTheme(TestLoggerExtension extension) { this.type = extension.theme - this.showExceptions = extension.showExceptions - this.slowThreshold = extension.slowThreshold - this.showSummary = extension.showSummary - this.showStandardStreams = extension.showStandardStreams - this.showPassed = extension.showPassed - this.showSkipped = extension.showSkipped - this.showFailed = extension.showFailed + this.extension = extension } @Override @@ -69,26 +55,107 @@ abstract class AbstractTheme implements Theme { protected String exceptionText(TestDescriptorWrapper descriptor, TestResultWrapper result, int indent) { def line = new StringBuilder() - if (showExceptions) { - def indentation = ' ' * indent + if (!extension.showExceptions) { + return line + } + + line << "${lineSeparator()}${lineSeparator()}" + + new StackTracePrinter(descriptor, ' ' * indent, line) + .printStackTrace(result.exception) + .toString() + } + + private class StackTracePrinter { + final TestDescriptorWrapper descriptor + final String indentation + final StringBuilder line - line << "${lineSeparator()}${lineSeparator()}" + StackTracePrinter(TestDescriptorWrapper descriptor, String indentation, StringBuilder line) { + this.descriptor = descriptor + this.indentation = indentation + this.line = line + } - line << result.exception.toString().trim().readLines().collect { - "${indentation}${escape(it)}" - }.join(lineSeparator()) + StackTracePrinter printStackTrace(Throwable exception, List parentStackTrace = [], boolean cause = false) { + if (cause) { + line << "${indentation}Caused by: " + } + line << message(exception, cause) line << lineSeparator() - line << result.exception.stackTrace.find { - it.className == descriptor.className - }.collect { - "${indentation} at ${escape(it.toString())}" - }.join(lineSeparator()) + if (!extension.showStackTraces) { + return this + } + + def filteredTrace = filter(exception.stackTrace) + line << stackTrace(filteredTrace, countCommonFrames(parentStackTrace, filteredTrace)) line << lineSeparator() + + if (extension.showCauses && exception.cause) { + printStackTrace(exception.cause, filteredTrace, true) + } + + this + } + + String message(Throwable exception, boolean cause) { + exception.toString() + .trim() + .readLines() + .withIndex() + .collect { String message, index -> + "${index != 0 || !cause ? indentation : ''}${preserveAnsi(message)}" + }.join(lineSeparator()) + } + + String stackTrace(List stackTrace, int commonFrames) { + def trace = new StringBuilder(stackTrace + .subList(0, stackTrace.size() - commonFrames) + .collect { + "${indentation} at ${preserveAnsi(it.toString())}" + }.join(lineSeparator())) + + if (commonFrames) { + trace << "${lineSeparator()}${indentation} ... ${commonFrames} more" + } + + trace.toString() } - line + int countCommonFrames(List parentStackTrace, List stackTrace) { + int count = 0 + + if (parentStackTrace.empty) { + return count; + } + + int i = stackTrace.size() - 1, j = parentStackTrace.size() - 1 + + while (i >= 1 && j >= 0 && stackTrace[i] == parentStackTrace[j]) { + ++count; i--; j-- + } + + count + } + + List filter(StackTraceElement[] stackTrace) { + if (extension.showFullStackTraces) { + return stackTrace.toList() + } + + stackTrace.find { + it.className == descriptor.className + }.collect { + it as StackTraceElement + } + } + + @Override + String toString() { + line.toString() + } } } diff --git a/src/main/groovy/com/adarshr/gradle/testlogger/theme/MochaTheme.groovy b/src/main/groovy/com/adarshr/gradle/testlogger/theme/MochaTheme.groovy index f75d689..b140e8e 100644 --- a/src/main/groovy/com/adarshr/gradle/testlogger/theme/MochaTheme.groovy +++ b/src/main/groovy/com/adarshr/gradle/testlogger/theme/MochaTheme.groovy @@ -83,7 +83,7 @@ class MochaTheme extends AbstractTheme { } protected String summaryText(TestDescriptorWrapper descriptor, TestResultWrapper result, int indent) { - if (!showSummary) { + if (!extension.showSummary) { return '' } @@ -113,7 +113,7 @@ class MochaTheme extends AbstractTheme { } protected String standardStreamTextInternal(String lines, int indent) { - if (!showStandardStreams || !lines) { + if (!extension.showStandardStreams || !lines) { return '' } diff --git a/src/main/groovy/com/adarshr/gradle/testlogger/theme/PlainTheme.groovy b/src/main/groovy/com/adarshr/gradle/testlogger/theme/PlainTheme.groovy index 5e45ff9..cb1004c 100644 --- a/src/main/groovy/com/adarshr/gradle/testlogger/theme/PlainTheme.groovy +++ b/src/main/groovy/com/adarshr/gradle/testlogger/theme/PlainTheme.groovy @@ -45,7 +45,7 @@ class PlainTheme extends AbstractTheme { @Override String summaryText(TestDescriptorWrapper descriptor, TestResultWrapper result) { - if (!showSummary) { + if (!extension.showSummary) { return '' } @@ -88,7 +88,7 @@ class PlainTheme extends AbstractTheme { } protected String standardStreamTextInternal(String lines, int indent) { - if (!showStandardStreams || !lines) { + if (!extension.showStandardStreams || !lines) { return '' } diff --git a/src/main/groovy/com/adarshr/gradle/testlogger/theme/StandardTheme.groovy b/src/main/groovy/com/adarshr/gradle/testlogger/theme/StandardTheme.groovy index 658b900..19073c9 100644 --- a/src/main/groovy/com/adarshr/gradle/testlogger/theme/StandardTheme.groovy +++ b/src/main/groovy/com/adarshr/gradle/testlogger/theme/StandardTheme.groovy @@ -61,7 +61,7 @@ class StandardTheme extends AbstractTheme { @Override String summaryText(TestDescriptorWrapper descriptor, TestResultWrapper result) { - if (!showSummary) { + if (!extension.showSummary) { return '' } @@ -105,7 +105,7 @@ class StandardTheme extends AbstractTheme { } protected String standardStreamTextInternal(String lines, int indent) { - if (!showStandardStreams || !lines) { + if (!extension.showStandardStreams || !lines) { return '' } diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/TestLoggerExtensionSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/TestLoggerExtensionSpec.groovy index fb93360..f941ebb 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/TestLoggerExtensionSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/TestLoggerExtensionSpec.groovy @@ -9,6 +9,9 @@ import org.gradle.api.tasks.testing.logging.TestLogging import spock.lang.Specification import spock.lang.Unroll +import static org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL +import static org.gradle.api.tasks.testing.logging.TestExceptionFormat.SHORT + class TestLoggerExtensionSpec extends Specification { def projectMock = Mock(Project) { @@ -110,31 +113,56 @@ class TestLoggerExtensionSpec extends Specification { } @Unroll - def "test logger extension showStandardStreams reacts to testLogging.showStandardStreams"() { + def "test logger extension reacts to testLogging properties #testLoggingProperties"() { given: - def testLoggingMock = Mock(TestLogging) { - getShowStandardStreams() >> value + def testLoggingMock = Mock(TestLogging) + testLoggingProperties.each { property, value -> + testLoggingMock."${property}" >> value } def extension = new TestLoggerExtension(projectMock) when: def reacted = extension.reactTo(testLoggingMock) then: - reacted.showStandardStreams == value + extensionProperties.each { property, value -> + assert reacted."${property}" == value + } where: - value << [true, false] + testLoggingProperties | extensionProperties + [showStandardStreams: true] | [showStandardStreams: true] + [showStandardStreams: false] | [showStandardStreams: false] + [showExceptions: true] | [showExceptions: true] + [showExceptions: false] | [showExceptions: false] + [showCauses: true] | [showCauses: true] + [showCauses: false] | [showCauses: false] + [showStackTraces: true, exceptionFormat: SHORT] | [showStackTraces: true, showFullStackTraces: false] + [showStackTraces: false] | [showStackTraces: false, showFullStackTraces: false] + [showStackTraces: true, exceptionFormat: FULL] | [showStackTraces: true, showFullStackTraces: true] } - def "test logger extension does not react to testLogging if showStandardStreams has been configured"() { + @Unroll + def "test logger extension does not react to testLogging if extension properties #extensionProperties have been configured"() { given: - def testLoggingMock = Mock(TestLogging) { - getShowStandardStreams() >> true + def testLoggingMock = Mock(TestLogging) + testLoggingProperties.each { property, value -> + testLoggingMock."${property}" >> value } def extension = new TestLoggerExtension(projectMock) and: - extension.showStandardStreams = false + extensionProperties.each { property, value -> + extension."${property}" = value + } when: def reacted = extension.reactTo(testLoggingMock) then: - !reacted.showStandardStreams + extensionProperties.each { property, value -> + assert reacted."${property}" == value + } + where: + testLoggingProperties | extensionProperties + [showStandardStreams: true] | [showStandardStreams: false] + [showExceptions: true] | [showExceptions: false] + [showCauses: true] | [showCauses: false] + [showStackTraces: true, exceptionFormat: SHORT] | [showStackTraces: false, showFullStackTraces: false] + [showStackTraces: true, exceptionFormat: FULL] | [showStackTraces: false, showFullStackTraces: false] } } diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/theme/AbstractThemeSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/theme/AbstractThemeSpec.groovy index ba4f71d..b78fc89 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/theme/AbstractThemeSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/theme/AbstractThemeSpec.groovy @@ -4,10 +4,41 @@ import com.adarshr.gradle.testlogger.TestDescriptorWrapper import com.adarshr.gradle.testlogger.TestLoggerExtension import com.adarshr.gradle.testlogger.TestResultWrapper import groovy.transform.InheritConstructors -import spock.lang.Specification import spock.lang.Unroll -class AbstractThemeSpec extends Specification { +import static java.lang.System.lineSeparator + +class AbstractThemeSpec extends BaseThemeSpec { + + private static final Throwable TEST_EXCEPTION = generateException() + + private static final Throwable generateException() { + def error = new Serializable() { + Throwable one() { two() } + + Throwable two() { three() } + + Throwable three() { + new RuntimeException('Middle error', new RuntimeException('Inner error')) + } + } + + lightenStackTrace(new RuntimeException('Outer error', error.one())) + } + + private static Throwable lightenStackTrace(Throwable throwable) { + throwable.stackTrace = throwable.stackTrace.findAll { + it.className.contains 'adarshr' + } + + if (throwable.cause) { + lightenStackTrace(throwable.cause) + } + + throwable + } + + private static final int LINE_NUMBER = generateException().stackTrace.find { it.className == owner.name }.lineNumber def testLoggerExtensionMock = Mock(TestLoggerExtension) def theme = new TestTheme(testLoggerExtensionMock) @@ -62,6 +93,105 @@ class AbstractThemeSpec extends Specification { '' | false } + def "test exception text with default settings"() { + given: + testLoggerExtensionMock.showExceptions >> true + testLoggerExtensionMock.showCauses >> true + testLoggerExtensionMock.showStackTraces >> true + testDescriptorMock.className >> AbstractThemeSpec.name + testResultMock.exception >> TEST_EXCEPTION + when: + def actual = theme.exceptionText(testDescriptorMock, testResultMock) + then: + actual == + """| + | + | java.lang.RuntimeException: Outer error + | at com.adarshr.gradle.testlogger.theme.AbstractThemeSpec.generateException(AbstractThemeSpec.groovy:${LINE_NUMBER}) + | Caused by: java.lang.RuntimeException: Middle error + | at com.adarshr.gradle.testlogger.theme.AbstractThemeSpec.generateException(AbstractThemeSpec.groovy:${LINE_NUMBER}) + | Caused by: java.lang.RuntimeException: Inner error + | at com.adarshr.gradle.testlogger.theme.AbstractThemeSpec.generateException(AbstractThemeSpec.groovy:${LINE_NUMBER}) + |""".stripMargin().replace('\n', lineSeparator()) + } + + def "test exception text with showFullStackTraces on"() { + given: + testLoggerExtensionMock.showExceptions >> true + testLoggerExtensionMock.showCauses >> true + testLoggerExtensionMock.showStackTraces >> true + testLoggerExtensionMock.showFullStackTraces >> true + testDescriptorMock.className >> AbstractThemeSpec.name + testResultMock.exception >> TEST_EXCEPTION + when: + def actual = theme.exceptionText(testDescriptorMock, testResultMock) + then: + actual == + """| + | + | java.lang.RuntimeException: Outer error + | at com.adarshr.gradle.testlogger.theme.AbstractThemeSpec.generateException(AbstractThemeSpec.groovy:${LINE_NUMBER}) + | at com.adarshr.gradle.testlogger.theme.AbstractThemeSpec.(AbstractThemeSpec.groovy:13) + | Caused by: java.lang.RuntimeException: Middle error + | at com.adarshr.gradle.testlogger.theme.AbstractThemeSpec\$1.three(AbstractThemeSpec.groovy:22) + | at com.adarshr.gradle.testlogger.theme.AbstractThemeSpec\$1.two(AbstractThemeSpec.groovy:19) + | at com.adarshr.gradle.testlogger.theme.AbstractThemeSpec\$1.one(AbstractThemeSpec.groovy:17) + | at com.adarshr.gradle.testlogger.theme.AbstractThemeSpec\$1\$one.call(Unknown Source) + | ... 2 more + | Caused by: java.lang.RuntimeException: Inner error + | at com.adarshr.gradle.testlogger.theme.AbstractThemeSpec\$1.three(AbstractThemeSpec.groovy:22) + | ... 5 more + |""".stripMargin().replace('\n', lineSeparator()) + } + + def "test exception text with showCauses off"() { + given: + testLoggerExtensionMock.showExceptions >> true + testLoggerExtensionMock.showCauses >> false + testLoggerExtensionMock.showStackTraces >> true + testLoggerExtensionMock.showFullStackTraces >> true + testDescriptorMock.className >> AbstractThemeSpec.name + testResultMock.exception >> TEST_EXCEPTION + when: + def actual = theme.exceptionText(testDescriptorMock, testResultMock) + then: + actual == + """| + | + | java.lang.RuntimeException: Outer error + | at com.adarshr.gradle.testlogger.theme.AbstractThemeSpec.generateException(AbstractThemeSpec.groovy:${LINE_NUMBER}) + | at com.adarshr.gradle.testlogger.theme.AbstractThemeSpec.(AbstractThemeSpec.groovy:13) + |""".stripMargin().replace('\n', lineSeparator()) + } + + def "test exception text with showStackTraces off"() { + given: + testLoggerExtensionMock.showExceptions >> true + testLoggerExtensionMock.showCauses >> true + testLoggerExtensionMock.showStackTraces >> false + testDescriptorMock.className >> AbstractThemeSpec.name + testResultMock.exception >> TEST_EXCEPTION + when: + def actual = theme.exceptionText(testDescriptorMock, testResultMock) + then: + actual == + """| + | + | java.lang.RuntimeException: Outer error + |""".stripMargin().replace('\n', lineSeparator()) + } + + def "test exception text with showExceptions off"() { + given: + testLoggerExtensionMock.showExceptions >> false + testDescriptorMock.className >> AbstractThemeSpec.name + testResultMock.exception >> TEST_EXCEPTION + when: + def actual = theme.exceptionText(testDescriptorMock, testResultMock) + then: + !actual + } + @InheritConstructors static class TestTheme extends AbstractTheme { diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaParallelThemeSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaParallelThemeSpec.groovy index 3297cf7..7eeba19 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaParallelThemeSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaParallelThemeSpec.groovy @@ -57,6 +57,8 @@ class MochaParallelThemeSpec extends BaseThemeSpec { given: System.setProperty('os.name', 'Linux') testLoggerExtensionMock.showExceptions >> true + testLoggerExtensionMock.showStackTraces >> true + testLoggerExtensionMock.showCauses >> true theme = new MochaParallelTheme(testLoggerExtensionMock) and: testResultMock.resultType >> FAILURE @@ -78,6 +80,8 @@ class MochaParallelThemeSpec extends BaseThemeSpec { def "exception text when showExceptions is true"() { given: testLoggerExtensionMock.showExceptions >> true + testLoggerExtensionMock.showStackTraces >> true + testLoggerExtensionMock.showCauses >> true theme = new MochaParallelTheme(testLoggerExtensionMock) and: testResultMock.resultType >> FAILURE diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaThemeSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaThemeSpec.groovy index 4259499..8138bb5 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaThemeSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/theme/MochaThemeSpec.groovy @@ -60,6 +60,8 @@ class MochaThemeSpec extends BaseThemeSpec { given: System.setProperty('os.name', 'Linux') testLoggerExtensionMock.showExceptions >> true + testLoggerExtensionMock.showStackTraces >> true + testLoggerExtensionMock.showCauses >> true theme = new MochaTheme(testLoggerExtensionMock) and: testResultMock.resultType >> FAILURE @@ -80,6 +82,8 @@ class MochaThemeSpec extends BaseThemeSpec { def "exception text when showExceptions is true"() { given: testLoggerExtensionMock.showExceptions >> true + testLoggerExtensionMock.showStackTraces >> true + testLoggerExtensionMock.showCauses >> true theme = new MochaTheme(testLoggerExtensionMock) and: testResultMock.resultType >> FAILURE diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainParallelThemeSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainParallelThemeSpec.groovy index 0a80874..ae660ac 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainParallelThemeSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainParallelThemeSpec.groovy @@ -46,6 +46,8 @@ class PlainParallelThemeSpec extends BaseThemeSpec { def "after test with result type failure and showExceptions true"() { given: testLoggerExtensionMock.showExceptions >> true + testLoggerExtensionMock.showStackTraces >> true + testLoggerExtensionMock.showCauses >> true theme = new PlainParallelTheme(testLoggerExtensionMock) and: testResultMock.resultType >> FAILURE @@ -67,6 +69,8 @@ class PlainParallelThemeSpec extends BaseThemeSpec { def "exception text when showExceptions is true"() { given: testLoggerExtensionMock.showExceptions >> true + testLoggerExtensionMock.showStackTraces >> true + testLoggerExtensionMock.showCauses >> true theme = new PlainParallelTheme(testLoggerExtensionMock) and: testResultMock.resultType >> FAILURE diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainThemeSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainThemeSpec.groovy index 078d30f..3728d5a 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainThemeSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/theme/PlainThemeSpec.groovy @@ -49,6 +49,8 @@ class PlainThemeSpec extends BaseThemeSpec { def "after test with result type failure and showExceptions true"() { given: testLoggerExtensionMock.showExceptions >> true + testLoggerExtensionMock.showStackTraces >> true + testLoggerExtensionMock.showCauses >> true theme = new PlainTheme(testLoggerExtensionMock) and: testResultMock.resultType >> FAILURE @@ -69,6 +71,8 @@ class PlainThemeSpec extends BaseThemeSpec { def "exception text when showExceptions is true"() { given: testLoggerExtensionMock.showExceptions >> true + testLoggerExtensionMock.showStackTraces >> true + testLoggerExtensionMock.showCauses >> true theme = new PlainTheme(testLoggerExtensionMock) and: testResultMock.resultType >> FAILURE diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardParallelThemeSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardParallelThemeSpec.groovy index 5ee081d..2d96624 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardParallelThemeSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardParallelThemeSpec.groovy @@ -46,6 +46,8 @@ class StandardParallelThemeSpec extends BaseThemeSpec { def "after test with result type failure and showExceptions true"() { given: testLoggerExtensionMock.showExceptions >> true + testLoggerExtensionMock.showStackTraces >> true + testLoggerExtensionMock.showCauses >> true theme = new StandardParallelTheme(testLoggerExtensionMock) and: testResultMock.resultType >> FAILURE @@ -69,6 +71,8 @@ class StandardParallelThemeSpec extends BaseThemeSpec { def "exception text when showExceptions is true"() { given: testLoggerExtensionMock.showExceptions >> true + testLoggerExtensionMock.showStackTraces >> true + testLoggerExtensionMock.showCauses >> true theme = new StandardParallelTheme(testLoggerExtensionMock) and: testResultMock.resultType >> FAILURE diff --git a/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardThemeSpec.groovy b/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardThemeSpec.groovy index 10bf587..cceb56f 100644 --- a/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardThemeSpec.groovy +++ b/src/test/groovy/com/adarshr/gradle/testlogger/theme/StandardThemeSpec.groovy @@ -49,6 +49,8 @@ class StandardThemeSpec extends BaseThemeSpec { def "after test with result type failure and showExceptions true"() { given: testLoggerExtensionMock.showExceptions >> true + testLoggerExtensionMock.showStackTraces >> true + testLoggerExtensionMock.showCauses >> true theme = new StandardTheme(testLoggerExtensionMock) and: testResultMock.resultType >> FAILURE @@ -69,6 +71,8 @@ class StandardThemeSpec extends BaseThemeSpec { def "exception text when showExceptions is true"() { given: testLoggerExtensionMock.showExceptions >> true + testLoggerExtensionMock.showStackTraces >> true + testLoggerExtensionMock.showCauses >> true theme = new StandardTheme(testLoggerExtensionMock) and: testResultMock.resultType >> FAILURE From 9bb9b507f5efcd0ad54b9382335f6d9edb01ac2b Mon Sep 17 00:00:00 2001 From: radarsh Date: Wed, 29 May 2019 23:12:06 +0100 Subject: [PATCH 8/8] Release v1.7.0 --- CHANGELOG.md | 24 +++++++++++++++++++++++- README.md | 4 ++-- gradle.properties | 4 ++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44e962d..43c7f3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,29 @@ # Change Log -## [v1.6.0](https://github.com/radarsh/gradle-test-logger-plugin/tree/v1.6.0) (2018-11-20) +## [v1.7.0](https://github.com/radarsh/gradle-test-logger-plugin/tree/v1.7.0) (2019-05-29) +[Full Changelog](https://github.com/radarsh/gradle-test-logger-plugin/compare/v1.6.0...v1.7.0) + +**Closed issues:** + +- Not enough details about exception thrown by the test. [\#118](https://github.com/radarsh/gradle-test-logger-plugin/issues/118) +- NoSuchMethodError: org.fusesource.jansi.Ansi.fgGreen\(\)Lorg/fusesource/jansi/Ans [\#116](https://github.com/radarsh/gradle-test-logger-plugin/issues/116) +- Mocha on dark terminals [\#115](https://github.com/radarsh/gradle-test-logger-plugin/issues/115) +- Add support for @Nested and @DisplayName [\#106](https://github.com/radarsh/gradle-test-logger-plugin/issues/106) +- Get rid of logs original test logs [\#105](https://github.com/radarsh/gradle-test-logger-plugin/issues/105) +- Prints corrupted json [\#104](https://github.com/radarsh/gradle-test-logger-plugin/issues/104) +- Bad encoding on standard and mocha themes when printing to Eclipse's console [\#92](https://github.com/radarsh/gradle-test-logger-plugin/issues/92) +- Testsuite fatal error output not shown [\#89](https://github.com/radarsh/gradle-test-logger-plugin/issues/89) +**Merged pull requests:** + +- Show full stacktraces [\#119](https://github.com/radarsh/gradle-test-logger-plugin/pull/119) ([radarsh](https://github.com/radarsh)) +- Improve Windows build stability [\#117](https://github.com/radarsh/gradle-test-logger-plugin/pull/117) ([radarsh](https://github.com/radarsh)) +- Show output from before System.exit\(5\) was called [\#113](https://github.com/radarsh/gradle-test-logger-plugin/pull/113) ([radarsh](https://github.com/radarsh)) +- Configure build-scan plugin [\#112](https://github.com/radarsh/gradle-test-logger-plugin/pull/112) ([aalmiray](https://github.com/aalmiray)) +- Use classDisplayName for friendlier suite names [\#109](https://github.com/radarsh/gradle-test-logger-plugin/pull/109) ([radarsh](https://github.com/radarsh)) +- Fix double escaping of brackets [\#108](https://github.com/radarsh/gradle-test-logger-plugin/pull/108) ([radarsh](https://github.com/radarsh)) + +## [v1.6.0](https://github.com/radarsh/gradle-test-logger-plugin/tree/v1.6.0) (2018-11-20) [Full Changelog](https://github.com/radarsh/gradle-test-logger-plugin/compare/v1.5.0...v1.6.0) **Implemented enhancements:** diff --git a/README.md b/README.md index 58b009d..6952684 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Scroll down for more themes and customisation options or visit the [screenshots ```groovy plugins { - id 'com.adarshr.test-logger' version '1.6.0' + id 'com.adarshr.test-logger' version '1.7.0' } ``` @@ -39,7 +39,7 @@ buildscript { } } dependencies { - classpath 'com.adarshr:gradle-test-logger-plugin:1.6.0' + classpath 'com.adarshr:gradle-test-logger-plugin:1.7.0' } } diff --git a/gradle.properties b/gradle.properties index 08cd650..5701f22 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ -version=1.6.0 +version=1.7.0 group=com.adarshr org.gradle.daemon = true org.gradle.caching = true -org.gradle.parallel = true \ No newline at end of file +org.gradle.parallel = true