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

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

Issue 1092153003: Support an @OnPlatform annotation. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes 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/browser/runner_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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 expect(() => parseMetadata(_path), throwsFormatException); 277 expect(() => parseMetadata(_path), throwsFormatException);
278 }); 278 });
279 279
280 test("multiple @Skips", () { 280 test("multiple @Skips", () {
281 new File(_path).writeAsStringSync( 281 new File(_path).writeAsStringSync(
282 "@Skip('foo')\n@Skip('bar')\nlibrary foo;"); 282 "@Skip('foo')\n@Skip('bar')\nlibrary foo;");
283 expect(() => parseMetadata(_path), throwsFormatException); 283 expect(() => parseMetadata(_path), throwsFormatException);
284 }); 284 });
285 }); 285 });
286 }); 286 });
287
288 group("@OnPlatform:", () {
289 test("parses a valid annotation", () {
290 new File(_path).writeAsStringSync("""
291 @OnPlatform(const {
292 'chrome': const Timeout.factor(2),
293 'vm': const [const Skip(), const Timeout.factor(3)]
294 })
295 library foo;""");
296 var metadata = parseMetadata(_path);
297
298 var key = metadata.onPlatform.keys.first;
299 expect(key.evaluate(TestPlatform.chrome), isTrue);
300 expect(key.evaluate(TestPlatform.vm), isFalse);
301 var value = metadata.onPlatform.values.first;
302 expect(value.timeout.scaleFactor, equals(2));
303
304 key = metadata.onPlatform.keys.last;
305 expect(key.evaluate(TestPlatform.vm), isTrue);
306 expect(key.evaluate(TestPlatform.chrome), isFalse);
307 value = metadata.onPlatform.values.last;
308 expect(value.skip, isTrue);
309 expect(value.timeout.scaleFactor, equals(3));
310 });
311
312 test("ignores a constructor named OnPlatform", () {
313 new File(_path).writeAsStringSync("@foo.OnPlatform('foo')\nlibrary foo;");
314 var metadata = parseMetadata(_path);
315 expect(metadata.testOn, equals(PlatformSelector.all));
316 });
317
318 group("throws an error for", () {
319 test("a named constructor", () {
320 new File(_path).writeAsStringSync(
321 "@OnPlatform.name(const {})\nlibrary foo;");
322 expect(() => parseMetadata(_path), throwsFormatException);
323 });
324
325 test("no argument list", () {
326 new File(_path).writeAsStringSync("@OnPlatform\nlibrary foo;");
327 expect(() => parseMetadata(_path), throwsFormatException);
328 });
329
330 test("an empty argument list", () {
331 new File(_path).writeAsStringSync("@OnPlatform()\nlibrary foo;");
332 expect(() => parseMetadata(_path), throwsFormatException);
333 });
334
335 test("a named argument", () {
336 new File(_path).writeAsStringSync(
337 "@OnPlatform(map: const {})\nlibrary foo;");
338 expect(() => parseMetadata(_path), throwsFormatException);
339 });
340
341 test("multiple arguments", () {
342 new File(_path).writeAsStringSync(
343 "@OnPlatform(const {}, const {})\nlibrary foo;");
344 expect(() => parseMetadata(_path), throwsFormatException);
345 });
346
347 test("a non-map argument", () {
348 new File(_path).writeAsStringSync(
349 "@OnPlatform(const Skip())\nlibrary foo;");
350 expect(() => parseMetadata(_path), throwsFormatException);
351 });
352
353 test("a non-const map", () {
354 new File(_path).writeAsStringSync("@OnPlatform({})\nlibrary foo;");
355 expect(() => parseMetadata(_path), throwsFormatException);
356 });
357
358 test("a map with a non-String key", () {
359 new File(_path).writeAsStringSync(
360 "@OnPlatform(const {1: const Skip()})\nlibrary foo;");
361 expect(() => parseMetadata(_path), throwsFormatException);
362 });
363
364 test("a map with a unparseable key", () {
365 new File(_path).writeAsStringSync(
366 "@OnPlatform(const {'invalid': const Skip()})\nlibrary foo;");
367 expect(() => parseMetadata(_path), throwsFormatException);
368 });
369
370 test("a map with an invalid value", () {
371 new File(_path).writeAsStringSync(
372 "@OnPlatform(const {'vm': const TestOn('vm')})\nlibrary foo;");
373 expect(() => parseMetadata(_path), throwsFormatException);
374 });
375
376 test("a map with an invalid value in a list", () {
377 new File(_path).writeAsStringSync(
378 "@OnPlatform(const {'vm': [const TestOn('vm')]})\nlibrary foo;");
379 expect(() => parseMetadata(_path), throwsFormatException);
380 });
381
382 test("multiple @OnPlatforms", () {
383 new File(_path).writeAsStringSync(
384 "@OnPlatform(const {})\n@OnPlatform(const {})\nlibrary foo;");
385 expect(() => parseMetadata(_path), throwsFormatException);
386 });
387 });
388 });
287 } 389 }
OLDNEW
« no previous file with comments | « test/runner/browser/runner_test.dart ('k') | test/runner/runner_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698