Skip to content

Commit e1e742a

Browse files
authored
Remove hidden dependencies on the default LocalPlatform (#147342)
This is part 13 of a broken down version of the #140101 refactor. This only makes one dependency explicit. Further PRs will do the same for other dependencies, until these APIs have no hidden dependencies.
1 parent 94a7151 commit e1e742a

File tree

3 files changed

+68
-47
lines changed

3 files changed

+68
-47
lines changed

packages/flutter_goldens/lib/flutter_goldens.dart

Lines changed: 57 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ Future<void> testExecutable(FutureOr<void> Function() testMain, {String? namePre
5959
if (FlutterPostSubmitFileComparator.isForEnvironment(platform)) {
6060
goldenFileComparator = await FlutterPostSubmitFileComparator.fromLocalFileComparator(
6161
localFileComparator: goldenFileComparator as LocalFileComparator,
62-
platform,
62+
platform: platform,
6363
namePrefix: namePrefix,
6464
log: print,
6565
fs: fs,
6666
);
6767
} else if (FlutterPreSubmitFileComparator.isForEnvironment(platform)) {
6868
goldenFileComparator = await FlutterPreSubmitFileComparator.fromLocalFileComparator(
6969
localFileComparator: goldenFileComparator as LocalFileComparator,
70-
platform,
70+
platform: platform,
7171
namePrefix: namePrefix,
7272
log: print,
7373
fs: fs,
@@ -78,14 +78,15 @@ Future<void> testExecutable(FutureOr<void> Function() testMain, {String? namePre
7878
'Golden file testing is not executed on Cirrus, or LUCI environments '
7979
'outside of flutter/flutter, or in test shards that are not configured '
8080
'for using goldctl.',
81+
platform: platform,
8182
namePrefix: namePrefix,
8283
log: print,
8384
fs: fs,
8485
);
8586
} else {
8687
goldenFileComparator = await FlutterLocalFileComparator.fromLocalFileComparator(
8788
localFileComparator: goldenFileComparator as LocalFileComparator,
88-
platform,
89+
platform: platform,
8990
log: print,
9091
fs: fs,
9192
);
@@ -133,15 +134,12 @@ abstract class FlutterGoldenFileComparator extends GoldenFileComparator {
133134
/// information and files for interacting with the [skiaClient]. When testing
134135
/// locally, the [basedir] will also contain any diffs from failed tests, or
135136
/// goldens generated from newly introduced tests.
136-
///
137-
/// The [platform] parameter is useful in tests, where the default
138-
/// platform can be replaced by a mock instance.
139137
@visibleForTesting
140138
FlutterGoldenFileComparator(
141139
this.basedir,
142140
this.skiaClient, {
143141
required this.fs,
144-
this.platform = const LocalPlatform(),
142+
required this.platform,
145143
this.namePrefix,
146144
required this.log,
147145
});
@@ -157,8 +155,8 @@ abstract class FlutterGoldenFileComparator extends GoldenFileComparator {
157155
/// The file system used to perform file access.
158156
final FileSystem fs;
159157

160-
/// A wrapper for the [dart:io.Platform] API.
161-
@visibleForTesting
158+
/// The environment (current working directory, identity of the OS,
159+
/// environment variables, etc).
162160
final Platform platform;
163161

164162
/// The prefix that is added to all golden names.
@@ -186,8 +184,8 @@ abstract class FlutterGoldenFileComparator extends GoldenFileComparator {
186184
@protected
187185
@visibleForTesting
188186
static Directory getBaseDirectory(
189-
LocalFileComparator defaultComparator,
190-
Platform platform, {
187+
LocalFileComparator defaultComparator, {
188+
required Platform platform,
191189
String? suffix,
192190
required FileSystem fs,
193191
}) {
@@ -260,13 +258,13 @@ class FlutterPostSubmitFileComparator extends FlutterGoldenFileComparator {
260258
/// Creates a [FlutterPostSubmitFileComparator] that will test golden file
261259
/// images against Skia Gold.
262260
///
263-
/// The [fs] and [platform] parameters are useful in tests, where the default
264-
/// file system and platform can be replaced by mock instances.
261+
/// The [fs] parameter is useful in tests, where the default
262+
/// file system can be replaced by mock instances.
265263
FlutterPostSubmitFileComparator(
266264
super.basedir,
267265
super.skiaClient, {
268266
required super.fs,
269-
super.platform,
267+
required super.platform,
270268
super.namePrefix,
271269
required super.log,
272270
});
@@ -275,27 +273,32 @@ class FlutterPostSubmitFileComparator extends FlutterGoldenFileComparator {
275273
/// path resolution of the provided `localFileComparator`.
276274
///
277275
/// The [goldens] parameter is visible for testing purposes only.
278-
static Future<FlutterPostSubmitFileComparator> fromLocalFileComparator(
279-
final Platform platform, {
276+
static Future<FlutterPostSubmitFileComparator> fromLocalFileComparator({
280277
SkiaGoldClient? goldens,
281278
required LocalFileComparator localFileComparator,
279+
required Platform platform,
282280
String? namePrefix,
283281
required LogCallback log,
284282
required FileSystem fs,
285283
}) async {
286284
final Directory baseDirectory = FlutterGoldenFileComparator.getBaseDirectory(
287285
localFileComparator,
288-
platform,
286+
platform: platform,
289287
suffix: 'flutter_goldens_postsubmit.',
290288
fs: fs,
291289
);
292290
baseDirectory.createSync(recursive: true);
293291

294-
goldens ??= SkiaGoldClient(baseDirectory, log: log);
292+
goldens ??= SkiaGoldClient(
293+
baseDirectory,
294+
log: log,
295+
platform: platform,
296+
);
295297
await goldens.auth();
296298
return FlutterPostSubmitFileComparator(
297299
baseDirectory.uri,
298300
goldens,
301+
platform: platform,
299302
namePrefix: namePrefix,
300303
log: log,
301304
fs: fs,
@@ -342,13 +345,13 @@ class FlutterPreSubmitFileComparator extends FlutterGoldenFileComparator {
342345
/// Creates a [FlutterPreSubmitFileComparator] that will test golden file
343346
/// images against baselines requested from Flutter Gold.
344347
///
345-
/// The [fs] and [platform] parameters are useful in tests, where the default
346-
/// file system and platform can be replaced by mock instances.
348+
/// The [fs] parameter is useful in tests, where the default
349+
/// file system can be replaced by mock instances.
347350
FlutterPreSubmitFileComparator(
348351
super.basedir,
349352
super.skiaClient, {
350353
required super.fs,
351-
super.platform,
354+
required super.platform,
352355
super.namePrefix,
353356
required super.log,
354357
});
@@ -357,18 +360,18 @@ class FlutterPreSubmitFileComparator extends FlutterGoldenFileComparator {
357360
/// relative path resolution of the default [goldenFileComparator].
358361
///
359362
/// The [goldens] parameter is visible for testing purposes only.
360-
static Future<FlutterGoldenFileComparator> fromLocalFileComparator(
361-
final Platform platform, {
363+
static Future<FlutterGoldenFileComparator> fromLocalFileComparator({
362364
SkiaGoldClient? goldens,
363365
required LocalFileComparator localFileComparator,
366+
required Platform platform,
364367
Directory? testBasedir,
365368
String? namePrefix,
366369
required LogCallback log,
367370
required FileSystem fs,
368371
}) async {
369372
final Directory baseDirectory = testBasedir ?? FlutterGoldenFileComparator.getBaseDirectory(
370373
localFileComparator,
371-
platform,
374+
platform: platform,
372375
suffix: 'flutter_goldens_presubmit.',
373376
fs: fs,
374377
);
@@ -377,12 +380,17 @@ class FlutterPreSubmitFileComparator extends FlutterGoldenFileComparator {
377380
baseDirectory.createSync(recursive: true);
378381
}
379382

380-
goldens ??= SkiaGoldClient(baseDirectory, log: log);
383+
goldens ??= SkiaGoldClient(
384+
baseDirectory,
385+
platform: platform,
386+
log: log,
387+
);
381388

382389
await goldens.auth();
383390
return FlutterPreSubmitFileComparator(
384391
baseDirectory.uri,
385-
goldens, platform: platform,
392+
goldens,
393+
platform: platform,
386394
namePrefix: namePrefix,
387395
log: log,
388396
fs: fs,
@@ -439,6 +447,7 @@ class FlutterSkippingFileComparator extends FlutterGoldenFileComparator {
439447
super.skiaClient,
440448
this.reason, {
441449
super.namePrefix,
450+
required super.platform,
442451
required super.log,
443452
required super.fs,
444453
});
@@ -452,16 +461,22 @@ class FlutterSkippingFileComparator extends FlutterGoldenFileComparator {
452461
String reason, {
453462
required LocalFileComparator localFileComparator,
454463
String? namePrefix,
464+
required Platform platform,
455465
required LogCallback log,
456466
required FileSystem fs,
457467
}) {
458468
final Uri basedir = localFileComparator.basedir;
459-
final SkiaGoldClient skiaClient = SkiaGoldClient(fs.directory(basedir), log: log);
469+
final SkiaGoldClient skiaClient = SkiaGoldClient(
470+
fs.directory(basedir),
471+
platform: platform,
472+
log: log,
473+
);
460474
return FlutterSkippingFileComparator(
461475
basedir,
462476
skiaClient,
463477
reason,
464478
namePrefix: namePrefix,
479+
platform: platform,
465480
log: log,
466481
fs: fs,
467482
);
@@ -519,13 +534,13 @@ class FlutterLocalFileComparator extends FlutterGoldenFileComparator with LocalC
519534
/// Creates a [FlutterLocalFileComparator] that will test golden file
520535
/// images against baselines requested from Flutter Gold.
521536
///
522-
/// The [fs] and [platform] parameters are useful in tests, where the default
523-
/// file system and platform can be replaced by mock instances.
537+
/// The [fs] parameter is useful in tests, where the default
538+
/// file system can be replaced by mock instances.
524539
FlutterLocalFileComparator(
525540
super.basedir,
526541
super.skiaClient, {
527542
required super.fs,
528-
super.platform,
543+
required super.platform,
529544
required super.log,
530545
});
531546

@@ -534,25 +549,29 @@ class FlutterLocalFileComparator extends FlutterGoldenFileComparator with LocalC
534549
///
535550
/// The [goldens] and [baseDirectory] parameters are
536551
/// visible for testing purposes only.
537-
static Future<FlutterGoldenFileComparator> fromLocalFileComparator(
538-
final Platform platform, {
552+
static Future<FlutterGoldenFileComparator> fromLocalFileComparator({
539553
SkiaGoldClient? goldens,
540554
required LocalFileComparator localFileComparator,
555+
required Platform platform,
541556
Directory? baseDirectory,
542557
required LogCallback log,
543558
required FileSystem fs,
544559
}) async {
545560
baseDirectory ??= FlutterGoldenFileComparator.getBaseDirectory(
546561
localFileComparator,
547-
platform,
562+
platform: platform,
548563
fs: fs,
549564
);
550565

551566
if (!baseDirectory.existsSync()) {
552567
baseDirectory.createSync(recursive: true);
553568
}
554569

555-
goldens ??= SkiaGoldClient(baseDirectory, log: log);
570+
goldens ??= SkiaGoldClient(
571+
baseDirectory,
572+
platform: platform,
573+
log: log,
574+
);
556575
try {
557576
// Check if we can reach Gold.
558577
await goldens.getExpectationForTest('');
@@ -562,6 +581,7 @@ class FlutterLocalFileComparator extends FlutterGoldenFileComparator with LocalC
562581
goldens,
563582
'OSError occurred, could not reach Gold. '
564583
'Switching to FlutterSkippingGoldenFileComparator.',
584+
platform: platform,
565585
log: log,
566586
fs: fs,
567587
);
@@ -571,6 +591,7 @@ class FlutterLocalFileComparator extends FlutterGoldenFileComparator with LocalC
571591
goldens,
572592
'SocketException occurred, could not reach Gold. '
573593
'Switching to FlutterSkippingGoldenFileComparator.',
594+
platform: platform,
574595
log: log,
575596
fs: fs,
576597
);
@@ -580,6 +601,7 @@ class FlutterLocalFileComparator extends FlutterGoldenFileComparator with LocalC
580601
goldens,
581602
'FormatException occurred, could not reach Gold. '
582603
'Switching to FlutterSkippingGoldenFileComparator.',
604+
platform: platform,
583605
log: log,
584606
fs: fs,
585607
);
@@ -588,6 +610,7 @@ class FlutterLocalFileComparator extends FlutterGoldenFileComparator with LocalC
588610
return FlutterLocalFileComparator(
589611
baseDirectory.uri,
590612
goldens,
613+
platform: platform,
591614
log: log,
592615
fs: fs,
593616
);

packages/flutter_goldens/lib/skia_client.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ class SkiaException implements Exception {
4444
/// A client for uploading image tests and making baseline requests to the
4545
/// Flutter Gold Dashboard.
4646
class SkiaGoldClient {
47-
/// Creates a [SkiaGoldClient] with the given [workDirectory].
47+
/// Creates a [SkiaGoldClient] with the given [workDirectory] and [Platform].
4848
///
4949
/// All other parameters are optional. They may be provided in tests to
50-
/// override the defaults for [fs], [process], [platform], and [httpClient].
50+
/// override the defaults for [fs], [process], and [httpClient].
5151
SkiaGoldClient(
5252
this.workDirectory, {
5353
this.fs = const LocalFileSystem(),
5454
this.process = const LocalProcessManager(),
55-
this.platform = const LocalPlatform(),
55+
required this.platform,
5656
Abi? abi,
5757
io.HttpClient? httpClient,
5858
required this.log,
@@ -65,10 +65,8 @@ class SkiaGoldClient {
6565
/// replaced by a memory file system.
6666
final FileSystem fs;
6767

68-
/// A wrapper for the [dart:io.Platform] API.
69-
///
70-
/// This is useful in tests, where the system platform (the default) can be
71-
/// replaced by a mock platform instance.
68+
/// The environment (current working directory, identity of the OS,
69+
/// environment variables, etc).
7270
final Platform platform;
7371

7472
/// A controller for launching sub-processes.

packages/flutter_goldens/test/flutter_goldens_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ void main() {
716716
defaultComparator.basedir = flutterRoot.childDirectory('baz').uri;
717717
final Directory basedir = FlutterGoldenFileComparator.getBaseDirectory(
718718
defaultComparator,
719-
platform,
719+
platform: platform,
720720
fs: fs,
721721
);
722722
expect(
@@ -854,7 +854,7 @@ void main() {
854854
expect(fakeSkiaClient.initCalls, 0);
855855
FlutterPostSubmitFileComparator.fromLocalFileComparator(
856856
localFileComparator: LocalFileComparator(Uri.parse('/test'), pathStyle: path.Style.posix),
857-
platform,
857+
platform: platform,
858858
goldens: fakeSkiaClient,
859859
log: (String message) => fail('skia gold client printed unexpected output: "$message"'),
860860
fs: fs,
@@ -940,7 +940,7 @@ void main() {
940940
expect(fakeSkiaClient.tryInitCalls, 0);
941941
FlutterPostSubmitFileComparator.fromLocalFileComparator(
942942
localFileComparator: LocalFileComparator(Uri.parse('/test'), pathStyle: path.Style.posix),
943-
platform,
943+
platform: platform,
944944
goldens: fakeSkiaClient,
945945
log: (String message) => fail('skia gold client printed unexpected output: "$message"'),
946946
fs: fs,
@@ -1042,7 +1042,7 @@ void main() {
10421042
fakeSkiaClient.getExpectationForTestThrowable = const OSError("Can't reach Gold");
10431043
final FlutterGoldenFileComparator comparator1 = await FlutterLocalFileComparator.fromLocalFileComparator(
10441044
localFileComparator: LocalFileComparator(Uri.parse('/test'), pathStyle: path.Style.posix),
1045-
platform,
1045+
platform: platform,
10461046
goldens: fakeSkiaClient,
10471047
baseDirectory: fakeDirectory,
10481048
log: (String message) => fail('skia gold client printed unexpected output: "$message"'),
@@ -1053,7 +1053,7 @@ void main() {
10531053
fakeSkiaClient.getExpectationForTestThrowable = const SocketException("Can't reach Gold");
10541054
final FlutterGoldenFileComparator comparator2 = await FlutterLocalFileComparator.fromLocalFileComparator(
10551055
localFileComparator: LocalFileComparator(Uri.parse('/test'), pathStyle: path.Style.posix),
1056-
platform,
1056+
platform: platform,
10571057
goldens: fakeSkiaClient,
10581058
baseDirectory: fakeDirectory,
10591059
log: (String message) => fail('skia gold client printed unexpected output: "$message"'),
@@ -1064,7 +1064,7 @@ void main() {
10641064
fakeSkiaClient.getExpectationForTestThrowable = const FormatException("Can't reach Gold");
10651065
final FlutterGoldenFileComparator comparator3 = await FlutterLocalFileComparator.fromLocalFileComparator(
10661066
localFileComparator: LocalFileComparator(Uri.parse('/test'), pathStyle: path.Style.posix),
1067-
platform,
1067+
platform: platform,
10681068
goldens: fakeSkiaClient,
10691069
baseDirectory: fakeDirectory,
10701070
log: (String message) => fail('skia gold client printed unexpected output: "$message"'),

0 commit comments

Comments
 (0)