Merge branch 'master' into pmd/7.0.x

This commit is contained in:
Andreas Dangel
2020-07-30 11:51:53 +02:00
50 changed files with 359 additions and 117 deletions

View File

@@ -105,13 +105,14 @@
of the pmd-lang-test module
-->
<dependency>
<groupId>io.kotlintest</groupId>
<artifactId>kotlintest-assertions</artifactId>
<groupId>io.kotest</groupId>
<artifactId>kotest-assertions-core-jvm</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<!-- Contains stuff like FunSpec, etc -->
<groupId>io.kotest</groupId>
<artifactId>kotest-runner-junit5-jvm</artifactId>
<scope>compile</scope>
</dependency>

View File

@@ -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

View File

@@ -28,7 +28,7 @@ typealias ValuedNodeSpec<I, O> = TreeNodeWrapper<Node, I>.() -> O
/** A subtree matcher written in the DSL documented on [TreeNodeWrapper]. */
typealias NodeSpec<N> = ValuedNodeSpec<N, 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> = (M) -> Unit
fun <N : Node> ValuedNodeSpec<N, *>.ignoreResult(): NodeSpec<N> {
@@ -50,7 +50,7 @@ inline fun <reified N : Node> 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<ASTExpression> {}`.
* Use it with [io.kotest.matchers.should], e.g. `node should matchNode<ASTExpression> {}`.
*
* See also the samples on [TreeNodeWrapper].
*
@@ -63,7 +63,7 @@ inline fun <reified N : Node> 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 <reified N : Node> matchNode(ignoreChildren: Boolean = false, noinline nodeSpec: ValuedNodeSpec<N, *>)
: Assertions<Node?> = { it.shouldMatchNode(ignoreChildren, nodeSpec) }

View File

@@ -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 <N, V> assertWrapper(callable: KCallable<N>, 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 <N, V : N> KCallable<N>.shouldBe(expected: V?) = this.shouldEqual(expected)