-
-
Notifications
You must be signed in to change notification settings - Fork 257
refactor: cleanup platform mocking #2730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
fc54e2e
replace platform checker
denrase b8fe88f
Merge branch 'v9' into v9-feat/replace-custom-platform-checker
denrase b80690d
fixes
denrase f18c72b
refactor: cleanup platform mocking
vaind a863fae
cleanup
vaind fd173e5
remove fake platform checker
vaind d68f74b
fix: mockplatform should use defaults based on the current platform
vaind 3f9f749
default to isWeb: false in mockplatform factories
vaind fa462da
fix: web tests
vaind 504be25
formatting
vaind 8411978
Merge branch 'v9' into refactor/cleanup-platform-mocking
vaind 58e55ff
Merge branch 'v9' into refactor/cleanup-platform-mocking
denrase 71a58da
Merge branch 'v9' into refactor/cleanup-platform-mocking
vaind 68e3fb8
move platfomr out of paltform checker
denrase b484ef4
Merge branch 'refactor/cleanup-platform-mocking' of github.com:getsen…
denrase 90f0e93
rename platform check to runtime checker
denrase 91851e6
remove todos
denrase e9351bd
add cl entry
denrase d70dc31
fix test expectations
denrase 313aef8
Merge branch 'v9' into refactor/cleanup-platform-mocking
denrase cd186ad
fix typo
denrase 067b84c
fix warnings
denrase 1f9fff6
Merge branch 'v9' into refactor/cleanup-platform-mocking
denrase File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,33 @@ | ||
import 'dart:io' as io show Platform; | ||
import 'dart:io' as io; | ||
|
||
import 'platform.dart'; | ||
|
||
const Platform instance = IOPlatform(); | ||
|
||
/// [Platform] implementation that delegates directly to `dart:io`. | ||
class IOPlatform extends Platform { | ||
/// Creates a new [IOPlatform]. | ||
const IOPlatform(); | ||
class PlatformBase { | ||
const PlatformBase(); | ||
|
||
@override | ||
String get operatingSystem => io.Platform.operatingSystem; | ||
OperatingSystem get operatingSystem { | ||
switch (io.Platform.operatingSystem) { | ||
case 'macos': | ||
return OperatingSystem.macos; | ||
case 'windows': | ||
return OperatingSystem.windows; | ||
case 'linux': | ||
return OperatingSystem.linux; | ||
case 'android': | ||
return OperatingSystem.android; | ||
case 'ios': | ||
return OperatingSystem.ios; | ||
case 'fuchsia': | ||
return OperatingSystem.fuchsia; | ||
default: | ||
return OperatingSystem.unknown; | ||
} | ||
} | ||
|
||
@override | ||
String get operatingSystemVersion => io.Platform.operatingSystemVersion; | ||
String? get operatingSystemVersion => io.Platform.operatingSystemVersion; | ||
|
||
@override | ||
String get localHostname => io.Platform.localHostname; | ||
|
||
bool get isWeb => false; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import 'platform.dart'; | ||
|
||
class MockPlatform extends Platform { | ||
@override | ||
late final bool isWeb; | ||
|
||
@override | ||
late final OperatingSystem operatingSystem; | ||
|
||
@override | ||
late final String? operatingSystemVersion; | ||
|
||
@override | ||
late final bool supportsNativeIntegration; | ||
|
||
MockPlatform( | ||
{OperatingSystem? operatingSystem, | ||
String? operatingSystemVersion, | ||
bool? isWeb, | ||
bool? supportsNativeIntegration}) { | ||
this.isWeb = isWeb ?? super.isWeb; | ||
this.operatingSystem = operatingSystem ?? super.operatingSystem; | ||
this.operatingSystemVersion = | ||
operatingSystemVersion ?? super.operatingSystemVersion; | ||
this.supportsNativeIntegration = | ||
supportsNativeIntegration ?? super.supportsNativeIntegration; | ||
} | ||
|
||
factory MockPlatform.android({bool isWeb = false}) { | ||
return MockPlatform(operatingSystem: OperatingSystem.android, isWeb: isWeb); | ||
} | ||
|
||
factory MockPlatform.iOS({bool isWeb = false}) { | ||
return MockPlatform(operatingSystem: OperatingSystem.ios, isWeb: isWeb); | ||
} | ||
|
||
factory MockPlatform.macOS({bool isWeb = false}) { | ||
return MockPlatform(operatingSystem: OperatingSystem.macos, isWeb: isWeb); | ||
} | ||
|
||
factory MockPlatform.linux({bool isWeb = false}) { | ||
return MockPlatform(operatingSystem: OperatingSystem.linux, isWeb: isWeb); | ||
} | ||
|
||
factory MockPlatform.windows({bool isWeb = false}) { | ||
return MockPlatform(operatingSystem: OperatingSystem.windows, isWeb: isWeb); | ||
} | ||
|
||
factory MockPlatform.fuchsia({bool isWeb = false}) { | ||
return MockPlatform(operatingSystem: OperatingSystem.fuchsia, isWeb: isWeb); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,30 @@ | ||
import 'dart:typed_data'; | ||
|
||
import '_io_platform.dart' if (dart.library.js_interop) '_web_platform.dart' | ||
as platform; | ||
|
||
const Platform instance = platform.instance; | ||
as impl; | ||
|
||
abstract class Platform { | ||
class Platform extends impl.PlatformBase { | ||
const Platform(); | ||
|
||
/// A string (`linux`, `macos`, `windows`, `android`, `ios`, or `fuchsia`) | ||
/// representing the operating system. | ||
String get operatingSystem; | ||
|
||
/// A string representing the version of the operating system or platform. | ||
String get operatingSystemVersion; | ||
bool get isLinux => operatingSystem == OperatingSystem.linux; | ||
|
||
/// Get the local hostname for the system. | ||
String get localHostname; | ||
bool get isMacOS => operatingSystem == OperatingSystem.macos; | ||
|
||
/// Endianness of this platform. | ||
Endian get endian => Endian.host; | ||
bool get isWindows => operatingSystem == OperatingSystem.windows; | ||
|
||
/// True if the operating system is Linux. | ||
bool get isLinux => (operatingSystem == 'linux'); | ||
bool get isAndroid => operatingSystem == OperatingSystem.android; | ||
|
||
/// True if the operating system is OS X. | ||
bool get isMacOS => (operatingSystem == 'macos'); | ||
bool get isIOS => operatingSystem == OperatingSystem.ios; | ||
|
||
/// True if the operating system is Windows. | ||
bool get isWindows => (operatingSystem == 'windows'); | ||
bool get isFuchsia => operatingSystem == OperatingSystem.fuchsia; | ||
|
||
/// True if the operating system is Android. | ||
bool get isAndroid => (operatingSystem == 'android'); | ||
|
||
/// True if the operating system is iOS. | ||
bool get isIOS => (operatingSystem == 'ios'); | ||
bool get supportsNativeIntegration => !isFuchsia; | ||
} | ||
|
||
/// True if the operating system is Fuchsia | ||
bool get isFuchsia => (operatingSystem == 'fuchsia'); | ||
enum OperatingSystem { | ||
android, | ||
fuchsia, | ||
ios, | ||
linux, | ||
macos, | ||
windows, | ||
unknown, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.