Line data Source code
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
3 : // BSD-style license that can be found in the LICENSE file.
4 :
5 : /// An enum of all operating systems supported by Dart.
6 : ///
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
9 : /// running the test runner.
10 : class OperatingSystem {
11 : /// Microsoft Windows.
12 : static const windows = const OperatingSystem._("Windows", "windows");
13 :
14 : /// Mac OS X.
15 : static const macOS = const OperatingSystem._("OS X", "mac-os");
16 :
17 : /// GNU/Linux.
18 : static const linux = const OperatingSystem._("Linux", "linux");
19 :
20 : /// Android.
21 : ///
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.
24 : static const android = const OperatingSystem._("Android", "android");
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 :
32 : /// No operating system.
33 : ///
34 : /// This is used when running in the browser, or if an unrecognized operating
35 : /// system is used. It can't be referenced by name in platform selectors.
36 : static const none = const OperatingSystem._("none", "none");
37 :
38 : /// A list of all instances of [OperatingSystem] other than [none].
39 : static const all = const [windows, macOS, linux, android, iOS];
40 :
41 : /// Finds an operating system by its name.
42 : ///
43 : /// If no operating system is found, returns [none].
44 : static OperatingSystem find(String identifier) =>
45 0 : all.firstWhere((platform) => platform.identifier == identifier,
46 : orElse: () => null);
47 :
48 : /// Finds an operating system by the return value from `dart:io`'s
49 : /// `Platform.operatingSystem`.
50 : ///
51 : /// If no operating system is found, returns [none].
52 : static OperatingSystem findByIoName(String name) {
53 : switch (name) {
54 0 : case "windows":
55 : return windows;
56 0 : case "macos":
57 : return macOS;
58 0 : case "linux":
59 : return linux;
60 0 : case "android":
61 : return android;
62 0 : case "ios":
63 : return iOS;
64 : default:
65 : return none;
66 : }
67 : }
68 :
69 : /// The human-friendly of the operating system.
70 : final String name;
71 :
72 : /// The identifier used to look up the operating system.
73 : final String identifier;
74 :
75 : /// Whether this is a POSIX-ish operating system.
76 0 : bool get isPosix => this != windows && this != none;
77 :
78 5 : const OperatingSystem._(this.name, this.identifier);
79 :
80 0 : String toString() => name;
81 : }
|