Skip to content

Commit

Permalink
Lines marked as covered will be displayed in the html report
Browse files Browse the repository at this point in the history
  • Loading branch information
domohuhn committed Mar 24, 2024
1 parent addf9f2 commit 5c9bbe2
Show file tree
Hide file tree
Showing 15 changed files with 273 additions and 109 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.7.0
- Added new builtin rules that remove lines of code (void function calls and contents of arrays)
- Coverage information is provided in the html report: line numbers of instrumented lines are displayed in red and executed lines are displayed in green

## 1.6.0
- Added the option to exclude lines not covered by tests. You can pass a file with coverage information in the lcov format via
the command line flag "--coverage".
Expand Down
64 changes: 38 additions & 26 deletions doc/output/example/source.dart.html

Large diffs are not rendered by default.

114 changes: 61 additions & 53 deletions doc/output/example/source2.dart.html

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions doc/output/example/source3.dart.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
background-color: #DAE7FE;
}

.covered {
background-color: #9EFF83;
}
.instrumented {
background-color: #FF8983;
}

.hit:hover {
color: white;
background-color: #6688D4;
Expand Down Expand Up @@ -308,6 +315,12 @@
.hit {
background-color: #26334F;
}
.covered {
background-color: #0A3302;
}
.instrumented {
background-color: #391D1D;
}
.addedLine {
background-color: rgb(37, 83, 37);
}
Expand All @@ -320,7 +333,6 @@
a:link, a:visited {
color: #58a6ff;
}

.match .tooltip {
background-color: black;
color: #fff;
Expand Down Expand Up @@ -348,7 +360,7 @@

<tr>
<td class="ItemLabel" width="10%">Date:</td>
<td class="ItemText" width="35%">2024-03-24 15:27:37.231554</td>
<td class="ItemText" width="35%">2024-03-24 17:47:31.491803</td>
<td class="ItemLabel" width="10%">Mutations:</td>
<td class="ItemReport" width="15%">0</td>
<td class="ItemReport" width="15%">0</td>
Expand Down Expand Up @@ -407,7 +419,7 @@
}
</script><table width ="100%" cellspacing="0" border="0">
<tr><td><hr class="ruler"/></td></tr>
<tr><td class="footer">Generated by mutation-test version: 1.6.1</td></tr>
<tr><td class="footer">Generated by mutation-test version: 1.7.0</td></tr>
</table>
</body>
</html>
26 changes: 19 additions & 7 deletions doc/output/mutation-test-report.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
background-color: #DAE7FE;
}

.covered {
background-color: #9EFF83;
}
.instrumented {
background-color: #FF8983;
}

.hit:hover {
color: white;
background-color: #6688D4;
Expand Down Expand Up @@ -308,6 +315,12 @@
.hit {
background-color: #26334F;
}
.covered {
background-color: #0A3302;
}
.instrumented {
background-color: #391D1D;
}
.addedLine {
background-color: rgb(37, 83, 37);
}
Expand All @@ -320,7 +333,6 @@
a:link, a:visited {
color: #58a6ff;
}

.match .tooltip {
background-color: black;
color: #fff;
Expand Down Expand Up @@ -348,7 +360,7 @@

<tr>
<td class="ItemLabel" width="10%">Date:</td>
<td class="ItemText" width="35%">2024-03-24 15:27:37.229545</td>
<td class="ItemText" width="35%">2024-03-24 17:47:31.491803</td>
<td class="ItemLabel" width="10%">Mutations:</td>
<td class="ItemReport" width="15%">24</td>
<td class="ItemReport" width="15%">98</td>
Expand All @@ -359,9 +371,9 @@
<td class="ItemLabel" width="10%">Builtin rules:</td>
<td class="ItemText" width="35%">true</td>
<td class="ItemLabel" width="10%">Blocked:</td>
<td class="ItemReport" width="15%">0</td>
<td class="ItemReport" width="15%">37</td>
<td class="ItemReport" width="15%">98</td>
<td class="ItemReportHigh" width="15%">0.0 %</td>
<td class="ItemReportMedium" width="15%">37.8 %</td>
</tr>
<tr>
<td class="ItemLabel" width="10%">Quality rating:</td>
Expand Down Expand Up @@ -395,7 +407,7 @@
</td>
<td class="ItemReportMedium" width="10%">52.4 %</td>
<td class="ItemReportMedium" width="10%">22 / 42</td>
<td class="ItemReportHigh" width="10%">0 / 42</td>
<td class="ItemReportHigh" width="10%">5 / 42</td>
</tr>
<tr><td class="FileLink" width="60%"><a href="example/source2.dart.html">example/source2.dart</a></td>
<td class="ItemReport" width="10%">
Expand All @@ -406,7 +418,7 @@
</td>
<td class="ItemReportLow" width="10%">3.6 %</td>
<td class="ItemReportLow" width="10%">2 / 56</td>
<td class="ItemReportHigh" width="10%">0 / 56</td>
<td class="ItemReportLow" width="10%">32 / 56</td>
</tr>
<tr><td class="FileLink" width="60%"><a href="example/source3.dart.html">example/source3.dart</a></td>
<td class="ItemReport" width="10%">
Expand All @@ -426,7 +438,7 @@

<table width ="100%" cellspacing="0" border="0">
<tr><td><hr class="ruler"/></td></tr>
<tr><td class="footer">Generated by mutation-test version: 1.6.1</td></tr>
<tr><td class="footer">Generated by mutation-test version: 1.7.0</td></tr>
</table>
</body>
</html>
53 changes: 53 additions & 0 deletions example/lcov.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
SF:example\source2.dart
DA:14,1
DA:15,4
DA:19,1
DA:20,3
DA:21,2
DA:22,1
DA:23,0
DA:25,1
DA:28,0
DA:29,0
DA:30,0
DA:31,0
DA:32,0
DA:33,0
DA:38,0
DA:39,0
DA:40,0
DA:41,0
DA:42,0
DA:43,0
DA:48,1
DA:49,5
DA:52,1
DA:53,1
DA:54,1
LF:25
LH:12
end_of_record
SF:example\source.dart
DA:5,1
DA:6,2
DA:7,1
DA:8,2
DA:9,1
DA:11,2
DA:13,1
DA:14,1
DA:16,2
DA:19,1
DA:20,5
DA:23,1
DA:24,1
DA:27,1
DA:28,1
DA:31,1
DA:32,1
DA:35,2
DA:37,0
DA:38,0
LF:20
LH:18
end_of_record
31 changes: 30 additions & 1 deletion lib/src/configuration/coverage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ class FileCoverage {
}
return false;
}

/// Returns true if a [line] is instrumented and executed
bool lineIsCovered(int line) {
return lineIsInstrumented(line) && coverage[line]! > 0;
}

/// Returns true if a [line] is instrumented
bool lineIsInstrumented(int line) {
return coverage.containsKey(line);
}
}

