diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md
index 32c102919b..e5edabd1ea 100644
--- a/docs/pages/release_notes.md
+++ b/docs/pages/release_notes.md
@@ -18,6 +18,7 @@ This is a {{ site.pmd.release_type }} release.
* core
* [#724](https://github.com/pmd/pmd/issues/724): \[core] Avoid parsing rulesets multiple times
+ * [#2653](https://github.com/pmd/pmd/issues/2653): \[lang-test] Upgrade kotlintest to Kotest
* java-performance
* [#2441](https://github.com/pmd/pmd/issues/2441): \[java] RedundantFieldInitializer can not detect a special case for char initialize: `char foo = '\0';`
diff --git a/pmd-java/pom.xml b/pmd-java/pom.xml
index bd201d9494..ed1d2a5f53 100644
--- a/pmd-java/pom.xml
+++ b/pmd-java/pom.xml
@@ -172,13 +172,14 @@
test
- io.kotlintest
- kotlintest-assertions
+ io.kotest
+ kotest-assertions-core-jvm
test
- io.kotlintest
- kotlintest-core
+
+ io.kotest
+ kotest-runner-junit5-jvm
test
@@ -193,7 +194,7 @@
org.jetbrains.kotlin
- kotlin-test
+ kotlin-test-junit
test
diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTCatchStatementTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTCatchStatementTest.kt
index 8c4d34181f..f6534b1415 100644
--- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTCatchStatementTest.kt
+++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTCatchStatementTest.kt
@@ -1,8 +1,8 @@
package net.sourceforge.pmd.lang.java.ast
-import io.kotlintest.matchers.collections.shouldContainExactly
-import io.kotlintest.should
-import io.kotlintest.shouldBe
+import io.kotest.matchers.collections.shouldContainExactly
+import io.kotest.matchers.should
+import io.kotest.matchers.shouldBe
import net.sourceforge.pmd.lang.java.ast.JavaVersion.*
import net.sourceforge.pmd.lang.java.ast.JavaVersion.Companion.Earliest
import net.sourceforge.pmd.lang.java.ast.JavaVersion.Companion.Latest
diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/Java11Test.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/Java11Test.kt
index 110b01c3e1..4f7e3fa53d 100644
--- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/Java11Test.kt
+++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/Java11Test.kt
@@ -1,5 +1,5 @@
-import io.kotlintest.shouldBe
+import io.kotest.matchers.shouldBe
import net.sourceforge.pmd.lang.java.ast.*
import net.sourceforge.pmd.lang.java.ast.JavaVersion.*
import net.sourceforge.pmd.lang.java.ast.JavaVersion.Companion.Latest
@@ -88,4 +88,4 @@ class Java11Test : ParserTestSpec({
}
}
-})
\ No newline at end of file
+})
diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/KotlinTestingDsl.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/KotlinTestingDsl.kt
index dc34b3db28..e3401c2c37 100644
--- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/KotlinTestingDsl.kt
+++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/KotlinTestingDsl.kt
@@ -1,7 +1,7 @@
package net.sourceforge.pmd.lang.java.ast
-import io.kotlintest.matchers.string.shouldContain
-import io.kotlintest.shouldThrow
+import io.kotest.assertions.throwables.shouldThrow
+import io.kotest.matchers.string.shouldContain
import net.sourceforge.pmd.lang.ast.Node
import net.sourceforge.pmd.lang.ast.test.Assertions
import net.sourceforge.pmd.lang.ast.test.NodeSpec
@@ -56,7 +56,7 @@ enum class JavaVersion : Comparable {
*
* These are implicitly used by [matchExpr] and [matchStmt], which specify a matcher directly
* on the strings, using their type parameter and the info in this test context to parse, find
- * the node, and execute the matcher in a single call. These may be used by [io.kotlintest.should],
+ * the node, and execute the matcher in a single call. These may be used by [io.kotest.matchers.should],
* e.g.
*
* parserTest("Test ShiftExpression operator") {
@@ -69,7 +69,7 @@ enum class JavaVersion : Comparable {
* Import statements in the parsing contexts can be configured by adding types to [importedTypes],
* or strings to [otherImports].
*
- * Technically the utilities provided by this class may be used outside of [io.kotlintest.specs.FunSpec]s,
+ * Technically the utilities provided by this class may be used outside of [io.kotest.specs.FunSpec]s,
* e.g. in regular JUnit tests, but I think we should strive to uniformize our testing style,
* especially since KotlinTest defines so many.
*
diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ParserTestSpec.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ParserTestSpec.kt
index 741b2bff65..c877e8e860 100644
--- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ParserTestSpec.kt
+++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ParserTestSpec.kt
@@ -1,10 +1,17 @@
package net.sourceforge.pmd.lang.java.ast
-import io.kotlintest.AbstractSpec
-import io.kotlintest.TestContext
-import io.kotlintest.TestType
+import io.kotest.core.config.Project
+import io.kotest.core.spec.style.DslDrivenSpec
+import io.kotest.core.spec.style.scopes.Lifecycle
+import io.kotest.core.spec.style.scopes.RootScope
+import io.kotest.core.spec.style.scopes.RootTestRegistration
+import io.kotest.core.test.TestCaseConfig
+import io.kotest.core.test.TestContext
+import io.kotest.core.test.TestName
+import io.kotest.core.test.TestType
+import io.kotest.runner.junit.platform.IntelliMarker
import net.sourceforge.pmd.lang.ast.test.Assertions
-import io.kotlintest.should as kotlintestShould
+import io.kotest.matchers.should as kotlintestShould
/**
* Base class for grammar tests that use the DSL. Tests are layered into
@@ -14,14 +21,23 @@ import io.kotlintest.should as kotlintestShould
*
* @author Clément Fournier
*/
-abstract class ParserTestSpec(body: ParserTestSpec.() -> Unit) : AbstractSpec() {
+abstract class ParserTestSpec(body: ParserTestSpec.() -> Unit) : DslDrivenSpec(), RootScope, IntelliMarker {
init {
body()
}
- fun test(name: String, test: TestContext.() -> Unit) =
- addTestCase(name, test, defaultTestCaseConfig, TestType.Test)
+ override fun lifecycle(): Lifecycle = Lifecycle.from(this)
+ override fun defaultConfig(): TestCaseConfig = actualDefaultConfig()
+ override fun registration(): RootTestRegistration = RootTestRegistration.from(this)
+
+ fun test(name: String, disabled: Boolean = false, test: suspend TestContext.() -> Unit) =
+ registration().addTest(
+ name = TestName(name),
+ xdisabled = disabled,
+ test = test,
+ config = actualDefaultConfig()
+ )
/**
* Defines a group of tests that should be named similarly,
@@ -34,14 +50,19 @@ abstract class ParserTestSpec(body: ParserTestSpec.() -> Unit) : AbstractSpec()
* regression tests without bothering to find a name.
*
* @param name Name of the container test
- * @param spec Assertions. Each call to [io.kotlintest.should] on a string
+ * @param spec Assertions. Each call to [io.kotest.matchers.should] on a string
* receiver is replaced by a [GroupTestCtx.should], which creates a
* new parser test.
*
*/
fun parserTestGroup(name: String,
- spec: GroupTestCtx.() -> Unit) =
- addTestCase(name, { GroupTestCtx(this).spec() }, defaultTestCaseConfig, TestType.Container)
+ disabled: Boolean = false,
+ spec: suspend GroupTestCtx.() -> Unit) =
+ registration().addContainerTest(
+ name = TestName(name),
+ test = { GroupTestCtx(this).spec() },
+ xdisabled = disabled
+ )
/**
* Defines a group of tests that should be named similarly.
@@ -53,14 +74,14 @@ abstract class ParserTestSpec(body: ParserTestSpec.() -> Unit) : AbstractSpec()
*
* @param name Name of the container test
* @param javaVersion Language versions to use when parsing
- * @param spec Assertions. Each call to [io.kotlintest.should] on a string
+ * @param spec Assertions. Each call to [io.kotest.matchers.should] on a string
* receiver is replaced by a [GroupTestCtx.should], which creates a
* new parser test.
*
*/
fun parserTest(name: String,
javaVersion: JavaVersion = JavaVersion.Latest,
- spec: GroupTestCtx.VersionedTestCtx.() -> Unit) =
+ spec: suspend GroupTestCtx.VersionedTestCtx.() -> Unit) =
parserTest(name, listOf(javaVersion), spec)
/**
@@ -74,44 +95,46 @@ abstract class ParserTestSpec(body: ParserTestSpec.() -> Unit) : AbstractSpec()
*
* @param name Name of the container test
* @param javaVersions Language versions for which to generate tests
- * @param spec Assertions. Each call to [io.kotlintest.should] on a string
+ * @param spec Assertions. Each call to [io.kotest.matchers.should] on a string
* receiver is replaced by a [GroupTestCtx.should], which creates a
* new parser test.
*/
fun parserTest(name: String,
javaVersions: List,
- spec: GroupTestCtx.VersionedTestCtx.() -> Unit) =
+ spec: suspend GroupTestCtx.VersionedTestCtx.() -> Unit) =
parserTestGroup(name) {
onVersions(javaVersions) {
spec()
}
}
- private fun containedParserTestImpl(
+ private suspend fun containedParserTestImpl(
context: TestContext,
name: String,
javaVersion: JavaVersion,
assertions: ParserTestCtx.() -> Unit) {
context.registerTestCase(
- name = name,
- spec = this,
+ name = TestName(name),
test = { ParserTestCtx(javaVersion).assertions() },
- config = defaultTestCaseConfig,
+ config = actualDefaultConfig(),
type = TestType.Test
)
}
+ private fun actualDefaultConfig() =
+ defaultTestConfig ?: defaultTestCaseConfig()
+ ?: Project.testCaseConfig()
+
inner class GroupTestCtx(private val context: TestContext) {
- fun onVersions(javaVersions: List, spec: VersionedTestCtx.() -> Unit) {
+ suspend fun onVersions(javaVersions: List, spec: suspend VersionedTestCtx.() -> Unit) {
javaVersions.forEach { javaVersion ->
context.registerTestCase(
- name = "Java ${javaVersion.pmdName}",
- spec = this@ParserTestSpec,
+ name = TestName("Java ${javaVersion.pmdName}"),
test = { VersionedTestCtx(this, javaVersion).spec() },
- config = defaultTestCaseConfig,
+ config = actualDefaultConfig(),
type = TestType.Container
)
}
@@ -119,11 +142,11 @@ abstract class ParserTestSpec(body: ParserTestSpec.() -> Unit) : AbstractSpec()
inner class VersionedTestCtx(private val context: TestContext, javaVersion: JavaVersion) : ParserTestCtx(javaVersion) {
- infix fun String.should(matcher: Assertions) {
+ suspend infix fun String.should(matcher: Assertions) {
containedParserTestImpl(context, "'$this'", javaVersion = javaVersion) {
this@should kotlintestShould matcher
}
}
}
}
-}
\ No newline at end of file
+}
diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/SwitchExpressionTests.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/SwitchExpressionTests.kt
index 4dd28b2bb2..7455d07bc8 100644
--- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/SwitchExpressionTests.kt
+++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/SwitchExpressionTests.kt
@@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.java.ast
-import io.kotlintest.shouldBe
+import io.kotest.matchers.shouldBe
/**
* @author Clément Fournier
diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/WildcardBoundsTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/WildcardBoundsTest.kt
index b62a9ac638..c5f174e2f7 100644
--- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/WildcardBoundsTest.kt
+++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/WildcardBoundsTest.kt
@@ -1,6 +1,6 @@
package net.sourceforge.pmd.lang.java.ast
-import io.kotlintest.shouldBe
+import io.kotest.matchers.shouldBe
class WildcardBoundsTest : ParserTestSpec({
diff --git a/pmd-lang-test/pom.xml b/pmd-lang-test/pom.xml
index 53aca66687..2fcedf2c44 100644
--- a/pmd-lang-test/pom.xml
+++ b/pmd-lang-test/pom.xml
@@ -105,13 +105,14 @@
of the pmd-lang-test module
-->
- io.kotlintest
- kotlintest-assertions
+ io.kotest
+ kotest-assertions-core-jvm
compile
- org.jetbrains.kotlin
- kotlin-test
+
+ io.kotest
+ kotest-runner-junit5-jvm
compile
diff --git a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/cpd/test/CpdTextComparisonTest.kt b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/cpd/test/CpdTextComparisonTest.kt
index 2b198984cd..8335f58b12 100644
--- a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/cpd/test/CpdTextComparisonTest.kt
+++ b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/cpd/test/CpdTextComparisonTest.kt
@@ -4,7 +4,7 @@
package net.sourceforge.pmd.cpd.test
-import io.kotlintest.shouldThrow
+import io.kotest.assertions.throwables.shouldThrow
import net.sourceforge.pmd.cpd.SourceCode
import net.sourceforge.pmd.cpd.TokenEntry
import net.sourceforge.pmd.cpd.Tokenizer
diff --git a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/AstMatcherDslAdapter.kt b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/AstMatcherDslAdapter.kt
index 419fafabff..3d90212be9 100644
--- a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/AstMatcherDslAdapter.kt
+++ b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/AstMatcherDslAdapter.kt
@@ -26,7 +26,7 @@ object NodeTreeLikeAdapter : DoublyLinkedTreeLikeAdapter {
/** A subtree matcher written in the DSL documented on [TreeNodeWrapper]. */
typealias NodeSpec = TreeNodeWrapper.() -> Unit
-/** A function feedable to [io.kotlintest.should], which fails the test if an [AssertionError] is thrown. */
+/** A function feedable to [io.kotest.matchers.should], which fails the test if an [AssertionError] is thrown. */
typealias Assertions = (M) -> Unit
/** A shorthand for [baseShouldMatchSubtree] providing the [NodeTreeLikeAdapter]. */
@@ -37,7 +37,7 @@ inline fun Node?.shouldMatchNode(ignoreChildren: Boolean = fa
/**
* Returns [an assertion function][Assertions] asserting that its parameter conforms to the given [NodeSpec].
*
- * Use it with [io.kotlintest.should], e.g. `node should matchNode {}`.
+ * Use it with [io.kotest.matchers.should], e.g. `node should matchNode {}`.
*
* See also the samples on [TreeNodeWrapper].
*
@@ -50,7 +50,7 @@ inline fun Node?.shouldMatchNode(ignoreChildren: Boolean = fa
* Assertions may consist of [NWrapper.child] calls, which perform the same type of node
* matching on a child of the tested node.
*
- * @return A matcher for AST nodes, suitable for use by [io.kotlintest.should].
+ * @return A matcher for AST nodes, suitable for use by [io.kotest.matchers.should].
*/
inline fun matchNode(ignoreChildren: Boolean = false, noinline nodeSpec: NodeSpec)
: Assertions = { it.shouldMatchNode(ignoreChildren, nodeSpec) }
diff --git a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/TestUtils.kt b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/TestUtils.kt
index 779308632c..47dba9b1d4 100644
--- a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/TestUtils.kt
+++ b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/TestUtils.kt
@@ -4,10 +4,10 @@
package net.sourceforge.pmd.lang.ast.test
-import io.kotlintest.should
+import io.kotest.matchers.should
import kotlin.reflect.KCallable
import kotlin.reflect.jvm.isAccessible
-import io.kotlintest.shouldBe as ktShouldBe
+import io.kotest.matchers.shouldBe as ktShouldBe
/**
* Extension to add the name of a property to error messages.
@@ -48,7 +48,7 @@ private fun assertWrapper(callable: KCallable, right: V, asserter: (N,
* have to use the name of the getter instead of that of the generated
* property (with the get prefix).
*
- * If this conflicts with [io.kotlintest.shouldBe], use the equivalent [shouldEqual]
+ * If this conflicts with [io.kotest.matchers.shouldBe], use the equivalent [shouldEqual]
*
*/
infix fun KCallable.shouldBe(expected: V?) = this.shouldEqual(expected)
diff --git a/pmd-modelica/pom.xml b/pmd-modelica/pom.xml
index a40ac6063e..3f64be86b0 100644
--- a/pmd-modelica/pom.xml
+++ b/pmd-modelica/pom.xml
@@ -111,7 +111,7 @@
org.jetbrains.kotlin
- kotlin-test
+ kotlin-test-junit
test
@@ -120,13 +120,8 @@
test
- io.kotlintest
- kotlintest-assertions
- test
-
-
- io.kotlintest
- kotlintest-core
+ io.kotest
+ kotest-assertions-core-jvm
test
diff --git a/pmd-modelica/src/test/kotlin/net/sourceforge/pmd/lang/modelica/ast/ModelicaCoordsTest.kt b/pmd-modelica/src/test/kotlin/net/sourceforge/pmd/lang/modelica/ast/ModelicaCoordsTest.kt
index dfa62e29b5..d2b0bc9ac6 100644
--- a/pmd-modelica/src/test/kotlin/net/sourceforge/pmd/lang/modelica/ast/ModelicaCoordsTest.kt
+++ b/pmd-modelica/src/test/kotlin/net/sourceforge/pmd/lang/modelica/ast/ModelicaCoordsTest.kt
@@ -4,16 +4,16 @@
package net.sourceforge.pmd.lang.modelica.ast
-import io.kotlintest.should
-import io.kotlintest.shouldBe
-import io.kotlintest.specs.AbstractFunSpec
+import io.kotest.core.spec.style.FunSpec
+import io.kotest.matchers.should
+import io.kotest.matchers.shouldBe
import net.sourceforge.pmd.lang.LanguageRegistry
import net.sourceforge.pmd.lang.ast.Node
import net.sourceforge.pmd.lang.ast.test.matchNode
import net.sourceforge.pmd.lang.ast.test.shouldBe
import java.io.StringReader
-class ModelicaCoordsTest : AbstractFunSpec({
+class ModelicaCoordsTest : FunSpec({
test("Test line/column numbers for implicit nodes") {
diff --git a/pmd-scala-modules/pmd-scala-common/pom.xml b/pmd-scala-modules/pmd-scala-common/pom.xml
index 35e5653a3b..78238212f8 100644
--- a/pmd-scala-modules/pmd-scala-common/pom.xml
+++ b/pmd-scala-modules/pmd-scala-common/pom.xml
@@ -140,13 +140,8 @@
test
- io.kotlintest
- kotlintest-assertions
- test
-
-
- io.kotlintest
- kotlintest-core
+ io.kotest
+ kotest-assertions-core-jvm
test
@@ -156,7 +151,7 @@
org.jetbrains.kotlin
- kotlin-test
+ kotlin-test-junit
test
diff --git a/pmd-scala-modules/pmd-scala-common/src/test/kotlin/net/sourceforge/pmd/lang/scala/ast/ScalaTreeTests.kt b/pmd-scala-modules/pmd-scala-common/src/test/kotlin/net/sourceforge/pmd/lang/scala/ast/ScalaTreeTests.kt
index 32d808af26..48867dd383 100644
--- a/pmd-scala-modules/pmd-scala-common/src/test/kotlin/net/sourceforge/pmd/lang/scala/ast/ScalaTreeTests.kt
+++ b/pmd-scala-modules/pmd-scala-common/src/test/kotlin/net/sourceforge/pmd/lang/scala/ast/ScalaTreeTests.kt
@@ -4,15 +4,15 @@
package net.sourceforge.pmd.lang.scala.ast
-import io.kotlintest.should
-import io.kotlintest.specs.AbstractFunSpec
+import io.kotest.core.spec.style.FunSpec
+import io.kotest.matchers.should
import net.sourceforge.pmd.lang.LanguageRegistry
import net.sourceforge.pmd.lang.ast.Node
import net.sourceforge.pmd.lang.ast.test.matchNode
import net.sourceforge.pmd.lang.ast.test.shouldBe
import java.io.StringReader
-class ScalaTreeTests : AbstractFunSpec({
+class ScalaTreeTests : FunSpec({
test("Test line/column numbers") {
diff --git a/pom.xml b/pom.xml
index 8f65d4784f..1846f3823b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -85,8 +85,8 @@
${maven.compiler.test.target}
- 1.3.0
- 3.1.8
+ 1.3.72
+ 4.1.2
0.10.1
@@ -269,9 +269,9 @@
- io.kotlintest
- kotlintest-runner-junit5
- ${kotlintest.version}
+ io.kotest
+ kotest-runner-junit5-jvm
+ ${kotest.version}
@@ -827,22 +827,21 @@
test
- org.jetbrains.kotlin
- kotlin-test
- ${kotlin.version}
- test
-
-
-
- io.kotlintest
- kotlintest-assertions
- ${kotlintest.version}
+ io.kotest
+ kotest-runner-junit5-jvm
+ ${kotest.version}
test
- io.kotlintest
- kotlintest-core
- ${kotlintest.version}
+ io.kotest
+ kotest-assertions-core-jvm
+ ${kotest.version}
+ test
+
+
+ io.kotest
+ kotest-property-jvm
+ ${kotest.version}
test