public double convertLstFiles(
    string packagePath, 
    string packageName)

Converts coverage lst files to html

public getCoverageSummary(string fileContent)

Get the line that contains the coverage summary

Example

It should get the coverage summary from the .lst file with no coverage

"
     |  double threadUsage(uint index);
     |}
core/cloud/source/cloud/system.d has no code
".getCoverageSummary.front.should.equal("core/cloud/source/cloud/system.d has no code");

Example

It should get the coverage summary from the .lst file with missing data

"

".getCoverageSummary.empty.should.equal(true);

Example

It should get the coverage summary from the .lst file with percentage

"
    2|  statusList[0].properties[\"thread1\"].value.should.startWith(\"1;\");
     |}
core/cloud/source/cloud/system.d is 88% covered
".getCoverageSummary.front.should.equal("core/cloud/source/cloud/system.d is 88% covered");

public string getFileName(string fileContent)

Get the filename from the coverage summary

Example

It should get the filename from the .lst file with no coverage

"
     |  double threadUsage(uint index);
     |}
core/cloud/source/cloud/system.d has no code
".getFileName.should.equal("core/cloud/source/cloud/system.d");

Example

It should get the filename from the .lst file with no code

"


".getFileName.should.equal("");

Example

It should get the filename from the .lst file with percentage

"
    2|  statusList[0].properties[\"thread1\"].value.should.startWith(\"1;\");
     |}
core/cloud/source/cloud/system.d is 88% covered
".getFileName.should.equal("core/cloud/source/cloud/system.d");

public double getCoveragePercent(string fileContent)

Get the percentage from the covered summary

Example

It should get the filename from the .lst file with no coverage

"
     |  double threadUsage(uint index);
     |}
core/cloud/source/cloud/system.d has no code
".getCoveragePercent.should.equal(100);

Example

It should get the filename from the .lst file with no code

"


".getCoveragePercent.should.equal(100);

Example

It should get the filename from the .lst file with percentage

"
    2|  statusList[0].properties[\"thread1\"].value.should.startWith(\"1;\");
     |}
core/cloud/source/cloud/system.d is 88% covered
".getCoveragePercent.should.equal(88);

public toCoverageLines(string fileContent)

Parse the file lines

Example

It should convert a .lst file to covered line structs

  auto lines =
 "      |
       |import std.stdio;
     75|  this(File f) {
       |  }
core/cloud/source/cloud/system.d is 88% covered
".toCoverageLines.array;

  lines.length.should.equal(4);

  lines[0].code.should.equal("");
  lines[0].hits.should.equal(0);
  lines[0].hasCode.should.equal(false);

  lines[1].code.should.equal("import std.stdio;");
  lines[1].hits.should.equal(0);
  lines[1].hasCode.should.equal(false);

  lines[2].code.should.equal("  this(File f) {");
  lines[2].hits.should.equal(75);
  lines[2].hasCode.should.equal(true);

  lines[3].code.should.equal("  }");
  lines[3].hits.should.equal(0);
  lines[3].hasCode.should.equal(false);

public bool isIgnored(const string content)

Check if a file should be ignored from the report

Example

It should return true for ignored coverage files

"// IGNORE COVERAGE".isIgnored.should.equal(true);
"// \t IGNORE \t COVERAGE".isIgnored.should.equal(true);
"// ignore coverage".isIgnored.should.equal(true);
"//IGNORE COVERAGE".isIgnored.should.equal(true);
"/////IGNORE COVERAGE".isIgnored.should.equal(true);
"//     IGNORE     COVERAGE     ".isIgnored.should.equal(true);
"/*     IGNORE     COVERAGE     */".isIgnored.should.equal(true);
"/*****     IGNORE     COVERAGE  ".isIgnored.should.equal(true);
"/*****     IGNORE     COVERAGE     ****/".isIgnored.should.equal(true);
"/+     IGNORE     COVERAGE     +/".isIgnored.should.equal(true);
"/+++++     IGNORE     COVERAGE  ".isIgnored.should.equal(true);
"/+++++     IGNORE     COVERAGE     +++++/".isIgnored.should.equal(true);

Example

It should return false for when the ignore coverage file is missing

"".isIgnored.should.equal(false);
"//\nIGNORE COVERAGE".isIgnored.should.equal(false);
"//\nIGNORE COVERAGE".isIgnored.should.equal(false);
"/////\nIGNORE COVERAGE".isIgnored.should.equal(false);
"//\n     IGNORE     COVERAGE     ".isIgnored.should.equal(false);
"/*\n     IGNORE     COVERAGE     */".isIgnored.should.equal(false);
"/*****  \n   IGNORE     COVERAGE  ".isIgnored.should.equal(false);
"/*****  \n   IGNORE     COVERAGE     ****/".isIgnored.should.equal(false);
"/+   \n  IGNORE     COVERAGE     +/".isIgnored.should.equal(false);
"/+++++  \n   IGNORE     COVERAGE  ".isIgnored.should.equal(false);
"/+++++   \n  IGNORE     COVERAGE     +++++/".isIgnored.should.equal(false);
"// IGNORE\nCOVERAGE".isIgnored.should.equal(false);
"//IGNORE\nCOVERAGE".isIgnored.should.equal(false);

public bool isPackagePath(
    string fullPath, 
    string packagePath)

Check if a file is in the current path

Example

Check project paths

