radarsh / gradle-test-logger-plugin

A Gradle plugin for printing beautiful logs on the console while running tests
Apache License 2.0
839 stars 37 forks source link

Add option to filter full stacktrace #261

Open shwaka opened 2 years ago

shwaka commented 2 years ago

Description

When showFullStackTraces is true, the plugin prints the whole stacktrace. But I think that most lines of the stacktrace is useless since they come from test framework (e.g. Kotest). So I request a feature that can filter lines of a stacktrace.

Additional information

Example

(See shwaka/gradle-test-logger-issue for the complete example.)

Consider the following simple code.

// main/kotlin/Foo.kt
class Foo {
    fun method1(): Int {
        return this.method2()
    }

    private fun method2(): Int {
        return this.divideByZero()
    }

    private fun divideByZero(): Int {
        return 1 / 0
    }
}

// test/kotlin/FooTest.kt
class FooTest : StringSpec({
    "failing test" {
        val foo = Foo()
        foo.method1() shouldBe 1
    }
})

This test fails since the method divideByZero() throws an error. Using the plugin with showFullStackTraces = true, the output looks like as follows:

Screenshot from 2022-03-12 11-18-35

But all lines below the 7th line of the stacktrace have class names starting from io.kotest or kotlinx.coroutines, which are useless for debugging. So I want to filter the stacktrace as follows:

Screenshot from 2022-03-12 11-17-54

Implementation

I have a fork shwaka/gradle-test-logger-plugin which implements the filtering feature. Setting filterFullStackTraces = "io\\.kotest.*", the plugin will filter stacktrace as in the 2nd screenshot.

I'm willing to create a pull request if you like it.

koppor commented 1 year ago

@shwaka Could you create a pull request right ahead, so that other developers browsing this repository see it, too?

shwaka commented 1 year ago

Sure! I will do it in a few days.