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

Migrate some flutter_tools tests to null safety (#88850)

parent 59f3f23a
...@@ -187,7 +187,7 @@ Future<Map<String, String>?> getCodeSigningIdentityDevelopmentTeam({ ...@@ -187,7 +187,7 @@ Future<Map<String, String>?> getCodeSigningIdentityDevelopmentTeam({
final String opensslOutput = await utf8.decodeStream(opensslProcess.stdout); final String opensslOutput = await utf8.decodeStream(opensslProcess.stdout);
// Fire and forget discard of the stderr stream so we don't hold onto resources. // Fire and forget discard of the stderr stream so we don't hold onto resources.
// Don't care about the result. // Don't care about the result.
unawaited(opensslProcess.stderr.drain<String>()); unawaited(opensslProcess.stderr.drain<String?>());
if (await opensslProcess.exitCode != 0) { if (await opensslProcess.exitCode != 0) {
return null; return 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:io' as io; // flutter_ignore: dart_io_import; import 'dart:io' as io; // flutter_ignore: dart_io_import;
import 'package:file/file.dart'; import 'package:file/file.dart';
...@@ -103,7 +101,7 @@ void main() { ...@@ -103,7 +101,7 @@ void main() {
const int kUserPermissionDenied = 5; const int kUserPermissionDenied = 5;
const int kFatalDeviceHardwareError = 483; const int kFatalDeviceHardwareError = 483;
FileExceptionHandler exceptionHandler; late FileExceptionHandler exceptionHandler;
setUp(() { setUp(() {
exceptionHandler = FileExceptionHandler(); exceptionHandler = FileExceptionHandler();
...@@ -340,7 +338,7 @@ void main() { ...@@ -340,7 +338,7 @@ void main() {
testWithoutContext('When reading from a file or directory without permission', () { testWithoutContext('When reading from a file or directory without permission', () {
final ErrorHandlingFileSystem fileSystem = ErrorHandlingFileSystem( final ErrorHandlingFileSystem fileSystem = ErrorHandlingFileSystem(
delegate: ThrowsOnCurrentDirectoryFileSystem()..errorCode = kUserPermissionDenied, delegate: ThrowsOnCurrentDirectoryFileSystem(kUserPermissionDenied),
platform: windowsPlatform, platform: windowsPlatform,
); );
...@@ -354,7 +352,7 @@ void main() { ...@@ -354,7 +352,7 @@ void main() {
const int enospc = 28; const int enospc = 28;
const int eacces = 13; const int eacces = 13;
FileExceptionHandler exceptionHandler; late FileExceptionHandler exceptionHandler;
setUp(() { setUp(() {
exceptionHandler = FileExceptionHandler(); exceptionHandler = FileExceptionHandler();
...@@ -531,7 +529,7 @@ void main() { ...@@ -531,7 +529,7 @@ void main() {
testWithoutContext('When the current working directory disappears', () async { testWithoutContext('When the current working directory disappears', () async {
final ErrorHandlingFileSystem fileSystem = ErrorHandlingFileSystem( final ErrorHandlingFileSystem fileSystem = ErrorHandlingFileSystem(
delegate: ThrowsOnCurrentDirectoryFileSystem()..errorCode = kSystemCannotFindFile, delegate: ThrowsOnCurrentDirectoryFileSystem(kSystemCannotFindFile),
platform: linuxPlatform, platform: linuxPlatform,
); );
...@@ -560,7 +558,7 @@ void main() { ...@@ -560,7 +558,7 @@ void main() {
const int eperm = 1; const int eperm = 1;
const int enospc = 28; const int enospc = 28;
const int eacces = 13; const int eacces = 13;
FileExceptionHandler exceptionHandler; late FileExceptionHandler exceptionHandler;
setUp(() { setUp(() {
exceptionHandler = FileExceptionHandler(); exceptionHandler = FileExceptionHandler();
...@@ -754,7 +752,7 @@ void main() { ...@@ -754,7 +752,7 @@ void main() {
testWithoutContext('When reading from current directory without permission', () { testWithoutContext('When reading from current directory without permission', () {
final ErrorHandlingFileSystem fileSystem = ErrorHandlingFileSystem( final ErrorHandlingFileSystem fileSystem = ErrorHandlingFileSystem(
delegate: ThrowsOnCurrentDirectoryFileSystem()..errorCode = eacces, delegate: ThrowsOnCurrentDirectoryFileSystem(eacces),
platform: linuxPlatform, platform: linuxPlatform,
); );
...@@ -781,11 +779,9 @@ void main() { ...@@ -781,11 +779,9 @@ void main() {
); );
final Object firstPath = fs.path; final Object firstPath = fs.path;
expect(firstPath, isNotNull);
fs.currentDirectory = null; fs.currentDirectory = null;
// For fs.path.absolute usage.
fileSystem.path = MemoryFileSystem.test().path;
expect(identical(firstPath, fs.path), false); expect(identical(firstPath, fs.path), false);
}); });
...@@ -1089,8 +1085,8 @@ void main() { ...@@ -1089,8 +1085,8 @@ void main() {
group('CopySync' , () { group('CopySync' , () {
const int eaccess = 13; const int eaccess = 13;
FileExceptionHandler exceptionHandler; late FileExceptionHandler exceptionHandler;
ErrorHandlingFileSystem fileSystem; late ErrorHandlingFileSystem fileSystem;
setUp(() { setUp(() {
exceptionHandler = FileExceptionHandler(); exceptionHandler = FileExceptionHandler();
...@@ -1191,20 +1187,22 @@ class ThrowingFakeProcessManager extends Fake implements ProcessManager { ...@@ -1191,20 +1187,22 @@ class ThrowingFakeProcessManager extends Fake implements ProcessManager {
final Exception _exception; final Exception _exception;
@override @override
bool canRun(dynamic executable, {String workingDirectory}) { bool canRun(dynamic executable, {String? workingDirectory}) {
throw _exception; throw _exception;
} }
} }
class ThrowsOnCurrentDirectoryFileSystem extends Fake implements FileSystem { class ThrowsOnCurrentDirectoryFileSystem extends Fake implements FileSystem {
int errorCode; ThrowsOnCurrentDirectoryFileSystem(this.errorCode);
final int errorCode;
@override @override
Directory get currentDirectory => throw FileSystemException('', '', OSError('', errorCode)); Directory get currentDirectory => throw FileSystemException('', '', OSError('', errorCode));
} }
class FakeExistsFile extends Fake implements File { class FakeExistsFile extends Fake implements File {
Object error; late Object error;
int existsCount = 0; int existsCount = 0;
...@@ -1225,10 +1223,7 @@ class FakeExistsFile extends Fake implements File { ...@@ -1225,10 +1223,7 @@ class FakeExistsFile extends Fake implements File {
class FakeFileSystem extends Fake implements FileSystem { class FakeFileSystem extends Fake implements FileSystem {
@override @override
p.Context path; p.Context get path => p.Context();
@override
Directory get currentDirectory => null;
@override @override
set currentDirectory(dynamic path) { } set currentDirectory(dynamic path) { }
......
...@@ -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 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
...@@ -16,8 +14,8 @@ import '../../src/fakes.dart'; ...@@ -16,8 +14,8 @@ import '../../src/fakes.dart';
void main() { void main() {
group('process exceptions', () { group('process exceptions', () {
FakeProcessManager fakeProcessManager; late FakeProcessManager fakeProcessManager;
ProcessUtils processUtils; late ProcessUtils processUtils;
setUp(() { setUp(() {
fakeProcessManager = FakeProcessManager.empty(); fakeProcessManager = FakeProcessManager.empty();
...@@ -42,7 +40,7 @@ void main() { ...@@ -42,7 +40,7 @@ void main() {
group('shutdownHooks', () { group('shutdownHooks', () {
testWithoutContext('runInExpectedOrder', () async { testWithoutContext('runInExpectedOrder', () async {
int i = 1; int i = 1;
int cleanup; int? cleanup;
final ShutdownHooks shutdownHooks = ShutdownHooks(logger: BufferLogger.test()); final ShutdownHooks shutdownHooks = ShutdownHooks(logger: BufferLogger.test());
...@@ -57,9 +55,9 @@ void main() { ...@@ -57,9 +55,9 @@ void main() {
}); });
group('output formatting', () { group('output formatting', () {
FakeProcessManager processManager; late FakeProcessManager processManager;
ProcessUtils processUtils; late ProcessUtils processUtils;
BufferLogger logger; late BufferLogger logger;
setUp(() { setUp(() {
processManager = FakeProcessManager.empty(); processManager = FakeProcessManager.empty();
...@@ -104,8 +102,8 @@ void main() { ...@@ -104,8 +102,8 @@ void main() {
}); });
group('run', () { group('run', () {
FakeProcessManager fakeProcessManager; late FakeProcessManager fakeProcessManager;
ProcessUtils processUtils; late ProcessUtils processUtils;
setUp(() { setUp(() {
fakeProcessManager = FakeProcessManager.empty(); fakeProcessManager = FakeProcessManager.empty();
...@@ -180,9 +178,9 @@ void main() { ...@@ -180,9 +178,9 @@ void main() {
}); });
group('runSync', () { group('runSync', () {
FakeProcessManager fakeProcessManager; late FakeProcessManager fakeProcessManager;
ProcessUtils processUtils; late ProcessUtils processUtils;
BufferLogger testLogger; late BufferLogger testLogger;
setUp(() { setUp(() {
fakeProcessManager = FakeProcessManager.empty(); fakeProcessManager = FakeProcessManager.empty();
...@@ -331,8 +329,8 @@ void main() { ...@@ -331,8 +329,8 @@ void main() {
}); });
group('exitsHappySync', () { group('exitsHappySync', () {
FakeProcessManager processManager; late FakeProcessManager processManager;
ProcessUtils processUtils; late ProcessUtils processUtils;
setUp(() { setUp(() {
processManager = FakeProcessManager.empty(); processManager = FakeProcessManager.empty();
...@@ -388,8 +386,8 @@ void main() { ...@@ -388,8 +386,8 @@ void main() {
}); });
group('exitsHappy', () { group('exitsHappy', () {
FakeProcessManager processManager; late FakeProcessManager processManager;
ProcessUtils processUtils; late ProcessUtils processUtils;
setUp(() { setUp(() {
processManager = FakeProcessManager.empty(); processManager = FakeProcessManager.empty();
......
...@@ -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 'package:flutter_tools/src/build_system/build_system.dart'; import 'package:flutter_tools/src/build_system/build_system.dart';
import '../../src/common.dart'; import '../../src/common.dart';
......
...@@ -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 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
......
...@@ -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 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/logger.dart';
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +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.
import 'dart:async'; import 'dart:async';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
......
...@@ -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';
...@@ -25,9 +23,9 @@ const String kCertificates = ''' ...@@ -25,9 +23,9 @@ const String kCertificates = '''
void main() { void main() {
group('Auto signing', () { group('Auto signing', () {
Config testConfig; late Config testConfig;
AnsiTerminal testTerminal; late AnsiTerminal testTerminal;
BufferLogger logger; late BufferLogger logger;
setUp(() async { setUp(() async {
logger = BufferLogger.test(); logger = BufferLogger.test();
...@@ -37,7 +35,7 @@ void main() { ...@@ -37,7 +35,7 @@ void main() {
}); });
testWithoutContext('No auto-sign if Xcode project settings are not available', () async { testWithoutContext('No auto-sign if Xcode project settings are not available', () async {
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam( final Map<String, String>? signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
buildSettings: null, buildSettings: null,
processManager: FakeProcessManager.empty(), processManager: FakeProcessManager.empty(),
logger: logger, logger: logger,
...@@ -48,7 +46,7 @@ void main() { ...@@ -48,7 +46,7 @@ void main() {
}); });
testWithoutContext('No discovery if development team specified in Xcode project', () async { testWithoutContext('No discovery if development team specified in Xcode project', () async {
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam( final Map<String, String>? signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
buildSettings: <String, String>{ buildSettings: <String, String>{
'DEVELOPMENT_TEAM': 'abc', 'DEVELOPMENT_TEAM': 'abc',
}, },
...@@ -71,7 +69,7 @@ void main() { ...@@ -71,7 +69,7 @@ void main() {
), ),
]); ]);
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam( final Map<String, String>? signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
buildSettings: <String, String>{ buildSettings: <String, String>{
'bogus': 'bogus', 'bogus': 'bogus',
}, },
...@@ -135,13 +133,13 @@ void main() { ...@@ -135,13 +133,13 @@ void main() {
]); ]);
// Verify that certifacte value is passed into openssl command. // Verify that certifacte value is passed into openssl command.
String stdin; String? stdin;
controller.stream.listen((List<int> chunk) { controller.stream.listen((List<int> chunk) {
stdin = utf8.decode(chunk); stdin = utf8.decode(chunk);
completer.complete(); completer.complete();
}); });
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam( final Map<String, String>? signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
buildSettings: <String, String>{ buildSettings: <String, String>{
'bogus': 'bogus', 'bogus': 'bogus',
}, },
...@@ -187,13 +185,13 @@ void main() { ...@@ -187,13 +185,13 @@ void main() {
]); ]);
// Verify that certifacte value is passed into openssl command. // Verify that certifacte value is passed into openssl command.
String stdin; String? stdin;
controller.stream.listen((List<int> chunk) { controller.stream.listen((List<int> chunk) {
stdin = utf8.decode(chunk); stdin = utf8.decode(chunk);
completer.complete(); completer.complete();
}); });
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam( final Map<String, String>? signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
buildSettings: <String, String>{ buildSettings: <String, String>{
'bogus': 'bogus', 'bogus': 'bogus',
}, },
...@@ -237,13 +235,13 @@ void main() { ...@@ -237,13 +235,13 @@ void main() {
]); ]);
// Verify that certifacte value is passed into openssl command. // Verify that certifacte value is passed into openssl command.
String stdin; String? stdin;
controller.stream.listen((List<int> chunk) { controller.stream.listen((List<int> chunk) {
stdin = utf8.decode(chunk); stdin = utf8.decode(chunk);
completer.complete(); completer.complete();
}); });
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam( final Map<String, String>? signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
buildSettings: <String, String>{ buildSettings: <String, String>{
'bogus': 'bogus', 'bogus': 'bogus',
}, },
...@@ -295,13 +293,13 @@ void main() { ...@@ -295,13 +293,13 @@ void main() {
]); ]);
// Verify that certifacte value is passed into openssl command. // Verify that certifacte value is passed into openssl command.
String stdin; String? stdin;
controller.stream.listen((List<int> chunk) { controller.stream.listen((List<int> chunk) {
stdin = utf8.decode(chunk); stdin = utf8.decode(chunk);
completer.complete(); completer.complete();
}); });
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam( final Map<String, String>? signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
buildSettings: <String, String>{ buildSettings: <String, String>{
'bogus': 'bogus', 'bogus': 'bogus',
}, },
...@@ -348,13 +346,13 @@ void main() { ...@@ -348,13 +346,13 @@ void main() {
]); ]);
// Verify that certifacte value is passed into openssl command. // Verify that certifacte value is passed into openssl command.
String stdin; String? stdin;
controller.stream.listen((List<int> chunk) { controller.stream.listen((List<int> chunk) {
stdin = utf8.decode(chunk); stdin = utf8.decode(chunk);
completer.complete(); completer.complete();
}); });
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam( final Map<String, String>? signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
buildSettings: <String, String>{ buildSettings: <String, String>{
'bogus': 'bogus', 'bogus': 'bogus',
}, },
...@@ -406,13 +404,13 @@ void main() { ...@@ -406,13 +404,13 @@ void main() {
]); ]);
// Verify that certifacte value is passed into openssl command. // Verify that certifacte value is passed into openssl command.
String stdin; String? stdin;
controller.stream.listen((List<int> chunk) { controller.stream.listen((List<int> chunk) {
stdin = utf8.decode(chunk); stdin = utf8.decode(chunk);
completer.complete(); completer.complete();
}); });
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam( final Map<String, String>? signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
buildSettings: <String, String>{ buildSettings: <String, String>{
'bogus': 'bogus', 'bogus': 'bogus',
}, },
...@@ -449,7 +447,7 @@ void main() { ...@@ -449,7 +447,7 @@ void main() {
), ),
]); ]);
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam( final Map<String, String>? signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
buildSettings: <String, String>{ buildSettings: <String, String>{
'bogus': 'bogus', 'bogus': 'bogus',
}, },
...@@ -481,7 +479,7 @@ void main() { ...@@ -481,7 +479,7 @@ void main() {
), ),
]); ]);
final Map<String, String> signingConfigs = await getCodeSigningIdentityDevelopmentTeam( final Map<String, String>? signingConfigs = await getCodeSigningIdentityDevelopmentTeam(
buildSettings: <String, String>{ buildSettings: <String, String>{
'bogus': 'bogus', 'bogus': 'bogus',
}, },
...@@ -495,7 +493,7 @@ void main() { ...@@ -495,7 +493,7 @@ void main() {
}); });
} }
Stream<String> mockTerminalStdInStream; late Stream<String> mockTerminalStdInStream;
class TestTerminal extends AnsiTerminal { class TestTerminal extends AnsiTerminal {
TestTerminal() : super(stdio: globals.stdio, platform: globals.platform); TestTerminal() : super(stdio: globals.stdio, platform: globals.platform);
......
...@@ -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 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/macos/macos_workflow.dart'; import 'package:flutter_tools/src/macos/macos_workflow.dart';
......
...@@ -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 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:file_testing/file_testing.dart'; import 'package:file_testing/file_testing.dart';
......
...@@ -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 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/project.dart'; import 'package:flutter_tools/src/project.dart';
......
...@@ -2,15 +2,13 @@ ...@@ -2,15 +2,13 @@
// 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 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/convert.dart'; import 'package:flutter_tools/src/convert.dart';
import 'package:flutter_tools/src/custom_devices/custom_device_config.dart'; import 'package:flutter_tools/src/custom_devices/custom_device_config.dart';
void writeCustomDevicesConfigFile( void writeCustomDevicesConfigFile(
Directory dir, { Directory dir, {
List<CustomDeviceConfig> configs, List<CustomDeviceConfig>? configs,
dynamic json dynamic json
}) { }) {
dir.createSync(recursive: true); dir.createSync(recursive: true);
......
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