From 05747cfa6582ee1dca3e968fe4e13aa8b8645f19 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Wed, 17 Apr 2024 14:55:54 -0700 Subject: [PATCH] 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. --- packages/flutter_goldens/lib/flutter_goldens.dart | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/flutter_goldens/lib/flutter_goldens.dart b/packages/flutter_goldens/lib/flutter_goldens.dart index 2b052adbe57..34477f2ae22 100644 --- a/packages/flutter_goldens/lib/flutter_goldens.dart +++ b/packages/flutter_goldens/lib/flutter_goldens.dart @@ -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 testExecutable(FutureOr 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)) {