mirror of
https://github.com/flutter/flutter
synced 2024-08-25 02:46:31 +00:00
Remove hidden dependencies on the default goldenFileComparator. (#146956)
This is part 12 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.
This commit is contained in:
parent
5a63b1df95
commit
a2a54fe47f
|
@ -57,21 +57,24 @@ Future<void> testExecutable(FutureOr<void> Function() testMain, {String? namePre
|
||||||
const Platform platform = LocalPlatform();
|
const Platform platform = LocalPlatform();
|
||||||
const FileSystem fs = LocalFileSystem();
|
const FileSystem fs = LocalFileSystem();
|
||||||
if (FlutterPostSubmitFileComparator.isForEnvironment(platform)) {
|
if (FlutterPostSubmitFileComparator.isForEnvironment(platform)) {
|
||||||
goldenFileComparator = await FlutterPostSubmitFileComparator.fromDefaultComparator(
|
goldenFileComparator = await FlutterPostSubmitFileComparator.fromLocalFileComparator(
|
||||||
|
localFileComparator: goldenFileComparator as LocalFileComparator,
|
||||||
platform,
|
platform,
|
||||||
namePrefix: namePrefix,
|
namePrefix: namePrefix,
|
||||||
log: print,
|
log: print,
|
||||||
fs: fs,
|
fs: fs,
|
||||||
);
|
);
|
||||||
} else if (FlutterPreSubmitFileComparator.isForEnvironment(platform)) {
|
} else if (FlutterPreSubmitFileComparator.isForEnvironment(platform)) {
|
||||||
goldenFileComparator = await FlutterPreSubmitFileComparator.fromDefaultComparator(
|
goldenFileComparator = await FlutterPreSubmitFileComparator.fromLocalFileComparator(
|
||||||
|
localFileComparator: goldenFileComparator as LocalFileComparator,
|
||||||
platform,
|
platform,
|
||||||
namePrefix: namePrefix,
|
namePrefix: namePrefix,
|
||||||
log: print,
|
log: print,
|
||||||
fs: fs,
|
fs: fs,
|
||||||
);
|
);
|
||||||
} else if (FlutterSkippingFileComparator.isForEnvironment(platform)) {
|
} else if (FlutterSkippingFileComparator.isForEnvironment(platform)) {
|
||||||
goldenFileComparator = FlutterSkippingFileComparator.fromDefaultComparator(
|
goldenFileComparator = FlutterSkippingFileComparator.fromLocalFileComparator(
|
||||||
|
localFileComparator: goldenFileComparator as LocalFileComparator,
|
||||||
'Golden file testing is not executed on Cirrus, or LUCI environments '
|
'Golden file testing is not executed on Cirrus, or LUCI environments '
|
||||||
'outside of flutter/flutter, or in test shards that are not configured '
|
'outside of flutter/flutter, or in test shards that are not configured '
|
||||||
'for using goldctl.',
|
'for using goldctl.',
|
||||||
|
@ -80,7 +83,8 @@ Future<void> testExecutable(FutureOr<void> Function() testMain, {String? namePre
|
||||||
fs: fs,
|
fs: fs,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
goldenFileComparator = await FlutterLocalFileComparator.fromDefaultComparator(
|
goldenFileComparator = await FlutterLocalFileComparator.fromLocalFileComparator(
|
||||||
|
localFileComparator: goldenFileComparator as LocalFileComparator,
|
||||||
platform,
|
platform,
|
||||||
log: print,
|
log: print,
|
||||||
fs: fs,
|
fs: fs,
|
||||||
|
@ -268,21 +272,19 @@ class FlutterPostSubmitFileComparator extends FlutterGoldenFileComparator {
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Creates a new [FlutterPostSubmitFileComparator] that mirrors the relative
|
/// Creates a new [FlutterPostSubmitFileComparator] that mirrors the relative
|
||||||
/// path resolution of the default [goldenFileComparator].
|
/// path resolution of the provided `localFileComparator`.
|
||||||
///
|
///
|
||||||
/// The [goldens] and [defaultComparator] parameters are visible for testing
|
/// The [goldens] parameter is visible for testing purposes only.
|
||||||
/// purposes only.
|
static Future<FlutterPostSubmitFileComparator> fromLocalFileComparator(
|
||||||
static Future<FlutterPostSubmitFileComparator> fromDefaultComparator(
|
|
||||||
final Platform platform, {
|
final Platform platform, {
|
||||||
SkiaGoldClient? goldens,
|
SkiaGoldClient? goldens,
|
||||||
LocalFileComparator? defaultComparator,
|
required LocalFileComparator localFileComparator,
|
||||||
String? namePrefix,
|
String? namePrefix,
|
||||||
required LogCallback log,
|
required LogCallback log,
|
||||||
required FileSystem fs,
|
required FileSystem fs,
|
||||||
}) async {
|
}) async {
|
||||||
defaultComparator ??= goldenFileComparator as LocalFileComparator;
|
|
||||||
final Directory baseDirectory = FlutterGoldenFileComparator.getBaseDirectory(
|
final Directory baseDirectory = FlutterGoldenFileComparator.getBaseDirectory(
|
||||||
defaultComparator,
|
localFileComparator,
|
||||||
platform,
|
platform,
|
||||||
suffix: 'flutter_goldens_postsubmit.',
|
suffix: 'flutter_goldens_postsubmit.',
|
||||||
fs: fs,
|
fs: fs,
|
||||||
|
@ -354,20 +356,18 @@ class FlutterPreSubmitFileComparator extends FlutterGoldenFileComparator {
|
||||||
/// Creates a new [FlutterPreSubmitFileComparator] that mirrors the
|
/// Creates a new [FlutterPreSubmitFileComparator] that mirrors the
|
||||||
/// relative path resolution of the default [goldenFileComparator].
|
/// relative path resolution of the default [goldenFileComparator].
|
||||||
///
|
///
|
||||||
/// The [goldens] and [defaultComparator] parameters are visible for testing
|
/// The [goldens] parameter is visible for testing purposes only.
|
||||||
/// purposes only.
|
static Future<FlutterGoldenFileComparator> fromLocalFileComparator(
|
||||||
static Future<FlutterGoldenFileComparator> fromDefaultComparator(
|
|
||||||
final Platform platform, {
|
final Platform platform, {
|
||||||
SkiaGoldClient? goldens,
|
SkiaGoldClient? goldens,
|
||||||
LocalFileComparator? defaultComparator,
|
required LocalFileComparator localFileComparator,
|
||||||
Directory? testBasedir,
|
Directory? testBasedir,
|
||||||
String? namePrefix,
|
String? namePrefix,
|
||||||
required LogCallback log,
|
required LogCallback log,
|
||||||
required FileSystem fs,
|
required FileSystem fs,
|
||||||
}) async {
|
}) async {
|
||||||
defaultComparator ??= goldenFileComparator as LocalFileComparator;
|
|
||||||
final Directory baseDirectory = testBasedir ?? FlutterGoldenFileComparator.getBaseDirectory(
|
final Directory baseDirectory = testBasedir ?? FlutterGoldenFileComparator.getBaseDirectory(
|
||||||
defaultComparator,
|
localFileComparator,
|
||||||
platform,
|
platform,
|
||||||
suffix: 'flutter_goldens_presubmit.',
|
suffix: 'flutter_goldens_presubmit.',
|
||||||
fs: fs,
|
fs: fs,
|
||||||
|
@ -447,16 +447,15 @@ class FlutterSkippingFileComparator extends FlutterGoldenFileComparator {
|
||||||
final String reason;
|
final String reason;
|
||||||
|
|
||||||
/// Creates a new [FlutterSkippingFileComparator] that mirrors the
|
/// Creates a new [FlutterSkippingFileComparator] that mirrors the
|
||||||
/// relative path resolution of the default [goldenFileComparator].
|
/// relative path resolution of the given [localFileComparator].
|
||||||
static FlutterSkippingFileComparator fromDefaultComparator(
|
static FlutterSkippingFileComparator fromLocalFileComparator(
|
||||||
String reason, {
|
String reason, {
|
||||||
LocalFileComparator? defaultComparator,
|
required LocalFileComparator localFileComparator,
|
||||||
String? namePrefix,
|
String? namePrefix,
|
||||||
required LogCallback log,
|
required LogCallback log,
|
||||||
required FileSystem fs,
|
required FileSystem fs,
|
||||||
}) {
|
}) {
|
||||||
defaultComparator ??= goldenFileComparator as LocalFileComparator;
|
final Uri basedir = localFileComparator.basedir;
|
||||||
final Uri basedir = defaultComparator.basedir;
|
|
||||||
final SkiaGoldClient skiaClient = SkiaGoldClient(fs.directory(basedir), log: log);
|
final SkiaGoldClient skiaClient = SkiaGoldClient(fs.directory(basedir), log: log);
|
||||||
return FlutterSkippingFileComparator(
|
return FlutterSkippingFileComparator(
|
||||||
basedir,
|
basedir,
|
||||||
|
@ -531,21 +530,20 @@ class FlutterLocalFileComparator extends FlutterGoldenFileComparator with LocalC
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Creates a new [FlutterLocalFileComparator] that mirrors the
|
/// Creates a new [FlutterLocalFileComparator] that mirrors the
|
||||||
/// relative path resolution of the default [goldenFileComparator].
|
/// relative path resolution of the given [localFileComparator].
|
||||||
///
|
///
|
||||||
/// The [goldens], [defaultComparator], and [baseDirectory] parameters are
|
/// The [goldens] and [baseDirectory] parameters are
|
||||||
/// visible for testing purposes only.
|
/// visible for testing purposes only.
|
||||||
static Future<FlutterGoldenFileComparator> fromDefaultComparator(
|
static Future<FlutterGoldenFileComparator> fromLocalFileComparator(
|
||||||
final Platform platform, {
|
final Platform platform, {
|
||||||
SkiaGoldClient? goldens,
|
SkiaGoldClient? goldens,
|
||||||
LocalFileComparator? defaultComparator,
|
required LocalFileComparator localFileComparator,
|
||||||
Directory? baseDirectory,
|
Directory? baseDirectory,
|
||||||
required LogCallback log,
|
required LogCallback log,
|
||||||
required FileSystem fs,
|
required FileSystem fs,
|
||||||
}) async {
|
}) async {
|
||||||
defaultComparator ??= goldenFileComparator as LocalFileComparator;
|
|
||||||
baseDirectory ??= FlutterGoldenFileComparator.getBaseDirectory(
|
baseDirectory ??= FlutterGoldenFileComparator.getBaseDirectory(
|
||||||
defaultComparator,
|
localFileComparator,
|
||||||
platform,
|
platform,
|
||||||
fs: fs,
|
fs: fs,
|
||||||
);
|
);
|
||||||
|
|
|
@ -13,6 +13,7 @@ import 'package:file/memory.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter_goldens/flutter_goldens.dart';
|
import 'package:flutter_goldens/flutter_goldens.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:path/path.dart' as path;
|
||||||
import 'package:platform/platform.dart';
|
import 'package:platform/platform.dart';
|
||||||
import 'package:process/process.dart';
|
import 'package:process/process.dart';
|
||||||
|
|
||||||
|
@ -851,7 +852,8 @@ void main() {
|
||||||
fs.directory(_kFlutterRoot).createSync(recursive: true);
|
fs.directory(_kFlutterRoot).createSync(recursive: true);
|
||||||
final FakeSkiaGoldClient fakeSkiaClient = FakeSkiaGoldClient();
|
final FakeSkiaGoldClient fakeSkiaClient = FakeSkiaGoldClient();
|
||||||
expect(fakeSkiaClient.initCalls, 0);
|
expect(fakeSkiaClient.initCalls, 0);
|
||||||
FlutterPostSubmitFileComparator.fromDefaultComparator(
|
FlutterPostSubmitFileComparator.fromLocalFileComparator(
|
||||||
|
localFileComparator: LocalFileComparator(Uri.parse('/test'), pathStyle: path.Style.posix),
|
||||||
platform,
|
platform,
|
||||||
goldens: fakeSkiaClient,
|
goldens: fakeSkiaClient,
|
||||||
log: (String message) => fail('skia gold client printed unexpected output: "$message"'),
|
log: (String message) => fail('skia gold client printed unexpected output: "$message"'),
|
||||||
|
@ -936,7 +938,8 @@ void main() {
|
||||||
fs.directory(_kFlutterRoot).createSync(recursive: true);
|
fs.directory(_kFlutterRoot).createSync(recursive: true);
|
||||||
final FakeSkiaGoldClient fakeSkiaClient = FakeSkiaGoldClient();
|
final FakeSkiaGoldClient fakeSkiaClient = FakeSkiaGoldClient();
|
||||||
expect(fakeSkiaClient.tryInitCalls, 0);
|
expect(fakeSkiaClient.tryInitCalls, 0);
|
||||||
FlutterPostSubmitFileComparator.fromDefaultComparator(
|
FlutterPostSubmitFileComparator.fromLocalFileComparator(
|
||||||
|
localFileComparator: LocalFileComparator(Uri.parse('/test'), pathStyle: path.Style.posix),
|
||||||
platform,
|
platform,
|
||||||
goldens: fakeSkiaClient,
|
goldens: fakeSkiaClient,
|
||||||
log: (String message) => fail('skia gold client printed unexpected output: "$message"'),
|
log: (String message) => fail('skia gold client printed unexpected output: "$message"'),
|
||||||
|
@ -1037,7 +1040,8 @@ void main() {
|
||||||
fakeDirectory.uri = Uri.parse('/flutter');
|
fakeDirectory.uri = Uri.parse('/flutter');
|
||||||
|
|
||||||
fakeSkiaClient.getExpectationForTestThrowable = const OSError("Can't reach Gold");
|
fakeSkiaClient.getExpectationForTestThrowable = const OSError("Can't reach Gold");
|
||||||
final FlutterGoldenFileComparator comparator1 = await FlutterLocalFileComparator.fromDefaultComparator(
|
final FlutterGoldenFileComparator comparator1 = await FlutterLocalFileComparator.fromLocalFileComparator(
|
||||||
|
localFileComparator: LocalFileComparator(Uri.parse('/test'), pathStyle: path.Style.posix),
|
||||||
platform,
|
platform,
|
||||||
goldens: fakeSkiaClient,
|
goldens: fakeSkiaClient,
|
||||||
baseDirectory: fakeDirectory,
|
baseDirectory: fakeDirectory,
|
||||||
|
@ -1047,7 +1051,8 @@ void main() {
|
||||||
expect(comparator1.runtimeType, FlutterSkippingFileComparator);
|
expect(comparator1.runtimeType, FlutterSkippingFileComparator);
|
||||||
|
|
||||||
fakeSkiaClient.getExpectationForTestThrowable = const SocketException("Can't reach Gold");
|
fakeSkiaClient.getExpectationForTestThrowable = const SocketException("Can't reach Gold");
|
||||||
final FlutterGoldenFileComparator comparator2 = await FlutterLocalFileComparator.fromDefaultComparator(
|
final FlutterGoldenFileComparator comparator2 = await FlutterLocalFileComparator.fromLocalFileComparator(
|
||||||
|
localFileComparator: LocalFileComparator(Uri.parse('/test'), pathStyle: path.Style.posix),
|
||||||
platform,
|
platform,
|
||||||
goldens: fakeSkiaClient,
|
goldens: fakeSkiaClient,
|
||||||
baseDirectory: fakeDirectory,
|
baseDirectory: fakeDirectory,
|
||||||
|
@ -1057,7 +1062,8 @@ void main() {
|
||||||
expect(comparator2.runtimeType, FlutterSkippingFileComparator);
|
expect(comparator2.runtimeType, FlutterSkippingFileComparator);
|
||||||
|
|
||||||
fakeSkiaClient.getExpectationForTestThrowable = const FormatException("Can't reach Gold");
|
fakeSkiaClient.getExpectationForTestThrowable = const FormatException("Can't reach Gold");
|
||||||
final FlutterGoldenFileComparator comparator3 = await FlutterLocalFileComparator.fromDefaultComparator(
|
final FlutterGoldenFileComparator comparator3 = await FlutterLocalFileComparator.fromLocalFileComparator(
|
||||||
|
localFileComparator: LocalFileComparator(Uri.parse('/test'), pathStyle: path.Style.posix),
|
||||||
platform,
|
platform,
|
||||||
goldens: fakeSkiaClient,
|
goldens: fakeSkiaClient,
|
||||||
baseDirectory: fakeDirectory,
|
baseDirectory: fakeDirectory,
|
||||||
|
|
Loading…
Reference in a new issue