Skip to content

Commit

Permalink
Switch to Junit 5 (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
ansman authored May 7, 2023
1 parent 8ebc465 commit ff3f279
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 11 deletions.
2 changes: 1 addition & 1 deletion api/src/test/kotlin/se/ansman/kotshi/TestKotshiUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isNotEqualTo
import com.squareup.moshi.JsonQualifier
import org.junit.Test
import org.junit.jupiter.api.Test
import se.ansman.kotshi.KotshiUtils.createJsonQualifierImplementation
import se.ansman.kotshi.KotshiUtils.matches
import kotlin.reflect.KClass
Expand Down
13 changes: 13 additions & 0 deletions gradle-plugin/src/main/kotlin/library.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,23 @@ tasks.withType<KotlinCompile>().configureEach {
}
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).coerceAtLeast(1)
systemProperties(
"junit.jupiter.execution.parallel.enabled" to "true",
"junit.jupiter.execution.parallel.config.strategy" to "dynamic",
"junit.jupiter.execution.parallel.config.dynamic.factor" to "1",
"junit.jupiter.execution.parallel.mode.default" to "concurrent",
"junit.jupiter.execution.parallel.mode.classes.default" to "concurrent",
)
}

tasks.withType<Javadoc> { enabled = false }

dependencies {
testImplementation(libs.junit)
testImplementation(libs.junit.jupiter)
testImplementation(libs.assertk)
testImplementation(libs.kotlin.test.junit)
}
1 change: 0 additions & 1 deletion gradle-plugin/src/main/kotlin/test-library.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ sourceSets {
}

tasks.withType<Test>().configureEach {
maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).coerceAtLeast(1)
jvmArgs(
"--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ kotlinpoet-ksp = { module = "com.squareup:kotlinpoet-ksp", version.ref = "kotlin
kotlinx-metadata = "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.6.0"

junit = "junit:junit:4.13.2"
junit-jupiter = "org.junit.jupiter:junit-jupiter:5.9.1"

assertk = "com.willowtreeapps.assertk:assertk-jvm:0.25"

compileTesting-core = { module = "com.github.tschuchortdev:kotlin-compile-testing", version.ref = "compileTesting" }
Expand Down
14 changes: 14 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ pluginManagement {
}
}

plugins {
id("com.gradle.enterprise") version "3.9"
}

rootProject.name = "kotshi"
include("compiler")
include("api")
Expand All @@ -20,4 +24,14 @@ dependencyResolutionManagement {
google()
mavenCentral()
}
}

gradleEnterprise {
if (System.getenv("CI") != null) {
buildScan {
publishAlways()
termsOfServiceUrl = "https://gradle.com/terms-of-service"
termsOfServiceAgree = "yes"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ import com.tschuchort.compiletesting.SourceFile
import com.tschuchort.compiletesting.kspArgs
import com.tschuchort.compiletesting.kspIncremental
import com.tschuchort.compiletesting.symbolProcessorProviders
import org.junit.Test
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.parallel.Execution
import org.junit.jupiter.api.parallel.ExecutionMode
import se.ansman.kotshi.ksp.KotshiSymbolProcessor
import se.ansman.kotshi.ksp.KotshiSymbolProcessorProvider
import java.io.File
import kotlin.test.assertEquals

@Execution(ExecutionMode.SAME_THREAD)
class KspGeneratorTest : BaseGeneratorTest() {
override val processorClassName: String get() = KotshiSymbolProcessor::class.java.canonicalName

override val extraGeneratedFiles: List<File>
get() = temporaryFolder.root.resolve("ksp/sources/kotlin/").listFiles()?.asList() ?: emptyList()
get() = temporaryFolder.resolve("ksp/sources/kotlin/").listFiles()?.asList() ?: emptyList()

override fun KotlinCompilation.setUp(options: Map<String, String>) {
kspIncremental = true
Expand Down
12 changes: 5 additions & 7 deletions tests/src/test/kotlin/se/ansman/kotshi/BaseGeneratorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import com.tschuchort.compiletesting.KotlinCompilation
import com.tschuchort.compiletesting.SourceFile
import com.tschuchort.compiletesting.SourceFile.Companion.java
import com.tschuchort.compiletesting.SourceFile.Companion.kotlin
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import se.ansman.kotshi.Errors.ignoredDataClassPropertyWithoutDefaultValue
import se.ansman.kotshi.Errors.javaClassNotSupported
import se.ansman.kotshi.Errors.jsonDefaultValueAppliedToInvalidType
Expand All @@ -29,9 +28,8 @@ import se.ansman.kotshi.assertions.isAssignableTo
import java.io.File

abstract class BaseGeneratorTest {
@Rule
@JvmField
val temporaryFolder: TemporaryFolder = TemporaryFolder()
@TempDir
lateinit var temporaryFolder: File

protected abstract val processorClassName: String
protected open val extraGeneratedFiles: List<File> get() = emptyList()
Expand Down Expand Up @@ -572,7 +570,7 @@ abstract class BaseGeneratorTest {
protected fun compile(vararg sources: SourceFile, options: Map<String, String> = emptyMap()) =
KotlinCompilation()
.apply {
workingDir = temporaryFolder.root
workingDir = temporaryFolder
this.sources = sources.asList()
inheritClassPath = true
messageOutputStream = System.out // see diagnostics in real time
Expand Down

0 comments on commit ff3f279

Please sign in to comment.