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

Side by Side Diff: pkg/testing/lib/src/expectation.dart

Issue 2623413003: Implement custom status file expectations. (Closed)
Patch Set: Created 3 years, 11 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 | « pkg/testing/lib/src/chain.dart ('k') | pkg/testing/lib/src/log.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) 2017, 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.md file.
4
5 library testing.expectation;
6
karlklose 2017/01/16 08:09:20 Please add some documentation that explains the di
ahe 2017/01/16 08:53:04 Done.
7 class Expectation {
8 static const Expectation Pass =
9 const Expectation("Pass", ExpectationGroup.Pass);
10
11 static const Expectation Crash =
12 const Expectation("Crash", ExpectationGroup.Crash);
13
14 static const Expectation Timeout =
15 const Expectation("Timeout", ExpectationGroup.Timeout);
16
17 static const Expectation Fail =
18 const Expectation("Fail", ExpectationGroup.Fail);
19
20 static const Expectation Skip =
21 const Expectation("Skip", ExpectationGroup.Skip);
22
23 final String name;
24
25 final ExpectationGroup group;
26
27 const Expectation(this.name, this.group);
28
29 String toString() => name;
30 }
31
32 class ExpectationSet {
33 static const ExpectationSet Default = const ExpectationSet(
34 const <String, Expectation>{
35 "pass": Expectation.Pass,
36 "crash": Expectation.Crash,
37 "timeout": Expectation.Timeout,
38 "fail": Expectation.Fail,
39 "skip": Expectation.Skip,
40 "missingcompiletimeerror":
41 const Expectation("MissingCompileTimeError", ExpectationGroup.Fail),
42 "missingruntimeerror":
43 const Expectation("MissingRuntimeError", ExpectationGroup.Fail),
44 });
45
46 final Map<String, Expectation> internalMap;
47
48 const ExpectationSet(this.internalMap);
49
50 operator[] (String name) {
51 return internalMap[name.toLowerCase()]
52 ?? (throw "No expectation named: '$name'.");
53 }
54
55 factory ExpectationSet.fromJsonList(List data) {
56 Map<String, Expectation> internalMap =
57 new Map<String, Expectation>.from(Default.internalMap);
58 for (Map map in data) {
59 String name;
60 String group;
61 map.forEach((String key, String value) {
62 switch (key) {
63 case "name":
64 name = value;
65 break;
66
67 case "group":
68 group = value;
69 break;
70
71 default:
72 throw "Unrecoginized key: '$key' in '$map'.";
73 }
74 });
75 if (name == null) {
76 throw "No name provided in '$map'";
77 }
78 if (group == null) {
79 throw "No group provided in '$map'";
80 }
81 Expectation expectation = new Expectation(name, groupFromString(group));
82 name = name.toLowerCase();
83 if (internalMap.containsKey(name)) {
84 throw "Duplicated expectation name: '$name'.";
85 }
86 internalMap[name] = expectation;
87 }
88 return new ExpectationSet(internalMap);
89 }
90 }
91
92 enum ExpectationGroup {
93 Crash,
94 Fail,
95 Meta,
96 Pass,
97 Skip,
98 Timeout,
99 }
100
101 ExpectationGroup groupFromString(String name) {
102 switch (name) {
103 case "Crash": return ExpectationGroup.Crash;
104 case "Fail": return ExpectationGroup.Fail;
105 case "Meta": return ExpectationGroup.Meta;
106 case "Pass": return ExpectationGroup.Pass;
107 case "Skip": return ExpectationGroup.Skip;
108 case "Timeout": return ExpectationGroup.Timeout;
109 default:
110 throw "Unrecoginized group: '$name'.";
karlklose 2017/01/16 08:09:20 'Unrecoginized' -> 'Unrecognized'
ahe 2017/01/16 08:53:04 Done.
111 }
112 }
OLDNEW
« no previous file with comments | « pkg/testing/lib/src/chain.dart ('k') | pkg/testing/lib/src/log.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698