Fixing KT-9196 (broken kotlin-compiler-embeddable.jar in M13) by excluding org.fusesource.jansi.internal.CLibrary from relocation, adding smoke test for embeddable jar

This commit is contained in:
Ilya Chernikov
2015-09-23 16:54:41 +02:00
parent 3dd076efa8
commit 9c7d6c1649
3 changed files with 137 additions and 0 deletions
@@ -0,0 +1,82 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.compiler.embeddable
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.io.File
import java.io.FileNotFoundException
import java.io.InputStream
import kotlin.test.assertEquals
private val COMPILER_CLASS_FQN = "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler"
public class CompilerSmokeTest {
public val _workingDir: TemporaryFolder = TemporaryFolder()
@Rule
public fun getWorkingDir(): TemporaryFolder = _workingDir
private val javaExecutable = File( File(System.getProperty("java.home"), "bin"), "java")
private val embeddableJar = File(".").listFiles { it.name.startsWith("kotlin-compiler-embeddable", ignoreCase = true) && it.name.endsWith(".jar", ignoreCase = true) }?.firstOrNull()
?: throw FileNotFoundException("cannot find kotlin-compiler-embeddable*.jar in the directory " + File(".").absolutePath)
@Test
fun testSmoke() {
val (out, code) = runCompiler(File("../test/resources/projects/smoke/Smoke.kt").absolutePath)
assertEquals(0, code, "compilation failed:\n" + out)
}
private fun createProcess(cmd: List<String>, projectDir: File): Process {
val builder = ProcessBuilder(cmd)
builder.directory(projectDir)
builder.redirectErrorStream(true)
return builder.start()
}
private fun runCompiler(vararg arguments: String): Pair<String, Int> {
val cmd = listOf(javaExecutable.absolutePath,
"-Djava.awt.headless=true",
"-cp",
embeddableJar.absolutePath,
COMPILER_CLASS_FQN) +
arguments
val proc = createProcess(cmd, _workingDir.root)
return readOutput(proc)
}
private fun readOutput(process: Process): Pair<String, Int> {
fun InputStream.readFully(): String {
val text = reader().readText()
close()
return text
}
val stdout = process.getInputStream()!!.readFully()
System.out.println(stdout)
val stderr = process.getErrorStream()!!.readFully()
System.err.println(stderr)
val result = process.waitFor()
return stdout to result
}
}
@@ -0,0 +1,21 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package smoke
fun main(args: Array<String>) {
System.out.print(args)
}