From 661d2a8fcc4ac3d3fa93db010fcc082b018340ef Mon Sep 17 00:00:00 2001 From: Szabo Bogdan Date: Wed, 8 Aug 2018 18:19:23 +0200 Subject: [PATCH] generate code coverage html in the artifact location --- lifecycle/trial/coverage.d | 17 +++++++++-------- runner/app.d | 6 +++++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lifecycle/trial/coverage.d b/lifecycle/trial/coverage.d index eed5131..dcc663f 100644 --- a/lifecycle/trial/coverage.d +++ b/lifecycle/trial/coverage.d @@ -38,16 +38,17 @@ version(D_Coverage) { } /// Converts coverage lst files to html -double convertLstFiles(string packagePath, string packageName) { - if(!exists(buildPath("coverage", "raw"))) { +double convertLstFiles(string source, string destination, string packagePath, string packageName) { + auto htmlPath = buildPath(destination, "html"); + if(!source.exists) { return 0; } - if(!exists(buildPath("coverage", "html"))) { - mkdirRecurse(buildPath("coverage", "html")); + if(!htmlPath.exists) { + htmlPath.mkdirRecurse; } - std.file.write(buildPath("coverage", "html", "coverage.css"), import("templates/coverage.css")); + std.file.write(buildPath(htmlPath, "coverage.css"), import("templates/coverage.css")); auto coverageData = dirEntries(buildPath("coverage", "raw"), SpanMode.shallow) @@ -56,13 +57,13 @@ double convertLstFiles(string packagePath, string packageName) { .map!(a => readText(a.name)) .map!(a => a.toCoverageFile(packagePath)).array; - std.file.write(buildPath("coverage", "html", "coverage-shield.svg"), coverageShield(coverageData.filter!"a.isInCurrentProject".array.coveragePercent.to!int.to!string)); - std.file.write(buildPath("coverage", "html", "index.html"), coverageData.toHtmlIndex(packageName)); + std.file.write(buildPath(htmlPath, "coverage-shield.svg"), coverageShield(coverageData.filter!"a.isInCurrentProject".array.coveragePercent.to!int.to!string)); + std.file.write(buildPath(htmlPath, "index.html"), coverageData.toHtmlIndex(packageName)); foreach (data; coverageData) { auto htmlFile = data.path.toCoverageHtmlFileName; - std.file.write(buildPath("coverage", "html", htmlFile), data.toHtml); + std.file.write(buildPath(htmlPath, htmlFile), data.toHtml); } return coverageData.coveragePercent; diff --git a/runner/app.d b/runner/app.d index 9652b93..5ba2351 100644 --- a/runner/app.d +++ b/runner/app.d @@ -168,8 +168,12 @@ version(unitttest) {} else { return 1; } finally { if(arguments.canFind("--coverage")) { + string source = buildPath("coverage", "raw"); + string destination = buildPath(runnerSettings.settings.artifactsLocation, "coverage"); logDiagnostic("calculate the code coverage"); - writeln("Line coverage: ", convertLstFiles(dub.rootPath.toString, dub.projectName), "%"); + + writeln("Line coverage: ", + convertLstFiles(source, destination, dub.rootPath.toString, dub.projectName), "%"); } }