Update _goldens_io.dart to generate failure images during a size mism… (#142177)

Update the `matchesGoldenFile()` / `LocalComparisonOutput` code to generate failure images for golden tests that fail when the image sizes do not match. This can make it far quicker to identify what is wrong with the test image.

Fixes https://github.com/flutter/flutter/issues/141488

- [ x I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
This commit is contained in:
Andrew Brampton 2024-02-06 19:23:29 -08:00 committed by GitHub
parent 310a7edbca
commit 10f1e63579
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 2 deletions

View file

@ -210,9 +210,11 @@ Future<ComparisonResult> compareLists(List<int>? test, List<int>? master) async
error: 'Pixel test failed, image sizes do not match.\n'
'Master Image: ${masterImage.width} X ${masterImage.height}\n'
'Test Image: ${testImage.width} X ${testImage.height}',
diffs: <String, Image>{
'masterImage': masterImage,
'testImage': testImage,
},
);
masterImage.dispose();
testImage.dispose();
return result;
}

View file

@ -244,6 +244,34 @@ void main() {
expect(masked.existsSync(), isTrue);
});
test('and generates correct output when images are not the same size', () async {
await fs.file(fix('/golden.png')).writeAsBytes(_kSizeFailurePngBytes);
await expectLater(
() => doComparison(),
throwsA(isFlutterError.having(
(FlutterError error) => error.message,
'message',
contains('image sizes do not match'),
)),
);
final io.File master = fs.file(
fix('/failures/golden_masterImage.png')
);
final io.File test = fs.file(
fix('/failures/golden_testImage.png')
);
final io.File isolated = fs.file(
fix('/failures/golden_isolatedDiff.png')
);
final io.File masked = fs.file(
fix('/failures/golden_maskedDiff.png')
);
expect(master.existsSync(), isTrue);
expect(test.existsSync(), isTrue);
expect(isolated.existsSync(), isFalse);
expect(masked.existsSync(), isFalse);
});
test('when golden file does not exist', () async {
await expectLater(
() => doComparison(),