gradle-plugin: Add tests for project library support
This commit is contained in:
+2
-2
@@ -17,7 +17,7 @@ internal interface KonanToolRunner: Named {
|
||||
internal abstract class KonanCliRunner(val toolName: String, val fullName: String, val project: Project): KonanToolRunner {
|
||||
override val mainClass = "org.jetbrains.kotlin.cli.utilities.MainKt"
|
||||
|
||||
override fun getName() = fullName
|
||||
override fun getName() = toolName
|
||||
|
||||
override val classpath: FileCollection =
|
||||
project.fileTree("${project.konanHome}/konan/lib/")
|
||||
@@ -62,4 +62,4 @@ internal class KonanInteropRunner(project: Project)
|
||||
}
|
||||
|
||||
internal class KonanCompilerRunner(project: Project) : KonanCliRunner("konanc", "Kotlin/Native compiler", project)
|
||||
internal class KonnaKlibRunner(project: Project) : KonanCliRunner("klib", "Klib management tool", project)
|
||||
internal class KonanKlibRunner(project: Project) : KonanCliRunner("klib", "Klib management tool", project)
|
||||
|
||||
+83
@@ -3,6 +3,8 @@ package org.jetbrains.kotlin.gradle.plugin.test
|
||||
import org.gradle.testkit.runner.BuildResult
|
||||
import org.gradle.testkit.runner.TaskOutcome
|
||||
|
||||
import java.nio.file.Paths
|
||||
|
||||
class TaskSpecification extends BaseKonanSpecification {
|
||||
|
||||
def 'Configs should allow user to add dependencies to them'() {
|
||||
@@ -119,4 +121,85 @@ class TaskSpecification extends BaseKonanSpecification {
|
||||
failOnTaskAccess("gen${KonanInteropProject.DEFAULT_INTEROP_NAME.capitalize()}InteropStubs")
|
||||
failOnTaskAccess("compile${KonanInteropProject.DEFAULT_INTEROP_NAME.capitalize()}InteropStubs")
|
||||
}
|
||||
|
||||
def 'Compilation task should be able to use another project as a library (with artifact name)'() {
|
||||
when:
|
||||
def project = KonanProject.createEmpty(projectDirectory) { KonanProject prj ->
|
||||
prj.generateSrcFile("main.kt", """\
|
||||
external fun foo()
|
||||
fun main(args: Array<String>) = foo()
|
||||
""")
|
||||
prj.settingsFile.append("include ':foo'")
|
||||
}
|
||||
def subproject = KonanProject.createEmpty(project.projectPath.resolve("foo").toFile()) {
|
||||
KonanProject prj ->
|
||||
prj.generateSrcFile("foo.kt", "fun foo() { println(42) } ")
|
||||
prj.addCompilationSetting("produce", "'library'")
|
||||
def buildScript = prj.buildFile.text.replace("plugins { id 'konan' }", "apply plugin: 'konan'")
|
||||
prj.buildFile.write(buildScript)
|
||||
}
|
||||
project.addCompilationSetting("library", "findProject(':foo'), 'main'")
|
||||
|
||||
def result = project.createRunner().withArguments("build").build()
|
||||
def successfulTasks = project.buildingTasks + subproject.buildingTasks.collect { ":foo$it".toString() }
|
||||
|
||||
subproject.addCompilationSetting("produce", "'program'")
|
||||
def failedResult = project.createRunner().withArguments("build").buildAndFail()
|
||||
|
||||
|
||||
then:
|
||||
result.taskPaths(TaskOutcome.SUCCESS).containsAll(successfulTasks)
|
||||
}
|
||||
|
||||
def 'Compilation task should be able to use another project as a library (all klibs in the project)'() {
|
||||
when:
|
||||
def project = KonanProject.createEmpty(projectDirectory) { KonanProject prj ->
|
||||
prj.generateSrcFile("main.kt", """\
|
||||
external fun foo()
|
||||
external fun bar()
|
||||
fun baz() { println("baz") }
|
||||
fun main(args: Array<String>) { foo(); bar(); baz() }
|
||||
""".stripIndent())
|
||||
prj.settingsFile.append("include ':foo'")
|
||||
}
|
||||
def subproject = KonanProject.createEmpty(project.projectPath.resolve("foo").toFile()) {
|
||||
KonanProject prj ->
|
||||
def buildScript = prj.buildFile.text.replace("plugins { id 'konan' }", "apply plugin: 'konan'")
|
||||
prj.buildFile.write(buildScript)
|
||||
|
||||
// Default artifact: main, should be recognized as a library with foo function.
|
||||
prj.generateSrcFile("foo.kt", "fun foo() { println(42) } ")
|
||||
prj.addCompilationSetting("produce", "'library'")
|
||||
|
||||
prj.generateSrcFile(Paths.get("src", "bar" , "kotlin"),
|
||||
"bar.kt", "fun bar() { println(\"bar\") }")
|
||||
|
||||
prj.generateSrcFile(Paths.get("src", "baz", "kotlin"),
|
||||
"baz.kt", "fun baz() { println(\"another baz\") }")
|
||||
|
||||
prj.buildFile.append("""\
|
||||
konanArtifacts {
|
||||
// Should be recognized as a library.
|
||||
bar {
|
||||
inputDir "src/bar/kotlin"
|
||||
produce "library"
|
||||
}
|
||||
|
||||
// Should not be recognized as a library.
|
||||
baz {
|
||||
inputDir "src/baz/kotlin"
|
||||
produce "bitcode"
|
||||
}
|
||||
}
|
||||
""".stripIndent())
|
||||
|
||||
}
|
||||
project.addCompilationSetting("library", "findProject(':foo')")
|
||||
|
||||
def result = project.createRunner().withArguments("build").build()
|
||||
def successfulTasks = project.buildingTasks + subproject.buildingTasks.collect { ":foo$it".toString() }
|
||||
|
||||
then:
|
||||
result.taskPaths(TaskOutcome.SUCCESS).containsAll(successfulTasks)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user