Skip to content

Commit

Permalink
Merge branch 'release/1.7.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
radarsh committed Oct 7, 2019
2 parents 6bb92a9 + e2c2d81 commit 8b7e6b6
Show file tree
Hide file tree
Showing 18 changed files with 100 additions and 50 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Change Log

## [v1.7.1](https://github.com/radarsh/gradle-test-logger-plugin/tree/v1.7.1) (2019-10-07)

[Full Changelog](https://github.com/radarsh/gradle-test-logger-plugin/compare/v1.7.0...v.1.7.1)

**Closed issues:**

- Add example image of summary to readme [\#126](https://github.com/radarsh/gradle-test-logger-plugin/issues/126)
- Output containing testlogger tags can interfere with the produced logs [\#123](https://github.com/radarsh/gradle-test-logger-plugin/issues/123)
- Clarify documentation about new stack trace options [\#120](https://github.com/radarsh/gradle-test-logger-plugin/issues/120)
- Filtering standard stream doesn't seem to be working properly [\#114](https://github.com/radarsh/gradle-test-logger-plugin/issues/114)
- A couple usability suggestions [\#88](https://github.com/radarsh/gradle-test-logger-plugin/issues/88)

**Merged pull requests:**

- Ignore tag like expressions in standard streams [\#128](https://github.com/radarsh/gradle-test-logger-plugin/pull/128) ([radarsh](https://github.com/radarsh))
- Fix typo in README [\#122](https://github.com/radarsh/gradle-test-logger-plugin/pull/122) ([radarsh](https://github.com/radarsh))
- Clarify documentation [\#121](https://github.com/radarsh/gradle-test-logger-plugin/pull/121) ([radarsh](https://github.com/radarsh))

## [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)

Expand Down
40 changes: 37 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.7.0'
id 'com.adarshr.test-logger' version '1.7.1'
}
```

Expand All @@ -39,7 +39,7 @@ buildscript {
}
}
dependencies {
classpath 'com.adarshr:gradle-test-logger-plugin:1.7.0'
classpath 'com.adarshr:gradle-test-logger-plugin:1.7.1'
}
}
Expand Down Expand Up @@ -135,6 +135,40 @@ testlogger {
}
```

### Hide exception stack traces

Sometimes it is useful to just see the exception message instead of the stack trace. This can be configured by
setting `showStackTraces` to `false`.

```groovy
testlogger {
showStackTraces false
}
```

### Hide exception causes

The default behaviour of the plugin is to print all the causes of the exception. If it is too verbose to your taste, you
can turn it off by setting `showCauses` to `false`.

```groovy
testlogger {
showCauses false
}
```

### Show full exception stack traces

Just like Gradle itself, by default only the last frame that matches the test class's name in a stack trace is printed. For vast
majority of cases, that is sufficient. Sometimes, it is useful to remove this filtering in order to see the entirety of the stack
trace. This can be done by setting `showFullStackTraces` to `true`.

```groovy
testlogger {
showFullStackTraces true
}
```

### Define slow threshold

Tests that are too slow will have their duration logged. However, "slow" is a relative terminology varying widely
Expand Down Expand Up @@ -233,7 +267,7 @@ Where possible, the plugin's `testlogger` extension tries to react to equivalent
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 |
| Property | `Test.testLogging` value | `testlogger` value | Effective value |
|---------------------------|---------------------------------------|------------------------|---------------- |
| `showStandardStreams` | `true` | not configured | `true` |
| `showStandardStreams` | `true` | `false` | `false` |
Expand Down
8 changes: 2 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ plugins {
}

buildScan {
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
termsOfServiceAgree = 'yes'
}

Expand Down Expand Up @@ -83,10 +83,6 @@ test {
classpath += sourceSets.functionalTest.runtimeClasspath
systemProperty 'file.encoding', 'UTF-8'

// testLogging {
// exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
// }

testlogger {
theme 'mocha'
}
Expand All @@ -101,7 +97,7 @@ task functionalTest(type: Test) {
systemProperty 'file.encoding', 'UTF-8'
minHeapSize '128m'
maxHeapSize '512m'

jacoco {
append = true
destinationFile = file("${buildDir}/jacoco/test.exec")
Expand Down
9 changes: 4 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
version=1.7.0
version=1.7.1
group=com.adarshr

org.gradle.daemon = true
org.gradle.caching = true
org.gradle.parallel = true
org.gradle.daemon=true
org.gradle.caching=false
org.gradle.parallel=true
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import groovy.transform.CompileStatic
import org.gradle.api.logging.LogLevel
import org.gradle.api.logging.Logger

import static com.adarshr.gradle.testlogger.util.RendererUtils.unescape

@CompileStatic
class ConsoleLogger {

Expand All @@ -21,7 +23,7 @@ class ConsoleLogger {

void log(String text) {
if (text) {
logger.log(level, renderer.render(text))
logger.log(level, unescape(renderer.render(text)))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.adarshr.gradle.testlogger.TestLoggerExtension
import com.adarshr.gradle.testlogger.TestResultWrapper
import groovy.transform.CompileStatic

import static com.adarshr.gradle.testlogger.util.RendererUtils.preserveAnsi
import static com.adarshr.gradle.testlogger.util.RendererUtils.escape
import static java.lang.System.lineSeparator

@CompileStatic
Expand Down Expand Up @@ -107,15 +107,15 @@ abstract class AbstractTheme implements Theme {
.readLines()
.withIndex()
.collect { String message, index ->
"${index != 0 || !cause ? indentation : ''}${preserveAnsi(message)}"
"${index != 0 || !cause ? indentation : ''}${escape(message)}"
}.join(lineSeparator())
}

String stackTrace(List<StackTraceElement> stackTrace, int commonFrames) {
def trace = new StringBuilder(stackTrace
.subList(0, stackTrace.size() - commonFrames)
.collect {
"${indentation} at ${preserveAnsi(it.toString())}"
"${indentation} at ${escape(it.toString())}"
}.join(lineSeparator()))

if (commonFrames) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +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 com.adarshr.gradle.testlogger.util.RendererUtils.escape
import static java.lang.System.lineSeparator
import static org.gradle.api.tasks.testing.TestResult.ResultType.*

Expand Down Expand Up @@ -117,7 +117,7 @@ class MochaTheme extends AbstractTheme {
return ''
}

lines = preserveAnsi(lines)
lines = escape(lines)

def indentation = ' ' * indent
def line = new StringBuilder("[grey]${lineSeparator()}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +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 com.adarshr.gradle.testlogger.util.RendererUtils.escape
import static java.lang.System.lineSeparator
import static org.gradle.api.tasks.testing.TestResult.ResultType.*

Expand Down Expand Up @@ -92,7 +92,7 @@ class PlainTheme extends AbstractTheme {
return ''
}

lines = preserveAnsi(lines)
lines = escape(lines)

def indentation = ' ' * indent
def line = new StringBuilder(lineSeparator())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +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 com.adarshr.gradle.testlogger.util.RendererUtils.escape
import static java.lang.System.lineSeparator
import static org.gradle.api.tasks.testing.TestResult.ResultType.*

Expand Down Expand Up @@ -109,7 +109,7 @@ class StandardTheme extends AbstractTheme {
return ''
}

lines = preserveAnsi(lines)
lines = escape(lines)

def indentation = ' ' * indent
def line = new StringBuilder("[default]${lineSeparator()}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import groovy.transform.CompileStatic
class RendererUtils {

static String escape(String text) {
text?.replace('\u001B', '')?.replace('[', '\\[')?.replace(']', '\\]')
text?.replace('[', '\\[')?.replace(']', '\\]')
}

static String preserveAnsi(String text) {
text?.replace('\u001B[', '\u001B\\[')
static String unescape(String text) {
text?.replace('\\[', '[')?.replace('\\]', ']')
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ class ConsoleLoggerSpec extends Specification {

def "log"() {
given:
textRendererMock.render('text to be logged') >> 'rendered ansi text'
def text = '[red]text \\[escaped\\]to be logged[/]'
textRendererMock.render(text) >> 'text \\[escaped\\] to be logged'
when:
consoleLogger.log('text to be logged')
consoleLogger.log(text)
then:
1 * loggerMock.log(LIFECYCLE, 'rendered ansi text')
1 * loggerMock.log(LIFECYCLE, 'text [escaped] to be logged')
}

def "does not log empty strings"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class MochaParallelThemeSpec extends BaseThemeSpec {
theme.testStandardStreamText(streamLines, testResultMock) ==
'''|[grey]
| Hello
| World [brackets] \u001B\\[0mANSI[/]
| World \\[brackets\\] \u001B\\[0mANSI[/]
|'''.stripMargin().replace('\n', lineSeparator())
}

Expand All @@ -212,7 +212,7 @@ class MochaParallelThemeSpec extends BaseThemeSpec {
theme.suiteStandardStreamText(streamLines, testResultMock) ==
'''|[grey]
| Hello
| World [brackets] \u001B\\[0mANSI[/]
| World \\[brackets\\] \u001B\\[0mANSI[/]
|'''.stripMargin().replace('\n', lineSeparator())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class MochaThemeSpec extends BaseThemeSpec {
theme.testStandardStreamText(streamLines, testResultMock) ==
'''|[grey]
| Hello
| World [brackets] \u001B\\[0mANSI[/]
| World \\[brackets\\] \u001B\\[0mANSI[/]
|'''.stripMargin().replace('\n', lineSeparator())
}

Expand All @@ -212,7 +212,7 @@ class MochaThemeSpec extends BaseThemeSpec {
theme.suiteStandardStreamText(streamLines, testResultMock) ==
'''|[grey]
| Hello
| World [brackets] \u001B\\[0mANSI[/]
| World \\[brackets\\] \u001B\\[0mANSI[/]
|'''.stripMargin().replace('\n', lineSeparator())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class PlainParallelThemeSpec extends BaseThemeSpec {
theme.testStandardStreamText(streamLines, testResultMock) ==
'''|
| Hello
| World [brackets] \u001B\\[0mANSI
| World \\[brackets\\] \u001B\\[0mANSI
|'''.stripMargin().replace('\n', lineSeparator())
}

Expand All @@ -168,7 +168,7 @@ class PlainParallelThemeSpec extends BaseThemeSpec {
theme.suiteStandardStreamText(streamLines, testResultMock) ==
'''|
| Hello
| World [brackets] \u001B\\[0mANSI
| World \\[brackets\\] \u001B\\[0mANSI
|'''.stripMargin().replace('\n', lineSeparator())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class PlainThemeSpec extends BaseThemeSpec {
theme.testStandardStreamText(streamLines, testResultMock) ==
'''|
| Hello
| World [brackets] \u001B\\[0mANSI
| World \\[brackets\\] \u001B\\[0mANSI
|'''.stripMargin().replace('\n', lineSeparator())
}

Expand All @@ -166,7 +166,7 @@ class PlainThemeSpec extends BaseThemeSpec {
theme.suiteStandardStreamText(streamLines, testResultMock) ==
'''|
| Hello
| World [brackets] \u001B\\[0mANSI
| World \\[brackets\\] \u001B\\[0mANSI
|'''.stripMargin().replace('\n', lineSeparator())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class StandardParallelThemeSpec extends BaseThemeSpec {
theme.testStandardStreamText(streamLines, testResultMock) ==
'''|[default]
| Hello
| World [brackets] \u001B\\[0mANSI[/]
| World \\[brackets\\] \u001B\\[0mANSI[/]
|'''.stripMargin().replace('\n', lineSeparator())
}

Expand All @@ -192,7 +192,7 @@ class StandardParallelThemeSpec extends BaseThemeSpec {
theme.suiteStandardStreamText(streamLines, testResultMock) ==
'''|[default]
| Hello
| World [brackets] \u001B\\[0mANSI[/]
| World \\[brackets\\] \u001B\\[0mANSI[/]
|'''.stripMargin().replace('\n', lineSeparator())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class StandardThemeSpec extends BaseThemeSpec {
theme.testStandardStreamText(streamLines, testResultMock) ==
'''|[default]
| Hello
| World [brackets] \u001B\\[0mANSI[/]
| World \\[brackets\\] \u001B\\[0mANSI[/]
|'''.stripMargin().replace('\n', lineSeparator())
}

Expand All @@ -188,7 +188,7 @@ class StandardThemeSpec extends BaseThemeSpec {
theme.suiteStandardStreamText(streamLines, testResultMock) ==
'''|[default]
| Hello
| World [brackets] \u001B\\[0mANSI[/]
| World \\[brackets\\] \u001B\\[0mANSI[/]
|'''.stripMargin().replace('\n', lineSeparator())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ class RendererUtilsSpec extends Specification {
null | null
'' | ''
'[escape]' | '\\[escape\\]'
'\u001Btext' | 'text'
'\u001Btext' | '\u001Btext'
}

@Unroll
def "preserve ansi #text"() {
def "unescape #text"() {
expect:
RendererUtils.preserveAnsi(text) == expected
RendererUtils.unescape(text) == expected
where:
text | expected
null | null
'' | ''
'[do not escape]' | '[do not escape]'
'\u001B[0mANSI' | '\u001B\\[0mANSI'
text | expected
null | null
'' | ''
'[red]\\[escaped\\]' | '[red][escaped]'
'\u001B[0mANSI' | '\u001B[0mANSI'
}
}

0 comments on commit 8b7e6b6

Please sign in to comment.