Add impl to parse focused attr
This commit is contained in:
@@ -100,6 +100,13 @@ class BaseTestParserImpl {
|
||||
|
||||
descriptor.setDisabled(disabled);
|
||||
|
||||
|
||||
boolean focused = parseBoolAttribute(testCode, "focused", false, err,
|
||||
"Attribute focused is used, do not forget to remove it when checking in sources");
|
||||
|
||||
descriptor.setFocused(focused);
|
||||
|
||||
|
||||
Properties properties = parseRuleProperties(testCode, descriptor.getRule(), err);
|
||||
descriptor.getProperties().putAll(properties);
|
||||
|
||||
|
@@ -28,4 +28,17 @@ public class RuleTestCollection {
|
||||
return Collections.unmodifiableList(tests);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last test of the collection which is focused.
|
||||
*/
|
||||
public RuleTestDescriptor getFocusedTestOrNull() {
|
||||
RuleTestDescriptor focused = null;
|
||||
for (RuleTestDescriptor test : tests) {
|
||||
if (test.isFocused()) {
|
||||
focused = test;
|
||||
}
|
||||
}
|
||||
return focused;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@ import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
public class RuleTestDescriptor {
|
||||
|
||||
private boolean disabled;
|
||||
private boolean focused;
|
||||
private String description;
|
||||
private LanguageVersion languageVersion;
|
||||
private final Properties properties = new Properties();
|
||||
@@ -106,4 +107,12 @@ public class RuleTestDescriptor {
|
||||
public List<String> getExpectedMessages() {
|
||||
return expectedMessages;
|
||||
}
|
||||
|
||||
public boolean isFocused() {
|
||||
return focused;
|
||||
}
|
||||
|
||||
public void setFocused(boolean focused) {
|
||||
this.focused = focused;
|
||||
}
|
||||
}
|
||||
|
@@ -5,9 +5,7 @@
|
||||
package net.sourceforge.pmd.testframework;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@@ -26,6 +24,8 @@ import org.junit.runners.model.InitializationError;
|
||||
import org.junit.runners.model.Statement;
|
||||
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.test.schema.RuleTestCollection;
|
||||
import net.sourceforge.pmd.test.schema.RuleTestDescriptor;
|
||||
|
||||
/**
|
||||
* A JUnit Runner, that executes all declared rule tests in the class.
|
||||
@@ -64,18 +64,18 @@ public class RuleTestRunner extends ParentRunner<TestDescriptor> {
|
||||
@Override
|
||||
protected List<TestDescriptor> getChildren() {
|
||||
List<Rule> rules = new ArrayList<>(instance.getRules());
|
||||
Collections.sort(rules, new Comparator<Rule>() {
|
||||
@Override
|
||||
public int compare(Rule o1, Rule o2) {
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
}
|
||||
});
|
||||
rules.sort(Comparator.comparing(Rule::getName));
|
||||
|
||||
List<TestDescriptor> tests = new LinkedList<>();
|
||||
List<TestDescriptor> tests = new ArrayList<>();
|
||||
for (Rule r : rules) {
|
||||
TestDescriptor[] ruleTests = instance.extractTestsFromXml(r);
|
||||
for (TestDescriptor t : ruleTests) {
|
||||
tests.add(t);
|
||||
RuleTestCollection ruleTests = instance.parseTestCollection(r);
|
||||
RuleTestDescriptor focused = ruleTests.getFocusedTestOrNull();
|
||||
for (RuleTestDescriptor t : ruleTests.getTests()) {
|
||||
TestDescriptor td = new TestDescriptor(t);
|
||||
if (focused != null && focused != t) {
|
||||
td.setRegressionTest(false); // disable it
|
||||
}
|
||||
tests.add(td);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -290,6 +290,16 @@ public abstract class RuleTst {
|
||||
return extractTestsFromXml(rule, testsFileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract a set of tests from an XML file. The file should be
|
||||
* ./xml/RuleName.xml relative to the test class. The format is defined in
|
||||
* test-data.xsd.
|
||||
*/
|
||||
RuleTestCollection parseTestCollection(Rule rule) {
|
||||
String testsFileName = getCleanRuleName(rule);
|
||||
return parseTestXml(rule, testsFileName, "xml/");
|
||||
}
|
||||
|
||||
public TestDescriptor[] extractTestsFromXml(Rule rule, String testsFileName) {
|
||||
return extractTestsFromXml(rule, testsFileName, "xml/");
|
||||
}
|
||||
|
@@ -32,6 +32,7 @@ public class TestDescriptor {
|
||||
private boolean isRegressionTest = true;
|
||||
private boolean useAuxClasspath = true;
|
||||
private int numberInDocument = -1;
|
||||
private boolean isFocused = false;
|
||||
|
||||
public TestDescriptor() {
|
||||
// Empty default descriptor added to please mvn surefire plugin
|
||||
@@ -62,6 +63,7 @@ public class TestDescriptor {
|
||||
this.numberInDocument = td.getIndex();
|
||||
this.properties = td.getProperties();
|
||||
this.languageVersion = td.getLanguageVersion();
|
||||
this.isFocused = td.isFocused();
|
||||
}
|
||||
|
||||
public int getNumberInDocument() {
|
||||
|
Reference in New Issue
Block a user