Last active
May 23, 2022 13:26
-
-
Save apaatsio/8a10e52bccc29a0d598f6a3841f8966f to your computer and use it in GitHub Desktop.
Calculate total test coverage from lcov.info file generated by `flutter test --coverage`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NOTE: The preferred way is to install lcov and use command `lcov --summary path/to/lcov.info` | |
// Use this script only if you can't install lcov on your platform. | |
// Usage: dart coverage.dart path/to/lcov.info | |
import 'dart:io'; | |
void main(List<String> args) async { | |
final lcovFile = args[0]; | |
final lines = await File(lcovFile).readAsLines(); | |
final coverage = lines.fold([0, 0], (List<int> data, line) { | |
var testedLines = data[0]; | |
var totalLines = data[1]; | |
if (line.startsWith('DA')) { | |
totalLines++; | |
if (!line.endsWith(',0')) { | |
testedLines++; | |
} | |
} | |
return [testedLines, totalLines]; | |
}); | |
final testedLines = coverage[0]; | |
final totalLines = coverage[1]; | |
print( | |
'Total test coverage: ${(testedLines / totalLines * 100).toStringAsFixed(2)}%'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
line number
16
should state:instead of
otherwise lines reported like
DA:103;10
will be considered as not covered at all