solution to CLI fails when it could not find output file. solves #1181
This commit is contained in:
parent
de7ba5593d
commit
8a3ccee491
2
pom.xml
2
pom.xml
|
|
@ -644,7 +644,7 @@
|
|||
|
||||
<regex><pattern>.*.DefaultConfiguration</pattern><branchRate>100</branchRate><lineRate>92</lineRate></regex>
|
||||
<regex><pattern>.*.DefaultLogger</pattern><branchRate>75</branchRate><lineRate>76</lineRate></regex>
|
||||
<regex><pattern>.*.Main</pattern><branchRate>65</branchRate><lineRate>78</lineRate></regex>
|
||||
<regex><pattern>.*.Main</pattern><branchRate>80</branchRate><lineRate>90</lineRate></regex>
|
||||
<regex><pattern>.*.PackageNamesLoader</pattern><branchRate>78</branchRate><lineRate>72</lineRate></regex>
|
||||
<regex><pattern>.*.PackageObjectFactory</pattern><branchRate>75</branchRate><lineRate>75</lineRate></regex>
|
||||
<regex><pattern>.*.PropertiesExpander</pattern><branchRate>50</branchRate><lineRate>83</lineRate></regex>
|
||||
|
|
|
|||
|
|
@ -162,8 +162,8 @@ public final class Main {
|
|||
if (cmdLine.hasOption("o")) {
|
||||
final String outputLocation = cmdLine.getOptionValue("o");
|
||||
final File file = new File(outputLocation);
|
||||
if (!file.exists()) {
|
||||
result.add(String.format("Could not find file '%s'.", outputLocation));
|
||||
if (file.exists() && !(file.canRead() && file.canWrite())) {
|
||||
result.add(String.format("Permission denied : '%s'.", outputLocation));
|
||||
}
|
||||
}
|
||||
final List<File> files = getFilesToProcess(cmdLine.getArgs());
|
||||
|
|
|
|||
|
|
@ -249,17 +249,16 @@ public class MainTest {
|
|||
@Test
|
||||
public void testExistingTargetFilePlainOutputToNonExistingFile()
|
||||
throws Exception {
|
||||
exit.expectSystemExitWithStatus(1);
|
||||
exit.expectSystemExitWithStatus(0);
|
||||
exit.checkAssertionAfterwards(new Assertion() {
|
||||
public void checkAssertion() {
|
||||
assertEquals("Could not find file 'myjava.java'." + System.lineSeparator(),
|
||||
standardLog.getLog());
|
||||
assertEquals("", standardLog.getLog());
|
||||
assertEquals("", errorLog.getLog());
|
||||
}
|
||||
});
|
||||
Main.main("-c", "src/test/resources/com/puppycrawl/tools/checkstyle/config-classname.xml",
|
||||
"-f", "plain",
|
||||
"-o", "myjava.java",
|
||||
"-o", temporaryFolder.getRoot() + "/output.txt",
|
||||
"src/test/resources/com/puppycrawl/tools/checkstyle/InputMain.java");
|
||||
}
|
||||
|
||||
|
|
@ -283,6 +282,26 @@ public class MainTest {
|
|||
"src/test/resources/com/puppycrawl/tools/checkstyle/InputMain.java");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExistingTargetFilePlainOutputToFileWithoutRwPermissions()
|
||||
throws Exception {
|
||||
final File file = temporaryFolder.newFile("file.output");
|
||||
file.setReadable(false, false);
|
||||
file.setWritable(false, false);
|
||||
exit.expectSystemExitWithStatus(1);
|
||||
exit.checkAssertionAfterwards(new Assertion() {
|
||||
public void checkAssertion() throws IOException {
|
||||
assertEquals("Permission denied : '" + file.getCanonicalPath() + "'."
|
||||
+ System.lineSeparator(), standardLog.getLog());
|
||||
assertEquals("", errorLog.getLog());
|
||||
}
|
||||
});
|
||||
Main.main("-c", "src/test/resources/com/puppycrawl/tools/checkstyle/config-classname.xml",
|
||||
"-f", "plain",
|
||||
"-o", file.getCanonicalPath(),
|
||||
"src/test/resources/com/puppycrawl/tools/checkstyle/InputMain.java");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExistingTargetFilePlainOutputProperties()
|
||||
throws Exception {
|
||||
|
|
|
|||
Loading…
Reference in New Issue