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