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