Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: lib/src/backend/operating_system.dart

Issue 1004013002: Add support for evaluating platform selectors. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 library unittest.backend.operating_system;
6
7 /// An enum of all operating systems supported by Dart.
8 ///
9 /// This is used for selecting which operating systems a test can run on. Even
10 /// for browser tests, this indicates the operating system of the machine
11 /// running the test runner.
12 class OperatingSystem {
13 /// Microsoft Windows.
14 static const windows = const OperatingSystem._("windows");
15
16 /// Mac OS X.
17 static const macOs = const OperatingSystem._("mac-os", isPosix: true);
Bob Nystrom 2015/03/16 16:54:26 "macOS".
Bob Nystrom 2015/03/16 16:54:26 "macOS".
nweiz 2015/03/24 01:03:28 Done.
18
19 /// GNU/Linux.
20 static const linux = const OperatingSystem._("linux", isPosix: true);
21
22 /// Android.
23 ///
24 /// Since this is the operating system the test runner is running on, this
25 /// won't be true when testing remotely on an Android browser.
26 static const android = const OperatingSystem._("android", isPosix: true);
27
28 /// No operating system.
29 ///
30 /// This is used when running in the browser, or if an unrecognized operating
31 /// system is used. It can't be referenced by name in platform selectors.
32 static const none = const OperatingSystem._("none");
33
34 /// A list of all instances of [OperatingSystem] other than [none].
35 static const all = const [windows, macOs, linux, android];
36
37 /// Finds an operating system by its name.
38 ///
39 /// If no operating system is found, returns [none].
40 static OperatingSystem find(String name) =>
41 all.firstWhere((platform) => platform.name == name, orElse: () => null);
42
43 /// Finds an operating system by the return value from `dart:io`'s
44 /// `Platform.operatingSystem`.
45 ///
46 /// If no operating system is found, returns [none].
47 static OperatingSystem findByIoName(String name) {
48 switch (name) {
49 case "windows": return windows;
50 case "macos": return macOs;
51 case "linux": return linux;
52 case "android": return android;
53 default: return none;
54 }
55 }
56
57 /// The name of the operating system.
58 final String name;
59
60 /// Whether this is a POSIX-ish operating system.
61 final bool isPosix;
Bob Nystrom 2015/03/16 16:54:26 How about just: bool get isPosix => this != Opera
nweiz 2015/03/24 01:03:28 Done.
62
63 const OperatingSystem._(this.name, {this.isPosix: false});
64
65 String toString() => name;
66 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698