From d893c540a3b028970f51daceef3e4cffe319eb33 Mon Sep 17 00:00:00 2001 From: Jan Seeger Date: Fri, 29 Sep 2023 16:26:08 +0200 Subject: [PATCH] Add Stacktrace property to dachlatten-debug --- .../de/sipgate/dachlatten/debug/Stacktrace.kt | 7 ++++++ .../dachlatten/debug/StacktraceKtTest.kt | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 dachlatten-debug/src/main/kotlin/de/sipgate/dachlatten/debug/Stacktrace.kt create mode 100644 dachlatten-debug/src/test/kotlin/de/sipgate/dachlatten/debug/StacktraceKtTest.kt diff --git a/dachlatten-debug/src/main/kotlin/de/sipgate/dachlatten/debug/Stacktrace.kt b/dachlatten-debug/src/main/kotlin/de/sipgate/dachlatten/debug/Stacktrace.kt new file mode 100644 index 0000000..8ec360e --- /dev/null +++ b/dachlatten-debug/src/main/kotlin/de/sipgate/dachlatten/debug/Stacktrace.kt @@ -0,0 +1,7 @@ +package de.sipgate.dachlatten.debug + +val stacktrace: String + get() = Thread.currentThread() + .stackTrace + .drop(2) + .joinToString(separator = "\n") \ No newline at end of file diff --git a/dachlatten-debug/src/test/kotlin/de/sipgate/dachlatten/debug/StacktraceKtTest.kt b/dachlatten-debug/src/test/kotlin/de/sipgate/dachlatten/debug/StacktraceKtTest.kt new file mode 100644 index 0000000..a4d1e95 --- /dev/null +++ b/dachlatten-debug/src/test/kotlin/de/sipgate/dachlatten/debug/StacktraceKtTest.kt @@ -0,0 +1,23 @@ +package de.sipgate.dachlatten.debug + +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test + +class StacktraceKtTest { + + @Test + fun stacktraceReturnsStacktrace() { + val result = stacktrace + + assertTrue(result.contains("stacktraceReturnsStacktrace")) + } + + @Test + fun stacktraceReturnsInnerFuncStacktrace() { + fun innerFunc() = stacktrace + + val result = innerFunc() + + assertTrue(result.contains("\$innerFunc")) + } +}