diff --git a/kotlin-native/prepare/kotlin-native-embeddable-compiler/testData/projects/serialization/serialization.kt b/kotlin-native/prepare/kotlin-native-embeddable-compiler/testData/projects/serialization/serialization.kt deleted file mode 100644 index 3bfe933563b..00000000000 --- a/kotlin-native/prepare/kotlin-native-embeddable-compiler/testData/projects/serialization/serialization.kt +++ /dev/null @@ -1,14 +0,0 @@ -package serialization - -import kotlinx.serialization.* -import kotlinx.serialization.json.* - -@Serializable -data class Data(val number: Int, val english: String, val germany:String) - -fun main() { - Data(42, "forty two", "zweiundvierzig").let { - println(Json.encodeToString(it)) - } -} - diff --git a/kotlin-native/prepare/kotlin-native-embeddable-compiler/tests/kotlin/org/jetbrains/kotlin/native/compiler/embeddable/CompilerEmbeddableSmokeTests.kt b/kotlin-native/prepare/kotlin-native-embeddable-compiler/tests/kotlin/org/jetbrains/kotlin/native/compiler/embeddable/CompilerEmbeddableSmokeTests.kt index fd3d4ecb61a..65f38d071a8 100644 --- a/kotlin-native/prepare/kotlin-native-embeddable-compiler/tests/kotlin/org/jetbrains/kotlin/native/compiler/embeddable/CompilerEmbeddableSmokeTests.kt +++ b/kotlin-native/prepare/kotlin-native-embeddable-compiler/tests/kotlin/org/jetbrains/kotlin/native/compiler/embeddable/CompilerEmbeddableSmokeTests.kt @@ -1,8 +1,7 @@ /* - * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ - package org.jetbrains.kotlin.native.compiler.embeddable import org.junit.Rule @@ -11,9 +10,9 @@ import org.junit.rules.TemporaryFolder import java.io.File import java.io.FileNotFoundException import java.io.InputStream +import java.lang.System.err import kotlin.test.assertEquals - private val COMPILER_CLASS_FQN = "org.jetbrains.kotlin.cli.bc.K2Native" class CompilerSmokeTest { @@ -25,15 +24,17 @@ class CompilerSmokeTest { private val javaExecutable = File(File(System.getProperty("java.home"), "bin"), "java") - private val compilerClasspath: List by lazy { - filesFromProp("compilerClasspath", "kotlin-native-compiler-embeddable.jar") - } + companion object { + val compilerClasspath: List by lazy { + filesFromProp("compilerClasspath", "kotlin-native-compiler-embeddable.jar") + } - private fun filesFromProp(propName: String, vararg defaultPaths: String): List = - (System.getProperty(propName)?.split(File.pathSeparator) ?: defaultPaths.asList()).map { - File(it).takeIf(File::exists) - ?: throw FileNotFoundException("cannot find ($it)") - } + private fun filesFromProp(propName: String, vararg defaultPaths: String): List = + (System.getProperty(propName)?.split(File.pathSeparator) ?: defaultPaths.asList()).map { + File(it).takeIf(File::exists) + ?: throw FileNotFoundException("cannot find ($it)") + } + } @Test fun testSmoke() { @@ -69,9 +70,9 @@ class CompilerSmokeTest { } val stdout = process.inputStream!!.readFully() - System.out.println(stdout) + println(stdout) val stderr = process.errorStream!!.readFully() - System.err.println(stderr) + err.println(stderr) val result = process.waitFor() return stdout to result diff --git a/kotlin-native/prepare/kotlin-native-embeddable-compiler/tests/kotlin/org/jetbrains/kotlin/native/compiler/embeddable/EmbeddableContentsTest.kt b/kotlin-native/prepare/kotlin-native-embeddable-compiler/tests/kotlin/org/jetbrains/kotlin/native/compiler/embeddable/EmbeddableContentsTest.kt new file mode 100644 index 00000000000..ea178bdd774 --- /dev/null +++ b/kotlin-native/prepare/kotlin-native-embeddable-compiler/tests/kotlin/org/jetbrains/kotlin/native/compiler/embeddable/EmbeddableContentsTest.kt @@ -0,0 +1,60 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.native.compiler.embeddable + +import java.io.File +import java.util.jar.JarFile +import kotlin.test.Test +import kotlin.test.assertFailsWith + +/** + * trove4j jars should not be included (embedded) into our JARs. + * This test checks that JARs don't contain any entry of trove library. + */ +class EmbeddableContentsTest { + @Test + fun `test current embeddable jars for trove classes`() { + CompilerSmokeTest.compilerClasspath.filterNot { + it.name.startsWith("trove") + }.forEach(::checkJarFile) + } + + private val konanHomeJars: List by lazy { + val home = System.getProperty("kotlin.native.home") ?: error("Property kotlin.native.home not specified") + File(home).resolve("konan/lib") + .listFiles { _, name -> name.endsWith("jar") } + ?.toList() ?: error("Unable to find JARs in the `$home/konan/lib` directory") + } + + @Test + fun `test distribution jars for trove`() { + konanHomeJars.filterNot { + it.name.startsWith("trove") + }.forEach(::checkJarFile) + } + + @Test + fun `self check on trove jar`() { + assertFailsWith { + konanHomeJars.single { + it.name.startsWith("trove") + }.let(::checkJarFile) + } + } + + private fun checkJarFile(it: File) { + JarFile(it).use { jar -> + jar.entries().iterator().forEachRemaining { entry -> + assert(!entry.name.contains("gnu/trove")) { + """ + Jar file ${it.name} contains trove element: ${entry.name} + Check dependencies of embeddable configurations + """.trimIndent() + } + } + } + } +} \ No newline at end of file