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

Side by Side Diff: test/backend/platform_selector/evaluate_test.dart

Issue 1004013002: Add support for evaluating platform selectors. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Code review changes 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
« no previous file with comments | « lib/src/runner/test_platform.dart ('k') | test/runner/browser/loader_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 import 'dart:io';
6
7 import 'package:unittest/unittest.dart';
8 import 'package:unittest/src/backend/operating_system.dart';
9 import 'package:unittest/src/backend/platform_selector.dart';
10 import 'package:unittest/src/backend/test_platform.dart';
11
12 void main() {
13 test("new PlatformSelector.parse() disallows invalid variables", () {
14 expect(() => new PlatformSelector.parse("undefined"),
15 throwsFormatException);
16 });
17
18 group("operator:", () {
19 test("conditional", () {
20 _expectEval("vm ? vm : browser", true);
21 _expectEval("vm ? browser : vm", false);
22 _expectEval("browser ? vm : browser", false);
23 _expectEval("browser ? browser : vm", true);
24 });
25
26 test("or", () {
27 _expectEval("vm || vm", true);
28 _expectEval("vm || browser", true);
29 _expectEval("browser || vm", true);
30 _expectEval("browser || browser", false);
31 });
32
33 test("and", () {
34 _expectEval("vm && vm", true);
35 _expectEval("vm && browser", false);
36 _expectEval("browser && vm", false);
37 _expectEval("browser && browser", false);
38 });
39
40 test("not", () {
41 _expectEval("!vm", false);
42 _expectEval("!browser", true);
43 });
44 });
45
46 group("baseline variable:", () {
47 test("vm", () {
48 _expectEval("vm", true, platform: TestPlatform.vm);
49 _expectEval("vm", false, platform: TestPlatform.chrome);
50 });
51
52 test("chrome", () {
53 _expectEval("chrome", true, platform: TestPlatform.chrome);
54 _expectEval("chrome", false, platform: TestPlatform.vm);
55 });
56
57 test("windows", () {
58 _expectEval("windows", true, os: OperatingSystem.windows);
59 _expectEval("windows", false, os: OperatingSystem.linux);
60 _expectEval("windows", false, os: OperatingSystem.none);
61 });
62
63 test("mac-os", () {
64 _expectEval("mac-os", true, os: OperatingSystem.macOS);
65 _expectEval("mac-os", false, os: OperatingSystem.linux);
66 _expectEval("mac-os", false, os: OperatingSystem.none);
67 });
68
69 test("linux", () {
70 _expectEval("linux", true, os: OperatingSystem.linux);
71 _expectEval("linux", false, os: OperatingSystem.android);
72 _expectEval("linux", false, os: OperatingSystem.none);
73 });
74
75 test("android", () {
76 _expectEval("android", true, os: OperatingSystem.android);
77 _expectEval("android", false, os: OperatingSystem.linux);
78 _expectEval("android", false, os: OperatingSystem.none);
79 });
80 });
81
82 group("derived variable:", () {
83 test("dart-vm", () {
84 _expectEval("dart-vm", true, platform: TestPlatform.vm);
85 _expectEval("dart-vm", false, platform: TestPlatform.chrome);
86 });
87
88 test("browser", () {
89 _expectEval("browser", true, platform: TestPlatform.chrome);
90 _expectEval("browser", false, platform: TestPlatform.vm);
91 });
92
93 test("js", () {
94 _expectEval("js", true, platform: TestPlatform.chrome);
95 _expectEval("js", false, platform: TestPlatform.vm);
96 });
97
98 test("blink", () {
99 _expectEval("blink", true, platform: TestPlatform.chrome);
100 _expectEval("blink", false, platform: TestPlatform.vm);
101 });
102
103 test("posix", () {
104 _expectEval("posix", false, os: OperatingSystem.windows);
105 _expectEval("posix", true, os: OperatingSystem.macOS);
106 _expectEval("posix", true, os: OperatingSystem.linux);
107 _expectEval("posix", true, os: OperatingSystem.android);
108 _expectEval("posix", false, os: OperatingSystem.none);
109 });
110 });
111 }
112
113 /// Asserts that [expression] evaluates to [result] on [platform] and [os].
114 ///
115 /// [platform] defaults to [TestPlatform.vm]; [os] defaults to the current
116 /// operating system.
117 void _expectEval(String expression, bool result, {TestPlatform platform,
118 OperatingSystem os}) {
119
120 var reason = 'Expected "$expression" to evaluate to $result';
121 if (platform != null && os != null) {
122 reason += ' on $platform and $os.';
123 } else if (platform != null || os != null) {
124 reason += ' on ${platform == null ? os : platform}';
125 }
126
127 expect(_eval(expression, platform: platform, os: os), equals(result),
128 reason: '$reason.');
129 }
130
131 /// Returns the result of evaluating [expression] on [platform] and [os].
132 ///
133 /// [platform] defaults to [TestPlatform.vm]; [os] defaults to the current
134 /// operating system.
135 bool _eval(String expression, {TestPlatform platform, OperatingSystem os}) {
136 if (platform == null) platform = TestPlatform.vm;
137 if (os == null) os = OperatingSystem.findByIoName(Platform.operatingSystem);
138 var selector = new PlatformSelector.parse(expression);
139 return selector.evaluate(platform, os: os);
140 }
OLDNEW
« no previous file with comments | « lib/src/runner/test_platform.dart ('k') | test/runner/browser/loader_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698