Skip to content

Commit

Permalink
Assert that the goldenFileComparator is a LocalFileComparator (#146802)
Browse files Browse the repository at this point in the history
This is part 9 of a broken down version of the flutter/flutter#140101 refactor.

This is an assumption already silently made by a bunch of casts in this file.
  • Loading branch information
Hixie authored Apr 17, 2024
1 parent 65d5d36 commit 05747cf
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/flutter_goldens/lib/flutter_goldens.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,22 @@ bool _isMainBranch(String? branch) {
/// instantiated is based on the current testing environment.
///
/// When set, the `namePrefix` is prepended to the names of all gold images.
///
/// This function assumes the [goldenFileComparator] has been set to a
/// [LocalFileComparator], which happens in the bootstrap code used when running
/// tests using `flutter test`. This should not be called when running a test
/// using `flutter run`, as in that environment, the [goldenFileComparator] is a
/// [TrivialComparator].
Future<void> testExecutable(FutureOr<void> Function() testMain, {String? namePrefix}) async {
assert(
goldenFileComparator is LocalFileComparator,
'The flutter_goldens package should be used from a flutter_test_config.dart '
'file, which is only invoked when using "flutter test". The "flutter test" '
'bootstrap logic sets "goldenFileComparator" to a LocalFileComparator. It '
'appears in this instance however that the "goldenFileComparator" is a '
'${goldenFileComparator.runtimeType}.\n'
'See also: https://api.flutter.dev/flutter/flutter_test/flutter_test-library.html',
);
const Platform platform = LocalPlatform();
const FileSystem fs = LocalFileSystem();
if (FlutterPostSubmitFileComparator.isForEnvironment(platform)) {
Expand Down

0 comments on commit 05747cf

Please sign in to comment.