forked from phoedos/pmd
Add --use-version tests
This commit is contained in:
@ -16,22 +16,40 @@ import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import net.sourceforge.pmd.PMDConfiguration;
|
||||
import net.sourceforge.pmd.lang.DummyLanguageModule;
|
||||
import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
|
||||
import picocli.CommandLine;
|
||||
import picocli.CommandLine.ParseResult;
|
||||
|
||||
class PmdCommandTest {
|
||||
|
||||
// @Test
|
||||
// void testVersion() throws Exception {
|
||||
// PMDParameters parameters = new PMDParameters();
|
||||
// // no language set, uses default language
|
||||
// assertEquals("1.7", parameters.getVersion());
|
||||
//
|
||||
// // now set language
|
||||
// FieldUtils.writeDeclaredField(parameters, "language", "dummy2", true);
|
||||
// assertEquals("1.0", parameters.getVersion());
|
||||
// }
|
||||
@Test
|
||||
void testVersionDefault() throws Exception {
|
||||
final PmdCommand cmd = setupAndParse("--use-version", "dummy", "-d", "a", "-R", "x.xml");
|
||||
final LanguageVersion dummyLatest = cmd.toConfiguration().getLanguageVersionOfFile("foo.dummy");
|
||||
|
||||
// LanguageVersion do not implement equals, but we can check their string representations
|
||||
assertEquals(DummyLanguageModule.getInstance().getDefaultVersion().toString(), dummyLatest.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testVersionLatest() throws Exception {
|
||||
final PmdCommand cmd = setupAndParse("--use-version", "dummy-latest", "-d", "a", "-R", "x.xml");
|
||||
final LanguageVersion dummyLatest = cmd.toConfiguration().getLanguageVersionOfFile("foo.dummy");
|
||||
|
||||
// LanguageVersion do not implement equals, but we can check their string representations
|
||||
assertEquals(DummyLanguageModule.getInstance().getDefaultVersion().toString(), dummyLatest.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testVersionGiven() throws Exception {
|
||||
final PmdCommand cmd = setupAndParse("--use-version", "dummy-1.2", "-d", "a", "-R", "x.xml");
|
||||
final LanguageVersion dummyLatest = cmd.toConfiguration().getLanguageVersionOfFile("foo.dummy");
|
||||
|
||||
// LanguageVersion do not implement equals, but we can check their string representations
|
||||
assertEquals(DummyLanguageModule.getInstance().getVersion("1.2").toString(), dummyLatest.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMultipleDirsAndRuleSets() {
|
||||
@ -98,18 +116,21 @@ class PmdCommandTest {
|
||||
}
|
||||
|
||||
private ParseResult parseCommand(final Object cmd, final String... params) {
|
||||
// Always run against dummy language
|
||||
final List<String> argList = new ArrayList<>();
|
||||
argList.add("--use-version");
|
||||
argList.add("dummy");
|
||||
|
||||
// If no language provided, set dummy latest
|
||||
if (!Arrays.stream(params).anyMatch(s -> s.equals("--use-version"))) {
|
||||
argList.add("--use-version");
|
||||
argList.add("dummy");
|
||||
}
|
||||
argList.addAll(Arrays.asList(params));
|
||||
|
||||
final CommandLine commandLine = new CommandLine(cmd)
|
||||
final CommandLine commandLine = new CommandLine(cmd)
|
||||
.setCaseInsensitiveEnumValuesAllowed(true);
|
||||
|
||||
// Collect errors instead of simply throwing during parsing
|
||||
commandLine.getCommandSpec().parser().collectErrors(true);
|
||||
|
||||
return commandLine.parseArgs(argList.toArray(new String[0]));
|
||||
|
||||
// Collect errors instead of simply throwing during parsing
|
||||
commandLine.getCommandSpec().parser().collectErrors(true);
|
||||
|
||||
return commandLine.parseArgs(argList.toArray(new String[0]));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user