"../../something.d".isPackagePath("/Users/trial/").should.equal(false);
"/Users/trial/trial_.d".isPackagePath("/Users/trial/").should.equal(false);
"/Users/trial/runner.d".isPackagePath("/Users/trial/").should.equal(true);
"C:\\Users\\trial\\runner.d".isPackagePath("C:/Users/trial/").should.equal(true);

public CoveredFile toCoverageFile(
    string content, 
    string packagePath)

Converts a .lst file content to a CoveredFile structure

Example

should convert a .lst file to CoveredFile structure

  auto result = `       |/++
       |  The main runner logic. You can find here some LifeCycle logic and test runner
       |  initalization
       |+/
       |module trial.runner;
       |
       |  /// Send the begin run event to all listeners
       |  void begin(ulong testCount) {
     23|    lifecycleListeners.each!(a => a.begin(testCount));
       |  }
lifecycle/trial/runner.d is 74% covered
`.toCoverageFile(buildPath(getcwd, "lifecycle/trial"));

  result.path.should.equal("lifecycle/trial/runner.d");
  result.isInCurrentProject.should.equal(true);
  result.moduleName.should.equal("trial.runner");
  result.coveragePercent.should.equal(74);
  result.lines.length.should.equal(10);
  result.lines[0].code.should.equal("/++");
  result.lines[9].code.should.equal("  }");

Example

should mark the
trial_.d
file as external file

  auto result = `trial_package.d is 74% covered
`.toCoverageFile(buildPath(getcwd, "lifecycle/trial"));

  result.isInCurrentProject.should.equal(false);

public string toLineCoverage(T)(
    LineCoverage line, 
    T index)

Generate the html for a line coverage

Example

Render line coverage column

LineCoverage("    |").toLineCoverage(1).should.contain([`line-number">1`, `0`]);
LineCoverage("    |").toLineCoverage(1).should.not.contain(["has-code", `hit"`]);

LineCoverage("    1|code").toLineCoverage(2).should.contain([ `line-number">2`, `1`, "has-code", `hit"` ]);

public string toHtmlCoverage(LineCoverage[] lines)

Get the line coverage column for the html report

public hitLines(LineCoverage[] lines)

Cont how many lines were hit

public codeLines(LineCoverage[] lines)

Cont how many lines were hit

public string replaceVariable(
    const string page, 
    const string key, 
    const string value) pure

Replace an

{variable}
inside a string

Example

It should replace a variable inside a page

`-{key}-`.replaceVariable("key", "value").should.equal("-value-");

public string wrapToHtml(
    string content, 
    string title)

wraps some string in a html page

Example

should replace the variables inside the page.html

auto page = wrapToHtml("some content", "some title");

page.should.contain(`some title`);
page.should.contain("\n  some content\n");

public string htmlProgress(string percent)

Create an html progress bar

Example

should replace the variables inside the page.html

htmlProgress("33").should.contain(`33%`);
htmlProgress("33").should.contain(`33% Covered`);

public string coverageHeader(CoveredFile coveredFile)

Generate the coverage page header

Example

Check variables for the coverage header

CoveredFile coveredFile;
coveredFile.moduleName = "module.name";
coveredFile.coveragePercent = 30;
coveredFile.path = "a/b";
coveredFile.lines = [ LineCoverage("       0| not code"), LineCoverage("    1| some code") ];

auto header = coverageHeader(coveredFile);

header.should.contain(`

module.name`); header.should.contain(`1/2`); header.should.contain(`30%`); header.should.contain(`
  • a
  • b
  • `);

    public string toHtml(CoveredFile coveredFile)
    

    Convert a

    CoveredFile
    struct to html

    Example

    Check variables for the coverage html

    CoveredFile coveredFile;
    coveredFile.moduleName = "module.name";
    coveredFile.coveragePercent = 30;
    coveredFile.path = "a/b";
    coveredFile.lines = [ LineCoverage("       0| "), LineCoverage("    1| some code") ];
    
    auto html = toHtml(coveredFile);
    
    html.should.contain(`

    module.name`); html.should.contain(`<not code>`); html.should.contain(`module.name coverage`); html.should.contain(`hit"`);

    public double coveragePercent(CoveredFile[] coveredFiles)
    

    Calculate the coverage percent from the current project

    Example

    No files are always 100% covered

    [].coveragePercent.should.equal(100);
    
    

    Example

    check a 50% covered file

    auto coveredFile = CoveredFile("", true, false, "", 50, [ LineCoverage("     75|  this(File f)"), LineCoverage("     0|  this(File f)") ]);
    [coveredFile].coveragePercent.should.equal(50);
    
    

    Example

    check a 50% external covered file

    auto coveredFile = CoveredFile("", false, false, "", 0, [ LineCoverage("     0|  this(File f)"), LineCoverage("     0|  this(File f)") ]);
    [coveredFile].coveragePercent.should.equal(100);
    
    
    public string indexHeader(string name)
    

    external files

    public string coverageShield(string percent)
    

    Create line coverage shield as svg

    Example

    The line coverage shield should contain the percent

    coverageShield("30").should.contain("30%");
    
    

    A module containing the logic for parsing and analysing the code coverage

    Copyright

    © 2017 Szabo Bogdan

    License

    Subject to the terms of the MIT license, as written in the included LICENSE.txt file.

    Authors

    Szabo Bogdan