OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 library testing.expectation; | 5 library testing.expectation; |
6 | 6 |
7 /// An expectation represents the expected outcome of a test (or if it should | 7 /// An expectation represents the expected outcome of a test (or if it should |
8 /// be skipped). | 8 /// be skipped). |
9 /// | 9 /// |
10 /// An expectation belongs to a group, for example, [ExpectationGroup.Fail]. | 10 /// An expectation belongs to a group, for example, [ExpectationGroup.Fail]. |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 static const Expectation Skip = | 28 static const Expectation Skip = |
29 const Expectation("Skip", ExpectationGroup.Skip); | 29 const Expectation("Skip", ExpectationGroup.Skip); |
30 | 30 |
31 final String name; | 31 final String name; |
32 | 32 |
33 final ExpectationGroup group; | 33 final ExpectationGroup group; |
34 | 34 |
35 const Expectation(this.name, this.group); | 35 const Expectation(this.name, this.group); |
36 | 36 |
| 37 /// Returns the canonical expectation representing [group]. That is, one of |
| 38 /// the above expectations (except for `Meta` which returns `this`). |
| 39 Expectation get canonical => fromGroup(group) ?? this; |
| 40 |
37 String toString() => name; | 41 String toString() => name; |
| 42 |
| 43 static Expectation fromGroup(ExpectationGroup group) { |
| 44 switch (group) { |
| 45 case ExpectationGroup.Crash: |
| 46 return Expectation.Crash; |
| 47 case ExpectationGroup.Fail: |
| 48 return Expectation.Fail; |
| 49 case ExpectationGroup.Meta: |
| 50 return null; |
| 51 case ExpectationGroup.Pass: |
| 52 return Expectation.Pass; |
| 53 case ExpectationGroup.Skip: |
| 54 return Expectation.Skip; |
| 55 case ExpectationGroup.Timeout: |
| 56 return Expectation.Timeout; |
| 57 } |
| 58 throw "Unhandled group: '$group'."; |
| 59 } |
38 } | 60 } |
39 | 61 |
40 class ExpectationSet { | 62 class ExpectationSet { |
41 static const ExpectationSet Default = | 63 static const ExpectationSet Default = |
42 const ExpectationSet(const <String, Expectation>{ | 64 const ExpectationSet(const <String, Expectation>{ |
43 "pass": Expectation.Pass, | 65 "pass": Expectation.Pass, |
44 "crash": Expectation.Crash, | 66 "crash": Expectation.Crash, |
45 "timeout": Expectation.Timeout, | 67 "timeout": Expectation.Timeout, |
46 "fail": Expectation.Fail, | 68 "fail": Expectation.Fail, |
47 "skip": Expectation.Skip, | 69 "skip": Expectation.Skip, |
48 "missingcompiletimeerror": | 70 "missingcompiletimeerror": |
49 const Expectation("MissingCompileTimeError", ExpectationGroup.Fail), | 71 const Expectation("MissingCompileTimeError", ExpectationGroup.Fail), |
50 "missingruntimeerror": | 72 "missingruntimeerror": |
51 const Expectation("MissingRuntimeError", ExpectationGroup.Fail), | 73 const Expectation("MissingRuntimeError", ExpectationGroup.Fail), |
| 74 "runtimeerror": const Expectation("RuntimeError", ExpectationGroup.Fail), |
52 }); | 75 }); |
53 | 76 |
54 final Map<String, Expectation> internalMap; | 77 final Map<String, Expectation> internalMap; |
55 | 78 |
56 const ExpectationSet(this.internalMap); | 79 const ExpectationSet(this.internalMap); |
57 | 80 |
58 operator [](String name) { | 81 operator [](String name) { |
59 return internalMap[name.toLowerCase()] ?? | 82 return internalMap[name.toLowerCase()] ?? |
60 (throw "No expectation named: '$name'."); | 83 (throw "No expectation named: '$name'."); |
61 } | 84 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 case "Pass": | 140 case "Pass": |
118 return ExpectationGroup.Pass; | 141 return ExpectationGroup.Pass; |
119 case "Skip": | 142 case "Skip": |
120 return ExpectationGroup.Skip; | 143 return ExpectationGroup.Skip; |
121 case "Timeout": | 144 case "Timeout": |
122 return ExpectationGroup.Timeout; | 145 return ExpectationGroup.Timeout; |
123 default: | 146 default: |
124 throw "Unrecognized group: '$name'."; | 147 throw "Unrecognized group: '$name'."; |
125 } | 148 } |
126 } | 149 } |
OLD | NEW |