OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /// An enum of all operating systems supported by Dart. | 5 /// An enum of all operating systems supported by Dart. |
6 /// | 6 /// |
7 /// This is used for selecting which operating systems a test can run on. Even | 7 /// This is used for selecting which operating systems a test can run on. Even |
8 /// for browser tests, this indicates the operating system of the machine | 8 /// for browser tests, this indicates the operating system of the machine |
9 /// running the test runner. | 9 /// running the test runner. |
10 class OperatingSystem { | 10 class OperatingSystem { |
11 /// Microsoft Windows. | 11 /// Microsoft Windows. |
12 static const windows = const OperatingSystem._("Windows", "windows"); | 12 static const windows = const OperatingSystem._("Windows", "windows"); |
13 | 13 |
14 /// Mac OS X. | 14 /// Mac OS X. |
15 static const macOS = const OperatingSystem._("OS X", "mac-os"); | 15 static const macOS = const OperatingSystem._("OS X", "mac-os"); |
16 | 16 |
17 /// GNU/Linux. | 17 /// GNU/Linux. |
18 static const linux = const OperatingSystem._("Linux", "linux"); | 18 static const linux = const OperatingSystem._("Linux", "linux"); |
19 | 19 |
20 /// Android. | 20 /// Android. |
21 /// | 21 /// |
22 /// Since this is the operating system the test runner is running on, this | 22 /// Since this is the operating system the test runner is running on, this |
23 /// won't be true when testing remotely on an Android browser. | 23 /// won't be true when testing remotely on an Android browser. |
24 static const android = const OperatingSystem._("Android", "android"); | 24 static const android = const OperatingSystem._("Android", "android"); |
25 | 25 |
| 26 /// iOS. |
| 27 /// |
| 28 /// Since this is the operating system the test runner is running on, this |
| 29 /// won't be true when testing remotely on an iOS browser. |
| 30 static const iOS = const OperatingSystem._("iOS", "ios"); |
| 31 |
26 /// No operating system. | 32 /// No operating system. |
27 /// | 33 /// |
28 /// This is used when running in the browser, or if an unrecognized operating | 34 /// This is used when running in the browser, or if an unrecognized operating |
29 /// system is used. It can't be referenced by name in platform selectors. | 35 /// system is used. It can't be referenced by name in platform selectors. |
30 static const none = const OperatingSystem._("none", "none"); | 36 static const none = const OperatingSystem._("none", "none"); |
31 | 37 |
32 /// A list of all instances of [OperatingSystem] other than [none]. | 38 /// A list of all instances of [OperatingSystem] other than [none]. |
33 static const all = const [windows, macOS, linux, android]; | 39 static const all = const [windows, macOS, linux, android, iOS]; |
34 | 40 |
35 /// Finds an operating system by its name. | 41 /// Finds an operating system by its name. |
36 /// | 42 /// |
37 /// If no operating system is found, returns [none]. | 43 /// If no operating system is found, returns [none]. |
38 static OperatingSystem find(String name) => | 44 static OperatingSystem find(String name) => |
39 all.firstWhere((platform) => platform.name == name, orElse: () => null); | 45 all.firstWhere((platform) => platform.name == name, orElse: () => null); |
40 | 46 |
41 /// Finds an operating system by the return value from `dart:io`'s | 47 /// Finds an operating system by the return value from `dart:io`'s |
42 /// `Platform.operatingSystem`. | 48 /// `Platform.operatingSystem`. |
43 /// | 49 /// |
44 /// If no operating system is found, returns [none]. | 50 /// If no operating system is found, returns [none]. |
45 static OperatingSystem findByIoName(String name) { | 51 static OperatingSystem findByIoName(String name) { |
46 switch (name) { | 52 switch (name) { |
47 case "windows": return windows; | 53 case "windows": return windows; |
48 case "macos": return macOS; | 54 case "macos": return macOS; |
49 case "linux": return linux; | 55 case "linux": return linux; |
50 case "android": return android; | 56 case "android": return android; |
| 57 case "ios": return iOS; |
51 default: return none; | 58 default: return none; |
52 } | 59 } |
53 } | 60 } |
54 | 61 |
55 /// The human-friendly of the operating system. | 62 /// The human-friendly of the operating system. |
56 final String name; | 63 final String name; |
57 | 64 |
58 /// The identifier used to look up the operating system. | 65 /// The identifier used to look up the operating system. |
59 final String identifier; | 66 final String identifier; |
60 | 67 |
61 /// Whether this is a POSIX-ish operating system. | 68 /// Whether this is a POSIX-ish operating system. |
62 bool get isPosix => this != windows && this != none; | 69 bool get isPosix => this != windows && this != none; |
63 | 70 |
64 const OperatingSystem._(this.name, this.identifier); | 71 const OperatingSystem._(this.name, this.identifier); |
65 | 72 |
66 String toString() => name; | 73 String toString() => name; |
67 } | 74 } |
OLD | NEW |