Skip to content

Commit

Permalink
Merge pull request #113 from OpenNingia/cobertura-on-windows-support
Browse files Browse the repository at this point in the history
Fix cobertura parsing on Windows
  • Loading branch information
ryanluker authored Jan 23, 2018
2 parents ad509a1 + 7c02060 commit cbad7d1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/indicators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,16 @@ export class Indicators {
if (err) { return reject(err); }
const section = data.find((lcovSection) => {
// consider windows and linux file paths
const cleanFile = file.replace(/[\\\/]/g, "");
const cleanLcovFileSection = lcovSection.file.replace(/[\\\/]/g, "");
let cleanFile = file.replace(/[\\\/]/g, "");
let cleanLcovFileSection = lcovSection.file.replace(/[\\\/]/g, "");

// on Windows remove drive letter from path because of cobertura format
// also convert both path to lowercase because Windows's filesystem is case insensitive
if ( process.platform === "win32" ) {
cleanFile = cleanFile.substr(2).toLowerCase();
cleanLcovFileSection = cleanLcovFileSection.toLowerCase();
}

return cleanFile.includes(cleanLcovFileSection);
});

Expand Down Expand Up @@ -100,6 +108,7 @@ export class Indicators {

private filterCoverage(section: Section, coverageLines: ICoverageLines): ICoverageLines {
section.lines.details.forEach((detail) => {
if (detail.line < 0) { return ; }
const lineRange = new Range(detail.line - 1, 0, detail.line - 1, 0);
if (detail.hit > 0) {
coverageLines.full.push(lineRange);
Expand All @@ -111,6 +120,7 @@ export class Indicators {
if (section.branches) {
section.branches.details.forEach((detail) => {
if (detail.branch === 0 && detail.taken === 0) {
if (detail.line < 0) { return ; }
const partialRange = new Range(detail.line - 1, 0, detail.line - 1, 0);
if (coverageLines.full.find((range) => range.isEqual(partialRange))) {
// remove full converage if partial is a better match
Expand Down

0 comments on commit cbad7d1

Please sign in to comment.