forked from phoedos/pmd
Better error messages
This commit is contained in:
@ -138,10 +138,20 @@ class NWrapper<N : Node> private constructor(val it: N,
|
||||
childType.isInstance(toWrap)
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val wrapper = NWrapper(toWrap as M, matcherPath + childType, ignoreChildrenMatchers)
|
||||
val childPath = matcherPath + childType
|
||||
|
||||
wrapper.spec()
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val wrapper = NWrapper(toWrap as M, childPath, ignoreChildrenMatchers)
|
||||
|
||||
try {
|
||||
wrapper.spec()
|
||||
} catch (e: AssertionError) {
|
||||
if (e.message?.matches("At (/.*?|<root>):.*".toRegex()) == false) {
|
||||
// the exception has no path, let's add one
|
||||
throw AssertionError(formatErrorMessage(childPath, e.message ?: "No explanation provided"), e)
|
||||
}
|
||||
throw e
|
||||
}
|
||||
|
||||
assertFalse(formatErrorMessage(matcherPath + childType, "Wrong number of children, expected ${wrapper.nextChildMatcherIdx}, actual ${wrapper.it.numChildren}")) {
|
||||
!ignoreChildrenMatchers && wrapper.nextChildMatcherIdx != wrapper.it.numChildren
|
||||
|
@ -90,6 +90,37 @@ class DslTest : FunSpec({
|
||||
}
|
||||
}
|
||||
|
||||
failureTest("All assertions should have a node path",
|
||||
messageContains = setOf("At /LocalVariableDeclaration/Type:", "expected: \"bratwurst\"")) {
|
||||
|
||||
parseStatement("int[] i = 0;") should matchNode<ASTLocalVariableDeclaration> {
|
||||
|
||||
child<ASTType> {
|
||||
|
||||
// this fails
|
||||
it.typeImage shouldBe "bratwurst"
|
||||
|
||||
}
|
||||
|
||||
unspecifiedChild()
|
||||
}
|
||||
}
|
||||
|
||||
failureTest("Child assertions should have a node path",
|
||||
messageContains = setOf("At /LocalVariableDeclaration/Type:", "expected", "type", "LambdaExpression")) {
|
||||
|
||||
parseStatement("int[] i = 0;") should matchNode<ASTLocalVariableDeclaration> {
|
||||
|
||||
child<ASTType> {
|
||||
|
||||
// this fails
|
||||
child<ASTLambdaExpression> { }
|
||||
}
|
||||
|
||||
unspecifiedChild()
|
||||
}
|
||||
}
|
||||
|
||||
failureTest("Leaf nodes should assert that they have no children",
|
||||
messageContains = setOf("number", "children", "expected 0")) {
|
||||
|
||||
|
Reference in New Issue
Block a user