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

Better zip test.

This commit is contained in:
Cedric Beust 2016-02-18 00:23:16 +04:00
parent 152ed057b4
commit 2f840a44fd

View file

@ -4,11 +4,18 @@ import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.log import com.beust.kobalt.misc.log
import org.testng.annotations.Test import org.testng.annotations.Test
import java.io.File
import java.io.FileInputStream import java.io.FileInputStream
import java.io.InputStream
import java.util.jar.JarFile import java.util.jar.JarFile
import java.util.jar.JarInputStream import java.util.jar.JarInputStream
class VerifyKobaltZipTest : KobaltTest() { class VerifyKobaltZipTest : KobaltTest() {
@Test
fun verifySourceJarFile() {
assertExistsInJar("kobalt-" + Kobalt.version + "-sources.jar", "com/beust/kobalt/Main.kt")
}
@Test @Test
fun verifyZipFile() { fun verifyZipFile() {
var success = true var success = true
@ -16,7 +23,7 @@ class VerifyKobaltZipTest : KobaltTest() {
var foundJar = false var foundJar = false
var foundWrapperJar = false var foundWrapperJar = false
val jarFilePath = "kobalt-" + Kobalt.version + ".jar" val mainJarFilePath = "kobalt-" + Kobalt.version + ".jar"
val zipFilePath = KFiles.joinDir("kobaltBuild", "libs", "kobalt-" + Kobalt.version + ".zip") val zipFilePath = KFiles.joinDir("kobaltBuild", "libs", "kobalt-" + Kobalt.version + ".zip")
val zipFile = JarFile(zipFilePath) val zipFile = JarFile(zipFilePath)
val stream = JarInputStream(FileInputStream(zipFilePath)) val stream = JarInputStream(FileInputStream(zipFilePath))
@ -24,11 +31,12 @@ class VerifyKobaltZipTest : KobaltTest() {
while (entry != null) { while (entry != null) {
if (entry.name == "kobaltw") { if (entry.name == "kobaltw") {
foundKobaltw = true foundKobaltw = true
} else if (entry.name.endsWith(jarFilePath)) { } else if (entry.name.endsWith(mainJarFilePath)) {
val ins = zipFile.getInputStream(entry) val ins = zipFile.getInputStream(entry)
if (ins.available() < 20000000) { if (ins.available() < 20000000) {
throw KobaltException(jarFilePath + " is too small: " + jarFilePath) throw KobaltException(mainJarFilePath + " is too small: " + mainJarFilePath)
} }
verifyMainJarFile(ins)
foundJar = true foundJar = true
} else if (entry.name.endsWith("kobalt-wrapper.jar")) { } else if (entry.name.endsWith("kobalt-wrapper.jar")) {
foundWrapperJar = true foundWrapperJar = true
@ -51,4 +59,25 @@ class VerifyKobaltZipTest : KobaltTest() {
} }
log(1, "$zipFilePath looks correct") log(1, "$zipFilePath looks correct")
} }
private fun assertExistsInJar(jarName: String, fileName: String) {
val sourceJarPath = KFiles.joinDir("kobaltBuild", "libs", jarName)
assertExistsInJar(JarInputStream(FileInputStream(File(sourceJarPath))), fileName)
}
private fun assertExistsInJar(stream: JarInputStream, fileName: String) {
var entry = stream.nextEntry
var found = false
while (entry != null) {
if (entry.name == fileName) found = true
entry = stream.nextEntry
}
if (! found) {
throw AssertionError("Couldn't find Main.kt in $fileName")
}
}
private fun verifyMainJarFile(ins: InputStream) {
assertExistsInJar(JarInputStream(ins), "com/beust/kobalt/MainKt.class")
}
} }