generateFailureOutput method

Future<void> generateFailureOutput (
  1. ComparisonResult result,
  2. Uri golden,
  3. Uri basedir,
  4. {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<void> generateFailureOutput(
  ComparisonResult result,
  Uri golden,
  Uri basedir, {
  String key = '',
}) 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.cast<String, Image>();
    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());
    }
  }
  throw test_package.TestFailure(
    'Golden "$golden": ${result.error}$additionalFeedback'
  );
}