Fixes #1481 no problems found results in blank file instead of empty xml

This commit is contained in:
Andreas Dangel
2016-05-28 11:27:22 +02:00
parent 0d20fe7e1c
commit 13f7675b67
3 changed files with 36 additions and 1 deletions

View File

@ -86,8 +86,8 @@ public class CPDCommandLineInterface {
}
cpd.go();
System.out.println(arguments.getRenderer().render(cpd.getMatches()));
if (cpd.getMatches().hasNext()) {
System.out.println(arguments.getRenderer().render(cpd.getMatches()));
setStatusCodeOrExit(DUPLICATE_CODE_FOUND);
}
}

View File

@ -0,0 +1,33 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.cpd;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.LogMode;
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
import org.junit.contrib.java.lang.system.StandardOutputStreamLog;
import org.junit.rules.TestRule;
public class CPDCommandLineInterfaceTest {
@Rule
public final TestRule restoreSystemProperties = new RestoreSystemProperties();
@Rule
public final StandardOutputStreamLog log = new StandardOutputStreamLog(LogMode.LOG_ONLY);
@Test
public void testEmptyResultRendering() {
System.setProperty(CPDCommandLineInterface.NO_EXIT_AFTER_RUN, "true");
CPDCommandLineInterface.main(new String[] {
"--minimum-tokens", "340",
"--language", "java",
"--files", "src/test/resources/net/sourceforge/pmd/cpd/files/",
"--format", "xml"
});
Assert.assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<pmd-cpd/>\n", log.getLog());
}
}

View File

@ -16,6 +16,8 @@
* java-unusedcode/UnusedLocalVariable
* [#1484](https://sourceforge.net/p/pmd/bugs/1484/): UnusedLocalVariable - false positive - parenthesis
* General
* [#1481](https://sourceforge.net/p/pmd/bugs/1481/): no problems found results in blank file instead of empty xml
**API Changes:**