Add unit test for inputfilepath parameter
This commit is contained in:
@ -431,11 +431,9 @@ public class PMD {
|
||||
} else {
|
||||
String filePaths = FileUtils.readFileToString(new File(inputFilePath));
|
||||
filePaths = StringUtils.trimToEmpty(filePaths);
|
||||
filePaths = filePaths.replaceAll("\\r?\\n", ",");
|
||||
filePaths = filePaths.replaceAll(",+", ",");
|
||||
|
||||
if (null == filePaths){
|
||||
LOG.log(Level.SEVERE, "Problem with Input File Path", inputFilePath);
|
||||
throw new RuntimeException("Problem with Input File Path: " + inputFilePath);
|
||||
}
|
||||
files.addAll(FileUtil.collectFiles(filePaths, fileSelector));
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
|
@ -314,6 +314,12 @@ public class PMDConfiguration extends AbstractConfiguration {
|
||||
return inputFilePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* The input file path points to a single file, which contains a
|
||||
* comma-separated list of source file names to process.
|
||||
*
|
||||
* @param inputFilePath path to the file
|
||||
*/
|
||||
public void setInputFilePath(String inputFilePath) {
|
||||
this.inputFilePath = inputFilePath;
|
||||
}
|
||||
|
50
pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDTest.java
Normal file
50
pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDTest.java
Normal file
@ -0,0 +1,50 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.cli;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.PMD;
|
||||
import net.sourceforge.pmd.PMDConfiguration;
|
||||
import net.sourceforge.pmd.lang.DummyLanguageModule;
|
||||
import net.sourceforge.pmd.lang.Language;
|
||||
import net.sourceforge.pmd.util.datasource.DataSource;
|
||||
|
||||
public class PMDTest {
|
||||
@Test
|
||||
public void testGetApplicableFiles() {
|
||||
Set<Language> languages = new HashSet<>();
|
||||
languages.add(new DummyLanguageModule());
|
||||
|
||||
PMDConfiguration configuration = new PMDConfiguration();
|
||||
configuration.setInputFilePath("src/test/resources/net/sourceforge/pmd/cli/filelist.txt");
|
||||
|
||||
List<DataSource> applicableFiles = PMD.getApplicableFiles(configuration, languages);
|
||||
Assert.assertEquals(2, applicableFiles.size());
|
||||
Assert.assertTrue(applicableFiles.get(0).getNiceFileName(false, "").endsWith("somefile.dummy"));
|
||||
Assert.assertTrue(applicableFiles.get(1).getNiceFileName(false, "").endsWith("anotherfile.dummy"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetApplicableFilesMultipleLines() {
|
||||
Set<Language> languages = new HashSet<>();
|
||||
languages.add(new DummyLanguageModule());
|
||||
|
||||
PMDConfiguration configuration = new PMDConfiguration();
|
||||
configuration.setInputFilePath("src/test/resources/net/sourceforge/pmd/cli/filelist2.txt");
|
||||
|
||||
List<DataSource> applicableFiles = PMD.getApplicableFiles(configuration, languages);
|
||||
Assert.assertEquals(3, applicableFiles.size());
|
||||
Assert.assertTrue(applicableFiles.get(0).getNiceFileName(false, "").endsWith("somefile.dummy"));
|
||||
Assert.assertTrue(applicableFiles.get(1).getNiceFileName(false, "").endsWith("anotherfile.dummy"));
|
||||
Assert.assertTrue(applicableFiles.get(2).getNiceFileName(false, "").endsWith("somefile.dummy"));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1 @@
|
||||
src/test/resources/net/sourceforge/pmd/cli/src/somefile.dummy,src/test/resources/net/sourceforge/pmd/cli/src/anotherfile.dummy
|
@ -0,0 +1,3 @@
|
||||
src/test/resources/net/sourceforge/pmd/cli/src/somefile.dummy,
|
||||
src/test/resources/net/sourceforge/pmd/cli/src/anotherfile.dummy
|
||||
src/test/resources/net/sourceforge/pmd/cli/src/somefile.dummy
|
@ -0,0 +1 @@
|
||||
Another file for testing
|
@ -0,0 +1 @@
|
||||
Some file for testing
|
Reference in New Issue
Block a user