diff --git a/docs/pages/pmd/userdocs/extending/writing_rules_intro.md b/docs/pages/pmd/userdocs/extending/writing_rules_intro.md index e98398684f..2c0b4dc478 100644 --- a/docs/pages/pmd/userdocs/extending/writing_rules_intro.md +++ b/docs/pages/pmd/userdocs/extending/writing_rules_intro.md @@ -120,6 +120,11 @@ Example: ``` +{% include note.html content="In PMD 7, the `language` attribute will be required on all `rule` + elements that declare a new rule. Some base rule classes set the language implicitly in their + constructor, and so this is not required in all cases for the rule to work. But this + behavior will be discontinued in PMD 7, so missing `language` attributes are + reported beginning with PMD 6.27.0 as a forward compatibility warning." %} ## Resource index diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 870cbde01f..afcc1b89ab 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -21,11 +21,26 @@ This is a {{ site.pmd.release_type }} release. ### Fixed Issues +* 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';` ### API Changes +* XML rule definition in rulesets: In PMD 7, the `language` attribute will be required on all `rule` + elements that declare a new rule. Some base rule classes set the language implicitly in their + constructor, and so this is not required in all cases for the rule to work. But this + behavior will be discontinued in PMD 7, so missing `language` attributes are now + reported as a forward compatibility warning. + +#### Deprecated API + +##### For removal + +* {% jdoc !!pmd-java::lang.java.ast.ASTThrowStatement#getFirstClassOrInterfaceTypeImage() %} + ### External Contributions * [#2677](https://github.com/pmd/pmd/pull/2677): \[java] RedundantFieldInitializer can not detect a special case for char initialize: `char foo = '\0';` - [Mykhailo Palahuta](https://github.com/Drofff) diff --git a/pmd-apex/src/main/resources/category/apex/bestpractices.xml b/pmd-apex/src/main/resources/category/apex/bestpractices.xml index f91fa5095a..5c13033efc 100644 --- a/pmd-apex/src/main/resources/category/apex/bestpractices.xml +++ b/pmd-apex/src/main/resources/category/apex/bestpractices.xml @@ -10,6 +10,7 @@ Rules which enforce generally accepted best practices. - diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java index f69923f760..37186a4064 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java @@ -8,9 +8,11 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.logging.Level; @@ -60,6 +62,8 @@ public class RuleSetFactory { private final boolean warnDeprecated; private final RuleSetFactoryCompatibility compatibilityFilter; + private final Map parsedRulesets = new HashMap<>(); + /** * @deprecated Use {@link RulesetsFactoryUtils#defaultFactory()} */ @@ -338,10 +342,16 @@ public class RuleSetFactory { private Rule createRule(RuleSetReferenceId ruleSetReferenceId, boolean withDeprecatedRuleReferences) throws RuleSetNotFoundException { if (ruleSetReferenceId.isAllRules()) { - throw new IllegalArgumentException( - "Cannot parse a single Rule from an all Rule RuleSet reference: <" + ruleSetReferenceId + ">."); + throw new IllegalArgumentException("Cannot parse a single Rule from an all Rule RuleSet reference: <" + ruleSetReferenceId + ">."); + } + RuleSet ruleSet; + // java8: computeIfAbsent + if (parsedRulesets.containsKey(ruleSetReferenceId)) { + ruleSet = parsedRulesets.get(ruleSetReferenceId); + } else { + ruleSet = createRuleSet(ruleSetReferenceId, withDeprecatedRuleReferences); + parsedRulesets.put(ruleSetReferenceId, ruleSet); } - RuleSet ruleSet = createRuleSet(ruleSetReferenceId, withDeprecatedRuleReferences); return ruleSet.getRuleByName(ruleSetReferenceId.getRuleName()); } @@ -610,12 +620,18 @@ public class RuleSetFactory { // Stop if we're looking for a particular Rule, and this element is not // it. if (StringUtils.isNotBlank(ruleSetReferenceId.getRuleName()) - && !isRuleName(ruleElement, ruleSetReferenceId.getRuleName())) { + && !isRuleName(ruleElement, ruleSetReferenceId.getRuleName())) { return; } Rule rule = new RuleFactory(resourceLoader).buildRule(ruleElement); rule.setRuleSetName(ruleSetBuilder.getName()); + if (StringUtils.isBlank(ruleElement.getAttribute("language"))) { + LOG.warning("Rule " + ruleSetReferenceId.getRuleSetFileName() + "/" + rule.getName() + " does not mention attribute" + + " language='" + rule.getLanguage().getTerseName() + "'," + + " please mention it explicitly to be compatible with PMD 7"); + } + ruleSetBuilder.addRule(rule); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/rules/RuleFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/rules/RuleFactory.java index cbd4ea0532..e115886c2d 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/rules/RuleFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/rules/RuleFactory.java @@ -152,9 +152,9 @@ public class RuleFactory { String name = ruleElement.getAttribute(NAME); RuleBuilder builder = new RuleBuilder(name, - resourceLoader, - ruleElement.getAttribute(CLASS), - ruleElement.getAttribute("language")); + resourceLoader, + ruleElement.getAttribute(CLASS), + ruleElement.getAttribute("language")); if (ruleElement.hasAttribute(MINIMUM_LANGUAGE_VERSION)) { builder.minimumLanguageVersion(ruleElement.getAttribute(MINIMUM_LANGUAGE_VERSION)); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java index 7e236e51db..fb4de80b6f 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java @@ -979,6 +979,7 @@ public class RuleSetFactoryTest { + " testdesc\n" + "\n" @@ -991,6 +992,7 @@ public class RuleSetFactoryTest { + " testdesc\n" + "\n" @@ -1028,6 +1030,7 @@ public class RuleSetFactoryTest { + "\n" + "testdesc\n" + "\n" @@ -1039,11 +1042,13 @@ public class RuleSetFactoryTest { + "\n" + "testdesc\n" + "\n" + "\n" + "\n" + "\n" + "\n" @@ -1053,6 +1058,7 @@ public class RuleSetFactoryTest { + "\n" + "testdesc\n" + "\n" + "\n" @@ -1074,6 +1080,7 @@ public class RuleSetFactoryTest { + "\n" + "testdesc\n" + "\n" + "3\n" @@ -1092,6 +1099,7 @@ public class RuleSetFactoryTest { + "\n" + "testdesc\n" + "\n" @@ -1104,7 +1112,8 @@ public class RuleSetFactoryTest { + "\n" + + "class=\"net.sourceforge.pmd.lang.rule.MockRule\" " + + "language=\"dummy\">\n" + ""; private static final String INCORRECT_LANGUAGE = "\n" @@ -1180,8 +1189,8 @@ public class RuleSetFactoryTest { + "\n" + "testdesc\n" + "\n" + ""; @@ -1210,6 +1219,7 @@ public class RuleSetFactoryTest { + "\n" + "testdesc\n" + "test - io.kotlintest - kotlintest-assertions + io.kotest + kotest-assertions-core-jvm test - io.kotlintest - kotlintest-core + + io.kotest + kotest-runner-junit5-jvm test @@ -194,7 +195,7 @@ org.jetbrains.kotlin - kotlin-test + kotlin-test-junit test diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTThrowStatement.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTThrowStatement.java index b7fff40b47..cd79bb3a87 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTThrowStatement.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTThrowStatement.java @@ -33,7 +33,10 @@ public class ASTThrowStatement extends AbstractJavaNode { * * @return the image of the first ASTClassOrInterfaceType node found or * null + * @deprecated This method is too specific and doesn't support all cases. + * It will be removed with PMD 7. */ + @Deprecated public final String getFirstClassOrInterfaceTypeImage() { final ASTClassOrInterfaceType t = getFirstDescendantOfType(ASTClassOrInterfaceType.class); return t == null ? null : t.getImage(); diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ExceptionAsFlowControlRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ExceptionAsFlowControlRule.java index a18f218d7c..9e491325cf 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ExceptionAsFlowControlRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ExceptionAsFlowControlRule.java @@ -6,6 +6,8 @@ package net.sourceforge.pmd.lang.java.rule.design; import java.util.List; +import org.apache.commons.lang3.StringUtils; + import net.sourceforge.pmd.lang.java.ast.ASTCatchStatement; import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType; import net.sourceforge.pmd.lang.java.ast.ASTFormalParameter; @@ -35,8 +37,7 @@ public class ExceptionAsFlowControlRule extends AbstractJavaRule { ASTFormalParameter fp = (ASTFormalParameter) catchStmt.getChild(0); ASTType type = fp.getFirstDescendantOfType(ASTType.class); ASTClassOrInterfaceType name = type.getFirstDescendantOfType(ASTClassOrInterfaceType.class); - if (node.getFirstClassOrInterfaceTypeImage() != null - && node.getFirstClassOrInterfaceTypeImage().equals(name.getImage())) { + if (isExceptionOfTypeThrown(node, name.getImage())) { addViolation(data, name); } } @@ -44,4 +45,9 @@ public class ExceptionAsFlowControlRule extends AbstractJavaRule { return data; } + private boolean isExceptionOfTypeThrown(ASTThrowStatement throwStatement, String typeName) { + final ASTClassOrInterfaceType t = throwStatement.getFirstDescendantOfType(ASTClassOrInterfaceType.class); + String thrownTypeName = t == null ? null : t.getImage(); + return StringUtils.equals(thrownTypeName, typeName); + } } diff --git a/pmd-java/src/main/resources/category/java/bestpractices.xml b/pmd-java/src/main/resources/category/java/bestpractices.xml index 66a1ea21ce..f885e481db 100644 --- a/pmd-java/src/main/resources/category/java/bestpractices.xml +++ b/pmd-java/src/main/resources/category/java/bestpractices.xml @@ -35,6 +35,7 @@ public abstract class Foo { @@ -481,6 +487,7 @@ public void bar(String string) { JavaNode?.shouldMatchNode(ignoreChildren: Boolean * * 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") { @@ -120,7 +118,7 @@ inline fun JavaNode?.shouldMatchNode(ignoreChildren: Boolean * 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 adf7d1dcfb..034e2c77ac 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,15 +1,17 @@ package net.sourceforge.pmd.lang.java.ast -import io.kotlintest.AbstractSpec -import io.kotlintest.Matcher -import io.kotlintest.TestContext -import io.kotlintest.TestType -import net.sourceforge.pmd.lang.ast.Node -import net.sourceforge.pmd.lang.ast.ParseException +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 net.sourceforge.pmd.lang.ast.test.ValuedNodeSpec -import net.sourceforge.pmd.lang.ast.test.matchNode -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 @@ -19,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, @@ -39,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. @@ -58,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) /** @@ -79,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 ) } @@ -124,7 +142,7 @@ 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 } 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-java/src/test/resources/rulesets/java/metrics_test.xml b/pmd-java/src/test/resources/rulesets/java/metrics_test.xml index b5b2a52b34..8d75b0a96d 100644 --- a/pmd-java/src/test/resources/rulesets/java/metrics_test.xml +++ b/pmd-java/src/test/resources/rulesets/java/metrics_test.xml @@ -10,56 +10,67 @@ diff --git a/pmd-javascript/src/main/resources/category/ecmascript/bestpractices.xml b/pmd-javascript/src/main/resources/category/ecmascript/bestpractices.xml index 5b39319cd2..28c82246d6 100644 --- a/pmd-javascript/src/main/resources/category/ecmascript/bestpractices.xml +++ b/pmd-javascript/src/main/resources/category/ecmascript/bestpractices.xml @@ -37,6 +37,7 @@ with (object) { - 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 82a52fcc86..da09839ead 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 @@ -28,7 +28,7 @@ typealias ValuedNodeSpec = TreeNodeWrapper.() -> O /** A subtree matcher written in the DSL documented on [TreeNodeWrapper]. */ typealias NodeSpec = ValuedNodeSpec -/** 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 fun ValuedNodeSpec.ignoreResult(): NodeSpec { @@ -50,7 +50,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]. * @@ -63,7 +63,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: ValuedNodeSpec) : 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 d3b6544c78..128ded79ff 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,14 +4,10 @@ package net.sourceforge.pmd.lang.ast.test -import io.kotlintest.Matcher -import io.kotlintest.equalityMatcher -import io.kotlintest.matchers.haveSize -import io.kotlintest.should -import java.util.stream.Stream +import io.kotest.matchers.should import kotlin.reflect.KCallable import kotlin.reflect.jvm.isAccessible -import kotlin.streams.toList +import io.kotest.matchers.shouldBe as ktShouldBe /** * Extension to add the name of a property to error messages. @@ -57,7 +53,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 5bbf6ba085..bdbac9570d 100644 --- a/pmd-modelica/pom.xml +++ b/pmd-modelica/pom.xml @@ -112,7 +112,7 @@ org.jetbrains.kotlin - kotlin-test + kotlin-test-junit test @@ -121,13 +121,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 d62fe2eb4b..36b3fcf662 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,15 +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 net.sourceforge.pmd.lang.modelica.ModelicaParsingHelper -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 1378ae0cc4..b40777dd21 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 2c2b385278..635b32722f 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,13 +4,14 @@ 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 -class ScalaTreeTests : AbstractFunSpec({ +class ScalaTreeTests : FunSpec({ test("Test line/column numbers") { diff --git a/pmd-test/pom.xml b/pmd-test/pom.xml index b7c1fcc9a8..31ffb0a5e5 100644 --- a/pmd-test/pom.xml +++ b/pmd-test/pom.xml @@ -44,7 +44,11 @@ commons-io commons-io - + + com.github.stefanbirkner + system-rules + compile + org.mockito mockito-core diff --git a/pmd-test/src/main/java/net/sourceforge/pmd/AbstractRuleSetFactoryTest.java b/pmd-test/src/main/java/net/sourceforge/pmd/AbstractRuleSetFactoryTest.java index 23834d26b2..164e0590a3 100644 --- a/pmd-test/src/main/java/net/sourceforge/pmd/AbstractRuleSetFactoryTest.java +++ b/pmd-test/src/main/java/net/sourceforge/pmd/AbstractRuleSetFactoryTest.java @@ -33,6 +33,7 @@ import javax.xml.parsers.SAXParserFactory; import org.apache.commons.io.FilenameUtils; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.contrib.java.lang.system.SystemErrRule; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; @@ -50,6 +51,9 @@ import net.sourceforge.pmd.util.ResourceLoader; * subclassed for each language. */ public abstract class AbstractRuleSetFactoryTest { + @org.junit.Rule + public final SystemErrRule systemErrRule = new SystemErrRule().enableLog().muteForSuccessfulTests(); + private static SAXParserFactory saxParserFactory; private static ValidateDefaultHandler validateDefaultHandler; private static SAXParser saxParser; diff --git a/pmd-visualforce/src/main/resources/category/vf/security.xml b/pmd-visualforce/src/main/resources/category/vf/security.xml index 1d07a8d3b9..fcb7c49a37 100644 --- a/pmd-visualforce/src/main/resources/category/vf/security.xml +++ b/pmd-visualforce/src/main/resources/category/vf/security.xml @@ -10,6 +10,7 @@ Rules that flag potential security flaws. diff --git a/pmd-vm/src/main/resources/category/vm/errorprone.xml b/pmd-vm/src/main/resources/category/vm/errorprone.xml index ad2c1b05bd..646d63aa69 100644 --- a/pmd-vm/src/main/resources/category/vm/errorprone.xml +++ b/pmd-vm/src/main/resources/category/vm/errorprone.xml @@ -10,6 +10,7 @@ Rules to detect constructs that are either broken, extremely confusing or prone ${maven.compiler.test.target} - 1.3.0 - 3.1.8 + 1.3.72 + 4.1.2 0.10.1 @@ -279,9 +279,9 @@ - io.kotlintest - kotlintest-runner-junit5 - ${kotlintest.version} + io.kotest + kotest-runner-junit5-jvm + ${kotest.version} @@ -837,22 +837,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