• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 import org.junit.Test
5 import java.io.*
6 import kotlin.test.*
7 
8 /*
9  * This is intentionally put here instead of coreAgentTest to avoid accidental classpath replacing
10  * and ruining core agent test.
11  */
12 class PrecompiledDebugProbesTest {
13 
14     private val overwrite = java.lang.Boolean.getBoolean("overwrite.probes")
15 
16     @Test
testClassFileContentnull17     fun testClassFileContent() {
18         val clz = Class.forName("kotlin.coroutines.jvm.internal.DebugProbesKt")
19         val className: String = clz.getName()
20         val classFileResourcePath = className.replace(".", "/") + ".class"
21         val stream = clz.classLoader.getResourceAsStream(classFileResourcePath)!!
22         val array = stream.readBytes()
23         // we expect the integration testing project to be in a subdirectory of the main kotlinx.coroutines project
24         val base = File("").absoluteFile.parentFile
25         val probes = File(base, "kotlinx-coroutines-core/jvm/resources/DebugProbesKt.bin")
26         val binContent = probes.readBytes()
27         if (overwrite) {
28             FileOutputStream(probes).use { it.write(array) }
29             println("Content was successfully overwritten!")
30         } else {
31             assertTrue(
32                 array.contentEquals(binContent),
33                 "Compiled DebugProbesKt.class does not match the file shipped as a resource in kotlinx-coroutines-core. " +
34                         "Typically it happens because of the Kotlin version update (-> binary metadata). In that case, run the same test with -Poverwrite.probes=true."
35             )
36         }
37     }
38 }
39