[gradle-plugin] Add tests for custom targets and artifact paths
This commit is contained in:
+5
-1
@@ -158,7 +158,11 @@ task gradlePluginJar {
|
||||
dependsOn gradle.includedBuild('kotlin-native-gradle-plugin').task(':shadowJar')
|
||||
}
|
||||
|
||||
task uploadGradlePlugin {
|
||||
task gradlePluginCheck() {
|
||||
dependsOn gradle.includedBuild('kotlin-native-gradle-plugin').task(':check')
|
||||
}
|
||||
|
||||
task gradlePluginUpload {
|
||||
dependsOn gradle.includedBuild('kotlin-native-gradle-plugin').task(':bintrayUpload')
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ test {
|
||||
if (project.hasProperty("konan.home")) {
|
||||
systemProperty("konan.home", project.property("konan.home"))
|
||||
} else {
|
||||
dependsOn ':dist'
|
||||
// The Koltin/Native compiler must be built before test execution.
|
||||
systemProperty("konan.home", distDir.absolutePath)
|
||||
}
|
||||
if (project.hasProperty("konan.jvmArgs")) {
|
||||
@@ -108,6 +108,10 @@ test {
|
||||
if (project.hasProperty("maxParallelForks")) {
|
||||
maxParallelForks=project.property("maxParallelForks")
|
||||
}
|
||||
if (project.hasProperty("filter")) {
|
||||
filter.includeTestsMatching project.property("filter")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
processResources {
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
rootProject.name = "kotlin-native-gradle-plugin"
|
||||
rootProject.name = "kotlin-native-gradle-plugin"
|
||||
// A hack to run the gradle plugin build not from the root build without
|
||||
// specifying '--include-build ../../shared' in the command line.
|
||||
if (gradle.parent == null) {
|
||||
includeBuild '../../shared'
|
||||
}
|
||||
-1
@@ -2,7 +2,6 @@ package org.jetbrains.kotlin.gradle.plugin.test
|
||||
|
||||
import org.gradle.testkit.runner.BuildResult
|
||||
import org.gradle.testkit.runner.TaskOutcome
|
||||
import spock.lang.IgnoreIf
|
||||
import spock.lang.Unroll
|
||||
|
||||
class IncrementalSpecification extends BaseKonanSpecification {
|
||||
|
||||
+3
-3
@@ -1,7 +1,6 @@
|
||||
package org.jetbrains.kotlin.gradle.plugin.test
|
||||
|
||||
import org.gradle.testkit.runner.GradleRunner
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
import org.jetbrains.kotlin.konan.target.TargetManager
|
||||
|
||||
import java.nio.file.Files
|
||||
@@ -12,7 +11,9 @@ enum ArtifactType {
|
||||
PROGRAM("program"),
|
||||
LIBRARY("library"),
|
||||
BITCODE("bitcode"),
|
||||
INTEROP("interop")
|
||||
INTEROP("interop"),
|
||||
DYNAMIC("dynamic"),
|
||||
FRAMEWORK("framework")
|
||||
|
||||
String type
|
||||
ArtifactType(String type) { this.type = type }
|
||||
@@ -199,7 +200,6 @@ class KonanProject {
|
||||
konan.home=$konanHome
|
||||
${!konanJvmArgs.isEmpty() ? "konan.jvmArgs=$konanJvmArgs\n" : ""}
|
||||
""".stripIndent())
|
||||
println(propertiesFile.text)
|
||||
return propertiesFile
|
||||
}
|
||||
|
||||
|
||||
-2
@@ -1,7 +1,5 @@
|
||||
package org.jetbrains.kotlin.gradle.plugin.test
|
||||
|
||||
import spock.lang.Ignore
|
||||
|
||||
class LibrarySpecification extends BaseKonanSpecification {
|
||||
|
||||
def libraries = [
|
||||
|
||||
+38
@@ -1,6 +1,7 @@
|
||||
package org.jetbrains.kotlin.gradle.plugin.test
|
||||
|
||||
import org.gradle.testkit.runner.TaskOutcome
|
||||
import org.jetbrains.kotlin.konan.target.TargetManager
|
||||
|
||||
class PathSpecification extends BaseKonanSpecification {
|
||||
|
||||
@@ -8,6 +9,43 @@ class PathSpecification extends BaseKonanSpecification {
|
||||
project.konanBuildDir.toPath().resolve(path).toFile().exists()
|
||||
}
|
||||
|
||||
def 'Plugin should provide a correct path to the artifacts created'() {
|
||||
expect:
|
||||
def project = KonanProject.createEmpty(
|
||||
projectDirectory,
|
||||
new TargetManager('host')
|
||||
.getTargets()
|
||||
.findAll { k, v -> v.enabled }
|
||||
.collect { k, v -> k }
|
||||
) { KonanProject it ->
|
||||
it.generateSrcFile("main.kt")
|
||||
it.generateDefFile("interop.def", "")
|
||||
it.buildFile.append("""
|
||||
konanArtifacts {
|
||||
program('program')
|
||||
library('library')
|
||||
bitcode('bitcode')
|
||||
interop('interop')
|
||||
framework('framework')
|
||||
dynamic('dynamic')
|
||||
}
|
||||
|
||||
task checkArtifacts(type: DefaultTask) {
|
||||
dependsOn(':build')
|
||||
doLast {
|
||||
for(artifact in konanArtifacts) {
|
||||
for (target in artifact) {
|
||||
if (!target.artifact.exists()) throw new Exception("Artifact doesn't exist. Type: \${artifact.name}, target: \${target.target}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""".stripIndent())
|
||||
}
|
||||
project.createRunner().withArguments("checkArtifacts").build()
|
||||
|
||||
}
|
||||
|
||||
def 'Plugin should create all necessary directories'() {
|
||||
when:
|
||||
def project = KonanProject.createWithInterop(projectDirectory)
|
||||
|
||||
+74
@@ -2,6 +2,9 @@ package org.jetbrains.kotlin.gradle.plugin.test
|
||||
|
||||
import org.gradle.testkit.runner.BuildResult
|
||||
import org.gradle.testkit.runner.TaskOutcome
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.konan.target.TargetManager
|
||||
import spock.lang.Requires
|
||||
import spock.lang.Unroll
|
||||
|
||||
class TaskSpecification extends BaseKonanSpecification {
|
||||
@@ -55,6 +58,77 @@ class TaskSpecification extends BaseKonanSpecification {
|
||||
"includeDirs" | ""
|
||||
}
|
||||
|
||||
@Requires({ TargetManager.host == KonanTarget.MACBOOK })
|
||||
def 'Plugin should create framework tasks only for Apple targets'() {
|
||||
when:
|
||||
def project = KonanProject.createEmpty(projectDirectory) { KonanProject it ->
|
||||
it.buildFile.append("""
|
||||
konan.targets = ['wasm32', 'macbook', 'iphone', 'iphone_sim']
|
||||
|
||||
konanArtifacts {
|
||||
framework('foo')
|
||||
}
|
||||
""".stripIndent())
|
||||
}
|
||||
def result = project.createRunner().withArguments('tasks', '--all').build()
|
||||
|
||||
then:
|
||||
!compilationTaskExists(result,'foo', 'wasm32')
|
||||
compilationTaskExists (result,'foo', 'macbook')
|
||||
compilationTaskExists (result,'foo', 'iphone')
|
||||
compilationTaskExists (result,'foo', 'iphone_sim')
|
||||
}
|
||||
|
||||
def 'Plugin should support different targets for different artifacts'() {
|
||||
when:
|
||||
def project = KonanProject.createEmpty(projectDirectory, ['host']) { KonanProject it ->
|
||||
it.buildFile.append("""
|
||||
konanArtifacts {
|
||||
program('defaultTarget')
|
||||
program('customTarget', targets: ['wasm32'])
|
||||
program('customTargets', targets: ['host', 'wasm32'])
|
||||
}
|
||||
""".stripIndent())
|
||||
}
|
||||
def result = project.createRunner().withArguments('tasks', '--all').build()
|
||||
def hostName = TargetManager.getHostName()
|
||||
|
||||
then:
|
||||
compilationTaskExists (result, 'defaultTarget', hostName)
|
||||
!compilationTaskExists(result, 'defaultTarget', 'wasm32')
|
||||
!compilationTaskExists(result, 'customTarget', hostName)
|
||||
compilationTaskExists (result, 'customTarget', 'wasm32')
|
||||
compilationTaskExists (result, 'customTargets', hostName)
|
||||
compilationTaskExists (result, 'customTargets', 'wasm32')
|
||||
}
|
||||
|
||||
def 'Plugin should not create dynamic task for wasm'() {
|
||||
when:
|
||||
def project = KonanProject.createEmpty(projectDirectory) { KonanProject it ->
|
||||
it.buildFile.append("""
|
||||
konan.targets = ['wasm32']
|
||||
|
||||
konanArtifacts {
|
||||
dynamic('foo')
|
||||
}
|
||||
""".stripIndent())
|
||||
}
|
||||
def result = project.createRunner().withArguments('tasks', '--all').build()
|
||||
|
||||
then:
|
||||
!compilationTaskExists(result, 'foo', 'wasm32')
|
||||
}
|
||||
|
||||
|
||||
boolean taskExists(BuildResult result, String taskName) {
|
||||
def taskNameForSearch = taskName.startsWith(':') ? taskName.substring(1) : taskName
|
||||
return result.output.contains(taskNameForSearch)
|
||||
}
|
||||
|
||||
boolean compilationTaskExists(BuildResult result, String artifactName, String targetName) {
|
||||
return taskExists(result, KonanProject.compilationTask(artifactName, targetName))
|
||||
}
|
||||
|
||||
BuildResult failOnPropertyAccess(KonanProject project, String property) {
|
||||
project.buildFile.append("""
|
||||
task testTask(type: DefaultTask) {
|
||||
|
||||
Reference in New Issue
Block a user