[K/N][build] Add test for intellij-deps-fastutil and openapi

Test that jars in the distribution contain desired libraries
This commit is contained in:
Pavel Punegov
2022-10-25 19:45:09 +02:00
committed by Space Team
parent 59d9da05fe
commit 2d8035ba9f
@@ -11,15 +11,17 @@ import kotlin.test.Test
import kotlin.test.assertFailsWith import kotlin.test.assertFailsWith
/** /**
* trove4j jars should not be included (embedded) into our JARs. * Some IntelliJ dependencies should be included (embedded) into our JARs, but some don't.
* This test checks that JARs don't contain any entry of trove library. *
* trove4j jars should not be included while openapi and fastutil should.
* This test checks JARs for entries of libraries.
*/ */
class EmbeddableContentsTest { class EmbeddableContentsTest {
@Test @Test
fun `test current embeddable jars for trove classes`() { fun `test current embeddable jars for trove classes`() {
CompilerSmokeTest.compilerClasspath.filterNot { CompilerSmokeTest.compilerClasspath.filterNot {
it.name.startsWith("trove") it.name.startsWith("trove")
}.forEach(::checkJarFile) }.forEach(::checkJarForTrove)
} }
private val konanHomeJars: List<File> by lazy { private val konanHomeJars: List<File> by lazy {
@@ -33,7 +35,7 @@ class EmbeddableContentsTest {
fun `test distribution jars for trove`() { fun `test distribution jars for trove`() {
konanHomeJars.filterNot { konanHomeJars.filterNot {
it.name.startsWith("trove") it.name.startsWith("trove")
}.forEach(::checkJarFile) }.forEach(::checkJarForTrove)
} }
@Test @Test
@@ -41,20 +43,41 @@ class EmbeddableContentsTest {
assertFailsWith<AssertionError> { assertFailsWith<AssertionError> {
konanHomeJars.single { konanHomeJars.single {
it.name.startsWith("trove") it.name.startsWith("trove")
}.let(::checkJarFile) }.let(::checkJarForTrove)
} }
} }
private fun checkJarFile(it: File) { private fun checkJarForTrove(file: File) {
JarFile(it).use { jar -> JarFile(file).use { jar ->
jar.entries().iterator().forEachRemaining { entry -> jar.entries().iterator().forEachRemaining { entry ->
assert(!entry.name.contains("gnu/trove")) { assert(!entry.name.contains("gnu/trove")) {
""" """
Jar file ${it.name} contains trove element: ${entry.name} Jar file ${jar.name} contains trove element: ${entry.name}
Check dependencies of embeddable configurations Check dependencies of embeddable configurations
""".trimIndent() """.trimIndent()
} }
} }
} }
} }
@Test
fun `test jars contain intellij dependencies`() {
konanHomeJars.filterNot {
it.name.startsWith("trove")
}.forEach {
it.checkJarContains("it/unimi/dsi/fastutil/objects/ReferenceOpenHashSet")
it.checkJarContains("com/intellij/openapi/util/")
}
}
private fun File.checkJarContains(string: String) {
JarFile(this).use { jar ->
assert(jar.entries()
.asSequence()
.any { it.name.contains(string) }
) {
"Jar file ${jar.name} doesn't contain element: $string"
}
}
}
} }