More restrictive check for violation location in tests#6559
Conversation
eb6eb0e to
505ef4f
Compare
505ef4f to
79e8fd2
Compare
|
Compared to main: (comment created at 2026-03-31 06:54:35+00:00 for 79e8fd2) |
|
While finishing up #6084, I have now an idea what we need. According to https://docs.pmd-code.org/latest/pmd_userdocs_extending_testing.html#test-xml-reference a test case looks currently like this: <test-code>
<description>Verify location of violation</description>
<expected-problems>1</expected-problems>
<expected-linenumbers>2-2</expected-linenumbers>
<code><![CDATA[
public class
Foo // <--violation: line 2
{}
]]></code>
</test-code>What about this way? <test-code>
<description>Verify location of violation</description>
<expected-violations>
<violation loc="1:14-1:17">optional message</violation>
</expected-violations>
<code><![CDATA[
public class Foo {}
]]></code>
</test-code>@zbynek WDYT? |
|
@adangel I'm not sure the columns are needed -- for rules where multiple violations may realistically happen on the same line, it would make sense to include the violating token in the message. But having an option to use columns may be useful. Also an idea that PMD could borrow from Checkstyle is using comment markers to indicate expected violations. For backward compatibility this could be something like <test-code>
<description>Verify location of violation</description>
<expected-problem-marker>pmd-violation</expected-problem-marker>
<code><![CDATA[
public class
Foo // pmd-violation: there is a reason for this error
{}
]]></code>
</test-code>(since PMD supports very different languages, the marker cannot be always part of |
Describe the PR
Related to #6084, this changes the interpretation of
expected-linenumbersin tests to be more restrictive, making it easier to check that the location is specific enoughRelated issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)