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)"
plugins {
`java`
kotlin("jvm")
}
val testCompilationClasspath by configurations.creating
dependencies {
runtime(kotlinStdlib())
runtime(project(":kotlin-script-runtime"))
runtime(project(":kotlin-reflect"))
runtime(project(":kotlin-daemon-embeddable"))
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()
@@ -22,7 +32,7 @@ compilerDummyJar(compilerDummyForDependenciesRewriting("compilerDummy") {
classifier = "dummy"
})
runtimeJar(embeddableCompiler()) {
val runtimeJar = runtimeJar(embeddableCompiler()) {
exclude("com/sun/jna/**")
exclude("org/jetbrains/annotations/**")
mergeServiceFiles()
@@ -31,3 +41,14 @@ runtimeJar(embeddableCompiler()) {
sourcesJar()
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 embeddableJar: File by lazy {
val f = File(System.getProperty("compilerJar") ?: "kotlin-compiler-embeddable.jar")
if (!f.exists())
throw FileNotFoundException("cannot find kotlin-compiler-embeddable.jar ($f)")
f
private val compilerClasspath: List<File> by lazy {
filesFromProp("compilerClasspath", "kotlin-compiler-embeddable.jar")
}
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
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)
}
@@ -58,12 +65,15 @@ public class CompilerSmokeTest {
}
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 cmd = listOf(
javaExecutable.absolutePath,
"-Djava.awt.headless=true",
"-cp",
compilerClasspath.joinToString(File.pathSeparator),
COMPILER_CLASS_FQN,
"-cp",
compilationClasspath.joinToString(File.pathSeparator)
) + arguments
val proc = createProcess(cmd, _workingDir.root)
return readOutput(proc)
}