Skip to content

Commit

Permalink
Merge pull request #213 from HaxeCheckstyle/branch_coverage
Browse files Browse the repository at this point in the history
added branch coverage results
  • Loading branch information
AlexHaxe committed Mar 26, 2016
2 parents 6831db7 + b2983d2 commit 6a3ca57
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion checkstyle.json
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,8 @@
"checkstyle.Main",
"checkstyle.Checker",
"checkstyle.ChecksInfo",
"checkstyle.checks.imports.UnusedImportCheck"
"checkstyle.checks.imports.UnusedImportCheck",
"TestMain"
],
"MultipleStringLiterals": [
"checks",
Expand Down
16 changes: 14 additions & 2 deletions test/TestMain.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import token.TokenTreeBuilderTest;
import mcover.coverage.client.PrintClient;
import mcover.coverage.data.CoverageResult;
import mcover.coverage.data.Statement;
import mcover.coverage.data.Branch;
import mcover.coverage.MCoverage;

using StringTools;
Expand Down Expand Up @@ -36,7 +37,7 @@ class TestMain {
var report = { coverage: {} };
var classes = logger.coverage.getClasses();
for (cls in classes) {
var coverageData = [null];
var coverageData:Array<LineCoverageResult> = [null];
var results:CoverageResult = cls.getResults();
for (i in 1...results.l) coverageData[i] = 1;
var c = cls.name.replace(".", "/") + ".hx";
Expand All @@ -45,6 +46,15 @@ class TestMain {
for (stmt in missingStatements) {
for (line in stmt.lines) coverageData[line] = 0;
}
var missingBranches:Array<Branch> = cls.getMissingBranches();
for (branch in missingBranches) {
if (branch.lines.length <= 0) continue;
var count:Int = 0;
if (branch.trueCount > 0) count++;
if (branch.falseCount > 0) count++;
var line:Int = branch.lines[branch.lines.length - 1];
coverageData[line] = count + "/2";
}

Reflect.setField(report.coverage, c, coverageData);
}
Expand All @@ -57,4 +67,6 @@ class TestMain {
static function main() {
new TestMain();
}
}
}

typedef LineCoverageResult = Dynamic;

0 comments on commit 6a3ca57

Please sign in to comment.