Skip to content

Commit

Permalink
Fix parameters and smoke test conditions.
Browse files Browse the repository at this point in the history
  • Loading branch information
TadeasKriz committed Apr 12, 2024
1 parent b42b3a6 commit 537b02d
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 81 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/smoke-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ jobs:
:test
-PtestLevel=smoke
-PtestType=gradle
-Pmatrix.targets=${{ inputs.target }}
-Pmatrix.configurations=${{ inputs.configuration}}
-Pmatrix.linkModes=${{ inputs.linkage }}
-Pmatrix.targets="${{ inputs.target || 'macos_arm64,ios_arm64,ios_simulator_arm64' }}"
-Pmatrix.configurations="${{ inputs.configuration || 'debug' }}"
-Pmatrix.linkModes="${{ inputs.linkage || 'static,dynamic' }}"
build-root-directory: test-runner
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package co.touchlab.skie.test.runner

import co.touchlab.skie.test.*
import co.touchlab.skie.test.util.*
import kotlin.properties.PropertyDelegateProvider
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
import org.slf4j.LoggerFactory

object SkieTestRunnerConfiguration {
private val logger = LoggerFactory.getLogger(SkieTestRunnerConfiguration::class.java)

val testLevel = value<TestLevel>("testLevel") ?: TestLevel.Thorough
val testTypes = set<TestType>("testTypes")
Expand Down Expand Up @@ -46,84 +44,50 @@ object SkieTestRunnerConfiguration {
this += SkieTestMatrix.Axis("Preset", filteredPresets.filterIsInstance<KotlinTarget.Preset.Native.Darwin>())
}.associateBy { it.type }


// private operator fun <E: Enum<E>> getValue(skieTestMatrix: SkieTestMatrix, property: KProperty<*>): E {
// // return System.getProperty(property.name, "").toBoolean()
// TODO()
// }

private fun <T: Any> value(property: String, deserialize: (String) -> T?): T? {
val properties = System.getProperties()
return if (properties.containsKey(property)) {
val rawValue = properties.getProperty(property)
val rawValue = properties.getProperty(property).trim()
deserialize(rawValue)
.logErrorOnUnknownValue(property, rawValue)
} else {
null
}
}

private inline fun <reified E: Enum<E>> value(property: String): E? = value(property) {
enumValueOf<E>(it)
private inline fun <reified E: Enum<E>> value(property: String): E? = value(property) { rawValue ->
enumValues<E>().singleOrNull { enumEntry ->
enumEntry.name.equals(rawValue, ignoreCase = true)
}
}

private fun <T: Any> list(property: String, deserialize: (String) -> T?): List<T>? {
val properties = System.getProperties()
return if (properties.containsKey(property)) {
val rawValue = properties.getProperty(property)
rawValue.split(',').mapNotNull {
deserialize(it.trim())
}
rawValue.split(',').mapNotNull { listItem ->
val trimmedListItem = listItem.trim()
deserialize(trimmedListItem)
.logErrorOnUnknownValue(property, trimmedListItem)
}.takeIf { it.isNotEmpty() }
} else {
null
}
}

private fun <T: Any> nestedList(property: String, deserialize: (String) -> List<T>): List<T>? {
val properties = System.getProperties()
return if (properties.containsKey(property)) {
val rawValue = properties.getProperty(property)
rawValue.split(',').flatMap {
deserialize(it.trim())
}
} else {
null
private inline fun <reified E: Enum<E>> list(property: String): List<E> = list(property) { rawValue ->
enumValues<E>().singleOrNull { enumEntry ->
enumEntry.name.equals(rawValue, ignoreCase = true)
}
}

private inline fun <reified E: Enum<E>> list(property: String): List<E> = list(property) {
enumValueOf<E>(it)
} ?: enumValues<E>().toList()

private fun <T: Any> set(property: String, deserialize: (String) -> T?): Set<T>? = list(property, deserialize)?.toSet()

private inline fun <reified E: Enum<E>> set(property: String): Set<E> = set(property) {
enumValueOf<E>(it)
} ?: enumValues<E>().toSet()

private inline fun <reified E: Enum<E>> singleValue(crossinline default: () -> E) = PropertyDelegateProvider { _: SkieTestRunnerConfiguration, property ->
val properties = System.getProperties()
val value = if (properties.containsKey(property.name)) {
val rawValue = properties.getProperty(property.name)
enumValueOf<E>(rawValue)
} else {
default()
}
PropertyStorage(value)
}

private inline fun <reified E: Enum<E>> multipleValues(crossinline default: () -> List<E> = { enumValues<E>().toList() }) = PropertyDelegateProvider { _: SkieTestRunnerConfiguration, property ->
val properties = System.getProperties()
val values = if (properties.containsKey(property.name)) {
val rawValue = properties.getProperty(property.name)
rawValue.split(',').map {
enumValueOf<E>(it)
}

} else {
default()
private inline fun <reified E: Enum<E>> set(property: String): Set<E> = set(property) { rawValue ->
enumValues<E>().singleOrNull { enumEntry ->
enumEntry.name.equals(rawValue, ignoreCase = true)
}
PropertyStorage(values)
}
} ?: enumValues<E>().toSet()

private fun <T> List<T>.intersectOrKeepIfEmpty(other: List<T>): List<T> {
return if (other.isNotEmpty()) {
Expand All @@ -134,7 +98,10 @@ object SkieTestRunnerConfiguration {
}
}

private data class PropertyStorage<T>(val value: T): ReadOnlyProperty<SkieTestRunnerConfiguration, T> {
override operator fun getValue(thisRef: SkieTestRunnerConfiguration, property: KProperty<*>): T = value
private fun <T: Any> T?.logErrorOnUnknownValue(property: String, rawValue: String): T? {
if (this == null) {
logger.error("Couldn't deserialize value $rawValue for property $property")
}
return this
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import co.touchlab.skie.test.annotation.filter.Smoke
import co.touchlab.skie.test.annotation.filter.SmokeOnly
import co.touchlab.skie.test.runner.SkieTestRunnerConfiguration
import co.touchlab.skie.test.runner.TestLevel
import co.touchlab.skie.test.util.isTestMethodOrClassAnnotated
import org.junit.jupiter.api.extension.ConditionEvaluationResult
import org.junit.jupiter.api.extension.ExecutionCondition
import org.junit.jupiter.api.extension.ExtensionContext
import org.junit.platform.commons.util.AnnotationUtils

class SmokeTestCondition: ExecutionCondition {
override fun evaluateExecutionCondition(context: ExtensionContext): ConditionEvaluationResult {
return when (SkieTestRunnerConfiguration.testLevel) {
TestLevel.Smoke -> if (AnnotationUtils.isAnnotated(context.element, Smoke::class.java)) {
TestLevel.Smoke -> if (isTestMethodOrClassAnnotated<Smoke>(context)) {
ConditionEvaluationResult.enabled("${context.element} is marked as @Smoke test")
} else {
ConditionEvaluationResult.disabled("${context.element} is not marked as @Smoke test")
}
TestLevel.Thorough -> if (AnnotationUtils.isAnnotated(context.element, SmokeOnly::class.java)) {
TestLevel.Thorough -> if (isTestMethodOrClassAnnotated<SmokeOnly>(context)) {
ConditionEvaluationResult.disabled("${context.element} is marked as @SmokeOnly test")
} else {
ConditionEvaluationResult.enabled("${context.element} is not marked as @SmokeOnly test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import co.touchlab.skie.test.util.LinkMode
@Smoke
@GradleTests
class KotlinArtifactDsl_Framework_AllDarwinTargetsAllFrameworkArtifactsTests: BaseGradleTests() {

@MatrixTest
fun `all darwin targets and all framework artifacts`(
kotlinVersion: KotlinVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import co.touchlab.skie.test.util.LinkMode
@Smoke
@GradleTests
class KotlinArtifactDsl_Framework_AllDarwinTargetsSingleFrameworkArtifactTests: BaseGradleTests() {

@MatrixTest
fun `all darwin targets and single framework artifact`(
kotlinVersion: KotlinVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import co.touchlab.skie.test.util.LinkMode
@Smoke
@GradleTests
class KotlinArtifactDsl_Framework_SingleTargetTests: BaseGradleTests() {

@MatrixTest
fun `single target and single framework artifact`(
kotlinVersion: KotlinVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import co.touchlab.skie.test.util.LinkMode
@Smoke
@GradleTests
class KotlinArtifactDsl_XCFramework_AllDarwinTargetsTests: BaseGradleTests() {

@MatrixTest
fun `all darwin targets and single xcframework artifact`(
kotlinVersion: KotlinVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import co.touchlab.skie.test.util.LinkMode
@Smoke
@GradleTests
class KotlinArtifactDsl_XCFramework_SingleTargetTests: BaseGradleTests() {

@MatrixTest
fun `single target`(
kotlinVersion: KotlinVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import co.touchlab.skie.test.util.KotlinVersion
import co.touchlab.skie.test.util.LinkMode

@Suppress("ClassName")
@Smoke
@GradleTests
class KotlinBinaryDsl_Framework_AllDarwinPresetsTests: BaseGradleTests() {
@Smoke
@MatrixTest
fun `basic project, all darwin presets`(
kotlinVersion: KotlinVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import co.touchlab.skie.test.util.KotlinVersion
import co.touchlab.skie.test.util.LinkMode

@Suppress("ClassName")
@Smoke
@GradleTests
class KotlinBinaryDsl_Framework_SinglePresetTests: BaseGradleTests() {

@Smoke
@MatrixTest
fun `basic project, single preset`(
kotlinVersion: KotlinVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import co.touchlab.skie.test.util.KotlinVersion
import co.touchlab.skie.test.util.LinkMode

@Suppress("ClassName")
@Smoke
@GradleTests
class KotlinBinaryDsl_Framework_SingleTargetTests: BaseGradleTests() {
@Smoke
@MatrixTest
fun `basic project, single target`(
kotlinVersion: KotlinVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import co.touchlab.skie.test.util.KotlinVersion
@Smoke
@GradleTests
class NoArtifact_AllDarwinTargetsTests: BaseGradleTests() {

@MatrixTest
fun `no artifact`(kotlinVersion: KotlinVersion) {
rootBuildFile(kotlinVersion) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import co.touchlab.skie.test.util.KotlinVersion
@Smoke
@GradleTests
class NoArtifact_SingleTargetTests: BaseGradleTests() {

@MatrixTest
fun `no artifact`(
kotlinVersion: KotlinVersion,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package co.touchlab.skie.test.util

import org.junit.jupiter.api.extension.ExtensionContext
import org.junit.platform.commons.util.AnnotationUtils

inline fun <reified A: Annotation> isTestMethodOrClassAnnotated(context: ExtensionContext): Boolean {
return AnnotationUtils.isAnnotated(context.requiredTestMethod, A::class.java) ||
AnnotationUtils.isAnnotated(context.requiredTestClass, A::class.java)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@ sealed interface KotlinTargetOrPreset {
val id: String
}


fun KotlinTargetOrPreset(id: String): KotlinTargetOrPreset {
fun KotlinTargetOrPreset(id: String): KotlinTargetOrPreset? {
fun KotlinTargetOrPreset.findById(id: String): KotlinTargetOrPreset? {
return when {
this.id == id -> this
this.id.equals(id, ignoreCase = true) -> this
this is KotlinTarget.Preset -> this.children.firstNotNullOfOrNull { it.findById(id) }
else -> null
}
}

return checkNotNull(KotlinTarget.Preset.Root.findById(id)) {
"Could not find target or preset with id '$id'"
}
return KotlinTarget.Preset.Root.findById(id)
}

val List<KotlinTargetOrPreset>.targets: List<KotlinTarget>
Expand Down

0 comments on commit 537b02d

Please sign in to comment.