generateFailureOutput method
- ComparisonResult result,
- Uri golden,
- Uri basedir, {
- String key = '',
Writes out diffs from the ComparisonResult of a golden file test.
Will throw an error if a null result is provided.
Implementation
Future<String> generateFailureOutput(
ComparisonResult result,
Uri golden,
Uri basedir, {
String key = '',
}) async => TestAsyncUtils.guard<String>(() async {
String additionalFeedback = '';
if (result.diffs != null) {
additionalFeedback = '\nFailure feedback can be found at ${path.join(basedir.path, 'failures')}';
final Map<String, Image> diffs = result.diffs!;
for (final MapEntry<String, Image> entry in diffs.entries) {
final File output = getFailureFile(
key.isEmpty ? entry.key : '${entry.key}_$key',
golden,
basedir,
);
output.parent.createSync(recursive: true);
final ByteData? pngBytes = await entry.value.toByteData(format: ImageByteFormat.png);
output.writeAsBytesSync(pngBytes!.buffer.asUint8List());
}
}
return 'Golden "$golden": ${result.error}$additionalFeedback';
});