Rearrange stdlib unit tests across packages.
Rearrange JS stdlib unit tests.
This commit is contained in:
@@ -1,52 +0,0 @@
|
||||
package test.collections
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import org.junit.Test as test
|
||||
import java.io.PrintWriter
|
||||
import java.io.*
|
||||
|
||||
class ExceptionTest {
|
||||
|
||||
@test fun printStackTraceOnRuntimeException() {
|
||||
assertPrintStackTrace(RuntimeException("Crikey!"))
|
||||
assertPrintStackTraceStream(RuntimeException("Crikey2"))
|
||||
}
|
||||
|
||||
@test fun printStackTraceOnError() {
|
||||
assertPrintStackTrace(Error("Oh dear"))
|
||||
assertPrintStackTraceStream(Error("Oh dear2"))
|
||||
}
|
||||
|
||||
|
||||
fun assertPrintStackTrace(t: Throwable) {
|
||||
val buffer = StringWriter()
|
||||
val writer = PrintWriter(buffer)
|
||||
t.printStackTrace(writer)
|
||||
println(buffer)
|
||||
}
|
||||
|
||||
fun assertPrintStackTraceStream(t: Throwable) {
|
||||
val byteBuffer = ByteArrayOutputStream()
|
||||
|
||||
PrintStream(byteBuffer).use {
|
||||
t.printStackTrace(it)
|
||||
}
|
||||
|
||||
val stream = PrintStream(byteBuffer)
|
||||
stream.use {
|
||||
t.printStackTrace(stream)
|
||||
}
|
||||
|
||||
val bytes = assertNotNull(byteBuffer.toByteArray())
|
||||
assertTrue(bytes.size > 10)
|
||||
}
|
||||
|
||||
@test fun changeStackTrace() {
|
||||
val exception = RuntimeException("Fail")
|
||||
var stackTrace = exception.stackTrace
|
||||
stackTrace = stackTrace.dropLast(1).toTypedArray()
|
||||
exception.stackTrace = stackTrace
|
||||
assertArrayNotSameButEquals(stackTrace, exception.stackTrace)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user