Add support for Future<List<int>?> to MatchesGoldenFile (#132965)

Otherwise when tests use `expectLater(getBytesOrNull(), matchesGoldenFile(...))`, they may fail in sound null safety mode and pass in weak null safety mode.

Fixes https://github.com/flutter/flutter/issues/132964
This commit is contained in:
Ivan Inozemtsev 2023-08-22 21:40:18 +02:00 committed by GitHub
parent 184323777a
commit 5665655d39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -60,8 +60,9 @@ class MatchesGoldenFile extends AsyncMatcher {
final Uri testNameUri = goldenFileComparator.getTestUri(key, version);
Uint8List? buffer;
if (item is Future<List<int>>) {
buffer = Uint8List.fromList(await item);
if (item is Future<List<int>?>) {
final List<int>? bytes = await item;
buffer = bytes == null ? null : Uint8List.fromList(bytes);
} else if (item is List<int>) {
buffer = Uint8List.fromList(item);
}

View File

@ -470,6 +470,14 @@ void main() {
expect(comparator.imageBytes, equals(<int>[1, 2]));
expect(comparator.golden, Uri.parse('foo.png'));
});
testWidgets('future nullable list of integers',
(WidgetTester tester) async {
await expectLater(Future<List<int>?>.value(<int>[1, 2]), matchesGoldenFile('foo.png'));
expect(comparator.invocation, _ComparatorInvocation.compare);
expect(comparator.imageBytes, equals(<int>[1, 2]));
expect(comparator.golden, Uri.parse('foo.png'));
});
});
group('does not match', () {