report method

  1. @override
void report(
  1. String approvedPath,
  2. String receivedPath, {
  3. String? message,
})
override

Implementation

@override
void report(String approvedPath, String receivedPath, {String? message}) {
  try {
    final StringBuffer buffer = StringBuffer(message ?? "Differences:\n");

    final List<String> approvedLines =
        ApprovalUtils.readFile(path: approvedPath).split('\n');
    final List<String> receivedLines =
        ApprovalUtils.readFile(path: receivedPath).split('\n');

    final int maxLines = max(approvedLines.length, receivedLines.length);

    for (int i = 0; i < maxLines; i++) {
      final String approvedLine =
          i < approvedLines.length ? approvedLines[i] : "";
      final String receivedLine =
          i < receivedLines.length ? receivedLines[i] : "";

      if (approvedLine != receivedLine) {
        buffer.writeln(
          '${ApprovalUtils.lines(20)} Difference at line ${i + 1} ${ApprovalUtils.lines(20)} \n',
        );
        buffer.writeln(
          'Approved file, line ${i + 1}: ${_highlightDifference(approvedLine, receivedLine, isApprovedFile: true)}',
        );
        buffer.writeln(
          'Received file, line ${i + 1}: ${_highlightDifference(approvedLine, receivedLine)}',
        );
      }
    }

    if (buffer.isNotEmpty) {
      ApprovalLogger.exception(buffer.toString());
    }
  } catch (e) {
    rethrow;
  }
}