diff --git a/test/reports/create_test_data.dart b/test/reports/create_test_data.dart index db75797..d957a4c 100644 --- a/test/reports/create_test_data.dart +++ b/test/reports/create_test_data.dart @@ -2,6 +2,7 @@ // License: BSD-3-Clause // See LICENSE for the full text of the license +import 'package:mutation_test/src/configuration/coverage.dart'; import 'package:mutation_test/src/core/mutated_line.dart'; import 'package:mutation_test/src/reports/report_data.dart'; import 'package:mutation_test/src/core/mutation.dart'; @@ -31,6 +32,15 @@ ReportData createTestData() { return reporter; } +ProjectLineCoverage createCodeCoverage() { + FileCoverage f = FileCoverage('path.dart'); + f.coverage[1] = 10; + f.coverage[2] = 0; + ProjectLineCoverage coverage = ProjectLineCoverage(); + coverage.coveredFiles['path.dart'] = f; + return coverage; +} + ReportData createTestDataWithNotCovered() { var reporter = createTestData(); reporter.addTestReport( diff --git a/test/reports/html_reporter_test.dart b/test/reports/html_reporter_test.dart index db4e116..fb9167d 100644 --- a/test/reports/html_reporter_test.dart +++ b/test/reports/html_reporter_test.dart @@ -32,6 +32,20 @@ void main() { expect(result.substring(0, end1), htmlSourceFileReport.substring(0, end1)); expect(result.substring(start2), htmlSourceFileReport.substring(start2)); }); + + test('Create html source report with coverage', () { + final reporter = createTestData(); + final coverage = createCodeCoverage(); + var result = createSourceHtmlFile( + reporter, reporter.testedFiles.values.first, 'test.html', coverage); + // exclude report creation time + final end1 = htmlSourceFileReport.indexOf('Date:') + 49; + final start2 = end1 + 26; + expect(result.substring(0, end1), + htmlSourceFileReportWithCoverage.substring(0, end1)); + expect(result.substring(start2), + htmlSourceFileReportWithCoverage.substring(start2)); + }); } final emptyTopLevel = '\n' @@ -210,3 +224,103 @@ final htmlSourceFileReport = '\n' '\n' '\n' ''; + +final htmlSourceFileReportWithCoverage = '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + ' \n' + ' \n' + '\n' + ' \n' + ' \n' + ' \n' + ' \n' + '\n' + ' \n' + ' \n' + '
Mutation test report

\n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + '\n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + ' \n' + '
Current display:path.dart - back to topDetectedTotalPercentage
Date:2022-10-30 16:37:03.526343Mutations:1333.3 %
Builtin rules:trueBlocked:1333.3 %
\n' + '

\n' + '\n' + '
          Source code
\n' + '
\n'
+    '\n'
+    '
\n' + 'Undetected mutations:\n' + '\n' + '
1 :+ var x = a;[0-9]+
\n' + 'Detected mutations:\n' + '\n' + '
1 :+ var x = -0;[0-9]+
\n' + 'Mutations that caused a time out:\n' + '\n' + '
1 :+ var x = c;[0-9]+Id: testId
\n' + '\n' + '
2 \n' + ' 3 // mooo\n' + ' 4 \n' + '
\n' + '\n' + ' \n' + ' \n' + '

\n' + '\n' + '\n' + '';