Skip to content

Commit

Permalink
cflint#323 - number 4 in the ticket and an initial set of accompanyin…
Browse files Browse the repository at this point in the history
…g tests
  • Loading branch information
TheRealAgentK committed Jul 2, 2017
1 parent 6250929 commit 8f0fa3d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/cflint/JSONOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -74,6 +75,15 @@ public void output(final BugList bugList, final Writer writer, CFLintStats stats
}
}

jg.writeStartObject();
jg.writeNumberField("totalfiles", stats.getFileCount());
jg.writeEndObject();

jg.writeStartObject();
jg.writeFieldName("totalsize");
jg.writeNumber(stats.getTotalSize());
jg.writeEndObject();

for (final String code : counts.bugTypes()) {
jg.writeStartObject();
jg.writeStringField("code", code);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/cflint/TextOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public void output(final BugList bugList, final Writer sb, CFLintStats stats) th
}
}

sb.append(newLine).append(newLine).append("Total files:" + stats.getFileCount());
sb.append(newLine).append("Total size " + stats.getTotalSize());

sb.append(newLine).append(newLine).append("Issue counts:" + counts.noBugTypes());

for (final String code : counts.bugTypes()) {
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/cflint/TestJSONOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void testOutput() throws IOException {
bugList.add(bugInfo);
CFLintStats stats = new CFLintStats(123456L,1,new BigInteger("545454"));
outputer.output(bugList, writer, stats);
String expectedText = "[{\"severity\":\"\",\"id\":\"PARSE_ERROR\",\"message\":\"PARSE_ERROR\",\"category\":\"CFLINT\",\"abbrev\":\"PE\",\"locations\":[{\"file\":\"c:\\\\temp\\\\test.cfc\",\"fileName\":\"test.cfc\",\"function\":\"testf\",\"column\":1,\"line\":1,\"message\":\"\",\"variable\":\"\",\"expression\":\"\"}]}]";
String expectedText = "[{\"severity\":\"\",\"id\":\"PARSE_ERROR\",\"message\":\"PARSE_ERROR\",\"category\":\"CFLINT\",\"abbrev\":\"PE\",\"locations\":[{\"file\":\"c:\\\\temp\\\\test.cfc\",\"fileName\":\"test.cfc\",\"function\":\"testf\",\"column\":1,\"line\":1,\"message\":\"\",\"variable\":\"\",\"expression\":\"\"}]},{\"totalfiles\":1},{\"totalsize\":545454}]";
// assertEquals(JSONValue.parse(expectedText),JSONValue.parse(writer.toString()));
assertEquals(expectedText,writer.toString());
}
Expand All @@ -43,7 +43,7 @@ public void testStats() throws IOException {
counts.add("PARSE_ERROR", null);
CFLintStats stats = new CFLintStats(123456L,1,new BigInteger("545454"),counts);
outputer.output(bugList, writer, stats);
String expectedText = "[{\"severity\":\"\",\"id\":\"PARSE_ERROR\",\"message\":\"PARSE_ERROR\",\"category\":\"CFLINT\",\"abbrev\":\"PE\",\"locations\":[{\"file\":\"c:\\\\temp\\\\test.cfc\",\"fileName\":\"test.cfc\",\"function\":\"testf\",\"column\":1,\"line\":1,\"message\":\"\",\"variable\":\"\",\"expression\":\"\"}]},{\"code\":\"PARSE_ERROR\",\"count\":1}]";
String expectedText = "[{\"severity\":\"\",\"id\":\"PARSE_ERROR\",\"message\":\"PARSE_ERROR\",\"category\":\"CFLINT\",\"abbrev\":\"PE\",\"locations\":[{\"file\":\"c:\\\\temp\\\\test.cfc\",\"fileName\":\"test.cfc\",\"function\":\"testf\",\"column\":1,\"line\":1,\"message\":\"\",\"variable\":\"\",\"expression\":\"\"}]},{\"totalfiles\":1},{\"totalsize\":545454},{\"code\":\"PARSE_ERROR\",\"count\":1}]";
assertEquals(expectedText,writer.toString());
}

Expand All @@ -55,7 +55,7 @@ public void testStatsWithSeverity() throws IOException {
counts.add("PARSE_ERROR", "ERROR");
CFLintStats stats = new CFLintStats(123456L,1,new BigInteger("545454"),counts);
outputer.output(bugList, writer, stats);
String expectedText = "[{\"severity\":\"ERROR\",\"id\":\"PARSE_ERROR\",\"message\":\"PARSE_ERROR\",\"category\":\"CFLINT\",\"abbrev\":\"PE\",\"locations\":[{\"file\":\"c:\\\\temp\\\\test.cfc\",\"fileName\":\"test.cfc\",\"function\":\"testf\",\"column\":1,\"line\":1,\"message\":\"\",\"variable\":\"\",\"expression\":\"\"}]},{\"code\":\"PARSE_ERROR\",\"count\":1},{\"severity\":\"ERROR\",\"count\":1}]";
String expectedText = "[{\"severity\":\"ERROR\",\"id\":\"PARSE_ERROR\",\"message\":\"PARSE_ERROR\",\"category\":\"CFLINT\",\"abbrev\":\"PE\",\"locations\":[{\"file\":\"c:\\\\temp\\\\test.cfc\",\"fileName\":\"test.cfc\",\"function\":\"testf\",\"column\":1,\"line\":1,\"message\":\"\",\"variable\":\"\",\"expression\":\"\"}]},{\"totalfiles\":1},{\"totalsize\":545454},{\"code\":\"PARSE_ERROR\",\"count\":1},{\"severity\":\"ERROR\",\"count\":1}]";
assertEquals(expectedText,writer.toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
"variable" : "getStringFromStruct",
"expression" : "public string function getStringFromStruct(interestingVar) {\n return interestingVar;\n\n }"
} ]
}, {
"totalfiles" : 3
}, {
"totalsize" : 18
}, {
"code" : "FUNCTION_HINT_MISSING",
"count" : 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
"variable" : "",
"expression" : "component {\n public string function getStringFromStruct(interestingVar) {\n return interestingVar;\n\n }\n}"
} ]
}, {
"totalfiles" : 3
}, {
"totalsize" : 18
}, {
"code" : "COMPONENT_INVALID_NAME",
"count" : 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
"variable" : "",
"expression" : "component {\n public string function getStringFromStruct(interestingVar) {\n return interestingVar;\n\n }\n}"
} ]
}, {
"totalfiles" : 3
}, {
"totalsize" : 18
}, {
"code" : "COMPONENT_INVALID_NAME",
"count" : 1
Expand Down

0 comments on commit 8f0fa3d

Please sign in to comment.