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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: lib/src/backend/operating_system.dart
diff --git a/lib/src/backend/operating_system.dart b/lib/src/backend/operating_system.dart
new file mode 100644
index 0000000000000000000000000000000000000000..78cff21c298198742fe16f3a4a29ddd443a25769
--- /dev/null
+++ b/lib/src/backend/operating_system.dart
@@ -0,0 +1,66 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library unittest.backend.operating_system;
+
+/// An enum of all operating systems supported by Dart.
+///
+/// This is used for selecting which operating systems a test can run on. Even
+/// for browser tests, this indicates the operating system of the machine
+/// running the test runner.
+class OperatingSystem {
+ /// Microsoft Windows.
+ static const windows = const OperatingSystem._("windows");
+
+ /// Mac OS X.
+ 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.
+
+ /// GNU/Linux.
+ static const linux = const OperatingSystem._("linux", isPosix: true);
+
+ /// Android.
+ ///
+ /// Since this is the operating system the test runner is running on, this
+ /// won't be true when testing remotely on an Android browser.
+ static const android = const OperatingSystem._("android", isPosix: true);
+
+ /// No operating system.
+ ///
+ /// This is used when running in the browser, or if an unrecognized operating
+ /// system is used. It can't be referenced by name in platform selectors.
+ static const none = const OperatingSystem._("none");
+
+ /// A list of all instances of [OperatingSystem] other than [none].
+ static const all = const [windows, macOs, linux, android];
+
+ /// Finds an operating system by its name.
+ ///
+ /// If no operating system is found, returns [none].
+ static OperatingSystem find(String name) =>
+ all.firstWhere((platform) => platform.name == name, orElse: () => null);
+
+ /// Finds an operating system by the return value from `dart:io`'s
+ /// `Platform.operatingSystem`.
+ ///
+ /// If no operating system is found, returns [none].
+ static OperatingSystem findByIoName(String name) {
+ switch (name) {
+ case "windows": return windows;
+ case "macos": return macOs;
+ case "linux": return linux;
+ case "android": return android;
+ default: return none;
+ }
+ }
+
+ /// The name of the operating system.
+ final String name;
+
+ /// Whether this is a POSIX-ish operating system.
+ 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.
+
+ const OperatingSystem._(this.name, {this.isPosix: false});
+
+ String toString() => name;
+}

Powered by Google App Engine
This is Rietveld 408576698