Browse Source

Allow to initialize the data classes with a structure

pull/2/head
Cédric Belin 1 month ago
parent
commit
9f5052ae35
6 changed files with 25 additions and 19 deletions
  1. +2
    -2
      doc/usage.md
  2. +2
    -2
      example/main.hx
  3. +3
    -1
      src/lcov/BranchData.hx
  4. +3
    -1
      src/lcov/FunctionData.hx
  5. +3
    -1
      src/lcov/LineData.hx
  6. +12
    -12
      src/lcov/Report.hx

+ 2
- 2
doc/usage.md View File

@@ -124,8 +124,8 @@ All you have to do is to create the adequate structure using these different cla
class Main {
static function main() {
final lineCoverage = new LineCoverage(2, 2, [
new LineData(6, 2, "PF4Rz2r7RTliO9u6bZ7h6g"),
new LineData(7, 2, "yGMB6FhEEAd8OyASe3Ni1w")
{lineNumber: 6, executionCount: 2, checksum: "PF4Rz2r7RTliO9u6bZ7h6g"},
{lineNumber: 7, executionCount: 2, checksum: "yGMB6FhEEAd8OyASe3Ni1w"}
]);

final record = new Record("/home/cedx/lcov.hx/fixture.hx", {


+ 2
- 2
example/main.hx View File

@@ -8,8 +8,8 @@ class Main {
/** Formats coverage data as LCOV report. **/
public function formatReport() {
final lineCoverage = new LineCoverage(2, 2, [
new LineData(6, 2, "PF4Rz2r7RTliO9u6bZ7h6g"),
new LineData(7, 2, "yGMB6FhEEAd8OyASe3Ni1w")
{lineNumber: 6, executionCount: 2, checksum: "PF4Rz2r7RTliO9u6bZ7h6g"},
{lineNumber: 7, executionCount: 2, checksum: "yGMB6FhEEAd8OyASe3Ni1w"}
]);

final record = new Record("/home/cedx/lcov.hx/fixture.hx", {


+ 3
- 1
src/lcov/BranchData.hx View File

@@ -1,7 +1,9 @@
package lcov;

/** Provides details for branch coverage. **/
@:expose class BranchData {
@:expose
@:structInit
class BranchData {

/** The block number. **/
public var blockNumber: Int;


+ 3
- 1
src/lcov/FunctionData.hx View File

@@ -1,7 +1,9 @@
package lcov;

/** Provides details for function coverage. **/
@:expose class FunctionData {
@:expose
@:structInit
class FunctionData {

/** The execution count. **/
public var executionCount: Int;


+ 3
- 1
src/lcov/LineData.hx View File

@@ -1,7 +1,9 @@
package lcov;

/** Provides details for line coverage. **/
@:expose class LineData {
@:expose
@:structInit
class LineData {

/** The data checksum. **/
public var checksum: String;


+ 12
- 12
src/lcov/Report.hx View File

@@ -47,12 +47,12 @@ using StringTools;

case BranchData:
if (data.length < 4) throw new LcovException("Invalid branch data.", coverage, offset);
record.branches.data.push(new BranchData(
Std.parseInt(data[0]),
Std.parseInt(data[1]),
Std.parseInt(data[2]),
data[3] == "-" ? 0 : Std.parseInt(data[3])
));
record.branches.data.push({
lineNumber: Std.parseInt(data[0]),
blockNumber: Std.parseInt(data[1]),
branchNumber: Std.parseInt(data[2]),
taken: data[3] == "-" ? 0 : Std.parseInt(data[3])
});

case FunctionData:
if (data.length < 2) throw new LcovException("Invalid function data.", coverage, offset);
@@ -63,15 +63,15 @@ using StringTools;

case FunctionName:
if (data.length < 2) throw new LcovException("Invalid function name.", coverage, offset);
record.functions.data.push(new FunctionData(data[1], Std.parseInt(data[0])));
record.functions.data.push({functionName: data[1], lineNumber: Std.parseInt(data[0])});

case LineData:
if (data.length < 2) throw new LcovException("Invalid line data.", coverage, offset);
record.lines.data.push(new LineData(
Std.parseInt(data[0]),
Std.parseInt(data[1]),
data.length >= 3 ? data[2] : ""
));
record.lines.data.push({
lineNumber: Std.parseInt(data[0]),
executionCount: Std.parseInt(data[1]),
checksum: data.length >= 3 ? data[2] : ""
});

case SourceFile: record = new Record(data[0], {
branches: new BranchCoverage(),


Loading…
Cancel
Save