verify static method

void verify(
  1. String output, {
  2. String? filePath,
})

Verifies the output against the approved file.

Implementation

static void verify(String output, {String? filePath}) {
  File file = File(filePath ?? approvedPath());
  if (!file.existsSync()) {
    file.writeAsStringSync(output);
    print("Error: Approved file does not exist.");
  } else {
    String approvedOutput = file.readAsStringSync();
    bool isApproved = output == approvedOutput;
    print("Output: '$output'\n\nApproved: '$approvedOutput'");
    if (!isApproved) {
      throw Exception("Output does not match the approved file.");
    }
    print("Output matches the approved file.");
    expect(output, equals(approvedOutput));
  }
}