Skip to content

Added new theme that mimics maven surefire plugin #147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.adarshr.gradle.testlogger.theme

import com.adarshr.gradle.testlogger.TestDescriptorWrapper
import com.adarshr.gradle.testlogger.TestResultWrapper
import groovy.transform.CompileStatic
import groovy.transform.InheritConstructors

import static com.adarshr.gradle.testlogger.theme.ThemeType.MAVEN_PARALLEL

@CompileStatic
@InheritConstructors
class MavenParallelTheme extends MavenTheme {

ThemeType type = MAVEN_PARALLEL

@Override
protected String suiteTextInternal(TestDescriptorWrapper descriptor) {
''
}

@Override
protected String testTextInternal(TestDescriptorWrapper descriptor, TestResultWrapper result) {
super.testTextInternal("[erase-ahead,bold]${descriptor.classDisplayName}[bold-off] ${descriptor.displayName}", descriptor, result)
}

@Override
String exceptionText(TestDescriptorWrapper descriptor, TestResultWrapper result) {
super.exceptionText(descriptor, result, 2)
}

@Override
protected String suiteStandardStreamTextInternal(String lines) {
super.standardStreamTextInternal(lines, 2)
}

@Override
protected String testStandardStreamTextInternal(String lines) {
super.standardStreamTextInternal(lines, 2)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.adarshr.gradle.testlogger.theme

import com.adarshr.gradle.testlogger.TestDescriptorWrapper
import com.adarshr.gradle.testlogger.TestResultWrapper
import groovy.transform.CompileStatic
import groovy.transform.InheritConstructors

import static com.adarshr.gradle.testlogger.theme.ThemeType.MAVEN_PLAIN_PARALLEL

@CompileStatic
@InheritConstructors
class MavenPlainParallelTheme extends MavenPlainTheme {

ThemeType type = MAVEN_PLAIN_PARALLEL

@Override
protected String suiteTextInternal(TestDescriptorWrapper descriptor) {
''
}

@Override
protected String testTextInternal(TestDescriptorWrapper descriptor, TestResultWrapper result) {
super.testTextInternal("${descriptor.classDisplayName} ${descriptor.displayName} ${RESULT_TYPE_MAPPING[result.resultType]}", descriptor, result)
}

@Override
protected String suiteStandardStreamTextInternal(String lines) {
super.standardStreamTextInternal(lines, 2)
}

@Override
protected String testStandardStreamTextInternal(String lines) {
super.standardStreamTextInternal(lines, 2)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.adarshr.gradle.testlogger.theme

import com.adarshr.gradle.testlogger.TestDescriptorWrapper
import com.adarshr.gradle.testlogger.TestResultWrapper
import groovy.transform.CompileStatic
import groovy.transform.InheritConstructors

import static com.adarshr.gradle.testlogger.theme.ThemeType.MAVEN
import static com.adarshr.gradle.testlogger.theme.ThemeType.MAVEN_PLAIN
import static com.adarshr.gradle.testlogger.theme.ThemeType.PLAIN
import static com.adarshr.gradle.testlogger.util.RendererUtils.escape
import static java.lang.System.lineSeparator
import static org.gradle.api.tasks.testing.TestResult.ResultType.*

@CompileStatic
@InheritConstructors
class MavenPlainTheme extends PlainTheme {

ThemeType type = MAVEN_PLAIN

@Override
String summaryText(TestDescriptorWrapper descriptor, TestResultWrapper result) {
if (!extension.showSummary) {
return ''
}
def line = new StringBuilder()

line << "Summary:${lineSeparator()}${lineSeparator()}"

line << " Tests run: ${result.testCount}, " +
"Failures: ${result.failedTestCount}, Skipped: ${result.skippedTestCount}, " +
"Time elapsed: ${result.duration}"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.adarshr.gradle.testlogger.theme

import com.adarshr.gradle.testlogger.TestDescriptorWrapper
import com.adarshr.gradle.testlogger.TestResultWrapper
import groovy.transform.CompileStatic
import groovy.transform.InheritConstructors

import static com.adarshr.gradle.testlogger.theme.ThemeType.MAVEN
import static java.lang.System.lineSeparator

@CompileStatic
@InheritConstructors
class MavenTheme extends StandardTheme {

ThemeType type = MAVEN

@Override
String summaryText(TestDescriptorWrapper descriptor, TestResultWrapper result) {
if (!extension.showSummary) {
return ''
}

String colour = 'green';

if (result.failedTestCount > 0) {
colour = 'red';
} else if (result.skippedTestCount > 0) {
colour = 'yellow';
}

def line = new StringBuilder()

line << "[erase-ahead,default]Summary:${lineSeparator()}${lineSeparator()}"

line << "[bold,${colour}] Tests run: ${result.testCount}, " +
"Failures: ${result.failedTestCount}, Skipped: ${result.skippedTestCount}, " +
"Time elapsed: ${result.duration}[/]"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import org.gradle.api.GradleException
enum ThemeType {
//@formatter:off
// name parallel themeClass parallelFallback
PLAIN( 'plain', false, PlainTheme, 'plain-parallel'),
PLAIN_PARALLEL( 'plain-parallel', true, PlainParallelTheme, null),
STANDARD( 'standard', false, StandardTheme, 'standard-parallel'),
STANDARD_PARALLEL( 'standard-parallel', true, StandardParallelTheme, null),
MOCHA( 'mocha', false, MochaTheme, 'mocha-parallel'),
MOCHA_PARALLEL( 'mocha-parallel', true, MochaParallelTheme, null)
PLAIN( 'plain', false, PlainTheme, 'plain-parallel'),
PLAIN_PARALLEL( 'plain-parallel', true, PlainParallelTheme, null),
STANDARD( 'standard', false, StandardTheme, 'standard-parallel'),
STANDARD_PARALLEL( 'standard-parallel', true, StandardParallelTheme, null),
MOCHA( 'mocha', false, MochaTheme, 'mocha-parallel'),
MOCHA_PARALLEL( 'mocha-parallel', true, MochaParallelTheme, null),
MAVEN( 'maven', false, MavenTheme, 'maven-parallel'),
MAVEN_PARALLEL( 'maven-parallel', true, MavenParallelTheme, null),
MAVEN_PLAIN( 'maven-plain', false, MavenPlainTheme, 'maven-plain-parallel'),
MAVEN_PLAIN_PARALLEL('maven-plain-parallel', true, MavenPlainParallelTheme,null)
//@formatter:on

final String name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.adarshr.gradle.testlogger.theme

import spock.lang.Unroll

import static java.lang.System.lineSeparator
import static org.gradle.api.tasks.testing.TestResult.ResultType.*

class MavenParallelThemeSpec extends BaseThemeSpec {

// right at the top to minimise line number changes
private static AssertionError getException() {
new AssertionError('This is wrong')
}

private static final int LINE_NUMBER = exception.stackTrace.find { it.className == owner.name }.lineNumber

Theme theme

def setup() {
theme = new MavenParallelTheme(testLoggerExtensionMock)
}

def "before suite"() {
expect:
!theme.suiteText(testDescriptorMock, testResultMock)
}

@Unroll
def "after test with result type #resultType"() {
given:
testResultMock.resultType >> resultType
testDescriptorMock.classDisplayName >> 'ClassName'
testDescriptorMock.displayName >> 'test name'
when:
def actual = theme.testText(testDescriptorMock, testResultMock)
then:
actual == expected
where:
resultType | expected
SUCCESS | '[erase-ahead,bold]ClassName[bold-off] test name[green] PASSED[/]'
FAILURE | '[erase-ahead,bold]ClassName[bold-off] test name[red] FAILED[/]'
SKIPPED | '[erase-ahead,bold]ClassName[bold-off] test name[yellow] SKIPPED[/]'
}

def "exception text when showExceptions is true"() {
given:
testLoggerExtensionMock.showExceptions >> true
testLoggerExtensionMock.showStackTraces >> true
testLoggerExtensionMock.showCauses >> true
theme = new MavenParallelTheme(testLoggerExtensionMock)
and:
testResultMock.resultType >> FAILURE
testResultMock.exception >> exception
testDescriptorMock.displayName >> 'floppy test'
testDescriptorMock.className >> this.class.name
expect:
theme.exceptionText(testDescriptorMock, testResultMock) ==
"""|[red]
|
| java.lang.AssertionError: This is wrong
| at com.adarshr.gradle.testlogger.theme.MavenParallelThemeSpec.getException(MavenParallelThemeSpec.groovy:${
LINE_NUMBER
})
|""".stripMargin().replace('\n', lineSeparator())
}

def "standard stream text"() {
given:
testLoggerExtensionMock.showStandardStreams >> true
theme = new MavenParallelTheme(testLoggerExtensionMock)
expect:
theme.testStandardStreamText(streamLines, testResultMock) ==
'''|[default]
| Hello
| World \\[brackets\\] \u001B\\[0mANSI[/]
|'''.stripMargin().replace('\n', lineSeparator())
}

def "suite stream text"() {
given:
testLoggerExtensionMock.showStandardStreams >> true
theme = new MavenParallelTheme(testLoggerExtensionMock)
expect:
theme.suiteStandardStreamText(streamLines, testResultMock) ==
'''|[default]
| Hello
| World \\[brackets\\] \u001B\\[0mANSI[/]
|'''.stripMargin().replace('\n', lineSeparator())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.adarshr.gradle.testlogger.theme

import spock.lang.Unroll

import static java.lang.System.lineSeparator
import static org.gradle.api.tasks.testing.TestResult.ResultType.*

class MavenPlainParallelThemeSpec extends BaseThemeSpec {

// right at the top to minimise line number changes
private static AssertionError getException() {
new AssertionError('This is wrong')
}

private static final int LINE_NUMBER = exception.stackTrace.find { it.className == owner.name }.lineNumber

Theme theme

def setup() {
theme = new MavenPlainParallelTheme(testLoggerExtensionMock)
}

def "before suite"() {
expect:
!theme.suiteText(testDescriptorMock, testResultMock)
}

@Unroll
def "after test with result type #resultType"() {
given:
testResultMock.resultType >> resultType
testDescriptorMock.classDisplayName >> 'ClassName'
testDescriptorMock.displayName >> 'test name'
when:
def actual = theme.testText(testDescriptorMock, testResultMock)
then:
actual == expected
where:
resultType | expected
SUCCESS | 'ClassName test name PASSED'
FAILURE | 'ClassName test name FAILED'
SKIPPED | 'ClassName test name SKIPPED'
}

def "exception text when showExceptions is true"() {
given:
testLoggerExtensionMock.showExceptions >> true
testLoggerExtensionMock.showStackTraces >> true
testLoggerExtensionMock.showCauses >> true
theme = new MavenPlainParallelTheme(testLoggerExtensionMock)
and:
testResultMock.resultType >> FAILURE
testResultMock.exception >> exception
testDescriptorMock.displayName >> 'floppy test'
testDescriptorMock.className >> this.class.name
expect:
theme.exceptionText(testDescriptorMock, testResultMock) ==
"""|
|
| java.lang.AssertionError: This is wrong
| at com.adarshr.gradle.testlogger.theme.MavenPlainParallelThemeSpec.getException(MavenPlainParallelThemeSpec.groovy:${LINE_NUMBER})
|""".stripMargin().replace('\n', lineSeparator())
}

def "standard stream text"() {
given:
testLoggerExtensionMock.showStandardStreams >> true
theme = new MavenPlainParallelTheme(testLoggerExtensionMock)
testResultMock.resultType >> SUCCESS
expect:
theme.testStandardStreamText(streamLines, testResultMock) ==
'''|
| Hello
| World \\[brackets\\] \u001B\\[0mANSI
|'''.stripMargin().replace('\n', lineSeparator())
}

def "suite stream text"() {
given:
testLoggerExtensionMock.showStandardStreams >> true
theme = new MavenPlainParallelTheme(testLoggerExtensionMock)
testResultMock.resultType >> SUCCESS
expect:
theme.suiteStandardStreamText(streamLines, testResultMock) ==
'''|
| Hello
| World \\[brackets\\] \u001B\\[0mANSI
|'''.stripMargin().replace('\n', lineSeparator())
}
}
Loading