Merge branch 'pr/4173'

This commit is contained in:
Clément Fournier committed 2022-11-16 13:01:04 +01:00
commit 384dec422d
4 files changed
+46 -63

No files matched your search

@@ -57,7 +57,7 @@ class ASTCatchStatementTest : ParserTestSpec({
}
child<ASTVariableDeclaratorId> {
it.image shouldBe "e"
it.name shouldBe "e"
}
listOf(ioe, aerr)
@@ -28,7 +28,7 @@ enum class JavaVersion : Comparable<JavaVersion> {
J19, J19__PREVIEW;
/** Name suitable for use with e.g. [JavaParsingHelper.parse] */
val pmdName: String = name.removePrefix("J").replaceFirst("__", "-").replace('_', '.').toLowerCase()
val pmdName: String = name.removePrefix("J").replaceFirst("__", "-").replace('_', '.').lowercase()
val parser: JavaParsingHelper = JavaParsingHelper.WITH_PROCESSING.withDefaultVersion(pmdName)
@@ -4,15 +4,15 @@
package net.sourceforge.pmd.lang.java.ast
import io.kotest.core.config.configuration
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.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.spec.style.scopes.addContainer
import io.kotest.core.spec.style.scopes.addTest
import io.kotest.core.test.NestedTest
import io.kotest.core.test.TestScope
import io.kotest.core.test.TestType
import io.kotest.core.test.createTestName
import net.sourceforge.pmd.lang.ast.test.Assertions
import net.sourceforge.pmd.lang.ast.test.IntelliMarker
import io.kotest.matchers.should as kotlintestShould
@@ -31,22 +31,16 @@ abstract class ParserTestSpec(body: ParserTestSpec.() -> Unit) : DslDrivenSpec()
body()
}
override fun lifecycle(): Lifecycle = Lifecycle.from(this)
override fun defaultConfig(): TestCaseConfig = actualDefaultConfig()
override fun defaultTestCaseConfig(): TestCaseConfig? = defaultTestConfig
override fun registration(): RootTestRegistration = RootTestRegistration.from(this)
private fun actualDefaultConfig() =
defaultTestConfig ?: defaultTestCaseConfig() ?: configuration.defaultTestConfig
fun test(name: String, disabled: Boolean = false, test: suspend TestContext.() -> Unit) =
registration().addTest(
name = createTestName(name),
xdisabled = disabled,
test = test,
config = actualDefaultConfig()
fun test(name: String, disabled: Boolean = false, test: suspend TestScope.() -> Unit) =
addTest(
testName = TestName(name),
disabled = disabled,
config = null,
type = TestType.Test,
test = test
)
/**
* Defines a group of tests that should be named similarly,
* with separate tests for separate versions.
@@ -66,10 +60,11 @@ abstract class ParserTestSpec(body: ParserTestSpec.() -> Unit) : DslDrivenSpec()
fun parserTestGroup(name: String,
disabled: Boolean = false,
spec: suspend GroupTestCtx.() -> Unit) =
registration().addContainerTest(
name = createTestName(name),
addContainer(
testName = TestName(name),
test = { GroupTestCtx(this).spec() },
xdisabled = disabled
disabled = disabled,
config = null
)
/**
@@ -117,37 +112,43 @@ abstract class ParserTestSpec(body: ParserTestSpec.() -> Unit) : DslDrivenSpec()
}
private suspend fun containedParserTestImpl(
context: TestContext,
scope: TestScope,
name: String,
javaVersion: JavaVersion,
assertions: ParserTestCtx.() -> Unit) {
context.registerTestCase(
name = createTestName(name),
test = { ParserTestCtx(javaVersion).assertions() },
config = actualDefaultConfig(),
type = TestType.Test
val nested = NestedTest(
name = TestName(name),
test = { ParserTestCtx(javaVersion).assertions() },
config = null,
type = TestType.Test,
disabled = false,
source = sourceRef()
)
scope.registerTestCase(nested)
}
inner class GroupTestCtx(private val context: TestContext) {
inner class GroupTestCtx(private val scope: TestScope) {
suspend fun onVersions(javaVersions: List<JavaVersion>, spec: suspend VersionedTestCtx.() -> Unit) {
javaVersions.forEach { javaVersion ->
context.registerTestCase(
name = createTestName("Java ${javaVersion.pmdName}"),
test = { VersionedTestCtx(this, javaVersion).spec() },
config = actualDefaultConfig(),
type = TestType.Container
val nested = NestedTest(
name = TestName("Java ${javaVersion.pmdName}"),
test = { VersionedTestCtx(this, javaVersion).spec() },
config = null,
type = TestType.Container,
disabled = false,
source = sourceRef()
)
scope.registerTestCase(nested)
}
}
inner class VersionedTestCtx(private val context: TestContext, javaVersion: JavaVersion) : ParserTestCtx(javaVersion) {
inner class VersionedTestCtx(private val scope: TestScope, javaVersion: JavaVersion) : ParserTestCtx(javaVersion) {
suspend infix fun String.should(matcher: Assertions<String>) {
containedParserTestImpl(context, "'$this'", javaVersion = javaVersion) {
containedParserTestImpl(scope, "'$this'", javaVersion = javaVersion) {
this@should kotlintestShould matcher
}
}
+6 -24
View File
@@ -85,13 +85,14 @@
<kotlin.compiler.jvmTarget>${maven.compiler.test.target}</kotlin.compiler.jvmTarget>
<kotlin.version>1.7.0</kotlin.version>
<kotest.version>4.4.3</kotest.version>
<dokka.version>1.6.21</dokka.version>
<kotlin.version>1.7.20</kotlin.version>
<kotest.version>5.5.4</kotest.version>
<junit5.version>5.8.2</junit5.version> <!-- needed by kotest -->
<dokka.version>1.7.20</dokka.version>
<javacc.version>5.0</javacc.version>
<surefire.version>3.0.0-M5</surefire.version>
<surefire.version>3.0.0-M7</surefire.version>
<checkstyle.version>10.3.3</checkstyle.version>
<checkstyle.plugin.version>3.2.0</checkstyle.plugin.version>
<pmd.plugin.version>3.19.0</pmd.plugin.version>
@@ -275,7 +276,7 @@
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.7.0</version>
<version>${junit5.version}</version>
</dependency>
<!-- Junit5 Platform Engine for Kotlin Tests -->
<dependency>
@@ -899,15 +900,6 @@
<artifactId>kotest-runner-junit5-jvm</artifactId>
<version>${kotest.version}</version>
<scope>test</scope>
<exclusions>
<!-- exclude transitive dependency to fix CVE-2021-29425
kotest 4.4.3 depends on commons-io 2.6
-->
<exclusion>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.kotest</groupId>
@@ -929,16 +921,6 @@
<scope>test</scope>
</dependency>
<!-- transitive dependency through io.kotest/kotest-runner-junit5-jvm@4.4.3
upgrade to 4.8.112 to fix [sonatype-2021-1074] CWE-611: Improper Restriction of XML External Entity Reference ('XXE')
https://github.com/classgraph/classgraph/releases/tag/classgraph-4.8.112
-->
<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
<version>4.8.112</version>
</dependency>
<!-- transitive dependency through org.scalameta:trees_2.13
upgrade to 3.16.1 to fix CVE-2021-22569 A potential Denial of Service issue in protobuf-java
https://github.com/protocolbuffers/protobuf/security/advisories/GHSA-wrvw-hg22-4m67