Just reading through the source there does not appear to be any sort of option like you describe. But it makes me wonder, what would you consider a file with 100% coverage? The html tool colors lines using a range of 0-10 where 0 is not covered at all and 10 has extensive coverage. So how would a line with a 1 or 2 be represented? I mean, it has some coverage, but certainly not very much (especially for something that is critical.)
It could be interesting to add a percentage in the drop down next to the files that shows a percentage of lines covered with a non-0 value. This wouldn't even be very hard to add, but would mean that htmlGen
would need either a struct to wrap the buffer and counter for percentages or an additional pointer would need to be passed in to track the percentage of covered lines. The rest would be pretty easy, adding a PercentCovered
to templateFile
type, and modifying the template html to include it in the drop down.
All in all, unless this is purely an exercise for yourself in trying to achieve "full code coverage" in tests, I would warn against putting too much emphasis on this stat as it can be entirely misleading as to the quality or completeness of ones tests.
EDIT
Come to think of it, you could probably do this yourself using a browser script injection plugin like TamperMonkey or GreaseMonkey (chrome and ff respectively.) I little bit of fairly straight forward javascript should give you pretty good results. As it turns out the classes for the colors are not defined per line, but per group of similarly covered lines, so your percentage of lines covered might be a little tricker as you would need to count the lines within each span block (splitting on "
"), but again, it wouldn't be all that hard. I think this is a worthwhile idea and might try implementing it myself if I find the time.
EDIT 2
Here is the relevant javascript (relies on jquery because I don't do JS)... If you stick this in the end of the generated file (before the closing </html>
tag it will add a percentage to the drop down per file for non-zero coverage. It also takes into account lines that are not tracked.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('#files').find("option").each(function(i, el) {
var id = $(this).val();
var div = $('#' + id);
var lines = div.html().split("
").length;
var covered = 0;
var not_tracked = lines;
div.find('span').each(function(i, el) {
var span_lines = $(this).html().split("
").length;
var klass = $(this).attr('class');
var coverage_type = parseInt(klass.replace("cov", ""));
if (coverage_type != 0) {
covered += span_lines;
}
not_tracked -= span_lines
});
lines -= not_tracked
$(this).text((covered*100/lines).toFixed(2) + "%" + " " + $(this).text());
});
});
</script>
I couldn't get TamperMonkey to work with file://
protocol (I don't think it supports it, but GreaseMonkey does with some setting changes.)
The screenshot has been blurred to protect the innocent.