Repository navigation
[scala] chore: Add test for #2153 - #7087
Conversation
9cc104c to
08b2a98
Compare
|
No relevant source code has been changed, pmdtester skipped. (comment created at 2026-09-26 11:46:07+00:00 for 0cd3540) |
|
I backported your test to PMD-6.20.0. I had to do some changes because of the old API. But the only material change I had to make the test pass is the addition of I don't think the test reproduces the failure. /*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.cpd;
import static org.junit.Assert.assertTrue;
import java.io.StringWriter;
import org.junit.Test;
public class ScalaCpdTest {
private static final String CODE = "object Foo {\n"
+ " void foo() {\n"
+ " String[] array = null;\n"
+ " array = {\"abc\", \"def\", \"ghi\"};\n"
+ " }\n"
+ "}\n";
/**
* @see <a href="https://github.com/pmd/pmd/issues/2153">GitHub Issue #2153</a>
*/
@Test
public void smallMinimumTokensRendersXml() throws Exception {
CPDConfiguration configuration = new CPDConfiguration();
configuration.setMinimumTileSize(20);
configuration.setLanguage(new ScalaLanguage());
CPD cpd = new CPD(configuration);
cpd.add(new SourceCode(new SourceCode.StringCodeLoader(CODE, "Foo.scala")));
cpd.add(new SourceCode(new SourceCode.StringCodeLoader(CODE, "Bar.scala")));
cpd.go();
assertTrue(cpd.getMatches().hasNext());
CPDReport report = cpd.toReport();
StringWriter xml = new StringWriter();
new XMLRenderer().render(report, xml);
// the XML serializer writes newlines as the platform line separator
String rendered = xml.toString().replace("\r\n", "\n");
assertTrue(rendered.contains("<codefragment><![CDATA[" + CODE.trim() + "]]></codefragment>"));
}
} |
|
I will later try out writing a test in PMD 6.20, but what I don't understand about your test sample is that Or am I missing something? |
|
No, I must have made a mistake yesterday. The code I posted above only works for 6.48.0 and 6.55.0 Sorry about that. Now I know what my mistake was. I first created the test in 6.55.0. Then I checked out 6.20.0. In that version, pmd-scala-modules doesn't exist, so my test wasn't executed at all. |
|
Here's the new test code, which indeed fails in 6.20.0, with a very similar stacktrace to that in #2153 /*
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.cpd;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class ScalaCpdTest {
private static final String CODE = "object Foo {\n"
+ " void foo() {\n"
+ " String[] array = null;\n"
+ " array = {\"abc\", \"def\", \"ghi\"};\n"
+ " }\n"
+ "}\n";
/**
* @see <a href="https://github.com/pmd/pmd/issues/2153">GitHub Issue #2153</a>
*/
@Test
public void smallMinimumTokensRendersXml() throws Exception {
CPDConfiguration configuration = new CPDConfiguration();
configuration.setMinimumTileSize(20);
configuration.setLanguage(new ScalaLanguage());
CPD cpd = new CPD(configuration);
cpd.add(new SourceCode(new SourceCode.StringCodeLoader(CODE, "Foo.scala")));
cpd.add(new SourceCode(new SourceCode.StringCodeLoader(CODE, "Bar.scala")));
cpd.go();
assertTrue(cpd.getMatches().hasNext());
String rendered = new XMLRenderer().render(cpd.getMatches()).replace("\r\n", "\n");
assertTrue(rendered.contains("<codefragment><![CDATA[" + CODE.trim() + "]]></codefragment>"));
}
} |
|
The test fails in 6.24.0, but succeeds in 6.25.0 (when moved to pmd-scala-modules/pmd-scala-common/src/test/java/net/sourceforge/pmd/cpd) |
|
Yes, it seems like the issue was actually fixed in 3df4506365 Sorry for the wrong attribution, I just speculated that the issue was resolved by the rewrite of CPD in PMD 7. |
08b2a98 to
b17ea8f
Compare
Describe the PR
The CPD failure in #2153 has already been fixed with PMD 6.25 (in 3df4506365).
This PR adds a regression test to close this issue.
Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)