[K/N][tests] Migrate various runtime/ tests ^KT-61259
This commit is contained in:
committed by
Space Team
parent
7ad4e58a7a
commit
d88092aa94
+25
@@ -0,0 +1,25 @@
|
||||
// DISABLE_NATIVE: gcType=NOOP
|
||||
import kotlin.native.ref.WeakReference
|
||||
import kotlin.native.runtime.GC
|
||||
import kotlin.test.*
|
||||
|
||||
@OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
private fun makeWeakRef(create: () -> Any) = WeakReference(create())
|
||||
|
||||
@OptIn(kotlin.native.runtime.NativeRuntimeApi::class, kotlin.experimental.ExperimentalNativeApi::class)
|
||||
private fun ensureGetsCollected(create: () -> Any) {
|
||||
val ref = makeWeakRef(create)
|
||||
GC.collect()
|
||||
assertNull(ref.get())
|
||||
}
|
||||
|
||||
@OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
@Test
|
||||
fun test() {
|
||||
ensureGetsCollected { Throwable() }
|
||||
ensureGetsCollected {
|
||||
val throwable = Throwable()
|
||||
throwable.getStackTrace()
|
||||
throwable
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user