| OLD | NEW |
| 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") |
| 6 |
| 5 import 'dart:io'; | 7 import 'dart:io'; |
| 6 | 8 |
| 7 import 'package:path/path.dart' as p; | 9 import 'package:path/path.dart' as p; |
| 8 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| 11 import 'package:unittest/src/backend/platform_selector.dart'; |
| 12 import 'package:unittest/src/backend/test_platform.dart'; |
| 9 import 'package:unittest/src/runner/parse_metadata.dart'; | 13 import 'package:unittest/src/runner/parse_metadata.dart'; |
| 10 | 14 |
| 11 String _sandbox; | 15 String _sandbox; |
| 12 String _path; | 16 String _path; |
| 13 | 17 |
| 14 void main() { | 18 void main() { |
| 15 setUp(() { | 19 setUp(() { |
| 16 _sandbox = Directory.systemTemp.createTempSync('unittest_').path; | 20 _sandbox = Directory.systemTemp.createTempSync('unittest_').path; |
| 17 _path = p.join(_sandbox, "test.dart"); | 21 _path = p.join(_sandbox, "test.dart"); |
| 18 }); | 22 }); |
| 19 | 23 |
| 20 tearDown(() { | 24 tearDown(() { |
| 21 new Directory(_sandbox).deleteSync(recursive: true); | 25 new Directory(_sandbox).deleteSync(recursive: true); |
| 22 }); | 26 }); |
| 23 | 27 |
| 24 test("returns empty metadata for an empty file", () { | 28 test("returns empty metadata for an empty file", () { |
| 25 new File(_path).writeAsStringSync(""); | 29 new File(_path).writeAsStringSync(""); |
| 26 var metadata = parseMetadata(_path); | 30 var metadata = parseMetadata(_path); |
| 27 expect(metadata.testOn, isNull); | 31 expect(metadata.testOn, equals(PlatformSelector.all)); |
| 28 }); | 32 }); |
| 29 | 33 |
| 30 test("ignores irrelevant annotations", () { | 34 test("ignores irrelevant annotations", () { |
| 31 new File(_path).writeAsStringSync("@Fblthp\n@Fblthp.foo\nlibrary foo;"); | 35 new File(_path).writeAsStringSync("@Fblthp\n@Fblthp.foo\nlibrary foo;"); |
| 32 var metadata = parseMetadata(_path); | 36 var metadata = parseMetadata(_path); |
| 33 expect(metadata.testOn, isNull); | 37 expect(metadata.testOn, equals(PlatformSelector.all)); |
| 34 }); | 38 }); |
| 35 | 39 |
| 36 test("parses a valid annotation", () { | 40 test("parses a valid annotation", () { |
| 37 new File(_path).writeAsStringSync("@TestOn('foo')\nlibrary foo;"); | 41 new File(_path).writeAsStringSync("@TestOn('vm')\nlibrary foo;"); |
| 38 var metadata = parseMetadata(_path); | 42 var metadata = parseMetadata(_path); |
| 39 expect(metadata.testOn, equals("foo")); | 43 expect(metadata.testOn.evaluate(TestPlatform.vm), isTrue); |
| 44 expect(metadata.testOn.evaluate(TestPlatform.chrome), isFalse); |
| 40 }); | 45 }); |
| 41 | 46 |
| 42 test("parses a prefixed annotation", () { | 47 test("parses a prefixed annotation", () { |
| 43 new File(_path).writeAsStringSync( | 48 new File(_path).writeAsStringSync( |
| 44 "@foo.TestOn('foo')\n" | 49 "@foo.TestOn('vm')\n" |
| 45 "import 'package:unittest/unittest.dart' as foo;"); | 50 "import 'package:unittest/unittest.dart' as foo;"); |
| 46 var metadata = parseMetadata(_path); | 51 var metadata = parseMetadata(_path); |
| 47 expect(metadata.testOn, equals("foo")); | 52 expect(metadata.testOn.evaluate(TestPlatform.vm), isTrue); |
| 53 expect(metadata.testOn.evaluate(TestPlatform.chrome), isFalse); |
| 48 }); | 54 }); |
| 49 | 55 |
| 50 test("ignores a constructor named TestOn", () { | 56 test("ignores a constructor named TestOn", () { |
| 51 new File(_path).writeAsStringSync("@foo.TestOn('foo')\nlibrary foo;"); | 57 new File(_path).writeAsStringSync("@foo.TestOn('foo')\nlibrary foo;"); |
| 52 var metadata = parseMetadata(_path); | 58 var metadata = parseMetadata(_path); |
| 53 expect(metadata.testOn, isNull); | 59 expect(metadata.testOn, equals(PlatformSelector.all)); |
| 54 }); | 60 }); |
| 55 | 61 |
| 56 group("throws an error for", () { | 62 group("throws an error for", () { |
| 57 test("a named constructor", () { | 63 test("a named constructor", () { |
| 58 new File(_path).writeAsStringSync("@TestOn.name('foo')\nlibrary foo;"); | 64 new File(_path).writeAsStringSync("@TestOn.name('foo')\nlibrary foo;"); |
| 59 expect(() => parseMetadata(_path), throwsFormatException); | 65 expect(() => parseMetadata(_path), throwsFormatException); |
| 60 }); | 66 }); |
| 61 | 67 |
| 62 test("no argument list", () { | 68 test("no argument list", () { |
| 63 new File(_path).writeAsStringSync("@TestOn\nlibrary foo;"); | 69 new File(_path).writeAsStringSync("@TestOn\nlibrary foo;"); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 85 expect(() => parseMetadata(_path), throwsFormatException); | 91 expect(() => parseMetadata(_path), throwsFormatException); |
| 86 }); | 92 }); |
| 87 | 93 |
| 88 test("multiple @TestOns", () { | 94 test("multiple @TestOns", () { |
| 89 new File(_path).writeAsStringSync( | 95 new File(_path).writeAsStringSync( |
| 90 "@TestOn('foo')\n@TestOn('bar')\nlibrary foo;"); | 96 "@TestOn('foo')\n@TestOn('bar')\nlibrary foo;"); |
| 91 expect(() => parseMetadata(_path), throwsFormatException); | 97 expect(() => parseMetadata(_path), throwsFormatException); |
| 92 }); | 98 }); |
| 93 }); | 99 }); |
| 94 } | 100 } |
| OLD | NEW |