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 d70f4b5d39..631207ee02 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 @@ -5,6 +5,8 @@ package net.sourceforge.pmd.lang.java.ast import io.kotest.assertions.throwables.shouldThrow +import io.kotest.core.spec.style.scopes.AbstractContainerScope +import io.kotest.core.test.TestScope import io.kotest.matchers.string.shouldContain import net.sourceforge.pmd.lang.ast.Node import net.sourceforge.pmd.lang.ast.test.Assertions @@ -96,10 +98,12 @@ enum class JavaVersion : Comparable { * @property otherImports Other imports, without the `import` and semicolon * @property genClassHeader Header of the enclosing class used in parsing contexts like parseExpression, etc. E.g. "class Foo" */ -open class ParserTestCtx(val javaVersion: JavaVersion = JavaVersion.Latest, - val importedTypes: MutableList> = mutableListOf(), - val otherImports: MutableList = mutableListOf(), - var genClassHeader: String = "class Foo") { +open class ParserTestCtx( + testScope : TestScope, + val javaVersion: JavaVersion = JavaVersion.Latest, + val importedTypes: MutableList> = mutableListOf(), + val otherImports: MutableList = mutableListOf(), + var genClassHeader: String = "class Foo") : AbstractContainerScope(testScope) { /** Imports to add to the top of the parsing contexts. */ internal val imports: List 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 c5e409a51f..efdca089ea 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 @@ -7,6 +7,7 @@ package net.sourceforge.pmd.lang.java.ast import io.kotest.core.names.TestName import io.kotest.core.source.sourceRef import io.kotest.core.spec.DslDrivenSpec +import io.kotest.core.spec.style.scopes.AbstractContainerScope import io.kotest.core.spec.style.scopes.RootScope import io.kotest.core.spec.style.scopes.addContainer import io.kotest.core.spec.style.scopes.addTest @@ -112,43 +113,43 @@ abstract class ParserTestSpec(body: ParserTestSpec.() -> Unit) : DslDrivenSpec() } private suspend fun containedParserTestImpl( - scope: TestScope, - name: String, - javaVersion: JavaVersion, - assertions: ParserTestCtx.() -> Unit) { + testScope: GroupTestCtx.VersionedTestCtx, + name: String, + javaVersion: JavaVersion, + assertions: ParserTestCtx.() -> Unit) { val nested = NestedTest( name = TestName(name), - test = { ParserTestCtx(javaVersion).assertions() }, + test = { ParserTestCtx(testScope, javaVersion).assertions() }, config = null, type = TestType.Test, disabled = false, source = sourceRef() ) - scope.registerTestCase(nested) + testScope.registerTestCase(nested) } - inner class GroupTestCtx(private val scope: TestScope) { + inner class GroupTestCtx(testScope: TestScope) : AbstractContainerScope(testScope) { suspend fun onVersions(javaVersions: List, spec: suspend VersionedTestCtx.() -> Unit) { javaVersions.forEach { javaVersion -> val nested = NestedTest( name = TestName("Java ${javaVersion.pmdName}"), - test = { VersionedTestCtx(this, javaVersion).spec() }, + test = { this@GroupTestCtx.VersionedTestCtx(this, javaVersion).spec() }, config = null, type = TestType.Container, disabled = false, source = sourceRef() ) - scope.registerTestCase(nested) + this.registerTestCase(nested) } } - inner class VersionedTestCtx(private val scope: TestScope, javaVersion: JavaVersion) : ParserTestCtx(javaVersion) { + inner class VersionedTestCtx(testScope: TestScope, javaVersion: JavaVersion) : ParserTestCtx(testScope, javaVersion) { suspend infix fun String.should(matcher: Assertions) { - containedParserTestImpl(scope, "'$this'", javaVersion = javaVersion) { + containedParserTestImpl(this@VersionedTestCtx, "'$this'", javaVersion = javaVersion) { this@should kotlintestShould matcher } }