/// This class holds the line coverage information for each source code file
Expand All @@ -58,7 +68,8 @@ class ProjectLineCoverage {
return null;
}

/// Checks if the lines in [file] are covered by tests.
/// Checks if the lines in [file] are covered by tests. This method should be used
/// to determine if a mutation has to be tested.
///
/// Returns true if there is no coverage information for the given file.
bool isCoveredByTests(String file, int lineStart, [int lineEnd = -1]) {
Expand All @@ -70,6 +81,24 @@ class ProjectLineCoverage {
return true;
}

/// Checks if the [line] in [file] is instrumented and covered.
bool lineIsCovered(String file, int line) {
var info = getFileOrNull(file);
if (info != null) {
return info.lineIsCovered(line);
}
return false;
}

/// Checks if the [line] in [file] is instrumented.
bool lineIsInstrumented(String file, int line) {
var info = getFileOrNull(file);
if (info != null) {
return info.lineIsInstrumented(line);
}
return false;
}

ProjectLineCoverage() : coveredFiles = {};

/// Creates the class by parsing a given string with the lcov file contents.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/mutation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class MutationTest {
addBuiltin: builtinRules,
useDefaultConfig: true);
}
createReport(reporter, outputPath, format);
createReport(reporter, outputPath, format, coverageData);
return foundAll;
}

Expand Down
10 changes: 7 additions & 3 deletions lib/src/reports/create_report.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:mutation_test/src/configuration/coverage.dart';
import 'package:mutation_test/src/reports/command_line_report.dart';
import 'package:mutation_test/src/reports/html_report.dart';
import 'package:mutation_test/src/reports/markdown_report.dart';
Expand All @@ -8,7 +9,10 @@ import 'package:mutation_test/src/reports/xunit_report.dart';

/// Creates the test report in directory [outputPath]
/// in the specified [format] using the [results].
void createReport(ReportData results, String outputPath, ReportFormat format) {
/// If the [coverage] is provided, then html reports will show the instrumented and
/// executed lines in the report.
void createReport(ReportData results, String outputPath, ReportFormat format,
[ProjectLineCoverage? coverage]) {
writeCommandLineReport(results, results.system);
results.sort();
switch (format) {
Expand All @@ -21,7 +25,7 @@ void createReport(ReportData results, String outputPath, ReportFormat format) {
writeMarkdownReport(outputPath, results, results.system);
break;
case ReportFormat.HTML:
writeHTMLReport(outputPath, results, results.system);
writeHTMLReport(outputPath, results, results.system, coverage);
break;
case ReportFormat.XUNIT:
writeXUnitReport(outputPath, results, results.system);
Expand All @@ -32,7 +36,7 @@ void createReport(ReportData results, String outputPath, ReportFormat format) {
case ReportFormat.ALL:
writeXMLReport(outputPath, results, results.system);
writeMarkdownReport(outputPath, results, results.system);
writeHTMLReport(outputPath, results, results.system);
writeHTMLReport(outputPath, results, results.system, coverage);
writeXUnitReport(outputPath, results, results.system);
writeJUnitReport(outputPath, results, results.system);
break;
Expand Down
Loading

0 comments on commit 5c9bbe2

Please sign in to comment.