Fix tests on windows

Bug in toLocation(Range2d)
Use RulePriority.LOW as default in PMDTask, so as not to create IndexOutOfBoundsException every time
This commit is contained in:
Clément Fournier committed 2022-04-23 19:58:33 +02:00
1 parent 2a0ce95a99
commit 246436ac7f
5 files changed
+10 -4

No files matched your search

@@ -15,6 +15,7 @@ import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
import net.sourceforge.pmd.RulePriority;
import net.sourceforge.pmd.ant.internal.PMDTaskImpl;
public class PMDTask extends Task {
@@ -31,7 +32,7 @@ public class PMDTask extends Task {
private boolean noRuleSetCompatibility;
private String encoding;
private int threads = 1; // same default as in PMDParameters (CLI)
private int minimumPriority;
private int minimumPriority = RulePriority.LOW.getPriority(); // inclusive
private int maxRuleViolations = 0;
private String failuresPropertyName;
private SourceLanguage sourceLanguage;
@@ -157,7 +157,7 @@ public interface TextDocument extends Closeable {
* @throws IndexOutOfBoundsException If the argument is not a valid region in this document
*/
default FileLocation toLocation(TextRange2d range) {
int startOffset = offsetAtLineColumn(range.getEndPos());
int startOffset = offsetAtLineColumn(range.getStartPos());
if (startOffset < 0) {
throw new IndexOutOfBoundsException("Region out of bounds: " + range.displayString());
}
@@ -4,6 +4,8 @@
package net.sourceforge.pmd.ant;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.fail;
import java.io.FileInputStream;
@@ -92,7 +94,7 @@ public class PMDTaskTest {
String actual = IOUtils.toString(in, StandardCharsets.UTF_8);
// remove any trailing newline
actual = actual.trim();
Assert.assertEquals("sample.dummy:1:\tSampleXPathRule:\tTest Rule 2", actual);
assertThat(actual, containsString("sample.dummy:1:\tSampleXPathRule:\tTest Rule 2"));
}
}
@@ -4,5 +4,8 @@
<violation beginline="1" endline="2" begincolumn="1" endcolumn="1" rule="SampleXPathRule" ruleset="Test Ruleset" package="foo" externalInfoUrl="${pmd.website.baseurl}/rules/dummy/basic.xml#SampleXPathRule" priority="3">
Test Rule 2
</violation>
<violation beginline="1" endline="2" begincolumn="1" endcolumn="1" rule="DeprecatedRule" ruleset="Test Ruleset" package="foo" externalInfoUrl="${pmd.website.baseurl}/rules/dummy/basic.xml#deprecatedrule" priority="3">
Test Rule 3
</violation>
</file>
</pmd>
@@ -47,7 +47,7 @@ Just for test
<property name="version" value="2.0"/>
<property name="xpath">
<value><![CDATA[
//DummyRootNode
//dummyRootNode
]]></value>
</property>
</properties>