Unverified Commit 23301557 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] simplify platform null safety (#77727)

parent fb2cffb0
...@@ -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 show Platform, stdin, stdout; import 'dart:io' as io show Platform, stdin, stdout;
/// Provides API parity with the `Platform` class in `dart:io`, but using /// Provides API parity with the `Platform` class in `dart:io`, but using
...@@ -103,7 +101,7 @@ abstract class Platform { ...@@ -103,7 +101,7 @@ abstract class Platform {
/// specifies how Dart packages are looked up. /// specifies how Dart packages are looked up.
/// ///
/// If there is no `--packages` flag, `null` is returned. /// If there is no `--packages` flag, `null` is returned.
String get packageConfig; String? get packageConfig;
/// The version of the current Dart runtime. /// The version of the current Dart runtime.
/// ///
...@@ -158,7 +156,7 @@ class LocalPlatform extends Platform { ...@@ -158,7 +156,7 @@ class LocalPlatform extends Platform {
List<String> get executableArguments => io.Platform.executableArguments; List<String> get executableArguments => io.Platform.executableArguments;
@override @override
String get packageConfig => io.Platform.packageConfig; String? get packageConfig => io.Platform.packageConfig;
@override @override
String get version => io.Platform.version; String get version => io.Platform.version;
...@@ -173,29 +171,30 @@ class LocalPlatform extends Platform { ...@@ -173,29 +171,30 @@ class LocalPlatform extends Platform {
String get localeName => io.Platform.localeName; String get localeName => io.Platform.localeName;
} }
final Uri _empty = Uri.parse('');
/// Provides a mutable implementation of the [Platform] interface. /// Provides a mutable implementation of the [Platform] interface.
class FakePlatform extends Platform { class FakePlatform extends Platform {
/// Creates a new [FakePlatform] with the specified properties. /// Creates a new [FakePlatform] with the specified properties.
/// ///
/// Unspecified properties will *not* be assigned default values (they will /// Unspecified properties will default to a 'linux' OS.
/// remain `null`).
FakePlatform({ FakePlatform({
this.numberOfProcessors, this.numberOfProcessors = 1,
this.pathSeparator, this.pathSeparator = '/',
this.operatingSystem, this.operatingSystem = 'linux',
this.operatingSystemVersion, this.operatingSystemVersion = '',
this.localHostname, this.localHostname = '',
this.environment, this.environment = const <String, String>{},
this.executable, this.executable = '',
this.resolvedExecutable, this.resolvedExecutable = '',
this.script, Uri? script,
this.executableArguments, this.executableArguments = const <String>[],
this.packageConfig, this.packageConfig,
this.version, this.version = '',
this.stdinSupportsAnsi, this.stdinSupportsAnsi = false,
this.stdoutSupportsAnsi, this.stdoutSupportsAnsi = false,
this.localeName, this.localeName = '',
}); }) : script = script ?? _empty;
/// Creates a new [FakePlatform] with properties whose initial values mirror /// Creates a new [FakePlatform] with properties whose initial values mirror
/// the specified [platform]. /// the specified [platform].
...@@ -248,7 +247,7 @@ class FakePlatform extends Platform { ...@@ -248,7 +247,7 @@ class FakePlatform extends Platform {
List<String> executableArguments; List<String> executableArguments;
@override @override
String packageConfig; String? packageConfig;
@override @override
String version; String version;
......
...@@ -20,7 +20,7 @@ void main() { ...@@ -20,7 +20,7 @@ void main() {
expect(message(macPlatform), contains('https://flutter.dev/docs/get-started/install/macos#android-setup')); expect(message(macPlatform), contains('https://flutter.dev/docs/get-started/install/macos#android-setup'));
expect(message(linuxPlatform), contains('https://flutter.dev/docs/get-started/install/linux#android-setup')); expect(message(linuxPlatform), contains('https://flutter.dev/docs/get-started/install/linux#android-setup'));
expect(message(windowsPlatform), contains('https://flutter.dev/docs/get-started/install/windows#android-setup')); expect(message(windowsPlatform), contains('https://flutter.dev/docs/get-started/install/windows#android-setup'));
expect(message(FakePlatform()), contains('https://flutter.dev/docs/get-started/install ')); expect(message(FakePlatform(operatingSystem: '')), contains('https://flutter.dev/docs/get-started/install '));
} }
testWithoutContext('Android installation instructions', () { testWithoutContext('Android installation instructions', () {
......
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