[core] Improve logging for CPD
This commit is contained in:
@ -87,6 +87,12 @@ class CpdCliTest extends BaseCliTest {
|
||||
result.checkStdErr(containsString("[main] INFO net.sourceforge.pmd.cli - Log level is at TRACE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void debugLoggingShouldMentionLanguage() throws Exception {
|
||||
final CliExecutionResult result = runCli(VIOLATIONS_FOUND, "--minimum-tokens", "34", "--dir", SRC_DIR, "--debug");
|
||||
result.checkStdErr(containsString("Created new FileCollector with LanguageVersionDiscoverer(LanguageRegistry(java))"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultLogging() throws Exception {
|
||||
CliExecutionResult result = runCliSuccessfully("--minimum-tokens", "340", "--dir", SRC_DIR);
|
||||
@ -112,6 +118,13 @@ class CpdCliTest extends BaseCliTest {
|
||||
result.checkStdErr(containsString("Usage: pmd cpd"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWrongCliOptionResultsInErrorLogging() throws Exception {
|
||||
// --ignore-identifiers doesn't take an argument anymore - it is interpreted as a file for inputPaths
|
||||
final CliExecutionResult result = runCli(VIOLATIONS_FOUND, "--minimum-tokens", "34", "--dir", SRC_DIR, "--ignore-identifiers", "false");
|
||||
result.checkStdErr(containsString("No such file false"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFindJavaDuplication() throws Exception {
|
||||
runCli(VIOLATIONS_FOUND, "--minimum-tokens", "7", "--dir", SRC_DIR)
|
||||
@ -125,7 +138,7 @@ class CpdCliTest extends BaseCliTest {
|
||||
*/
|
||||
@Test
|
||||
void testIgnoreIdentifiers() throws Exception {
|
||||
runCli(VIOLATIONS_FOUND, "--minimum-tokens", "34", "--dir", SRC_DIR, "--ignore-identifiers")
|
||||
runCli(VIOLATIONS_FOUND, "--minimum-tokens", "34", "--dir", SRC_DIR, "--ignore-identifiers", "false", "--debug")
|
||||
.verify(result -> result.checkStdOut(containsString(
|
||||
"Found a 14 line (89 tokens) duplication"
|
||||
)));
|
||||
|
@ -168,4 +168,11 @@ public class LanguageVersionDiscoverer {
|
||||
public void onlyRecognizeLanguages(LanguageRegistry lang) {
|
||||
this.languageRegistry = Objects.requireNonNull(lang);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LanguageVersionDiscoverer(" + languageRegistry
|
||||
+ (forcedVersion != null ? ",forcedVersion=" + forcedVersion : "")
|
||||
+ ")";
|
||||
}
|
||||
}
|
||||
|
@ -70,6 +70,7 @@ public final class FileCollector implements AutoCloseable {
|
||||
this.discoverer = discoverer;
|
||||
this.reporter = reporter;
|
||||
this.outerFsPath = outerFsPath;
|
||||
LOG.debug("Created new FileCollector with {}", discoverer);
|
||||
}
|
||||
|
||||
public void setRecursive(boolean collectFilesRecursively) {
|
||||
|
Reference in New Issue
Block a user