Skip to content

Commit

Permalink
[core] Fix Kotest based tests (#5022)
Browse files Browse the repository at this point in the history
Merge pull request #5022 from adangel:kotest-fixes
  • Loading branch information
adangel committed May 31, 2024
2 parents f30b535 + 3745193 commit 910c098
Show file tree
Hide file tree
Showing 92 changed files with 1,722 additions and 2,601 deletions.
1 change: 1 addition & 0 deletions docs/pages/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ For the changes, see [PMD Designer Changelog (7.2.0)](https://github.com/pmd/pmd
* [#4467](https://github.com/pmd/pmd/issues/4467): \[core] Expose collections from getters as XPath sequence attributes
* [#4978](https://github.com/pmd/pmd/issues/4978): \[core] Referenced Rulesets do not emit details on validation errors
* [#4983](https://github.com/pmd/pmd/pull/4983): \[cpd] Fix CPD crashes about unicode escapes
* [#5009](https://github.com/pmd/pmd/issues/5009): \[core] Kotest tests aren't picked up by surefire
* java
* [#4912](https://github.com/pmd/pmd/issues/4912): \[java] Unable to parse some Java9+ resource references
* [#4973](https://github.com/pmd/pmd/pull/4973): \[java] Stop parsing Java for CPD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import net.sourceforge.pmd.lang.java.ast.BinaryOp.*

class ASTAdditiveExpressionTest : ParserTestSpec({

parserTest("Simple additive expression should be flat") {

parserTestContainer("Simple additive expression should be flat") {
inContext(ExpressionParsingCtx) {
"1 + 2 + 3" should parseAs {
infixExpr(ADD) {
Expand Down Expand Up @@ -72,7 +71,7 @@ class ASTAdditiveExpressionTest : ParserTestSpec({
}
}

parserTest("Changing operators should push a new node") {
parserTestContainer("Changing operators should push a new node") {
inContext(ExpressionParsingCtx) {
"1 + 2 - 3" should parseAs {
infixExpr(SUB) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,15 @@ import net.sourceforge.pmd.lang.java.ast.JavaVersion.J1_5
*/
class ASTAnnotationTest : ParserTestSpec({


parserTest("Test annot fails before JDK 1.4", javaVersions = Earliest..J1_3) {

parserTestContainer("Test annot fails before JDK 1.4", javaVersions = Earliest..J1_3) {
inContext(AnnotationParsingCtx) {
"@F" shouldNot parse()
"@F(a=1)" shouldNot parse()
}
}

parserTest("Marker annotations", javaVersions = J1_5..Latest) {

parserTestContainer("Marker annotations", javaVersions = J1_5..Latest) {
inContext(AnnotationParsingCtx) {

"@F" should parseAs {
child<ASTAnnotation> {
it::getSimpleName shouldBe "F"
Expand Down Expand Up @@ -66,13 +62,10 @@ class ASTAnnotationTest : ParserTestSpec({
}
}
}

}

parserTest("Single-value shorthand", javaVersions = J1_5..Latest) {

parserTestContainer("Single-value shorthand", javaVersions = J1_5..Latest) {
inContext(AnnotationParsingCtx) {

"@F(\"ohio\")" should parseAs {
child<ASTAnnotation> {
it::getSimpleName shouldBe "F"
Expand Down Expand Up @@ -122,6 +115,7 @@ class ASTAnnotationTest : ParserTestSpec({
}
}
}

"@org.F(@Oh)" should parseAs {
child<ASTAnnotation> {
it::getSimpleName shouldBe "F"
Expand All @@ -136,13 +130,10 @@ class ASTAnnotationTest : ParserTestSpec({
}
}
}

}

parserTest("Normal annotation", javaVersions = J1_5..Latest) {

parserTestContainer("Normal annotation", javaVersions = J1_5..Latest) {
inContext(AnnotationParsingCtx) {

"@F(a=\"ohio\")" should parseAs {
child<ASTAnnotation> {
it::getSimpleName shouldBe "F"
Expand Down Expand Up @@ -179,7 +170,6 @@ class ASTAnnotationTest : ParserTestSpec({
}
}


"""
@TestAnnotation({@SuppressWarnings({}),
@SuppressWarnings(value = {"Beware the ides of March.",}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ import net.sourceforge.pmd.lang.java.ast.ModifierOwner.Visibility.V_ANONYMOUS

class ASTAnonymousClassTest : ParserTestSpec({

parserTest("Anon class modifiers") {

parserTestContainer("Anon class modifiers") {
inContext(StatementParsingCtx) {

"""
new java.lang.Runnable() {
Expand Down Expand Up @@ -56,6 +54,4 @@ class ASTAnonymousClassTest : ParserTestSpec({
}
}
}


})
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,22 @@ import net.sourceforge.pmd.lang.test.ast.shouldBe
*/
class ASTArrayAccessTest : ParserTestSpec({

parserTest("Array access auto disambiguation") {

parserTestContainer("Array access auto disambiguation") {
inContext(ExpressionParsingCtx) {

"a.b[0]" should parseAs {

arrayAccess {
it::getQualifier shouldBe fieldAccess("b") {
it::getQualifier shouldBe ambiguousName("a")
}

it::getIndexExpression shouldBe int(0)
}

}


"b[0]" should parseAs {

arrayAccess {

it::getQualifier shouldBe variableAccess("b")


it::getIndexExpression shouldBe int(0)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ import net.sourceforge.pmd.lang.java.types.JPrimitiveType.PrimitiveTypeKind.INT
*/
class ASTArrayAllocationTest : ParserTestSpec({

parserTest("Array creation") {

parserTestContainer("Array creation") {
inContext(ExpressionParsingCtx) {

"new int[2][]" should parseAs {

arrayAlloc {
it::getTypeNode shouldBe arrayType({ primitiveType(INT) }) {
dimExpr {
Expand All @@ -33,26 +30,23 @@ class ASTArrayAllocationTest : ParserTestSpec({

"new @Foo int[3][2]" should parseAs {
arrayAlloc {

it::getTypeNode shouldBe arrayType({
primitiveType(INT) {
annotation("Foo")
}
}) {
dimExpr {
int(3)
}
dimExpr {
int(2)
it::getTypeNode shouldBe arrayType({
primitiveType(INT) {
annotation("Foo")
}
}) {
dimExpr {
int(3)
}
dimExpr {
int(2)
}
}
}
}
}

}
"new @Foo int @Bar [3][2]" should parseAs {
arrayAlloc {


it::getTypeNode shouldBe arrayType({
primitiveType(INT) {
annotation("Foo")
Expand All @@ -69,7 +63,6 @@ class ASTArrayAllocationTest : ParserTestSpec({
}
}


"(new int[3])[2]" should parseAs {
arrayAccess {
parenthesized {
Expand Down Expand Up @@ -101,9 +94,8 @@ class ASTArrayAllocationTest : ParserTestSpec({
}
}

parserTest("With array initializer") {
parserTestContainer("With array initializer") {
inContext(ExpressionParsingCtx) {

"new Foo[] { f, g }" should parseAs {
arrayAlloc {

Expand Down Expand Up @@ -146,6 +138,7 @@ class ASTArrayAllocationTest : ParserTestSpec({
}
}
}

"new int[][] { { 1 , 2 }, null }" should parseAs {
arrayAlloc {
it::getArrayDepth shouldBe 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ import net.sourceforge.pmd.lang.test.ast.shouldBe
*/
class ASTArrayTypeTest : ParserTestSpec({

parserTest("Multi-Dim Array") {
parserTestContainer("Multi-Dim Array") {
inContext(TypeParsingCtx) {

"ArrayTypes[][][]" should parseAs {

arrayType {

it::getElementType shouldBe classType("ArrayTypes")

it::getDimensions shouldBe dimList {
Expand All @@ -32,11 +29,9 @@ class ASTArrayTypeTest : ParserTestSpec({
}
}

parserTest("Annotated array type") {
parserTestContainer("Annotated array type") {
inContext(TypeParsingCtx) {

"ArrayTypes[][] @A []" should parseAs {

arrayType {
it::getElementType shouldBe classType("ArrayTypes")

Expand All @@ -54,10 +49,9 @@ class ASTArrayTypeTest : ParserTestSpec({
}
}

parserTest("Multi-Dim Array allocation") {
parserTestContainer("Multi-Dim Array allocation") {
inContext(ExpressionParsingCtx) {
"new ArrayTypes[][][] { }" should parseAs {

arrayAlloc {

arrayType({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ import net.sourceforge.pmd.lang.java.ast.AssignmentOp.*
* @since 7.0.0
*/
class ASTAssignmentExpressionTest : ParserTestSpec({

parserTest("Simple assignment expressions") {

parserTestContainer("Simple assignment expressions") {
inContext(ExpressionParsingCtx) {

"a = b -> { foo(b); }" should parseAs {
assignmentExpr(ASSIGN) {
it::isCompound shouldBe false
Expand Down Expand Up @@ -104,8 +101,7 @@ class ASTAssignmentExpressionTest : ParserTestSpec({
}
}

parserTest("Right associativity") {

parserTestContainer("Right associativity") {
inContext(ExpressionParsingCtx) {
"a = b = c" should parseAs {
assignmentExpr(ASSIGN) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import net.sourceforge.pmd.lang.java.ast.BinaryOp.*
Tests for the rest of binary expressions
*/
class ASTBinaryExpressionTest : ParserTestSpec({


parserTest("Conditional and logical operators") {

parserTestContainer("Conditional and logical operators") {
inContext(ExpressionParsingCtx) {
"a && b && a || b" should parseAs {
infixExpr(CONDITIONAL_OR) {
Expand Down Expand Up @@ -57,5 +54,4 @@ class ASTBinaryExpressionTest : ParserTestSpec({
}
}
}

})
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ import net.sourceforge.pmd.lang.java.ast.JavaVersion.Companion.Latest
import net.sourceforge.pmd.lang.java.types.JPrimitiveType.PrimitiveTypeKind.*

class ASTCastExpressionTest : ParserTestSpec({

parserTest("Simple cast") {

parserTestContainer("Simple cast") {
inContext(ExpressionParsingCtx) {

"(Foo) obj" should parseAs {
castExpr {
it::getCastType shouldBe classType("Foo")
Expand All @@ -33,8 +30,7 @@ class ASTCastExpressionTest : ParserTestSpec({
}
}

parserTest("Nested casts") {

parserTestContainer("Nested casts") {
inContext(ExpressionParsingCtx) {
"(Foo) (int) obj" should parseAs {
castExpr {
Expand All @@ -48,8 +44,7 @@ class ASTCastExpressionTest : ParserTestSpec({
}
}

parserTest("Test intersection in cast", javaVersions = JavaVersion.J1_8..Latest) {

parserTestContainer("Test intersection in cast", javaVersions = JavaVersion.J1_8..Latest) {
inContext(ExpressionParsingCtx) {
"(@F Foo & Bar) obj" should parseAs {

Expand All @@ -72,7 +67,6 @@ class ASTCastExpressionTest : ParserTestSpec({
}

"(@F Foo & @B@C Bar) obj" should parseAs {

castExpr {
it::getCastType shouldBe child<ASTIntersectionType> {

Expand All @@ -94,10 +88,8 @@ class ASTCastExpressionTest : ParserTestSpec({
}
}

parserTest("Test intersection ambiguity", javaVersions = Earliest..Latest) {
parserTestContainer("Test intersection ambiguity", javaVersions = Earliest..Latest) {
inContext(ExpressionParsingCtx) {


"(modifiers & InputEvent.Foo) != 0" should parseAs {
infixExpr(BinaryOp.NE) {
parenthesized {
Expand All @@ -113,7 +105,6 @@ class ASTCastExpressionTest : ParserTestSpec({
}
}


"(modifiers) != 0" should parseAs {
infixExpr(BinaryOp.NE) {
parenthesized {
Expand All @@ -124,7 +115,6 @@ class ASTCastExpressionTest : ParserTestSpec({
}
}


"(modifiers) * 0" should parseAs {
infixExpr(BinaryOp.MUL) {
parenthesized {
Expand All @@ -137,8 +127,6 @@ class ASTCastExpressionTest : ParserTestSpec({

}
}


})

val Annotatable.declaredAnnotationsList: List<ASTAnnotation>
Expand Down
Loading

0 comments on commit 910c098

Please sign in to comment.