diff --git a/libraries/kotlin.test/shared/src/main/kotlin.jvm/kotlin/test/TestAssertionsJVM.kt b/libraries/kotlin.test/shared/src/main/kotlin.jvm/kotlin/test/TestAssertionsJVM.kt index e50b1d2b1a8..ff146cbba9b 100644 --- a/libraries/kotlin.test/shared/src/main/kotlin.jvm/kotlin/test/TestAssertionsJVM.kt +++ b/libraries/kotlin.test/shared/src/main/kotlin.jvm/kotlin/test/TestAssertionsJVM.kt @@ -36,11 +36,18 @@ inline fun assertFailsWith(message: String? = null, noin * Comments out a [block] of test code until it is implemented while keeping a link to the code * to implement in your unit test output */ +@kotlin.internal.InlineOnly inline fun todo(@Suppress("UNUSED_PARAMETER") block: () -> Unit) { - System.out.println("TODO at " + currentStackTrace()[1]) + System.out.println("TODO at " + currentStackTrace()[0]) } -@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN", "NOTHING_TO_INLINE") +/** + * Returns an array of stack trace elements, each representing one stack frame. + * The first element of the array (assuming the array is not empty) represents the top of the + * stack, which is the place where [currentStackTrace] function was called from. + */ +@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") +@kotlin.internal.InlineOnly inline fun currentStackTrace() = (java.lang.Exception() as java.lang.Throwable).stackTrace /** diff --git a/libraries/kotlin.test/shared/src/test/kotlin.jvm/BasicAssertionsJVMTest.kt b/libraries/kotlin.test/shared/src/test/kotlin.jvm/BasicAssertionsJVMTest.kt index 698a1d6bc7c..1c417f6283f 100644 --- a/libraries/kotlin.test/shared/src/test/kotlin.jvm/BasicAssertionsJVMTest.kt +++ b/libraries/kotlin.test/shared/src/test/kotlin.jvm/BasicAssertionsJVMTest.kt @@ -1,4 +1,4 @@ -package kotlinx.testing.tests +package kotlin.test.tests import kotlin.test.* import org.junit.* @@ -31,16 +31,4 @@ class BasicAssertionsJVMTest { throw IllegalArgumentException() }) } - - @Test - fun testToDo() { - todo { - fail("Shouldn't pass here") - } - } - - @Test - fun testCurrentStackTrace() { - assertEquals("BasicAssertionsJVMTest.kt", currentStackTrace()[0].fileName) - } } diff --git a/libraries/kotlin.test/shared/src/test/kotlin.jvm/StackTraceJVMTest.kt b/libraries/kotlin.test/shared/src/test/kotlin.jvm/StackTraceJVMTest.kt new file mode 100644 index 00000000000..f024e2c85c5 --- /dev/null +++ b/libraries/kotlin.test/shared/src/test/kotlin.jvm/StackTraceJVMTest.kt @@ -0,0 +1,23 @@ +package kotlin.test.tests + +import org.junit.Test +import kotlin.test.* + +// NOTE: These tests verify line numbers of stack frames, so they might be quite fragile to reordering etc + +class StackTraceJVMTest { + + @Test + fun testCurrentStackTrace() { +/* <-- line number */ val topFrame = currentStackTrace()[0] + assertEquals("StackTraceJVMTest.kt", topFrame.fileName) + assertEquals(12, topFrame.lineNumber) + } + + @Test + fun testToDo() { + todo { + fail("Shouldn't pass here") + } + } +} \ No newline at end of file