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

Side by Side Diff: test/backend/metadata_test.dart

Issue 1405633004: feature: tag tests; choose tags on command line Base URL: git@github.com:yjbanov/test.git@tags
Patch Set: address review comments Created 5 years, 1 month 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
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 import 'package:test/src/backend/metadata.dart'; 5 import 'package:test/src/backend/metadata.dart';
6 import 'package:test/src/backend/test_platform.dart'; 6 import 'package:test/src/backend/test_platform.dart';
7 import 'package:test/src/frontend/timeout.dart'; 7 import 'package:test/src/frontend/timeout.dart';
8 import 'package:test/src/frontend/skip.dart'; 8 import 'package:test/src/frontend/skip.dart';
9 import 'package:test/test.dart'; 9 import 'package:test/test.dart';
10 10
11 void main() { 11 void main() {
12 group("Metadata", () {
13 expectTags(tags, expected) {
14 expect(new Metadata(tags: tags).tags, unorderedEquals(expected));
15 expect(new Metadata.parse(tags: tags).tags, unorderedEquals(expected));
16 var serialized = {
17 "tags": tags,
18 "timeout": "none",
19 "onPlatform": [],
20 };
21 expect(new Metadata.deserialize(serialized).tags,
22 unorderedEquals(expected));
23 }
24
25 expectTagsError({tags, String message}) {
26 [
27 () => new Metadata(tags: tags),
28 () => new Metadata.parse(tags: tags),
29 ].forEach((fn()) {
30 try {
31 fn();
32 fail("Expected ArgumentError for $tags");
33 } on ArgumentError catch(e) {
34 expect(e.message, message);
35 expect(e.invalidValue, tags);
36 expect(e.name, "tags");
37 }
38 });
39 }
40
41 test("takes no tags", () {
42 expectTags(null, []);
43 expectTags("", []);
44 expectTags(" ", []);
45 expectTags([], []);
46 });
47
48 test("takes some tags as Iterable", () {
49 var tags = ["a", "b"];
50 expectTags(tags, tags);
51 expectTags(new Set.from(tags), tags);
52 });
53
54 test("takes some tags as String", () {
55 expectTags("a", ["a"]);
56 expectTags("a,b", ["a", "b"]);
57 expectTags(" a,,,b , c\n,d\t", ["a", "b", "c", "d"]);
58 });
59
60 test("refuses bad tag types", () {
61 expectTagsError(
62 tags: 1,
63 message: "must be either String or Iterable");
64 });
65
66 test("refuses non-String tag names", () {
67 expectTagsError(
68 tags: [1],
69 message: "tag name must be String");
70 expectTagsError(
71 tags: [null],
72 message: "tag name must be String");
73 });
74
75 test("refuses blank tag names", () {
76 var errorMsg = "tag name must contain non-whitespace characters";
77 expectTagsError(
78 tags: [""],
79 message: errorMsg);
80 expectTagsError(
81 tags: [" "],
82 message: errorMsg);
83 });
84
85 test("merges tags by computing the union of the two tag sets", () {
86 expect(new Metadata(tags: "a,b").merge(new Metadata(tags: "b,c")).tags,
87 unorderedEquals(["a", "b", "c"]));
88 });
89
90 test("serializes tags to a List", () {
91 var serialized = new Metadata(tags: "a,b").serialize()['tags'];
92 expect(serialized, new isInstanceOf<List>());
93 expect(serialized, ["a", "b"]);
94 });
95 });
96
12 group("onPlatform", () { 97 group("onPlatform", () {
13 test("parses a valid map", () { 98 test("parses a valid map", () {
14 var metadata = new Metadata.parse(onPlatform: { 99 var metadata = new Metadata.parse(onPlatform: {
15 "chrome": new Timeout.factor(2), 100 "chrome": new Timeout.factor(2),
16 "vm": [new Skip(), new Timeout.factor(3)] 101 "vm": [new Skip(), new Timeout.factor(3)]
17 }); 102 });
18 103
19 var key = metadata.onPlatform.keys.first; 104 var key = metadata.onPlatform.keys.first;
20 expect(key.evaluate(TestPlatform.chrome), isTrue); 105 expect(key.evaluate(TestPlatform.chrome), isTrue);
21 expect(key.evaluate(TestPlatform.vm), isFalse); 106 expect(key.evaluate(TestPlatform.vm), isFalse);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 }, throwsArgumentError); 141 }, throwsArgumentError);
57 }); 142 });
58 143
59 test("refuses multiple Skips", () { 144 test("refuses multiple Skips", () {
60 expect(() { 145 expect(() {
61 new Metadata.parse(onPlatform: {"chrome": [new Skip(), new Skip()]}); 146 new Metadata.parse(onPlatform: {"chrome": [new Skip(), new Skip()]});
62 }, throwsArgumentError); 147 }, throwsArgumentError);
63 }); 148 });
64 }); 149 });
65 } 150 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698