Unverified Commit f04616f7 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Migrate flutter_goldens to null safety (#74853)

parent 06f051b2
...@@ -671,7 +671,7 @@ Future<void> _runFrameworkTests() async { ...@@ -671,7 +671,7 @@ Future<void> _runFrameworkTests() async {
await _runFlutterTest(path.join(flutterRoot, 'dev', 'benchmarks', 'test_apps', 'stocks')); await _runFlutterTest(path.join(flutterRoot, 'dev', 'benchmarks', 'test_apps', 'stocks'));
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_driver'), tests: <String>[path.join('test', 'src', 'real_tests')]); await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_driver'), tests: <String>[path.join('test', 'src', 'real_tests')]);
await _runFlutterTest(path.join(flutterRoot, 'packages', 'integration_test')); await _runFlutterTest(path.join(flutterRoot, 'packages', 'integration_test'));
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_goldens')); await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_goldens'), options: soundNullSafetyOptions);
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_localizations'), options: soundNullSafetyOptions); await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_localizations'), options: soundNullSafetyOptions);
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_test'), options: soundNullSafetyOptions); await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_test'), options: soundNullSafetyOptions);
await _runFlutterTest(path.join(flutterRoot, 'packages', 'fuchsia_remote_debug_protocol'), options: soundNullSafetyOptions); await _runFlutterTest(path.join(flutterRoot, 'packages', 'fuchsia_remote_debug_protocol'), options: soundNullSafetyOptions);
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'dart:core'; import 'dart:core';
...@@ -49,10 +47,10 @@ Future<void> testWithOutput(String name, Future<void> body(), String expectedOut ...@@ -49,10 +47,10 @@ Future<void> testWithOutput(String name, Future<void> body(), String expectedOut
} }
void main() { void main() {
MemoryFileSystem fs; late MemoryFileSystem fs;
FakePlatform platform; late FakePlatform platform;
FakeProcessManager process; late FakeProcessManager process;
FakeHttpClient fakeHttpClient; late FakeHttpClient fakeHttpClient;
setUp(() { setUp(() {
fs = MemoryFileSystem(); fs = MemoryFileSystem();
...@@ -66,8 +64,8 @@ void main() { ...@@ -66,8 +64,8 @@ void main() {
}); });
group('SkiaGoldClient', () { group('SkiaGoldClient', () {
SkiaGoldClient skiaClient; late SkiaGoldClient skiaClient;
Directory workDirectory; late Directory workDirectory;
setUp(() { setUp(() {
workDirectory = fs.directory('/workDirectory') workDirectory = fs.directory('/workDirectory')
...@@ -144,6 +142,8 @@ void main() { ...@@ -144,6 +142,8 @@ void main() {
httpClient: fakeHttpClient, httpClient: fakeHttpClient,
); );
process.fallbackProcessResult = ProcessResult(123, 1, 'fail', 'fail');
const RunInvocation gitInvocation = RunInvocation( const RunInvocation gitInvocation = RunInvocation(
<String>['git', 'rev-parse', 'HEAD'], <String>['git', 'rev-parse', 'HEAD'],
'/flutter', '/flutter',
...@@ -285,11 +285,7 @@ void main() { ...@@ -285,11 +285,7 @@ void main() {
}); });
group('Request Handling', () { group('Request Handling', () {
String expectation; const String expectation = '55109a4bed52acc780530f7a9aeff6c0';
setUp(() {
expectation = '55109a4bed52acc780530f7a9aeff6c0';
});
test('image bytes are processed properly', () async { test('image bytes are processed properly', () async {
final Uri imageUrl = Uri.parse( final Uri imageUrl = Uri.parse(
...@@ -312,7 +308,7 @@ void main() { ...@@ -312,7 +308,7 @@ void main() {
}); });
group('FlutterGoldenFileComparator', () { group('FlutterGoldenFileComparator', () {
FlutterPostSubmitFileComparator comparator; late FlutterPostSubmitFileComparator comparator;
setUp(() { setUp(() {
final Directory basedir = fs.directory('flutter/test/library/') final Directory basedir = fs.directory('flutter/test/library/')
...@@ -553,7 +549,7 @@ void main() { ...@@ -553,7 +549,7 @@ void main() {
}); });
group('Local', () { group('Local', () {
FlutterLocalFileComparator comparator; late FlutterLocalFileComparator comparator;
final FakeSkiaGoldClient fakeSkiaClient = FakeSkiaGoldClient(); final FakeSkiaGoldClient fakeSkiaClient = FakeSkiaGoldClient();
setUp(() async { setUp(() async {
...@@ -660,7 +656,7 @@ class RunInvocation { ...@@ -660,7 +656,7 @@ class RunInvocation {
const RunInvocation(this.command, this.workingDirectory); const RunInvocation(this.command, this.workingDirectory);
final List<String> command; final List<String> command;
final String workingDirectory; final String? workingDirectory;
@override @override
int get hashCode => hashValues(hashList(command), workingDirectory); int get hashCode => hashValues(hashList(command), workingDirectory);
...@@ -697,69 +693,69 @@ class RunInvocation { ...@@ -697,69 +693,69 @@ class RunInvocation {
class FakeProcessManager extends Fake implements ProcessManager { class FakeProcessManager extends Fake implements ProcessManager {
Map<RunInvocation, ProcessResult> processResults = <RunInvocation, ProcessResult>{}; Map<RunInvocation, ProcessResult> processResults = <RunInvocation, ProcessResult>{};
/// Used if [processResults] does not contain an matching invocation. /// Used if [processResults] does not contain a matching invocation.
ProcessResult fallbackProcessResult; ProcessResult? fallbackProcessResult;
final List<String> workingDirectories = <String>[]; final List<String> workingDirectories = <String>[];
@override @override
Future<ProcessResult> run( Future<ProcessResult> run(
List<dynamic> command, { List<dynamic> command, {
String workingDirectory, String workingDirectory = '',
Map<String, String> environment, Map<String, String> environment = const <String, String>{},
bool includeParentEnvironment = true, bool includeParentEnvironment = true,
bool runInShell = false, bool runInShell = false,
Encoding stdoutEncoding = systemEncoding, Encoding stdoutEncoding = systemEncoding,
Encoding stderrEncoding = systemEncoding, Encoding stderrEncoding = systemEncoding,
}) async { }) async {
workingDirectories.add(workingDirectory); workingDirectories.add(workingDirectory);
final ProcessResult result = processResults[RunInvocation(command.cast<String>(), workingDirectory)]; final ProcessResult? result = processResults[RunInvocation(command.cast<String>(), workingDirectory)];
if (result == null && fallbackProcessResult == null) { if (result == null && fallbackProcessResult == null) {
// Throwing here might gobble up the exception message if a test fails. // Throwing here might gobble up the exception message if a test fails.
print('ProcessManager.run was called with $command ($workingDirectory) unexpectedly - $processResults.'); print('ProcessManager.run was called with $command ($workingDirectory) unexpectedly - $processResults.');
fail('see above'); fail('See above.');
} }
return result ?? fallbackProcessResult; return result ?? fallbackProcessResult!;
} }
} }
class FakeSkiaGoldClient extends Fake implements SkiaGoldClient { class FakeSkiaGoldClient extends Fake implements SkiaGoldClient {
Map<String, String> expectationForTestValues = <String, String>{}; Map<String, String> expectationForTestValues = <String, String>{};
Object getExpectationForTestThrowable; Object? getExpectationForTestThrowable;
@override @override
Future<String> getExpectationForTest(String testName) async { Future<String> getExpectationForTest(String testName) async {
if (getExpectationForTestThrowable != null) { if (getExpectationForTestThrowable != null) {
throw getExpectationForTestThrowable; throw getExpectationForTestThrowable!;
} }
return expectationForTestValues[testName]; return expectationForTestValues[testName] ?? '';
} }
Map<String, List<int>> imageBytesValues = <String, List<int>>{}; Map<String, List<int>> imageBytesValues = <String, List<int>>{};
@override @override
Future<List<int>> getImageBytes(String imageHash) async => imageBytesValues[imageHash]; Future<List<int>> getImageBytes(String imageHash) async => imageBytesValues[imageHash]!;
Map<String, String> cleanTestNameValues = <String, String>{}; Map<String, String> cleanTestNameValues = <String, String>{};
@override @override
String cleanTestName(String fileName) => cleanTestNameValues[fileName]; String cleanTestName(String fileName) => cleanTestNameValues[fileName] ?? '';
} }
class FakeLocalFileComparator extends Fake implements LocalFileComparator { class FakeLocalFileComparator extends Fake implements LocalFileComparator {
@override @override
Uri basedir; late Uri basedir;
} }
class FakeDirectory extends Fake implements Directory { class FakeDirectory extends Fake implements Directory {
bool existsSyncValue; late bool existsSyncValue;
@override @override
bool existsSync() => existsSyncValue; bool existsSync() => existsSyncValue;
@override @override
Uri uri; late Uri uri;
} }
class FakeHttpClient extends Fake implements HttpClient { class FakeHttpClient extends Fake implements HttpClient {
Uri lastUri; late Uri lastUri;
FakeHttpClientRequest request; late FakeHttpClientRequest request;
@override @override
Future<HttpClientRequest> getUrl(Uri url) async { Future<HttpClientRequest> getUrl(Uri url) async {
...@@ -769,7 +765,7 @@ class FakeHttpClient extends Fake implements HttpClient { ...@@ -769,7 +765,7 @@ class FakeHttpClient extends Fake implements HttpClient {
} }
class FakeHttpClientRequest extends Fake implements HttpClientRequest { class FakeHttpClientRequest extends Fake implements HttpClientRequest {
FakeHttpImageResponse response; late FakeHttpImageResponse response;
@override @override
Future<HttpClientResponse> close() async { Future<HttpClientResponse> close() async {
...@@ -784,10 +780,10 @@ class FakeHttpClientResponse extends Fake implements HttpClientResponse { ...@@ -784,10 +780,10 @@ class FakeHttpClientResponse extends Fake implements HttpClientResponse {
@override @override
StreamSubscription<List<int>> listen( StreamSubscription<List<int>> listen(
void onData(List<int> event), { void onData(List<int> event)?, {
Function onError, Function? onError,
void onDone(), void onDone()?,
bool cancelOnError, bool? cancelOnError,
}) { }) {
return Stream<List<int>>.fromFuture(Future<List<int>>.value(response)) return Stream<List<int>>.fromFuture(Future<List<int>>.value(response))
.listen(onData, onError: onError, onDone: onDone, cancelOnError: cancelOnError); .listen(onData, onError: onError, onDone: onDone, cancelOnError: cancelOnError);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment