Skip to content

Commit

Permalink
Allow filtering of combined coverage reports (dafny-lang#4673)
Browse files Browse the repository at this point in the history
Add a new `--only-label` option to `merge-coverage-reports` to include
only one category of highlighting in the output. For example, merging
coverage reports from test generation and verification using the option
`--only-label NotCovered` will highlight only the regions not covered by
either testing or verification.

By submitting this pull request, I confirm that my contribution
is made under the terms of the MIT license.
  • Loading branch information
atomb authored Oct 17, 2023
1 parent f14ce45 commit cd70e30
Show file tree
Hide file tree
Showing 5 changed files with 501 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Source/DafnyDriver/Commands/CoverageReportCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using DafnyCore;

namespace Microsoft.Dafny;

static class CoverageReportCommand {

public static readonly Option<CoverageLabel?> OnlyLabelOption = new("--only-label",
"Skip coverage labels other than the given one, after merging labels from the input reports.");

public static IEnumerable<Option> Options =>
new Option[] {
CommonOptionBag.NoTimeStampForCoverageReport,
OnlyLabelOption
};

static CoverageReportCommand() {
ReportsArgument = new("reports", r => {
return r.Tokens.Where(t => !string.IsNullOrEmpty(t.Value)).Select(t => new FileInfo(t.Value)).ToList();
}, true, "directories with coverage reports to be merged");
DooFile.RegisterNoChecksNeeded(OnlyLabelOption);
}

// FilesArgument is intended for Dafny files, so CoverageReportCommand adds its own argument instead
Expand Down
6 changes: 5 additions & 1 deletion Source/DafnyDriver/CoverageReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,15 @@ public void Merge(List<string> coverageReportsToMerge, string coverageReportOutD
reports.Add(ParseCoverageReport(reportDir, $"{name} ({Path.GetFileName(reportDir)})", units, suffix));
}
}

var onlyLabel = options.Get(CoverageReportCommand.OnlyLabelOption);
foreach (var report in reports) {
foreach (var fileName in report.AllFiles()) {
foreach (var span in report.CoverageSpansForFile(fileName)) {
mergedReport.RegisterFile(span.Span.Uri);
mergedReport.LabelCode(span.Span, span.Label);
if ((onlyLabel ?? span.Label) == span.Label) {
mergedReport.LabelCode(span.Span, span.Label);
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Test/logger/CoverageReport.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
// RUN: %baredafny merge-coverage-reports --no-timestamp-for-coverage-report "%t"/coverage_combined "%t"/coverage_testing "%t"/coverage_verification
// RUN: %sed 's/<h1 hidden.*//' "%t"/coverage_combined/ProofDependencyLogging.dfy_combined.html > "%t"/coverage_combined.html
// RUN: %diff "%S/ProofDependencyLogging.dfy_combined.html.expect" "%t/coverage_combined.html"
// Combined, limited coverage:
// RUN: rm -rf "%t"/coverage_combined
// RUN: %baredafny merge-coverage-reports --only-label NotCovered --no-timestamp-for-coverage-report "%t"/coverage_combined_limited "%t"/coverage_testing "%t"/coverage_verification
// RUN: %sed 's/<h1 hidden.*//' "%t"/coverage_combined_limited/ProofDependencyLogging.dfy_combined.html > "%t"/coverage_combined_limited.html
// RUN: %diff "%S/ProofDependencyLogging.dfy_combined_limited.html.expect" "%t/coverage_combined_limited.html"


include "ProofDependencyLogging.dfy"
Loading

0 comments on commit cd70e30

Please sign in to comment.