Migrate intellij tests and context_test to null safety (#80008)
This commit is contained in:
@@ -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 'package:flutter_tools/src/base/context.dart';
|
||||
@@ -13,7 +11,7 @@ import '../../src/common.dart';
|
||||
void main() {
|
||||
group('AppContext', () {
|
||||
group('global getter', () {
|
||||
bool called;
|
||||
late bool called;
|
||||
|
||||
setUp(() {
|
||||
called = false;
|
||||
@@ -78,7 +76,7 @@ void main() {
|
||||
test('still finds values if async code runs after body has finished', () async {
|
||||
final Completer<void> outer = Completer<void>();
|
||||
final Completer<void> inner = Completer<void>();
|
||||
String value;
|
||||
String? value;
|
||||
await context.run<void>(
|
||||
body: () {
|
||||
outer.future.then<void>((_) {
|
||||
@@ -98,10 +96,10 @@ void main() {
|
||||
|
||||
test('caches generated override values', () async {
|
||||
int consultationCount = 0;
|
||||
String value;
|
||||
String? value;
|
||||
await context.run<void>(
|
||||
body: () async {
|
||||
final StringBuffer buf = StringBuffer(context.get<String>());
|
||||
final StringBuffer buf = StringBuffer(context.get<String>()!);
|
||||
buf.write(context.get<String>());
|
||||
await context.run<void>(body: () {
|
||||
buf.write(context.get<String>());
|
||||
@@ -121,10 +119,10 @@ void main() {
|
||||
|
||||
test('caches generated fallback values', () async {
|
||||
int consultationCount = 0;
|
||||
String value;
|
||||
String? value;
|
||||
await context.run(
|
||||
body: () async {
|
||||
final StringBuffer buf = StringBuffer(context.get<String>());
|
||||
final StringBuffer buf = StringBuffer(context.get<String>()!);
|
||||
buf.write(context.get<String>());
|
||||
await context.run<void>(body: () {
|
||||
buf.write(context.get<String>());
|
||||
@@ -143,7 +141,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('returns null if generated value is null', () async {
|
||||
final String value = await context.run<String>(
|
||||
final String? value = await context.run<String?>(
|
||||
body: () => context.get<String>(),
|
||||
overrides: <Type, Generator>{
|
||||
String: () => null,
|
||||
@@ -153,14 +151,14 @@ void main() {
|
||||
});
|
||||
|
||||
test('throws if generator has dependency cycle', () async {
|
||||
final Future<String> value = context.run<String>(
|
||||
final Future<String?> value = context.run<String?>(
|
||||
body: () async {
|
||||
return context.get<String>();
|
||||
},
|
||||
fallbacks: <Type, Generator>{
|
||||
int: () => int.parse(context.get<String>()),
|
||||
int: () => int.parse(context.get<String>() ?? ''),
|
||||
String: () => '${context.get<double>()}',
|
||||
double: () => context.get<int>() * 1.0,
|
||||
double: () => context.get<int>()! * 1.0,
|
||||
},
|
||||
);
|
||||
try {
|
||||
@@ -187,16 +185,16 @@ void main() {
|
||||
});
|
||||
|
||||
group('fallbacks', () {
|
||||
bool called;
|
||||
late bool called;
|
||||
|
||||
setUp(() {
|
||||
called = false;
|
||||
});
|
||||
|
||||
test('are applied after parent context is consulted', () async {
|
||||
final String value = await context.run<String>(
|
||||
final String? value = await context.run<String?>(
|
||||
body: () {
|
||||
return context.run<String>(
|
||||
return context.run<String?>(
|
||||
body: () {
|
||||
called = true;
|
||||
return context.get<String>();
|
||||
@@ -213,9 +211,9 @@ void main() {
|
||||
|
||||
test('are not applied if parent context supplies value', () async {
|
||||
bool childConsulted = false;
|
||||
final String value = await context.run<String>(
|
||||
final String? value = await context.run<String?>(
|
||||
body: () {
|
||||
return context.run<String>(
|
||||
return context.run<String?>(
|
||||
body: () {
|
||||
called = true;
|
||||
return context.get<String>();
|
||||
@@ -238,7 +236,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('may depend on one another', () async {
|
||||
final String value = await context.run<String>(
|
||||
final String? value = await context.run<String?>(
|
||||
body: () {
|
||||
return context.get<String>();
|
||||
},
|
||||
@@ -254,9 +252,9 @@ void main() {
|
||||
group('overrides', () {
|
||||
test('intercept consultation of parent context', () async {
|
||||
bool parentConsulted = false;
|
||||
final String value = await context.run<String>(
|
||||
final String? value = await context.run<String?>(
|
||||
body: () {
|
||||
return context.run<String>(
|
||||
return context.run<String?>(
|
||||
body: () => context.get<String>(),
|
||||
overrides: <Type, Generator>{
|
||||
String: () => 'child',
|
||||
|
||||
@@ -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:archive/archive.dart';
|
||||
@@ -16,7 +14,7 @@ import 'package:flutter_tools/src/intellij/intellij.dart';
|
||||
import '../../src/common.dart';
|
||||
|
||||
void main() {
|
||||
FileSystem fileSystem;
|
||||
late FileSystem fileSystem;
|
||||
|
||||
void writeFileCreatingDirectories(String path, List<int> bytes) {
|
||||
final File file = fileSystem.file(path);
|
||||
@@ -40,7 +38,7 @@ void main() {
|
||||
''');
|
||||
writeFileCreatingDirectories(
|
||||
fileSystem.path.join(_kPluginsPath, 'Dart', 'lib', 'Dart.jar'),
|
||||
ZipEncoder().encode(dartJarArchive),
|
||||
ZipEncoder().encode(dartJarArchive)!,
|
||||
);
|
||||
|
||||
final Archive flutterJarArchive = buildSingleFileArchive('META-INF/plugin.xml', r'''
|
||||
@@ -51,7 +49,7 @@ void main() {
|
||||
''');
|
||||
writeFileCreatingDirectories(
|
||||
fileSystem.path.join(_kPluginsPath, 'flutter-intellij.jar'),
|
||||
ZipEncoder().encode(flutterJarArchive),
|
||||
ZipEncoder().encode(flutterJarArchive)!,
|
||||
);
|
||||
|
||||
final List<ValidationMessage> messages = <ValidationMessage>[];
|
||||
@@ -82,14 +80,14 @@ void main() {
|
||||
''');
|
||||
writeFileCreatingDirectories(
|
||||
fileSystem.path.join(_kPluginsPath, 'flutter-intellij', 'lib', 'flutter-idea-50.0.jar'),
|
||||
ZipEncoder().encode(flutterIdeaJarArchive),
|
||||
ZipEncoder().encode(flutterIdeaJarArchive)!,
|
||||
);
|
||||
final Archive flutterIntellijJarArchive = buildSingleFileArchive('META-INF/MANIFEST.MF', r'''
|
||||
Manifest-Version: 1.0
|
||||
''');
|
||||
writeFileCreatingDirectories(
|
||||
fileSystem.path.join(_kPluginsPath, 'flutter-intellij', 'lib', 'flutter-intellij-50.0.jar'),
|
||||
ZipEncoder().encode(flutterIntellijJarArchive),
|
||||
ZipEncoder().encode(flutterIntellijJarArchive)!,
|
||||
);
|
||||
|
||||
final List<ValidationMessage> messages = <ValidationMessage>[];
|
||||
@@ -118,7 +116,7 @@ Manifest-Version: 1.0
|
||||
''');
|
||||
writeFileCreatingDirectories(
|
||||
fileSystem.path.join(_kPluginsPath, 'flutter-intellij', 'lib', 'flutter-idea-50.0.jar'),
|
||||
ZipEncoder().encode(flutterIdeaJarArchive),
|
||||
ZipEncoder().encode(flutterIdeaJarArchive)!,
|
||||
);
|
||||
final Archive flutterIntellijJarArchive = buildSingleFileArchive('META-INF/plugin.xml', r'''
|
||||
<idea-plugin version="2">
|
||||
@@ -128,7 +126,7 @@ Manifest-Version: 1.0
|
||||
''');
|
||||
writeFileCreatingDirectories(
|
||||
fileSystem.path.join(_kPluginsPath, 'flutter-intellij', 'lib', 'flutter-intellij-50.0.jar'),
|
||||
ZipEncoder().encode(flutterIntellijJarArchive),
|
||||
ZipEncoder().encode(flutterIntellijJarArchive)!,
|
||||
);
|
||||
|
||||
final List<ValidationMessage> messages = <ValidationMessage>[];
|
||||
@@ -176,7 +174,7 @@ Manifest-Version: 1.0
|
||||
''');
|
||||
writeFileCreatingDirectories(
|
||||
fileSystem.path.join(_kPluginsPath, 'Dart', 'lib', 'Other.jar'),
|
||||
ZipEncoder().encode(dartJarArchive),
|
||||
ZipEncoder().encode(dartJarArchive)!,
|
||||
);
|
||||
|
||||
expect(
|
||||
|
||||
@@ -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:archive/archive.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
@@ -332,7 +330,7 @@ class FakePlistParser extends Fake implements PlistParser {
|
||||
final Map<String, String> values;
|
||||
|
||||
@override
|
||||
String getValueFromFile(String plistFilePath, String key) {
|
||||
String? getValueFromFile(String plistFilePath, String key) {
|
||||
return values[key];
|
||||
}
|
||||
}
|
||||
@@ -379,7 +377,7 @@ void createIntellijFlutterPluginJar(String pluginJarPath, FileSystem fileSystem,
|
||||
flutterPlugins.addFile(ArchiveFile('META-INF/plugin.xml', flutterPluginBytes.length, flutterPluginBytes));
|
||||
fileSystem.file(pluginJarPath)
|
||||
..createSync(recursive: true)
|
||||
..writeAsBytesSync(ZipEncoder().encode(flutterPlugins));
|
||||
..writeAsBytesSync(ZipEncoder().encode(flutterPlugins)!);
|
||||
|
||||
}
|
||||
|
||||
@@ -416,5 +414,5 @@ void createIntellijDartPluginJar(String pluginJarPath, FileSystem fileSystem) {
|
||||
dartPlugins.addFile(ArchiveFile('META-INF/plugin.xml', dartPluginBytes.length, dartPluginBytes));
|
||||
fileSystem.file(pluginJarPath)
|
||||
..createSync(recursive: true)
|
||||
..writeAsBytesSync(ZipEncoder().encode(dartPlugins));
|
||||
..writeAsBytesSync(ZipEncoder().encode(dartPlugins)!);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user