Unverified Commit 3e5f620a authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Convert some general.shard base tests to null safety (#79985)

parent 71e99d29
......@@ -33,4 +33,4 @@ class ToolExit implements Exception {
/// the flutter_tools package. However, there are times where one or more
/// futures are intentionally not awaited. This function may be used to ignore a
/// particular future. It silences the unawaited_futures lint.
void unawaited(Future<void> future) { }
void unawaited(Future<void>? future) { }
......@@ -118,7 +118,7 @@ class AppContext {
if (value == null && _parent != null) {
value = _parent!.get<T>();
}
return _unboxNull(value ?? _generateIfNecessary(T, _fallbacks)) as T;
return _unboxNull(value ?? _generateIfNecessary(T, _fallbacks)) as T?;
}
/// Runs [body] in a child context and returns the value returned by [body].
......
......@@ -2,7 +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';
......@@ -32,7 +31,7 @@ Future<void> syncAndAsyncError() {
Future<void> delayedThrow(FakeAsync time) {
final Future<void> result =
Future<void>.delayed(const Duration(milliseconds: 10))
.then((_) {
.then((_) async {
throw 'Delayed Doom';
});
time.elapse(const Duration(seconds: 1));
......@@ -41,10 +40,10 @@ Future<void> delayedThrow(FakeAsync time) {
}
void main() {
Completer<void> caughtInZone;
late Completer<void> caughtInZone;
bool caughtByZone = false;
bool caughtByHandler = false;
Zone zone;
late Zone zone;
setUp(() {
caughtInZone = Completer<void>();
......@@ -270,7 +269,7 @@ void main() {
unawaited(runZonedGuarded(() async {
final Future<void> f = asyncGuard<void>(
() => delayedThrow(time),
onError: (Object e, [StackTrace s]) {
onError: (Object e, [StackTrace? s]) {
caughtByOnError = true;
nonNullStackTrace = s != 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 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/context.dart';
......
......@@ -2,19 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/deferred_component.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import '../../src/common.dart';
import '../../src/context.dart';
void main() {
group('DeferredComponent basics', () {
test('constructor sets values', () {
testWithoutContext('constructor sets values', () {
final DeferredComponent component = DeferredComponent(
name: 'bestcomponent',
libraries: <String>['lib1', 'lib2'],
......@@ -25,7 +22,7 @@ void main() {
expect(component.assets, <Uri>[Uri.file('asset1'), Uri.file('asset2')]);
});
test('assignLoadingUnits selects the needed loading units and sets assigned', () {
testWithoutContext('assignLoadingUnits selects the needed loading units and sets assigned', () {
final DeferredComponent component = DeferredComponent(
name: 'bestcomponent',
libraries: <String>['lib1', 'lib2'],
......@@ -56,10 +53,10 @@ void main() {
component.assignLoadingUnits(loadingUnits1);
expect(component.assigned, true);
expect(component.loadingUnits.length, 2);
expect(component.loadingUnits.contains(loadingUnits1[0]), true);
expect(component.loadingUnits.contains(loadingUnits1[1]), true);
expect(component.loadingUnits.contains(loadingUnits1[2]), false);
expect(component.loadingUnits, hasLength(2));
expect(component.loadingUnits, contains(loadingUnits1[0]));
expect(component.loadingUnits, contains(loadingUnits1[1]));
expect(component.loadingUnits, isNot(contains(loadingUnits1[2])));
final List<LoadingUnit> loadingUnits2 = <LoadingUnit>[
LoadingUnit(
......@@ -82,18 +79,18 @@ void main() {
component.assignLoadingUnits(loadingUnits2);
expect(component.assigned, true);
expect(component.loadingUnits.length, 1);
expect(component.loadingUnits.contains(loadingUnits2[0]), true);
expect(component.loadingUnits.contains(loadingUnits2[1]), false);
expect(component.loadingUnits.contains(loadingUnits2[2]), false);
expect(component.loadingUnits, hasLength(1));
expect(component.loadingUnits, contains(loadingUnits2[0]));
expect(component.loadingUnits, isNot(contains(loadingUnits2[1])));
expect(component.loadingUnits, isNot(contains(loadingUnits2[2])));
component.assignLoadingUnits(<LoadingUnit>[]);
expect(component.assigned, true);
expect(component.loadingUnits.length, 0);
expect(component.loadingUnits, hasLength(0));
});
test('toString produces correct string for unassigned component', () {
testWithoutContext('toString produces correct string for unassigned component', () {
final DeferredComponent component = DeferredComponent(
name: 'bestcomponent',
libraries: <String>['lib1', 'lib2'],
......@@ -102,7 +99,7 @@ void main() {
expect(component.toString(), '\nDeferredComponent: bestcomponent\n Libraries:\n - lib1\n - lib2\n Assets:\n - asset1\n - asset2');
});
test('toString produces correct string for assigned component', () {
testWithoutContext('toString produces correct string for assigned component', () {
final DeferredComponent component = DeferredComponent(
name: 'bestcomponent',
libraries: <String>['lib1', 'lib2'],
......@@ -114,7 +111,7 @@ void main() {
});
group('LoadingUnit basics', () {
test('constructor sets values', () {
testWithoutContext('constructor sets values', () {
final LoadingUnit unit = LoadingUnit(
id: 2,
path: 'path/to/so.so',
......@@ -125,7 +122,7 @@ void main() {
expect(unit.libraries, <String>['lib1', 'lib4']);
});
test('toString produces correct string', () {
testWithoutContext('toString produces correct string', () {
final LoadingUnit unit = LoadingUnit(
id: 2,
path: 'path/to/so.so',
......@@ -134,7 +131,7 @@ void main() {
expect(unit.toString(),'\nLoadingUnit 2\n Libraries:\n - lib1\n - lib4');
});
test('equalsIgnoringPath works for various input', () {
testWithoutContext('equalsIgnoringPath works for various input', () {
final LoadingUnit unit1 = LoadingUnit(
id: 2,
path: 'path/to/so.so',
......@@ -172,7 +169,7 @@ void main() {
expect(unit5.equalsIgnoringPath(unit6), false);
});
test('parseLoadingUnitManifest parses single manifest file', () {
testWithoutContext('parseLoadingUnitManifest parses single manifest file', () {
final FileSystem fileSystem = MemoryFileSystem.test();
final File manifest = fileSystem.file('/manifest.json');
manifest.createSync(recursive: true);
......@@ -202,7 +199,7 @@ void main() {
expect(loadingUnits[1].libraries[1], 'lib4');
});
testUsingContext('parseLoadingUnitManifest returns empty when manifest is invalid JSON', () {
testWithoutContext('parseLoadingUnitManifest returns empty when manifest is invalid JSON', () {
final FileSystem fileSystem = MemoryFileSystem.test();
final File manifest = fileSystem.file('/manifest.json');
manifest.createSync(recursive: true);
......@@ -225,7 +222,7 @@ void main() {
expect(loadingUnits.isEmpty, true);
});
testUsingContext('parseLoadingUnitManifest does not exist', () {
testWithoutContext('parseLoadingUnitManifest does not exist', () {
final FileSystem fileSystem = MemoryFileSystem.test();
final File manifest = fileSystem.file('/manifest.json');
if (manifest.existsSync()) {
......@@ -236,7 +233,7 @@ void main() {
expect(loadingUnits.isEmpty, true);
});
test('parseGeneratedLoadingUnits parses all abis if no abis provided', () {
testWithoutContext('parseGeneratedLoadingUnits parses all abis if no abis provided', () {
final FileSystem fileSystem = MemoryFileSystem.test();
final File manifest1 = fileSystem.file('/test-abi1/manifest.json');
manifest1.createSync(recursive: true);
......@@ -293,7 +290,7 @@ void main() {
expect(loadingUnits[3].libraries[1], 'lib4');
});
test('parseGeneratedLoadingUnits only parses provided abis', () {
testWithoutContext('parseGeneratedLoadingUnits only parses provided abis', () {
final FileSystem fileSystem = MemoryFileSystem.test();
final File manifest1 = fileSystem.file('/test-abi1/manifest.json');
manifest1.createSync(recursive: true);
......@@ -340,7 +337,7 @@ void main() {
expect(loadingUnits[1].libraries[1], 'lib4');
});
test('parseGeneratedLoadingUnits returns empty when no manifest files exist', () {
testWithoutContext('parseGeneratedLoadingUnits returns empty when no manifest files exist', () {
final FileSystem fileSystem = MemoryFileSystem.test();
final List<LoadingUnit> loadingUnits =
LoadingUnit.parseGeneratedLoadingUnits(fileSystem.directory('/'), BufferLogger.test());
......
......@@ -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:io' as io;
......@@ -15,12 +13,11 @@ import 'package:flutter_tools/src/base/signals.dart';
import 'package:test/fake.dart';
import '../../src/common.dart';
import '../../src/context.dart';
void main() {
group('fsUtils', () {
MemoryFileSystem fs;
FileSystemUtils fsUtils;
late MemoryFileSystem fs;
late FileSystemUtils fsUtils;
setUp(() {
fs = MemoryFileSystem.test();
......@@ -129,15 +126,15 @@ void main() {
});
group('LocalFileSystem', () {
FakeProcessSignal fakeSignal;
ProcessSignal signalUnderTest;
late FakeProcessSignal fakeSignal;
late ProcessSignal signalUnderTest;
setUp(() {
fakeSignal = FakeProcessSignal();
signalUnderTest = ProcessSignal(fakeSignal);
});
testUsingContext('deletes system temp entry on a fatal signal', () async {
testWithoutContext('deletes system temp entry on a fatal signal', () async {
final Completer<void> completer = Completer<void>();
final Signals signals = Signals.test();
final LocalFileSystem localFileSystem = LocalFileSystem.test(
......
......@@ -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' show json;
import 'package:file/memory.dart';
......@@ -12,9 +10,10 @@ import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/utils.dart';
import '../../src/common.dart';
void main() {
group('Fingerprinter', () {
MemoryFileSystem fileSystem;
late MemoryFileSystem fileSystem;
setUp(() {
fileSystem = MemoryFileSystem.test();
......@@ -85,7 +84,7 @@ void main() {
group('Fingerprint', () {
group('fromBuildInputs', () {
MemoryFileSystem fileSystem;
late MemoryFileSystem fileSystem;
setUp(() {
fileSystem = MemoryFileSystem.test();
......@@ -104,8 +103,8 @@ void main() {
fileSystem.file('b.dart').writeAsStringSync('This is b');
final Fingerprint fingerprint = Fingerprint.fromBuildInputs(const <String>['a.dart', 'b.dart'], fileSystem);
final Map<String, dynamic> jsonObject = castStringKeyedMap(json.decode(fingerprint.toJson()));
expect(jsonObject['files'], hasLength(2));
final Map<String, dynamic>? jsonObject = castStringKeyedMap(json.decode(fingerprint.toJson()));
expect(jsonObject!['files'], hasLength(2));
expect(jsonObject['files']['a.dart'], '8a21a15fad560b799f6731d436c1b698');
expect(jsonObject['files']['b.dart'], '6f144e08b58cd0925328610fad7ac07c');
});
......@@ -124,9 +123,9 @@ void main() {
},
});
final Fingerprint fingerprint = Fingerprint.fromJson(jsonString);
final Map<String, dynamic> content = castStringKeyedMap(json.decode(fingerprint.toJson()));
final Map<String, dynamic>? content = castStringKeyedMap(json.decode(fingerprint.toJson()));
expect(content, hasLength(1));
expect(content['files'], hasLength(2));
expect(content!['files'], hasLength(2));
expect(content['files']['a.dart'], '8a21a15fad560b799f6731d436c1b698');
expect(content['files']['b.dart'], '6f144e08b58cd0925328610fad7ac07c');
});
......
......@@ -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:io' as io;
......@@ -13,11 +11,10 @@ import 'package:flutter_tools/src/base/platform.dart';
import 'package:test/fake.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/io.dart';
void main() {
test('IOOverrides can inject a memory file system', () async {
testWithoutContext('IOOverrides can inject a memory file system', () async {
final MemoryFileSystem memoryFileSystem = MemoryFileSystem.test();
final FlutterIOOverrides flutterIOOverrides = FlutterIOOverrides(fileSystem: memoryFileSystem);
await io.IOOverrides.runWithIOOverrides(() async {
......@@ -57,7 +54,8 @@ void main() {
expect(memoryFileSystem.link('ggg').resolveSymbolicLinksSync(), linkB.resolveSymbolicLinksSync());
}, flutterIOOverrides);
});
testUsingContext('ProcessSignal signals are properly delegated', () async {
testWithoutContext('ProcessSignal signals are properly delegated', () async {
final FakeProcessSignal signal = FakeProcessSignal();
final ProcessSignal signalUnderTest = ProcessSignal(signal);
......@@ -66,15 +64,15 @@ void main() {
expect(signalUnderTest, await signalUnderTest.watch().first);
});
testUsingContext('ProcessSignal toString() works', () async {
testWithoutContext('ProcessSignal toString() works', () async {
expect(io.ProcessSignal.sigint.toString(), ProcessSignal.sigint.toString());
});
test('exit throws a StateError if called without being overriden', () {
testWithoutContext('exit throws a StateError if called without being overriden', () {
expect(() => exit(0), throwsAssertionError);
});
test('exit does not throw a StateError if overriden', () {
testWithoutContext('exit does not throw a StateError if overriden', () {
try {
setExitFunctionForTests((int value) {});
......@@ -84,16 +82,16 @@ void main() {
}
});
test('test_api defines the Declarer in a known place', () {
testWithoutContext('test_api defines the Declarer in a known place', () {
expect(Zone.current[#test.declarer], isNotNull);
});
test('listNetworkInterfaces() uses overrides', () async {
testWithoutContext('listNetworkInterfaces() uses overrides', () async {
setNetworkInterfaceLister(
({
bool includeLoopback,
bool includeLinkLocal,
InternetAddressType type,
bool? includeLoopback,
bool? includeLinkLocal,
InternetAddressType? type,
}) async => <NetworkInterface>[],
);
......
......@@ -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:file/file.dart';
......@@ -20,7 +18,7 @@ import '../../src/common.dart';
import '../../src/fake_http_client.dart';
void main() {
BufferLogger testLogger;
late BufferLogger testLogger;
setUp(() {
testLogger = BufferLogger.test();
......@@ -36,7 +34,7 @@ void main() {
group('successful fetch', () {
const String responseString = 'response string';
List<int> responseData;
late List<int> responseData;
setUp(() {
responseData = utf8.encode(responseString);
......@@ -51,7 +49,7 @@ void main() {
])
);
final List<int> data = await net.fetchUrl(Uri.parse('http://example.invalid/'));
final List<int>? data = await net.fetchUrl(Uri.parse('http://example.invalid/'));
expect(data, equals(responseData));
});
......@@ -65,7 +63,7 @@ void main() {
);
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final File destFile = fileSystem.file('dest_file')..createSync();
final List<int> data = await net.fetchUrl(
final List<int>? data = await net.fetchUrl(
Uri.parse('http://example.invalid/'),
destFile: destFile,
);
......@@ -127,9 +125,9 @@ void main() {
FakeRequest(invalid, responseError: const io.SocketException('')),
])
);
String error;
String? error;
FakeAsync().run((FakeAsync time) {
net.fetchUrl(invalid).then((List<int> value) {
net.fetchUrl(invalid).then((List<int>? value) async {
error = 'test completed unexpectedly';
}, onError: (dynamic exception) {
error = 'test failed unexpectedly: $exception';
......@@ -158,9 +156,9 @@ void main() {
FakeRequest(invalid, responseError: const io.HandshakeException('')),
])
);
String error;
String? error;
FakeAsync().run((FakeAsync time) {
net.fetchUrl(invalid).then((List<int> value) {
net.fetchUrl(invalid).then((List<int>? value) async {
error = 'test completed unexpectedly';
}, onError: (dynamic exception) {
error = 'test failed: $exception';
......@@ -188,9 +186,9 @@ void main() {
},
),
);
String error;
String? error;
FakeAsync().run((FakeAsync time) {
net.fetchUrl(Uri.parse('example.invalid/')).then((List<int> value) {
net.fetchUrl(Uri.parse('example.invalid/')).then((List<int>? value) async {
error = 'test completed unexpectedly';
}, onError: (dynamic exception) {
error = 'test failed: $exception';
......@@ -214,9 +212,9 @@ void main() {
FakeRequest(invalid, responseError: const io.HttpException('')),
])
);
String error;
String? error;
FakeAsync().run((FakeAsync time) {
net.fetchUrl(invalid).then((List<int> value) {
net.fetchUrl(invalid).then((List<int>? value) async {
error = 'test completed unexpectedly';
}, onError: (dynamic exception) {
error = 'test failed unexpectedly: $exception';
......@@ -245,9 +243,9 @@ void main() {
FakeRequest(invalid, responseError: const io.HttpException('')),
])
);
String error;
String? error;
FakeAsync().run((FakeAsync time) {
net.fetchUrl(invalid).then((List<int> value) {
net.fetchUrl(invalid).then((List<int>? value) async {
error = 'test completed unexpectedly';
}, onError: (dynamic exception) {
error = 'test failed unexpectedly: $exception';
......@@ -281,10 +279,10 @@ void main() {
)),
])
);
String error;
List<int> actualResult;
String? error;
List<int>? actualResult;
FakeAsync().run((FakeAsync time) {
net.fetchUrl(invalid, maxAttempts: 3).then((List<int> value) {
net.fetchUrl(invalid, maxAttempts: 3).then((List<int>? value) async {
actualResult = value;
}, onError: (dynamic exception) {
error = 'test failed unexpectedly: $exception';
......
......@@ -13,7 +13,7 @@ import 'package:flutter_tools/src/base/os.dart';
import 'package:flutter_tools/src/base/platform.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/fake_process_manager.dart';
const String kExecutable = 'foo';
const String kPath1 = '/bar/bin/$kExecutable';
......
......@@ -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 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/os.dart';
......@@ -15,8 +13,8 @@ import '../../src/common.dart';
void main() {
group('OperatingSystemUtils', () {
Directory tempDir;
FileSystem fileSystem;
late Directory tempDir;
late FileSystem fileSystem;
setUp(() {
fileSystem = LocalFileSystem.test(signals: Signals.test());
......
......@@ -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 'package:flutter_tools/src/base/platform.dart';
import '../../src/common.dart';
......@@ -26,8 +24,8 @@ void _expectPlatformsEqual(Platform actual, Platform expected) {
void main() {
group('FakePlatform.fromPlatform', () {
FakePlatform fake;
LocalPlatform local;
late FakePlatform fake;
late LocalPlatform local;
setUp(() {
local = const LocalPlatform();
......
......@@ -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:io' as io;
......@@ -15,9 +13,9 @@ import '../../src/common.dart';
void main() {
group('Signals', () {
Signals signals;
FakeProcessSignal fakeSignal;
ProcessSignal signalUnderTest;
late Signals signals;
late FakeProcessSignal fakeSignal;
late ProcessSignal signalUnderTest;
setUp(() {
signals = Signals.test();
......@@ -58,7 +56,7 @@ void main() {
testWithoutContext('signal handlers do not cause concurrent modification errors when removing handlers in a signal callback', () async {
final Completer<void> completer = Completer<void>();
Object token;
late Object token;
Future<void> handle(ProcessSignal s) async {
expect(s, signalUnderTest);
expect(await signals.removeHandler(signalUnderTest, token), true);
......@@ -73,7 +71,7 @@ void main() {
testWithoutContext('signal handler error goes on error stream', () async {
final Exception exn = Exception('Error');
signals.addHandler(signalUnderTest, (ProcessSignal s) {
signals.addHandler(signalUnderTest, (ProcessSignal s) async {
throw exn;
});
......@@ -95,7 +93,7 @@ void main() {
testWithoutContext('removed signal handler does not run', () async {
final Object token = signals.addHandler(
signalUnderTest,
(ProcessSignal s) {
(ProcessSignal s) async {
fail('Signal handler should have been removed.');
},
);
......@@ -124,7 +122,7 @@ void main() {
final Object token = signals.addHandler(
signalUnderTest,
(ProcessSignal s) {
(ProcessSignal s) async {
fail('Signal handler should have been removed.');
},
);
......@@ -153,7 +151,7 @@ void main() {
completer.complete();
});
signals.addHandler(otherSignal, (ProcessSignal s) {
signals.addHandler(otherSignal, (ProcessSignal s) async {
fail('Wrong signal!.');
});
......
......@@ -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 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart';
......@@ -37,7 +35,7 @@ void main() {
});
group('ANSI coloring and bold', () {
AnsiTerminal terminal;
late AnsiTerminal terminal;
setUp(() {
terminal = AnsiTerminal(
......@@ -108,7 +106,7 @@ void main() {
});
group('character input prompt', () {
AnsiTerminal terminalUnderTest;
late AnsiTerminal terminalUnderTest;
setUp(() {
terminalUnderTest = TestTerminal(stdio: FakeStdio());
......@@ -118,7 +116,7 @@ void main() {
expect(terminalUnderTest.promptForCharInput(
<String>['a', 'b', 'c'],
prompt: 'Please choose something',
logger: null,
logger: BufferLogger.test(),
), throwsStateError);
});
......@@ -183,13 +181,13 @@ void main() {
});
}
Stream<String> mockStdInStream;
late Stream<String> mockStdInStream;
class TestTerminal extends AnsiTerminal {
TestTerminal({
Stdio stdio,
Stdio? stdio,
Platform platform = const LocalPlatform(),
}) : super(stdio: stdio, platform: platform);
}) : super(stdio: stdio ?? Stdio(), platform: platform);
@override
Stream<String> get keystrokes {
......
......@@ -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 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/user_messages.dart';
......
......@@ -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 'dart:typed_data';
......
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