Restore embeddable compiler smoke test

also move sources and testdata to the appropriate place
This commit is contained in:
Ilya Chernikov
2019-10-02 11:03:05 +02:00
parent cd4cce3f9f
commit 1a8bcee86c
3 changed files with 45 additions and 14 deletions
+23 -2
View File
@@ -2,15 +2,25 @@
description = "Kotlin Compiler (embeddable)" description = "Kotlin Compiler (embeddable)"
plugins { plugins {
`java` kotlin("jvm")
} }
val testCompilationClasspath by configurations.creating
dependencies { dependencies {
runtime(kotlinStdlib()) runtime(kotlinStdlib())
runtime(project(":kotlin-script-runtime")) runtime(project(":kotlin-script-runtime"))
runtime(project(":kotlin-reflect")) runtime(project(":kotlin-reflect"))
runtime(project(":kotlin-daemon-embeddable")) runtime(project(":kotlin-daemon-embeddable"))
runtime(commonDep("org.jetbrains.intellij.deps", "trove4j")) runtime(commonDep("org.jetbrains.intellij.deps", "trove4j"))
testCompile(commonDep("junit:junit"))
testCompile(project(":kotlin-test:kotlin-test-junit"))
testCompilationClasspath(kotlinStdlib())
}
sourceSets {
"main" {}
"test" { projectDefault() }
} }
publish() publish()
@@ -22,7 +32,7 @@ compilerDummyJar(compilerDummyForDependenciesRewriting("compilerDummy") {
classifier = "dummy" classifier = "dummy"
}) })
runtimeJar(embeddableCompiler()) { val runtimeJar = runtimeJar(embeddableCompiler()) {
exclude("com/sun/jna/**") exclude("com/sun/jna/**")
exclude("org/jetbrains/annotations/**") exclude("org/jetbrains/annotations/**")
mergeServiceFiles() mergeServiceFiles()
@@ -31,3 +41,14 @@ runtimeJar(embeddableCompiler()) {
sourcesJar() sourcesJar()
javadocJar() javadocJar()
projectTest {
dependsOn(runtimeJar)
doFirst {
val runtimeJarConfig = configurations["runtimeJar"]
val runtimeConfig = configurations["runtime"]
systemProperty("compilerClasspath", "${runtimeJarConfig.allArtifacts.files.files.first().path}${File.pathSeparator}${runtimeConfig.asPath}")
systemProperty("compilationClasspath", testCompilationClasspath.asPath)
}
}
@@ -36,16 +36,23 @@ public class CompilerSmokeTest {
private val javaExecutable = File( File(System.getProperty("java.home"), "bin"), "java") private val javaExecutable = File( File(System.getProperty("java.home"), "bin"), "java")
private val embeddableJar: File by lazy { private val compilerClasspath: List<File> by lazy {
val f = File(System.getProperty("compilerJar") ?: "kotlin-compiler-embeddable.jar") filesFromProp("compilerClasspath", "kotlin-compiler-embeddable.jar")
if (!f.exists())
throw FileNotFoundException("cannot find kotlin-compiler-embeddable.jar ($f)")
f
} }
private val compilationClasspath: List<File> by lazy {
filesFromProp("compilationClasspath", "kotlin-stdlib.jar", "kotlin-script-runtime.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)")
}
@Test @Test
fun testSmoke() { fun testSmoke() {
val (out, code) = runCompiler(File("../test/resources/projects/smoke/Smoke.kt").absolutePath) val (out, code) = runCompiler(File("testData/projects/smoke/Smoke.kt").absolutePath)
assertEquals(0, code, "compilation failed:\n" + out) assertEquals(0, code, "compilation failed:\n" + out)
} }
@@ -58,12 +65,15 @@ public class CompilerSmokeTest {
} }
private fun runCompiler(vararg arguments: String): Pair<String, Int> { private fun runCompiler(vararg arguments: String): Pair<String, Int> {
val cmd = listOf(javaExecutable.absolutePath, val cmd = listOf(
"-Djava.awt.headless=true", javaExecutable.absolutePath,
"-cp", "-Djava.awt.headless=true",
embeddableJar.absolutePath, "-cp",
COMPILER_CLASS_FQN) + compilerClasspath.joinToString(File.pathSeparator),
arguments COMPILER_CLASS_FQN,
"-cp",
compilationClasspath.joinToString(File.pathSeparator)
) + arguments
val proc = createProcess(cmd, _workingDir.root) val proc = createProcess(cmd, _workingDir.root)
return readOutput(proc) return readOutput(proc)
} }