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

Side by Side Diff: test/runner/parse_metadata_test.dart

Issue 1086213002: Support a @Timeout annotation. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: CHANGELOG + README Created 5 years, 8 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 | « test/runner/isolate_listener_test.dart ('k') | test/runner/runner_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
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 @TestOn("vm") 5 @TestOn("vm")
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:path/path.dart' as p; 9 import 'package:path/path.dart' as p;
10 import 'package:test/test.dart'; 10 import 'package:test/test.dart';
(...skipping 12 matching lines...) Expand all
23 }); 23 });
24 24
25 tearDown(() { 25 tearDown(() {
26 new Directory(_sandbox).deleteSync(recursive: true); 26 new Directory(_sandbox).deleteSync(recursive: true);
27 }); 27 });
28 28
29 test("returns empty metadata for an empty file", () { 29 test("returns empty metadata for an empty file", () {
30 new File(_path).writeAsStringSync(""); 30 new File(_path).writeAsStringSync("");
31 var metadata = parseMetadata(_path); 31 var metadata = parseMetadata(_path);
32 expect(metadata.testOn, equals(PlatformSelector.all)); 32 expect(metadata.testOn, equals(PlatformSelector.all));
33 expect(metadata.timeout.scaleFactor, equals(1));
33 }); 34 });
34 35
35 test("ignores irrelevant annotations", () { 36 test("ignores irrelevant annotations", () {
36 new File(_path).writeAsStringSync("@Fblthp\n@Fblthp.foo\nlibrary foo;"); 37 new File(_path).writeAsStringSync("@Fblthp\n@Fblthp.foo\nlibrary foo;");
37 var metadata = parseMetadata(_path); 38 var metadata = parseMetadata(_path);
38 expect(metadata.testOn, equals(PlatformSelector.all)); 39 expect(metadata.testOn, equals(PlatformSelector.all));
39 }); 40 });
40 41
41 test("parses a valid annotation", () {
42 new File(_path).writeAsStringSync("@TestOn('vm')\nlibrary foo;");
43 var metadata = parseMetadata(_path);
44 expect(metadata.testOn.evaluate(TestPlatform.vm), isTrue);
45 expect(metadata.testOn.evaluate(TestPlatform.chrome), isFalse);
46 });
47
48 test("parses a prefixed annotation", () { 42 test("parses a prefixed annotation", () {
49 new File(_path).writeAsStringSync( 43 new File(_path).writeAsStringSync(
50 "@foo.TestOn('vm')\n" 44 "@foo.TestOn('vm')\n"
51 "import 'package:test/test.dart' as foo;"); 45 "import 'package:test/test.dart' as foo;");
52 var metadata = parseMetadata(_path); 46 var metadata = parseMetadata(_path);
53 expect(metadata.testOn.evaluate(TestPlatform.vm), isTrue); 47 expect(metadata.testOn.evaluate(TestPlatform.vm), isTrue);
54 expect(metadata.testOn.evaluate(TestPlatform.chrome), isFalse); 48 expect(metadata.testOn.evaluate(TestPlatform.chrome), isFalse);
55 }); 49 });
56 50
57 test("ignores a constructor named TestOn", () { 51 group("@TestOn:", () {
58 new File(_path).writeAsStringSync("@foo.TestOn('foo')\nlibrary foo;"); 52 test("parses a valid annotation", () {
59 var metadata = parseMetadata(_path); 53 new File(_path).writeAsStringSync("@TestOn('vm')\nlibrary foo;");
60 expect(metadata.testOn, equals(PlatformSelector.all)); 54 var metadata = parseMetadata(_path);
55 expect(metadata.testOn.evaluate(TestPlatform.vm), isTrue);
56 expect(metadata.testOn.evaluate(TestPlatform.chrome), isFalse);
57 });
58
59 test("ignores a constructor named TestOn", () {
60 new File(_path).writeAsStringSync("@foo.TestOn('foo')\nlibrary foo;");
61 var metadata = parseMetadata(_path);
62 expect(metadata.testOn, equals(PlatformSelector.all));
63 });
64
65 group("throws an error for", () {
66 test("a named constructor", () {
67 new File(_path).writeAsStringSync("@TestOn.name('foo')\nlibrary foo;");
68 expect(() => parseMetadata(_path), throwsFormatException);
69 });
70
71 test("no argument list", () {
72 new File(_path).writeAsStringSync("@TestOn\nlibrary foo;");
73 expect(() => parseMetadata(_path), throwsFormatException);
74 });
75
76 test("an empty argument list", () {
77 new File(_path).writeAsStringSync("@TestOn()\nlibrary foo;");
78 expect(() => parseMetadata(_path), throwsFormatException);
79 });
80
81 test("a named argument", () {
82 new File(_path).writeAsStringSync(
83 "@TestOn(expression: 'foo')\nlibrary foo;");
84 expect(() => parseMetadata(_path), throwsFormatException);
85 });
86
87 test("multiple arguments", () {
88 new File(_path).writeAsStringSync("@TestOn('foo', 'bar')\nlibrary foo;") ;
89 expect(() => parseMetadata(_path), throwsFormatException);
90 });
91
92 test("a non-string argument", () {
93 new File(_path).writeAsStringSync("@TestOn(123)\nlibrary foo;");
94 expect(() => parseMetadata(_path), throwsFormatException);
95 });
96
97 test("multiple @TestOns", () {
98 new File(_path).writeAsStringSync(
99 "@TestOn('foo')\n@TestOn('bar')\nlibrary foo;");
100 expect(() => parseMetadata(_path), throwsFormatException);
101 });
102 });
61 }); 103 });
62 104
63 group("throws an error for", () { 105 group("@Timeout:", () {
64 test("a named constructor", () { 106 test("parses a valid duration annotation", () {
65 new File(_path).writeAsStringSync("@TestOn.name('foo')\nlibrary foo;"); 107 new File(_path).writeAsStringSync("""
66 expect(() => parseMetadata(_path), throwsFormatException); 108 @Timeout(const Duration(
109 hours: 1,
110 minutes: 2,
111 seconds: 3,
112 milliseconds: 4,
113 microseconds: 5))
114
115 library foo;
116 """);
117 var metadata = parseMetadata(_path);
118 expect(metadata.timeout.duration,
119 equals(new Duration(
120 hours: 1,
121 minutes: 2,
122 seconds: 3,
123 milliseconds: 4,
124 microseconds: 5)));
67 }); 125 });
68 126
69 test("no argument list", () { 127 test("parses a valid int factor annotation", () {
70 new File(_path).writeAsStringSync("@TestOn\nlibrary foo;"); 128 new File(_path).writeAsStringSync("""
71 expect(() => parseMetadata(_path), throwsFormatException); 129 @Timeout.factor(1)
130
131 library foo;
132 """);
133 var metadata = parseMetadata(_path);
134 expect(metadata.timeout.scaleFactor, equals(1));
72 }); 135 });
73 136
74 test("an empty argument list", () { 137 test("parses a valid double factor annotation", () {
75 new File(_path).writeAsStringSync("@TestOn()\nlibrary foo;"); 138 new File(_path).writeAsStringSync("""
76 expect(() => parseMetadata(_path), throwsFormatException); 139 @Timeout.factor(0.5)
140
141 library foo;
142 """);
143 var metadata = parseMetadata(_path);
144 expect(metadata.timeout.scaleFactor, equals(0.5));
77 }); 145 });
78 146
79 test("a named argument", () { 147 test("ignores a constructor named Timeout", () {
80 new File(_path).writeAsStringSync( 148 new File(_path).writeAsStringSync("@foo.Timeout('foo')\nlibrary foo;");
81 "@TestOn(expression: 'foo')\nlibrary foo;"); 149 var metadata = parseMetadata(_path);
82 expect(() => parseMetadata(_path), throwsFormatException); 150 expect(metadata.timeout.scaleFactor, equals(1));
83 }); 151 });
84 152
85 test("multiple arguments", () { 153 group("throws an error for", () {
86 new File(_path).writeAsStringSync("@TestOn('foo', 'bar')\nlibrary foo;"); 154 test("an unknown named constructor", () {
87 expect(() => parseMetadata(_path), throwsFormatException); 155 new File(_path).writeAsStringSync("@Timeout.name('foo')\nlibrary foo;");
88 }); 156 expect(() => parseMetadata(_path), throwsFormatException);
157 });
89 158
90 test("a non-string argument", () { 159 test("no argument list", () {
91 new File(_path).writeAsStringSync("@TestOn(123)\nlibrary foo;"); 160 new File(_path).writeAsStringSync("@Timeout\nlibrary foo;");
92 expect(() => parseMetadata(_path), throwsFormatException); 161 expect(() => parseMetadata(_path), throwsFormatException);
93 }); 162 });
94 163
95 test("multiple @TestOns", () { 164 test("an empty argument list", () {
96 new File(_path).writeAsStringSync( 165 new File(_path).writeAsStringSync("@Timeout()\nlibrary foo;");
97 "@TestOn('foo')\n@TestOn('bar')\nlibrary foo;"); 166 expect(() => parseMetadata(_path), throwsFormatException);
98 expect(() => parseMetadata(_path), throwsFormatException); 167 });
168
169 test("a named argument", () {
170 new File(_path).writeAsStringSync(
171 "@Timeout(duration: const Duration(seconds: 1))\nlibrary foo;");
172 expect(() => parseMetadata(_path), throwsFormatException);
173 });
174
175 test("multiple arguments", () {
176 new File(_path).writeAsStringSync(
177 "@Timeout.factor(1, 2)\nlibrary foo;");
178 expect(() => parseMetadata(_path), throwsFormatException);
179 });
180
181 test("a non-Duration argument", () {
182 new File(_path).writeAsStringSync("@Timeout(10)\nlibrary foo;");
183 expect(() => parseMetadata(_path), throwsFormatException);
184 });
185
186 test("a non-num argument", () {
187 new File(_path).writeAsStringSync(
188 "@Timeout.factor('foo')\nlibrary foo;");
189 expect(() => parseMetadata(_path), throwsFormatException);
190 });
191
192 test("multiple @Timeouts", () {
193 new File(_path).writeAsStringSync(
194 "@Timeout.factor(1)\n@Timeout.factor(2)\nlibrary foo;");
195 expect(() => parseMetadata(_path), throwsFormatException);
196 });
197
198 group("a Duration with", () {
199 test("a non-const constructor", () {
200 new File(_path).writeAsStringSync(
201 "@Timeout(new Duration(1))\nlibrary foo;");
202 expect(() => parseMetadata(_path), throwsFormatException);
203 });
204
205 test("a named constructor", () {
206 new File(_path).writeAsStringSync(
207 "@Timeout(const Duration.name(seconds: 1))\nlibrary foo;");
208 expect(() => parseMetadata(_path), throwsFormatException);
209 });
210
211 test("a positional argument", () {
212 new File(_path).writeAsStringSync(
213 "@Timeout(const Duration(1))\nlibrary foo;");
214 expect(() => parseMetadata(_path), throwsFormatException);
215 });
216
217 test("an unknown named argument", () {
218 new File(_path).writeAsStringSync(
219 "@Timeout(const Duration(name: 1))\nlibrary foo;");
220 expect(() => parseMetadata(_path), throwsFormatException);
221 });
222
223 test("a duplicate named argument", () {
224 new File(_path).writeAsStringSync(
225 "@Timeout(const Duration(seconds: 1, seconds: 1))\nlibrary foo;");
226 expect(() => parseMetadata(_path), throwsFormatException);
227 });
228 });
99 }); 229 });
100 }); 230 });
101 } 231 }
OLDNEW
« no previous file with comments | « test/runner/isolate_listener_test.dart ('k') | test/runner/runner_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698