@@ -39,16 +39,17 @@ bool _isMainBranch(String? branch) {
3939Future <void > testExecutable (FutureOr <void > Function () testMain, {String ? namePrefix}) async {
4040 const Platform platform = LocalPlatform ();
4141 if (FlutterPostSubmitFileComparator .isForEnvironment (platform)) {
42- goldenFileComparator = await FlutterPostSubmitFileComparator .fromDefaultComparator (platform, namePrefix: namePrefix);
42+ goldenFileComparator = await FlutterPostSubmitFileComparator .fromDefaultComparator (platform, namePrefix: namePrefix, log : print );
4343 } else if (FlutterPreSubmitFileComparator .isForEnvironment (platform)) {
44- goldenFileComparator = await FlutterPreSubmitFileComparator .fromDefaultComparator (platform, namePrefix: namePrefix);
44+ goldenFileComparator = await FlutterPreSubmitFileComparator .fromDefaultComparator (platform, namePrefix: namePrefix, log : print );
4545 } else if (FlutterSkippingFileComparator .isForEnvironment (platform)) {
4646 goldenFileComparator = FlutterSkippingFileComparator .fromDefaultComparator (
4747 'Golden file testing is not executed on Cirrus, or LUCI environments outside of flutter/flutter.' ,
48- namePrefix: namePrefix
48+ namePrefix: namePrefix,
49+ log: print
4950 );
5051 } else {
51- goldenFileComparator = await FlutterLocalFileComparator .fromDefaultComparator (platform);
52+ goldenFileComparator = await FlutterLocalFileComparator .fromDefaultComparator (platform, log : print );
5253 }
5354 await testMain ();
5455}
@@ -103,6 +104,7 @@ abstract class FlutterGoldenFileComparator extends GoldenFileComparator {
103104 this .fs = const LocalFileSystem (),
104105 this .platform = const LocalPlatform (),
105106 this .namePrefix,
107+ required this .log,
106108 });
107109
108110 /// The directory to which golden file URIs will be resolved in [compare] and
@@ -124,6 +126,9 @@ abstract class FlutterGoldenFileComparator extends GoldenFileComparator {
124126 /// The prefix that is added to all golden names.
125127 final String ? namePrefix;
126128
129+ /// The logging function to use when reporting messages to the console.
130+ final LogCallback log;
131+
127132 @override
128133 Future <void > update (Uri golden, Uint8List imageBytes) async {
129134 final File goldenFile = getGoldenFile (golden);
@@ -225,6 +230,7 @@ class FlutterPostSubmitFileComparator extends FlutterGoldenFileComparator {
225230 super .fs,
226231 super .platform,
227232 super .namePrefix,
233+ required super .log,
228234 });
229235
230236 /// Creates a new [FlutterPostSubmitFileComparator] that mirrors the relative
@@ -237,6 +243,7 @@ class FlutterPostSubmitFileComparator extends FlutterGoldenFileComparator {
237243 SkiaGoldClient ? goldens,
238244 LocalFileComparator ? defaultComparator,
239245 String ? namePrefix,
246+ required LogCallback log,
240247 }) async {
241248
242249 defaultComparator ?? = goldenFileComparator as LocalFileComparator ;
@@ -247,9 +254,9 @@ class FlutterPostSubmitFileComparator extends FlutterGoldenFileComparator {
247254 );
248255 baseDirectory.createSync (recursive: true );
249256
250- goldens ?? = SkiaGoldClient (baseDirectory);
257+ goldens ?? = SkiaGoldClient (baseDirectory, log : log );
251258 await goldens.auth ();
252- return FlutterPostSubmitFileComparator (baseDirectory.uri, goldens, namePrefix: namePrefix);
259+ return FlutterPostSubmitFileComparator (baseDirectory.uri, goldens, namePrefix: namePrefix, log : log );
253260 }
254261
255262 @override
@@ -302,6 +309,7 @@ class FlutterPreSubmitFileComparator extends FlutterGoldenFileComparator {
302309 super .fs,
303310 super .platform,
304311 super .namePrefix,
312+ required super .log,
305313 });
306314
307315 /// Creates a new [FlutterPreSubmitFileComparator] that mirrors the
@@ -315,6 +323,7 @@ class FlutterPreSubmitFileComparator extends FlutterGoldenFileComparator {
315323 LocalFileComparator ? defaultComparator,
316324 Directory ? testBasedir,
317325 String ? namePrefix,
326+ required LogCallback log,
318327 }) async {
319328
320329 defaultComparator ?? = goldenFileComparator as LocalFileComparator ;
@@ -328,13 +337,14 @@ class FlutterPreSubmitFileComparator extends FlutterGoldenFileComparator {
328337 baseDirectory.createSync (recursive: true );
329338 }
330339
331- goldens ?? = SkiaGoldClient (baseDirectory);
340+ goldens ?? = SkiaGoldClient (baseDirectory, log : log );
332341
333342 await goldens.auth ();
334343 return FlutterPreSubmitFileComparator (
335344 baseDirectory.uri,
336345 goldens, platform: platform,
337346 namePrefix: namePrefix,
347+ log: log,
338348 );
339349 }
340350
@@ -388,6 +398,7 @@ class FlutterSkippingFileComparator extends FlutterGoldenFileComparator {
388398 super .skiaClient,
389399 this .reason, {
390400 super .namePrefix,
401+ required super .log,
391402 });
392403
393404 /// Describes the reason for using the [FlutterSkippingFileComparator] .
@@ -399,21 +410,18 @@ class FlutterSkippingFileComparator extends FlutterGoldenFileComparator {
399410 String reason, {
400411 LocalFileComparator ? defaultComparator,
401412 String ? namePrefix,
413+ required LogCallback log,
402414 }) {
403415 defaultComparator ?? = goldenFileComparator as LocalFileComparator ;
404416 const FileSystem fs = LocalFileSystem ();
405417 final Uri basedir = defaultComparator.basedir;
406- final SkiaGoldClient skiaClient = SkiaGoldClient (fs.directory (basedir));
407- return FlutterSkippingFileComparator (basedir, skiaClient, reason, namePrefix: namePrefix);
418+ final SkiaGoldClient skiaClient = SkiaGoldClient (fs.directory (basedir), log : log );
419+ return FlutterSkippingFileComparator (basedir, skiaClient, reason, namePrefix: namePrefix, log : log );
408420 }
409421
410422 @override
411423 Future <bool > compare (Uint8List imageBytes, Uri golden) async {
412- // Ideally we would use markTestSkipped here but in some situations,
413- // comparators are called outside of tests.
414- // See also: https://github.com/flutter/flutter/issues/91285
415- // ignore: avoid_print
416- print ('Skipping "$golden " test: $reason ' );
424+ log ('Skipping "$golden " test: $reason ' );
417425 return true ;
418426 }
419427
@@ -471,6 +479,7 @@ class FlutterLocalFileComparator extends FlutterGoldenFileComparator with LocalC
471479 super .skiaClient, {
472480 super .fs,
473481 super .platform,
482+ required super .log,
474483 });
475484
476485 /// Creates a new [FlutterLocalFileComparator] that mirrors the
@@ -483,6 +492,7 @@ class FlutterLocalFileComparator extends FlutterGoldenFileComparator with LocalC
483492 SkiaGoldClient ? goldens,
484493 LocalFileComparator ? defaultComparator,
485494 Directory ? baseDirectory,
495+ required LogCallback log,
486496 }) async {
487497 defaultComparator ?? = goldenFileComparator as LocalFileComparator ;
488498 baseDirectory ?? = FlutterGoldenFileComparator .getBaseDirectory (
@@ -494,7 +504,7 @@ class FlutterLocalFileComparator extends FlutterGoldenFileComparator with LocalC
494504 baseDirectory.createSync (recursive: true );
495505 }
496506
497- goldens ?? = SkiaGoldClient (baseDirectory);
507+ goldens ?? = SkiaGoldClient (baseDirectory, log : log );
498508 try {
499509 // Check if we can reach Gold.
500510 await goldens.getExpectationForTest ('' );
@@ -503,25 +513,28 @@ class FlutterLocalFileComparator extends FlutterGoldenFileComparator with LocalC
503513 baseDirectory.uri,
504514 goldens,
505515 'OSError occurred, could not reach Gold. '
506- 'Switching to FlutterSkippingGoldenFileComparator.' ,
516+ 'Switching to FlutterSkippingGoldenFileComparator.' ,
517+ log: log,
507518 );
508519 } on io.SocketException catch (_) {
509520 return FlutterSkippingFileComparator (
510521 baseDirectory.uri,
511522 goldens,
512523 'SocketException occurred, could not reach Gold. '
513- 'Switching to FlutterSkippingGoldenFileComparator.' ,
524+ 'Switching to FlutterSkippingGoldenFileComparator.' ,
525+ log: log,
514526 );
515527 } on FormatException catch (_) {
516528 return FlutterSkippingFileComparator (
517529 baseDirectory.uri,
518530 goldens,
519531 'FormatException occurred, could not reach Gold. '
520- 'Switching to FlutterSkippingGoldenFileComparator.' ,
532+ 'Switching to FlutterSkippingGoldenFileComparator.' ,
533+ log: log,
521534 );
522535 }
523536
524- return FlutterLocalFileComparator (baseDirectory.uri, goldens);
537+ return FlutterLocalFileComparator (baseDirectory.uri, goldens, log : log );
525538 }
526539
527540 @override
@@ -532,12 +545,7 @@ class FlutterLocalFileComparator extends FlutterGoldenFileComparator with LocalC
532545 testExpectation = await skiaClient.getExpectationForTest (testName);
533546
534547 if (testExpectation == null || testExpectation.isEmpty) {
535- // There is no baseline for this test.
536- // Ideally we would use markTestSkipped here but in some situations,
537- // comparators are called outside of tests.
538- // See also: https://github.com/flutter/flutter/issues/91285
539- // ignore: avoid_print
540- print (
548+ log (
541549 'No expectations provided by Skia Gold for test: $golden . '
542550 'This may be a new test. If this is an unexpected result, check '
543551 'https://flutter-gold.skia.org.\n '
0 commit comments