Skip to content

Commit

Permalink
Add support for Future<List<int>?> to MatchesGoldenFile (#132965)
Browse files Browse the repository at this point in the history
Otherwise when tests use `expectLater(getBytesOrNull(), matchesGoldenFile(...))`, they may fail in sound null safety mode and pass in weak null safety mode.

Fixes flutter/flutter#132964
  • Loading branch information
iinozemtsev authored Aug 22, 2023
1 parent 1843237 commit 5665655
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/flutter_test/lib/src/_matchers_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 8 additions & 0 deletions packages/flutter_test/test/matchers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down

0 comments on commit 5665655

Please sign in to comment.