1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 16:28:12 -07:00

Test that BuildKt.class is not in the shipped jar file.

This commit is contained in:
Cedric Beust 2017-03-10 10:48:31 -08:00
parent 49d142659a
commit 187593b9b1

View file

@ -13,25 +13,11 @@ import java.util.jar.JarFile
import java.util.jar.JarInputStream import java.util.jar.JarInputStream
class VerifyKobaltZipTest : KobaltTest() { class VerifyKobaltZipTest : KobaltTest() {
private fun verifyMainJarFile(ins: InputStream) {
assertExistsInJarInputStream(JarInputStream(ins), "com/beust/kobalt/MainKt.class",
"templates/kobaltPlugin/kobaltPlugin.jar", "com/beust/kobalt/Args.class",
"com/beust/kobalt/wrapper/Main.class")
}
@Test @Test
fun verifySourceJarFile() { fun verifySourceJarFile() {
assertExistsInJar("kobalt-$KOBALT_VERSION-sources.jar", "com/beust/kobalt/Main.kt") assertExistsInJar("kobalt-$KOBALT_VERSION-sources.jar", "com/beust/kobalt/Main.kt")
} }
// Can't use Kobalt.version since the tests have their own src/test/resources/kobalt.properties
val KOBALT_VERSION: String
get() {
val p = Properties()
p.load(FileReader("src/main/resources/kobalt.properties"))
val result = p.getProperty("kobalt.version")
return result
}
@Test @Test
fun verifyZipFile() { fun verifyZipFile() {
var foundKobaltw = false var foundKobaltw = false
@ -57,7 +43,7 @@ class VerifyKobaltZipTest : KobaltTest() {
} else if (entry.name.endsWith("kobalt-wrapper.jar")) { } else if (entry.name.endsWith("kobalt-wrapper.jar")) {
val ins = zipFile.getInputStream(entry) val ins = zipFile.getInputStream(entry)
foundWrapperJar = true foundWrapperJar = true
assertExistsInJarInputStream(JarInputStream(ins), "kobalt.properties") assertExistsInJar(JarInputStream(ins), "kobalt.properties")
} }
entry = stream.nextEntry entry = stream.nextEntry
} }
@ -76,10 +62,38 @@ class VerifyKobaltZipTest : KobaltTest() {
} }
} }
private fun assertExistsInJarInputStream(ins: JarInputStream, vararg fileNames: String) { // Can't use Kobalt.version since the tests have their own src/test/resources/kobalt.properties
val KOBALT_VERSION: String
get() {
val p = Properties()
p.load(FileReader("src/main/resources/kobalt.properties"))
val result = p.getProperty("kobalt.version")
return result
}
private fun verifyMainJarFile(ins: InputStream) {
JarInputStream(ins).let { jar ->
assertExistsInJar(jar, "com/beust/kobalt/MainKt.class",
"templates/kobaltPlugin/kobaltPlugin.jar", "com/beust/kobalt/Args.class",
"com/beust/kobalt/wrapper/Main.class")
assertDoesNotExistInJar(jar, "BuildKt.class")
}
}
private fun assertExistsInJar(ins: JarInputStream, vararg fileNames: String)
= assertExistence(ins, true, *fileNames)
private fun assertDoesNotExistInJar(ins: JarInputStream, vararg fileNames: String)
= assertExistence(ins, false, *fileNames)
private fun assertExistence(ins: JarInputStream, verifyExistence: Boolean, vararg fileNames: String) {
with(jarContents(ins)) { with(jarContents(ins)) {
fileNames.forEach { fileName -> fileNames.forEach { fileName ->
Assert.assertTrue(contains(fileName), "Couldn't find $fileName") if (verifyExistence) {
Assert.assertTrue(contains(fileName), "Couldn't find $fileName")
} else {
Assert.assertFalse(contains(fileName), "Couldn't find $fileName")
}
} }
} }
} }
@ -88,7 +102,7 @@ class VerifyKobaltZipTest : KobaltTest() {
val sourceJarPath = KFiles.joinDir("kobaltBuild", "libs", jarName) val sourceJarPath = KFiles.joinDir("kobaltBuild", "libs", jarName)
val file = File(sourceJarPath) val file = File(sourceJarPath)
if (file.exists()) { if (file.exists()) {
assertExistsInJarInputStream(JarInputStream(FileInputStream(file)), *fileNames) assertExistsInJar(JarInputStream(FileInputStream(file)), *fileNames)
} else { } else {
kobaltLog(1, "Couldn't find $file, skipping test") kobaltLog(1, "Couldn't find $file, skipping test")
} }