Assert that the goldenFileComparator is a LocalFileComparator (#146802)

This is part 9 of a broken down version of the https://github.com/flutter/flutter/pull/140101 refactor.

This is an assumption already silently made by a bunch of casts in this file.
This commit is contained in:
Ian Hickson 2024-04-17 14:55:54 -07:00 committed by GitHub
parent 65d5d36759
commit 05747cfa65
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)) {