Introduce execution & test run API, KT-32679
* KotlinExecution * KotlinExecutionSource * KotlinTestRun * Aggregating executions and execution sources * KotlinTargetWithTests * Add a `testableTargets` extension * Make some Kotlin/Native targets testable (this requires having a separate preset type for them) * Implement test runs encapsulating the tests for all existing testable targets by refactoring their TargetConfigurator classes Issue #KT-32679 Fixed
This commit is contained in:
+56
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.plugin
|
||||
|
||||
import org.gradle.api.Named
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinExecution.ExecutionSource
|
||||
|
||||
/**
|
||||
* An execution of Kotlin code. Executions in a single family (e.g. test runs) are distinguished by [Named.getName].
|
||||
* Names may not be unique across different execution families, such as test runs of different targets.
|
||||
*
|
||||
* A particular kind of execution is a [KotlinTestRun] which runs tests.
|
||||
*/
|
||||
interface KotlinExecution<out SourceType : ExecutionSource> : Named {
|
||||
interface ExecutionSource
|
||||
|
||||
/**
|
||||
* The source of the executable code that this execution runs from. It is usually set via members of execution source support
|
||||
* interfaces, such as [CompilationExecutionSourceSupport] or [ClasspathTestRunSourceSupport], or `setExecutionSourceFrom*` functions.
|
||||
*/
|
||||
val executionSource: SourceType
|
||||
}
|
||||
|
||||
interface KotlinTargetExecution<out SourceType : ExecutionSource> : KotlinExecution<SourceType> {
|
||||
val target: KotlinTarget
|
||||
}
|
||||
|
||||
/**
|
||||
* An execution source that is produced by a [compilation].
|
||||
*
|
||||
* See also: [CompilationExecutionSourceSupport].
|
||||
*/
|
||||
interface CompilationExecutionSource<CompilationType : KotlinCompilation<*>> : ExecutionSource {
|
||||
val compilation: CompilationType
|
||||
}
|
||||
|
||||
interface CompilationExecutionSourceSupport<in T : KotlinCompilationToRunnableFiles<*>> {
|
||||
/**
|
||||
* Select a compilation to run the execution from.
|
||||
*
|
||||
* The [compilation]'s [KotlinCompilationToRunnableFiles.runtimeDependencyFiles]
|
||||
* will be treated as runtime dependencies, and its [output] as runnable files.
|
||||
*
|
||||
* This overrides other [KotlinExecution.executionSource] selection options.
|
||||
*/
|
||||
fun setExecutionSourceFrom(compilation: T)
|
||||
}
|
||||
|
||||
interface ExecutionTaskHolder<T : Task> {
|
||||
val executionTask: TaskProvider<T>
|
||||
}
|
||||
+10
@@ -54,4 +54,14 @@ interface KotlinTarget : Named, HasAttributes {
|
||||
val preset: KotlinTargetPreset<out KotlinTarget>?
|
||||
|
||||
override fun getName(): String = targetName
|
||||
}
|
||||
|
||||
interface KotlinTargetWithTests<E : KotlinExecution.ExecutionSource, T : KotlinTargetTestRun<E>> : KotlinTarget {
|
||||
/** The container with the test run executions.
|
||||
* A target may automatically create and configure a test run by the name [DEFAULT_TEST_RUN_NAME]. */
|
||||
val testRuns: NamedDomainObjectContainer<T>
|
||||
|
||||
companion object {
|
||||
const val DEFAULT_TEST_RUN_NAME = "test"
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.plugin
|
||||
|
||||
import groovy.lang.Closure
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.tasks.testing.TestFilter
|
||||
import org.gradle.util.ConfigureUtil
|
||||
|
||||
interface KotlinTestRun<out SourceType : KotlinExecution.ExecutionSource> : KotlinExecution<SourceType> {
|
||||
fun filter(configureFilter: TestFilter.() -> Unit)
|
||||
|
||||
fun filter(configureFilter: Closure<*>) = filter { ConfigureUtil.configureSelf(configureFilter, this) }
|
||||
}
|
||||
|
||||
interface KotlinTargetTestRun<ExecutionSource : KotlinExecution.ExecutionSource> :
|
||||
KotlinTestRun<ExecutionSource>,
|
||||
KotlinTargetExecution<ExecutionSource>
|
||||
|
||||
interface JvmClasspathTestRunSource : KotlinExecution.ExecutionSource {
|
||||
val testClassesDirs: FileCollection
|
||||
val classpath: FileCollection
|
||||
}
|
||||
|
||||
interface ClasspathTestRunSourceSupport {
|
||||
/**
|
||||
* Select the exact [classpath] to run the tests from.
|
||||
*
|
||||
* Only the classes from [testClasses] will be treated as tests.
|
||||
*
|
||||
* This overrides other [KotlinExecution.executionSource] selection options.
|
||||
*/
|
||||
fun setExecutionSourceFrom(classpath: FileCollection, testClassesDirs: FileCollection)
|
||||
}
|
||||
Reference in New Issue
Block a user