Unverified Commit e8d46fea authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Start migrating flutter_tools test src to null safety (#79908)

parent 408c52fd
...@@ -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 '../base/file_system.dart'; import '../base/file_system.dart';
...@@ -11,14 +9,14 @@ import '../globals_null_migrated.dart' as globals; ...@@ -11,14 +9,14 @@ import '../globals_null_migrated.dart' as globals;
/// Manages a Font configuration that can be shared across multiple tests. /// Manages a Font configuration that can be shared across multiple tests.
class FontConfigManager { class FontConfigManager {
Directory _fontsDirectory; Directory? _fontsDirectory;
File _cachedFontConfig; File? _cachedFontConfig;
/// Returns a Font configuration that limits font fallback to the artifact /// Returns a Font configuration that limits font fallback to the artifact
/// cache directory. /// cache directory.
File get fontConfigFile { File get fontConfigFile {
if (_cachedFontConfig != null) { if (_cachedFontConfig != null) {
return _cachedFontConfig; return _cachedFontConfig!;
} }
final StringBuffer sb = StringBuffer(); final StringBuffer sb = StringBuffer();
...@@ -29,19 +27,19 @@ class FontConfigManager { ...@@ -29,19 +27,19 @@ class FontConfigManager {
if (_fontsDirectory == null) { if (_fontsDirectory == null) {
_fontsDirectory = globals.fs.systemTempDirectory.createTempSync('flutter_test_fonts.'); _fontsDirectory = globals.fs.systemTempDirectory.createTempSync('flutter_test_fonts.');
globals.printTrace('Using this directory for fonts configuration: ${_fontsDirectory.path}'); globals.printTrace('Using this directory for fonts configuration: ${_fontsDirectory!.path}');
} }
_cachedFontConfig = globals.fs.file('${_fontsDirectory.path}/fonts.conf'); _cachedFontConfig = globals.fs.file('${_fontsDirectory!.path}/fonts.conf');
_cachedFontConfig.createSync(); _cachedFontConfig!.createSync();
_cachedFontConfig.writeAsStringSync(sb.toString()); _cachedFontConfig!.writeAsStringSync(sb.toString());
return _cachedFontConfig; return _cachedFontConfig!;
} }
Future<void> dispose() async { Future<void> dispose() async {
if (_fontsDirectory != null) { if (_fontsDirectory != null) {
globals.printTrace('Deleting ${_fontsDirectory.path}...'); globals.printTrace('Deleting ${_fontsDirectory!.path}...');
await _fontsDirectory.delete(recursive: true); await _fontsDirectory!.delete(recursive: true);
_fontsDirectory = null; _fontsDirectory = null;
} }
} }
......
...@@ -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:convert'; import 'dart:convert';
import 'package:process/process.dart'; import 'package:process/process.dart';
...@@ -39,12 +37,11 @@ bool containsBitcode(String pathToBinary, ProcessManager processManager) { ...@@ -39,12 +37,11 @@ bool containsBitcode(String pathToBinary, ProcessManager processManager) {
final List<String> lines = LineSplitter.split(loadCommands).toList(); final List<String> lines = LineSplitter.split(loadCommands).toList();
lines.asMap().forEach((int index, String line) { lines.asMap().forEach((int index, String line) {
if (line.contains('segname __LLVM') && lines.length - index - 1 > 3) { if (line.contains('segname __LLVM') && lines.length - index - 1 > 3) {
final String emptyBitcodeMarker = final bool bitcodeMarkerFound = lines
lines.skip(index - 1).take(4).firstWhere( .skip(index - 1)
(String line) => line.contains(' size 0x0000000000000001'), .take(4)
orElse: () => null, .any((String line) => line.contains(' size 0x0000000000000001'));
); if (bitcodeMarkerFound) {
if (emptyBitcodeMarker != null) {
emptyBitcodeMarkerFound = true; emptyBitcodeMarkerFound = true;
return; return;
} }
......
...@@ -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';
...@@ -54,8 +52,6 @@ String _toMethodString(HttpMethod method) { ...@@ -54,8 +52,6 @@ String _toMethodString(HttpMethod method) {
case HttpMethod.head: case HttpMethod.head:
return 'HEAD'; return 'HEAD';
} }
assert(false);
return null;
} }
/// Override the creation of all [HttpClient] objects with a zone injection. /// Override the creation of all [HttpClient] objects with a zone injection.
...@@ -73,7 +69,7 @@ class _FakeHttpClientOverrides extends HttpOverrides { ...@@ -73,7 +69,7 @@ class _FakeHttpClientOverrides extends HttpOverrides {
final FakeHttpClient httpClient; final FakeHttpClient httpClient;
@override @override
HttpClient createHttpClient(SecurityContext context) { HttpClient createHttpClient(SecurityContext? context) {
return httpClient; return httpClient;
} }
} }
...@@ -94,7 +90,7 @@ class FakeRequest { ...@@ -94,7 +90,7 @@ class FakeRequest {
final Uri uri; final Uri uri;
final HttpMethod method; final HttpMethod method;
final FakeResponse response; final FakeResponse response;
final dynamic responseError; final Object? responseError;
@override @override
String toString() => 'Request{${_toMethodString(method)}, $uri}'; String toString() => 'Request{${_toMethodString(method)}, $uri}';
...@@ -136,19 +132,19 @@ class FakeHttpClient implements HttpClient { ...@@ -136,19 +132,19 @@ class FakeHttpClient implements HttpClient {
final List<FakeRequest> _requests; final List<FakeRequest> _requests;
@override @override
bool autoUncompress; bool autoUncompress = true;
@override @override
Duration connectionTimeout; Duration? connectionTimeout;
@override @override
Duration idleTimeout; Duration idleTimeout = Duration.zero;
@override @override
int maxConnectionsPerHost; int? maxConnectionsPerHost;
@override @override
String userAgent; String? userAgent;
@override @override
void addCredentials(Uri url, String realm, HttpClientCredentials credentials) { void addCredentials(Uri url, String realm, HttpClientCredentials credentials) {
...@@ -161,17 +157,17 @@ class FakeHttpClient implements HttpClient { ...@@ -161,17 +157,17 @@ class FakeHttpClient implements HttpClient {
} }
@override @override
set authenticate(Future<bool> Function(Uri url, String scheme, String realm) f) { set authenticate(Future<bool> Function(Uri url, String scheme, String realm)? f) {
throw UnimplementedError(); throw UnimplementedError();
} }
@override @override
set authenticateProxy(Future<bool> Function(String host, int port, String scheme, String realm) f) { set authenticateProxy(Future<bool> Function(String host, int port, String scheme, String realm)? f) {
throw UnimplementedError(); throw UnimplementedError();
} }
@override @override
set badCertificateCallback(bool Function(X509Certificate cert, String host, int port) callback) { set badCertificateCallback(bool Function(X509Certificate cert, String host, int port)? callback) {
throw UnimplementedError(); throw UnimplementedError();
} }
...@@ -190,7 +186,7 @@ class FakeHttpClient implements HttpClient { ...@@ -190,7 +186,7 @@ class FakeHttpClient implements HttpClient {
} }
@override @override
set findProxy(String Function(Uri url) f) { } set findProxy(String Function(Uri url)? f) { }
@override @override
Future<HttpClientRequest> get(String host, int port, String path) { Future<HttpClientRequest> get(String host, int port, String path) {
...@@ -276,7 +272,7 @@ class FakeHttpClient implements HttpClient { ...@@ -276,7 +272,7 @@ class FakeHttpClient implements HttpClient {
null, null,
); );
} }
FakeRequest matchedRequest; FakeRequest? matchedRequest;
for (final FakeRequest request in _requests) { for (final FakeRequest request in _requests) {
if (request.method == method && request.uri.toString() == uri.toString()) { if (request.method == method && request.uri.toString() == uri.toString()) {
matchedRequest = request; matchedRequest = request;
...@@ -306,28 +302,28 @@ class _FakeHttpClientRequest implements HttpClientRequest { ...@@ -306,28 +302,28 @@ class _FakeHttpClientRequest implements HttpClientRequest {
final FakeResponse _response; final FakeResponse _response;
final String _method; final String _method;
final Uri _uri; final Uri _uri;
final dynamic _responseError; final Object? _responseError;
@override @override
bool bufferOutput; bool bufferOutput = true;
@override @override
int contentLength = 0; int contentLength = 0;
@override @override
Encoding encoding; late Encoding encoding;
@override @override
bool followRedirects; bool followRedirects = true;
@override @override
int maxRedirects; int maxRedirects = 5;
@override @override
bool persistentConnection; bool persistentConnection = true;
@override @override
void abort([Object exception, StackTrace stackTrace]) { void abort([Object? exception, StackTrace? stackTrace]) {
throw UnimplementedError(); throw UnimplementedError();
} }
...@@ -335,7 +331,7 @@ class _FakeHttpClientRequest implements HttpClientRequest { ...@@ -335,7 +331,7 @@ class _FakeHttpClientRequest implements HttpClientRequest {
void add(List<int> data) { } void add(List<int> data) { }
@override @override
void addError(Object error, [StackTrace stackTrace]) { } void addError(Object error, [StackTrace? stackTrace]) { }
@override @override
Future<void> addStream(Stream<List<int>> stream) async { } Future<void> addStream(Stream<List<int>> stream) async { }
...@@ -343,7 +339,7 @@ class _FakeHttpClientRequest implements HttpClientRequest { ...@@ -343,7 +339,7 @@ class _FakeHttpClientRequest implements HttpClientRequest {
@override @override
Future<HttpClientResponse> close() async { Future<HttpClientResponse> close() async {
if (_responseError != null) { if (_responseError != null) {
return Future<HttpClientResponse>.error(_responseError); return Future<HttpClientResponse>.error(_responseError!);
} }
return _FakeHttpClientResponse(_response); return _FakeHttpClientResponse(_response);
} }
...@@ -370,7 +366,7 @@ class _FakeHttpClientRequest implements HttpClientRequest { ...@@ -370,7 +366,7 @@ class _FakeHttpClientRequest implements HttpClientRequest {
Uri get uri => _uri; Uri get uri => _uri;
@override @override
void write(Object object) { } void write(Object? object) { }
@override @override
void writeAll(Iterable<dynamic> objects, [String separator = '']) { } void writeAll(Iterable<dynamic> objects, [String separator = '']) { }
...@@ -379,7 +375,7 @@ class _FakeHttpClientRequest implements HttpClientRequest { ...@@ -379,7 +375,7 @@ class _FakeHttpClientRequest implements HttpClientRequest {
void writeCharCode(int charCode) { } void writeCharCode(int charCode) { }
@override @override
void writeln([Object object = '']) { } void writeln([Object? object = '']) { }
} }
class _FakeHttpClientResponse extends Stream<List<int>> implements HttpClientResponse { class _FakeHttpClientResponse extends Stream<List<int>> implements HttpClientResponse {
...@@ -416,10 +412,10 @@ class _FakeHttpClientResponse extends Stream<List<int>> implements HttpClientRes ...@@ -416,10 +412,10 @@ class _FakeHttpClientResponse extends Stream<List<int>> implements HttpClientRes
@override @override
StreamSubscription<List<int>> listen( StreamSubscription<List<int>> listen(
void Function(List<int> event) onData, { void Function(List<int> event)? onData, {
Function onError, Function? onError,
void Function() onDone, void Function()? onDone,
bool cancelOnError, bool? cancelOnError,
}) { }) {
final Stream<List<int>> response = Stream<List<int>>.fromIterable(<List<int>>[ final Stream<List<int>> response = Stream<List<int>>.fromIterable(<List<int>>[
_response.body, _response.body,
...@@ -434,7 +430,7 @@ class _FakeHttpClientResponse extends Stream<List<int>> implements HttpClientRes ...@@ -434,7 +430,7 @@ class _FakeHttpClientResponse extends Stream<List<int>> implements HttpClientRes
String get reasonPhrase => 'OK'; String get reasonPhrase => 'OK';
@override @override
Future<HttpClientResponse> redirect([String method, Uri url, bool followLoops]) { Future<HttpClientResponse> redirect([String? method, Uri? url, bool? followLoops]) {
throw UnimplementedError(); throw UnimplementedError();
} }
...@@ -451,12 +447,12 @@ class _FakeHttpHeaders extends HttpHeaders { ...@@ -451,12 +447,12 @@ class _FakeHttpHeaders extends HttpHeaders {
final Map<String, List<String>> _backingData; final Map<String, List<String>> _backingData;
@override @override
List<String> operator [](String name) => _backingData[name]; List<String>? operator [](String name) => _backingData[name];
@override @override
void add(String name, Object value, {bool preserveHeaderCase = false}) { void add(String name, Object value, {bool preserveHeaderCase = false}) {
_backingData[name] ??= <String>[]; _backingData[name] ??= <String>[];
_backingData[name].add(value.toString()); _backingData[name]!.add(value.toString());
} }
@override @override
...@@ -486,7 +482,7 @@ class _FakeHttpHeaders extends HttpHeaders { ...@@ -486,7 +482,7 @@ class _FakeHttpHeaders extends HttpHeaders {
} }
@override @override
String value(String name) { String? value(String name) {
return _backingData[name]?.join('; '); return _backingData[name]?.join('; ');
} }
} }
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