[K/N][test] Add test on jar contents.

* Check jar for included entries.
* Small changes to embeddable jar smoke test.
* Delete not used test.
This commit is contained in:
Pavel Punegov
2022-10-20 12:43:59 +02:00
committed by Space Team
parent d2c58cdd27
commit ae7404878f
3 changed files with 74 additions and 27 deletions
@@ -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))
}
}
@@ -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<File> by lazy {
filesFromProp("compilerClasspath", "kotlin-native-compiler-embeddable.jar")
}
companion object {
val compilerClasspath: List<File> by lazy {
filesFromProp("compilerClasspath", "kotlin-native-compiler-embeddable.jar")
}
private fun filesFromProp(propName: String, vararg defaultPaths: String): List<File> =
(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<File> =
(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
@@ -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<File> 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<AssertionError> {
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()
}
}
}
}
}