Migrate more tool unit tests to null safety (#80002)
This commit is contained in:
parent
aa96eb299a
commit
ec14cef060
@ -48,7 +48,7 @@ bool _inUnitTest() {
|
|||||||
///
|
///
|
||||||
/// The specification for the language version tag is defined at:
|
/// The specification for the language version tag is defined at:
|
||||||
/// https://github.com/dart-lang/language/blob/master/accepted/future-releases/language-versioning/feature-specification.md#individual-library-language-version-override
|
/// https://github.com/dart-lang/language/blob/master/accepted/future-releases/language-versioning/feature-specification.md#individual-library-language-version-override
|
||||||
LanguageVersion determineLanguageVersion(File file, Package package, String flutterRoot) {
|
LanguageVersion determineLanguageVersion(File file, Package? package, String flutterRoot) {
|
||||||
int blockCommentDepth = 0;
|
int blockCommentDepth = 0;
|
||||||
// If reading the file fails, default to a null-safe version. The
|
// If reading the file fails, default to a null-safe version. The
|
||||||
// command will likely fail later in the process with a better error
|
// command will likely fail later in the process with a better error
|
||||||
|
@ -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/doctor_validator.dart';
|
import 'package:flutter_tools/src/doctor_validator.dart';
|
||||||
import 'package:flutter_tools/src/proxy_validator.dart';
|
import 'package:flutter_tools/src/proxy_validator.dart';
|
||||||
|
@ -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/android/build_validation.dart';
|
import 'package:flutter_tools/src/android/build_validation.dart';
|
||||||
import 'package:flutter_tools/src/build_info.dart';
|
import 'package:flutter_tools/src/build_info.dart';
|
||||||
|
|
||||||
|
@ -2,23 +2,20 @@
|
|||||||
// 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/logger.dart';
|
import 'package:flutter_tools/src/base/logger.dart';
|
||||||
import 'package:flutter_tools/src/build_info.dart';
|
import 'package:flutter_tools/src/build_info.dart';
|
||||||
|
|
||||||
import '../src/common.dart';
|
import '../src/common.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
BufferLogger logger;
|
late BufferLogger logger;
|
||||||
setUp(() {
|
setUp(() {
|
||||||
logger = BufferLogger.test();
|
logger = BufferLogger.test();
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Validate build number', () {
|
group('Validate build number', () {
|
||||||
testWithoutContext('CFBundleVersion for iOS', () async {
|
testWithoutContext('CFBundleVersion for iOS', () async {
|
||||||
String buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, 'xyz', logger);
|
String? buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, 'xyz', logger);
|
||||||
expect(buildName, isNull);
|
expect(buildName, isNull);
|
||||||
buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, '0.0.1', logger);
|
buildName = validatedBuildNumberForPlatform(TargetPlatform.ios, '0.0.1', logger);
|
||||||
expect(buildName, '0.0.1');
|
expect(buildName, '0.0.1');
|
||||||
@ -29,7 +26,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWithoutContext('versionCode for Android', () async {
|
testWithoutContext('versionCode for Android', () async {
|
||||||
String buildName = validatedBuildNumberForPlatform(TargetPlatform.android_arm, '123.abc+-', logger);
|
String? buildName = validatedBuildNumberForPlatform(TargetPlatform.android_arm, '123.abc+-', logger);
|
||||||
expect(buildName, '123');
|
expect(buildName, '123');
|
||||||
buildName = validatedBuildNumberForPlatform(TargetPlatform.android_arm, 'abc', logger);
|
buildName = validatedBuildNumberForPlatform(TargetPlatform.android_arm, 'abc', logger);
|
||||||
expect(buildName, '1');
|
expect(buildName, '1');
|
||||||
@ -38,7 +35,7 @@ void main() {
|
|||||||
|
|
||||||
group('Validate build name', () {
|
group('Validate build name', () {
|
||||||
testWithoutContext('CFBundleShortVersionString for iOS', () async {
|
testWithoutContext('CFBundleShortVersionString for iOS', () async {
|
||||||
String buildName = validatedBuildNameForPlatform(TargetPlatform.ios, 'xyz', logger);
|
String? buildName = validatedBuildNameForPlatform(TargetPlatform.ios, 'xyz', logger);
|
||||||
expect(buildName, isNull);
|
expect(buildName, isNull);
|
||||||
buildName = validatedBuildNameForPlatform(TargetPlatform.ios, '0.0.1', logger);
|
buildName = validatedBuildNameForPlatform(TargetPlatform.ios, '0.0.1', logger);
|
||||||
expect(buildName, '0.0.1');
|
expect(buildName, '0.0.1');
|
||||||
@ -52,7 +49,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWithoutContext('versionName for Android', () async {
|
testWithoutContext('versionName for Android', () async {
|
||||||
String buildName = validatedBuildNameForPlatform(TargetPlatform.android_arm, '123.abc+-', logger);
|
String? buildName = validatedBuildNameForPlatform(TargetPlatform.android_arm, '123.abc+-', logger);
|
||||||
expect(buildName, '123.abc+-');
|
expect(buildName, '123.abc+-');
|
||||||
buildName = validatedBuildNameForPlatform(TargetPlatform.android_arm, 'abc+-', logger);
|
buildName = validatedBuildNameForPlatform(TargetPlatform.android_arm, 'abc+-', logger);
|
||||||
expect(buildName, 'abc+-');
|
expect(buildName, 'abc+-');
|
||||||
|
@ -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';
|
||||||
@ -12,8 +10,8 @@ import 'package:flutter_tools/src/build_system/depfile.dart';
|
|||||||
import '../../src/common.dart';
|
import '../../src/common.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
FileSystem fileSystem;
|
late FileSystem fileSystem;
|
||||||
DepfileService depfileService;
|
late DepfileService depfileService;
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
fileSystem = MemoryFileSystem.test();
|
fileSystem = MemoryFileSystem.test();
|
||||||
|
@ -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 '../src/common.dart';
|
import '../src/common.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
@ -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/dart/language_version.dart';
|
import 'package:flutter_tools/src/dart/language_version.dart';
|
||||||
|
@ -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/flutter_project_metadata.dart';
|
import 'package:flutter_tools/src/flutter_project_metadata.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';
|
||||||
@ -12,9 +10,9 @@ import 'package:file/memory.dart';
|
|||||||
import '../src/common.dart';
|
import '../src/common.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
FileSystem fileSystem;
|
late FileSystem fileSystem;
|
||||||
BufferLogger logger;
|
late BufferLogger logger;
|
||||||
File metadataFile;
|
late File metadataFile;
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
fileSystem = MemoryFileSystem.test();
|
fileSystem = MemoryFileSystem.test();
|
||||||
|
@ -9,7 +9,7 @@ import 'package:flutter_tools/src/doctor_validator.dart';
|
|||||||
import 'package:flutter_tools/src/linux/linux_doctor.dart';
|
import 'package:flutter_tools/src/linux/linux_doctor.dart';
|
||||||
|
|
||||||
import '../../src/common.dart';
|
import '../../src/common.dart';
|
||||||
import '../../src/context.dart';
|
import '../../src/fake_process_manager.dart';
|
||||||
|
|
||||||
// A command that will return typical-looking 'clang++ --version' output with
|
// A command that will return typical-looking 'clang++ --version' output with
|
||||||
// the given version number.
|
// the given version number.
|
||||||
|
@ -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/test/event_printer.dart';
|
import 'package:flutter_tools/src/test/event_printer.dart';
|
||||||
import 'package:flutter_tools/src/test/test_device.dart';
|
import 'package:flutter_tools/src/test/test_device.dart';
|
||||||
import 'package:test/fake.dart';
|
import 'package:test/fake.dart';
|
||||||
@ -13,8 +11,8 @@ import '../../src/common.dart';
|
|||||||
void main() {
|
void main() {
|
||||||
group(EventPrinter, () {
|
group(EventPrinter, () {
|
||||||
final Uri observatoryUri = Uri.parse('http://localhost:1234');
|
final Uri observatoryUri = Uri.parse('http://localhost:1234');
|
||||||
EventPrinter eventPrinter;
|
late EventPrinter eventPrinter;
|
||||||
StringBuffer output;
|
late StringBuffer output;
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
output = StringBuffer();
|
output = StringBuffer();
|
||||||
|
@ -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/time.dart';
|
import 'package:flutter_tools/src/base/time.dart';
|
||||||
|
|
||||||
import '../src/common.dart';
|
import '../src/common.dart';
|
||||||
@ -29,9 +27,9 @@ void main() {
|
|||||||
final String formattedTime = formatDateTime(time);
|
final String formattedTime = formatDateTime(time);
|
||||||
// If a date time string has a timezone offset, DateTime.tryParse()
|
// If a date time string has a timezone offset, DateTime.tryParse()
|
||||||
// converts the parsed time to UTC.
|
// converts the parsed time to UTC.
|
||||||
final DateTime parsedTime = DateTime.tryParse(formattedTime);
|
final DateTime? parsedTime = DateTime.tryParse(formattedTime);
|
||||||
expect(parsedTime, isNotNull);
|
expect(parsedTime, isNotNull);
|
||||||
expect(parsedTime.isUtc, isTrue);
|
expect(parsedTime!.isUtc, isTrue);
|
||||||
// Convert the parsed time (which should be utc) to the local timezone and
|
// Convert the parsed time (which should be utc) to the local timezone and
|
||||||
// compare against the original time which is in the local timezone. They
|
// compare against the original time which is in the local timezone. They
|
||||||
// should be the same.
|
// should be the same.
|
||||||
|
@ -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/utils.dart';
|
import 'package:flutter_tools/src/base/utils.dart';
|
||||||
import 'package:flutter_tools/src/base/version.dart';
|
import 'package:flutter_tools/src/base/version.dart';
|
||||||
import 'package:flutter_tools/src/base/terminal.dart';
|
import 'package:flutter_tools/src/base/terminal.dart';
|
||||||
@ -29,24 +27,24 @@ baz=qux
|
|||||||
expect(Version.unknown.toString(), equals('unknown'));
|
expect(Version.unknown.toString(), equals('unknown'));
|
||||||
expect(Version(null, null, null).toString(), equals('0'));
|
expect(Version(null, null, null).toString(), equals('0'));
|
||||||
|
|
||||||
final Version v1 = Version.parse('1');
|
final Version v1 = Version.parse('1')!;
|
||||||
expect(v1.major, equals(1));
|
expect(v1.major, equals(1));
|
||||||
expect(v1.minor, equals(0));
|
expect(v1.minor, equals(0));
|
||||||
expect(v1.patch, equals(0));
|
expect(v1.patch, equals(0));
|
||||||
|
|
||||||
expect(v1, greaterThan(Version.unknown));
|
expect(v1, greaterThan(Version.unknown));
|
||||||
|
|
||||||
final Version v2 = Version.parse('1.2');
|
final Version v2 = Version.parse('1.2')!;
|
||||||
expect(v2.major, equals(1));
|
expect(v2.major, equals(1));
|
||||||
expect(v2.minor, equals(2));
|
expect(v2.minor, equals(2));
|
||||||
expect(v2.patch, equals(0));
|
expect(v2.patch, equals(0));
|
||||||
|
|
||||||
final Version v3 = Version.parse('1.2.3');
|
final Version v3 = Version.parse('1.2.3')!;
|
||||||
expect(v3.major, equals(1));
|
expect(v3.major, equals(1));
|
||||||
expect(v3.minor, equals(2));
|
expect(v3.minor, equals(2));
|
||||||
expect(v3.patch, equals(3));
|
expect(v3.patch, equals(3));
|
||||||
|
|
||||||
final Version v4 = Version.parse('1.12');
|
final Version v4 = Version.parse('1.12')!;
|
||||||
expect(v4, greaterThan(v2));
|
expect(v4, greaterThan(v2));
|
||||||
|
|
||||||
expect(v3, greaterThan(v2));
|
expect(v3, greaterThan(v2));
|
||||||
|
@ -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/version.dart';
|
import 'package:flutter_tools/src/base/version.dart';
|
||||||
import 'package:flutter_tools/src/vscode/vscode.dart';
|
import 'package:flutter_tools/src/vscode/vscode.dart';
|
||||||
|
@ -13,7 +13,7 @@ import 'package:flutter_tools/src/convert.dart';
|
|||||||
import 'package:flutter_tools/src/windows/visual_studio.dart';
|
import 'package:flutter_tools/src/windows/visual_studio.dart';
|
||||||
|
|
||||||
import '../../src/common.dart';
|
import '../../src/common.dart';
|
||||||
import '../../src/context.dart';
|
import '../../src/fake_process_manager.dart';
|
||||||
|
|
||||||
const String programFilesPath = r'C:\Program Files (x86)';
|
const String programFilesPath = r'C:\Program Files (x86)';
|
||||||
const String visualStudioPath = programFilesPath + r'\Microsoft Visual Studio\2017\Community';
|
const String visualStudioPath = programFilesPath + r'\Microsoft Visual Studio\2017\Community';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user