genUiFuzzSummary function
A table of findings, one line per component, for a CI log.
The detail is in the findings themselves; this is what to look at first when a run comes back with sixty of them and the question is which component to open.
Implementation
String genUiFuzzSummary(List<GenUiFuzzFinding> findings) {
if (findings.isEmpty) return 'nothing broke';
final byComponent = <String, List<GenUiFuzzFinding>>{};
for (final f in findings) {
byComponent.putIfAbsent(f.component, () => <GenUiFuzzFinding>[]).add(f);
}
final names = byComponent.keys.toList()
..sort((a, b) => byComponent[b]!.length.compareTo(byComponent[a]!.length));
final buffer = StringBuffer(
'${findings.length} in ${names.length} '
'component${names.length == 1 ? '' : 's'}\n',
);
for (final String name in names) {
final List<GenUiFuzzFinding> mine = byComponent[name]!;
final int threw = mine.where((f) => f.kind == GenUiFuzzKind.threw).length;
final int empty = mine.length - threw;
buffer.writeln(
' ${mine.length.toString().padLeft(4)} $name'
'${threw > 0 ? ' ($threw threw' : ' ('}'
'${empty > 0 ? '${threw > 0 ? ', ' : ''}$empty rendered nothing' : ''})',
);
}
return buffer.toString();
}