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

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

Issue 1008483003: Add a function to parse metadata into a usable object. (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 | « test/runner/loader_test.dart ('k') | test/util/parse_annotations_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:path/path.dart' as p;
8 import 'package:unittest/unittest.dart';
9 import 'package:unittest/src/runner/parse_metadata.dart';
10
11 String _sandbox;
12 String _path;
13
14 void main() {
15 setUp(() {
16 _sandbox = Directory.systemTemp.createTempSync('unittest_').path;
17 _path = p.join(_sandbox, "test.dart");
18 });
19
20 tearDown(() {
21 new Directory(_sandbox).deleteSync(recursive: true);
22 });
23
24 test("returns empty metadata for an empty file", () {
25 new File(_path).writeAsStringSync("");
26 var metadata = parseMetadata(_path);
27 expect(metadata.testOn, isNull);
28 });
29
30 test("ignores irrelevant annotations", () {
31 new File(_path).writeAsStringSync("@Fblthp\n@Fblthp.foo\nlibrary foo;");
32 var metadata = parseMetadata(_path);
33 expect(metadata.testOn, isNull);
34 });
35
36 test("parses a valid annotation", () {
37 new File(_path).writeAsStringSync("@TestOn('foo')\nlibrary foo;");
38 var metadata = parseMetadata(_path);
39 expect(metadata.testOn, equals("foo"));
40 });
41
42 test("parses a prefixed annotation", () {
43 new File(_path).writeAsStringSync(
44 "@foo.TestOn('foo')\n"
45 "import 'package:unittest/unittest.dart' as foo;");
46 var metadata = parseMetadata(_path);
47 expect(metadata.testOn, equals("foo"));
48 });
49
50 test("ignores a constructor named TestOn", () {
51 new File(_path).writeAsStringSync("@foo.TestOn('foo')\nlibrary foo;");
52 var metadata = parseMetadata(_path);
53 expect(metadata.testOn, isNull);
54 });
55
56 group("throws an error for", () {
57 test("a named constructor", () {
58 new File(_path).writeAsStringSync("@TestOn.name('foo')\nlibrary foo;");
59 expect(() => parseMetadata(_path), throwsFormatException);
60 });
61
62 test("no argument list", () {
63 new File(_path).writeAsStringSync("@TestOn\nlibrary foo;");
64 expect(() => parseMetadata(_path), throwsFormatException);
65 });
66
67 test("an empty argument list", () {
68 new File(_path).writeAsStringSync("@TestOn()\nlibrary foo;");
69 expect(() => parseMetadata(_path), throwsFormatException);
70 });
71
72 test("a named argument", () {
73 new File(_path).writeAsStringSync(
74 "@TestOn(expression: 'foo')\nlibrary foo;");
75 expect(() => parseMetadata(_path), throwsFormatException);
76 });
77
78 test("multiple arguments", () {
79 new File(_path).writeAsStringSync("@TestOn('foo', 'bar')\nlibrary foo;");
80 expect(() => parseMetadata(_path), throwsFormatException);
81 });
82
83 test("a non-string argument", () {
84 new File(_path).writeAsStringSync("@TestOn(123)\nlibrary foo;");
85 expect(() => parseMetadata(_path), throwsFormatException);
86 });
87
88 test("multiple @TestOns", () {
89 new File(_path).writeAsStringSync(
90 "@TestOn('foo')\n@TestOn('bar')\nlibrary foo;");
91 expect(() => parseMetadata(_path), throwsFormatException);
92 });
93 });
94 }
OLDNEW
« no previous file with comments | « test/runner/loader_test.dart ('k') | test/util/parse_annotations_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698