-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f06170e
commit b7ec023
Showing
13 changed files
with
283 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
test-runner/src/test/kotlin/co/touchlab/skie/test/annotation/filter/FilterMatrixWith.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package co.touchlab.skie.test.annotation.filter | ||
|
||
import kotlin.reflect.KClass | ||
|
||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
@Repeatable | ||
annotation class FilterMatrixWith( | ||
val value: KClass<out MatrixFilter> | ||
) |
8 changes: 8 additions & 0 deletions
8
test-runner/src/test/kotlin/co/touchlab/skie/test/annotation/filter/MatrixFilter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package co.touchlab.skie.test.annotation.filter | ||
|
||
import co.touchlab.skie.test.runner.SkieTestMatrixSource | ||
import org.junit.jupiter.api.extension.ExtensionContext | ||
|
||
interface MatrixFilter { | ||
fun apply(context: ExtensionContext, source: SkieTestMatrixSource) | ||
} |
9 changes: 9 additions & 0 deletions
9
...-runner/src/test/kotlin/co/touchlab/skie/test/annotation/filter/OnlyConfigurationCache.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package co.touchlab.skie.test.annotation.filter | ||
|
||
import co.touchlab.skie.test.filter.OnlyConfigurationCacheMatrixFilter | ||
|
||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
@Repeatable | ||
@FilterMatrixWith(OnlyConfigurationCacheMatrixFilter::class) | ||
annotation class OnlyConfigurationCache |
3 changes: 3 additions & 0 deletions
3
test-runner/src/test/kotlin/co/touchlab/skie/test/annotation/filter/OnlyFor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...runner/src/test/kotlin/co/touchlab/skie/test/filter/OnlyConfigurationCacheMatrixFilter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package co.touchlab.skie.test.filter | ||
|
||
import co.touchlab.skie.test.annotation.filter.MatrixFilter | ||
import co.touchlab.skie.test.runner.SkieTestMatrixSource | ||
import org.junit.jupiter.api.extension.ExtensionContext | ||
|
||
object OnlyConfigurationCacheMatrixFilter : MatrixFilter { | ||
override fun apply(context: ExtensionContext, source: SkieTestMatrixSource) { | ||
source.kotlinVersions.removeAll { kotlinVersion -> | ||
kotlinVersion.value.startsWith("1.8.") || | ||
kotlinVersion.value.startsWith("1.9.0") || | ||
kotlinVersion.value.startsWith("1.9.1") | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
test-runner/src/test/kotlin/co/touchlab/skie/test/filter/OnlyForMatrixFilter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package co.touchlab.skie.test.filter | ||
|
||
import co.touchlab.skie.test.annotation.filter.MatrixFilter | ||
import co.touchlab.skie.test.annotation.filter.OnlyFor | ||
import co.touchlab.skie.test.runner.SkieTestMatrixSource | ||
import co.touchlab.skie.test.util.KotlinVersion | ||
import org.junit.jupiter.api.extension.ExtensionContext | ||
import org.junit.platform.commons.util.AnnotationUtils | ||
|
||
object OnlyForMatrixFilter: MatrixFilter { | ||
|
||
override fun apply(context: ExtensionContext, source: SkieTestMatrixSource) { | ||
val parentClassFilterAnnotations = AnnotationUtils.findRepeatableAnnotations( | ||
context.requiredTestClass, | ||
OnlyFor::class.java, | ||
) | ||
val methodFilterAnnotations = AnnotationUtils.findRepeatableAnnotations( | ||
context.requiredTestMethod, | ||
OnlyFor::class.java, | ||
) | ||
|
||
(parentClassFilterAnnotations + methodFilterAnnotations).forEach { filter -> | ||
filter.targets.map { it.target }.applyTo(source.targets) | ||
filter.linkModes.toList().applyTo(source.linkModes) | ||
filter.configurations.toList().applyTo(source.configurations) | ||
filter.kotlinVersions.map(::KotlinVersion).applyTo(source.kotlinVersions) | ||
} | ||
} | ||
|
||
private inline fun <reified T> Collection<T>.applyTo(source: MutableList<T>) { | ||
if (this.isNotEmpty()) { | ||
val thisSet = this.toSet() | ||
source.removeAll { | ||
it !in thisSet | ||
} | ||
} | ||
} | ||
} |
39 changes: 8 additions & 31 deletions
39
test-runner/src/test/kotlin/co/touchlab/skie/test/runner/MatrixFilter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,13 @@ | ||
package co.touchlab.skie.test.runner | ||
|
||
import co.touchlab.skie.test.annotation.filter.OnlyFor | ||
import co.touchlab.skie.test.util.KotlinTarget | ||
import co.touchlab.skie.test.util.KotlinVersion | ||
import co.touchlab.skie.test.util.LinkMode | ||
|
||
data class MatrixFilter( | ||
val targets: Set<KotlinTarget>, | ||
val configurations: Set<BuildConfiguration>, | ||
val linkModes: Set<LinkMode>, | ||
val kotlinVersions: Set<String>, | ||
) { | ||
fun apply(onlyFor: OnlyFor): MatrixFilter = MatrixFilter( | ||
targets = targets.intersectOrChoose(onlyFor.targets.map { it.target }), | ||
configurations = configurations.intersectOrChoose(onlyFor.configurations.toList()), | ||
linkModes = linkModes.intersectOrChoose(onlyFor.linkModes.toList()), | ||
kotlinVersions = kotlinVersions.intersectOrChoose(onlyFor.kotlinVersions.toList()), | ||
) | ||
|
||
companion object { | ||
val empty = MatrixFilter( | ||
targets = emptySet(), | ||
configurations = emptySet(), | ||
linkModes = emptySet(), | ||
kotlinVersions = emptySet(), | ||
) | ||
|
||
private inline fun <reified T> Set<T>.intersectOrChoose(other: Collection<T>): Set<T> { | ||
return when { | ||
this.isEmpty() -> other.toSet() | ||
other.isEmpty() -> this | ||
else -> intersect(other.toSet()) | ||
} | ||
} | ||
} | ||
} | ||
data class SkieTestMatrixSource( | ||
val targets: MutableList<KotlinTarget>, | ||
val presets: MutableList<KotlinTarget.Preset>, | ||
val configurations: MutableList<BuildConfiguration>, | ||
val linkModes: MutableList<LinkMode>, | ||
val kotlinVersions: MutableList<KotlinVersion>, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.