Fix tests
This commit is contained in:
@ -103,7 +103,7 @@ public class PMDConfiguration extends AbstractConfiguration {
|
||||
// Rule and source file options
|
||||
private List<String> ruleSets = new ArrayList<>();
|
||||
private RulePriority minimumPriority = RulePriority.LOW;
|
||||
private List<String> inputPaths;
|
||||
private List<String> inputPaths = new ArrayList<>();
|
||||
private String inputUri;
|
||||
private String inputFilePath;
|
||||
private String ignoreFilePath;
|
||||
|
@ -39,7 +39,7 @@ public class PMDParameters {
|
||||
private String uri;
|
||||
|
||||
@Parameter(names = { "--dir", "-dir", "-d" }, description = "Root directory for sources.", variableArity = true)
|
||||
private List<String> inputPaths;
|
||||
private List<String> inputPaths = new ArrayList<>();
|
||||
|
||||
@Parameter(names = { "--file-list", "-filelist" }, description = "Path to a file containing a list of files to analyze.")
|
||||
private String fileListPath;
|
||||
|
@ -114,13 +114,16 @@ public final class PmdParametersParseResult {
|
||||
|
||||
private static void parseAndValidate(JCommander jcommander, PMDParameters result, String[] args) {
|
||||
jcommander.parse(args);
|
||||
if (result.isHelp() || result.isVersion()) {
|
||||
return;
|
||||
}
|
||||
// jcommander has no special support for global parameter validation like this
|
||||
// For consistency we report this with a ParameterException
|
||||
if (null == result.getSourceDir()
|
||||
if (result.getInputPaths().isEmpty()
|
||||
&& null == result.getUri()
|
||||
&& null == result.getFileListPath()) {
|
||||
throw new ParameterException(
|
||||
"Please provide a parameter for source root directory (-dir or -d), database URI (-uri or -u), or file list path (-filelist).");
|
||||
"Please provide a parameter for source root directory (--dir or -d), database URI (--uri or -u), or file list path (--file-list).");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,6 +36,8 @@ public class BinaryDistributionIT extends AbstractBinaryDistributionTest {
|
||||
}
|
||||
}
|
||||
|
||||
private final String srcDir = new File(".", "src/test/resources/sample-source/java/").getAbsolutePath();
|
||||
|
||||
@Test
|
||||
public void testFileExistence() {
|
||||
assertTrue(getBinaryDistribution().exists());
|
||||
@ -75,27 +77,34 @@ public class BinaryDistributionIT extends AbstractBinaryDistributionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runPMD() throws Exception {
|
||||
String srcDir = new File(".", "src/test/resources/sample-source/java/").getAbsolutePath();
|
||||
public void testPmdJavaQuickstart() throws Exception {
|
||||
ExecutionResult result = PMDExecutor.runPMDRules(folder.newFile().toPath(), tempDir, srcDir, "rulesets/java/quickstart.xml");
|
||||
result.assertExecutionResult(4, "");
|
||||
}
|
||||
|
||||
ExecutionResult result;
|
||||
|
||||
result = PMDExecutor.runPMD(tempDir); // without any argument, display usage help and error
|
||||
result.assertExecutionResultErrOutput(1, CliMessages.runWithHelpFlagMessage());
|
||||
|
||||
result = PMDExecutor.runPMD(tempDir, "-h");
|
||||
result.assertExecutionResult(0, SUPPORTED_LANGUAGES_PMD);
|
||||
|
||||
result = PMDExecutor.runPMDRules(folder.newFile().toPath(), tempDir, srcDir, "src/test/resources/rulesets/sample-ruleset.xml");
|
||||
result.assertExecutionResult(4, "", "JumbledIncrementer.java:8:");
|
||||
|
||||
// also test XML format
|
||||
result = PMDExecutor.runPMDRules(folder.newFile().toPath(), tempDir, srcDir, "src/test/resources/rulesets/sample-ruleset.xml", "xml");
|
||||
@Test
|
||||
public void testPmdXmlFormat() throws Exception {
|
||||
ExecutionResult result = PMDExecutor.runPMDRules(folder.newFile().toPath(), tempDir, srcDir, "src/test/resources/rulesets/sample-ruleset.xml", "xml");
|
||||
result.assertExecutionResult(4, "", "JumbledIncrementer.java\">");
|
||||
result.assertExecutionResult(4, "", "<violation beginline=\"8\" endline=\"10\" begincolumn=\"13\" endcolumn=\"13\" rule=\"JumbledIncrementer\"");
|
||||
}
|
||||
|
||||
result = PMDExecutor.runPMDRules(folder.newFile().toPath(), tempDir, srcDir, "rulesets/java/quickstart.xml");
|
||||
result.assertExecutionResult(4, "");
|
||||
@Test
|
||||
public void testPmdSample() throws Exception {
|
||||
ExecutionResult result = PMDExecutor.runPMDRules(folder.newFile().toPath(), tempDir, srcDir, "src/test/resources/rulesets/sample-ruleset.xml");
|
||||
result.assertExecutionResult(4, "", "JumbledIncrementer.java:8:");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPmdHelp() throws Exception {
|
||||
ExecutionResult result = PMDExecutor.runPMD(tempDir, "-h");
|
||||
result.assertExecutionResult(0, SUPPORTED_LANGUAGES_PMD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPmdNoArgs() throws Exception {
|
||||
ExecutionResult result = PMDExecutor.runPMD(tempDir); // without any argument, display usage help and error
|
||||
result.assertExecutionResultErrOutput(1, CliMessages.runWithHelpFlagMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user