Chromium Code Reviews| 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 library test.backend.metadata; | 5 library test.backend.metadata; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import '../frontend/skip.dart'; | 9 import '../frontend/skip.dart'; |
| 10 import '../frontend/timeout.dart'; | 10 import '../frontend/timeout.dart'; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 | 26 |
| 27 /// Whether the test or suite should be skipped. | 27 /// Whether the test or suite should be skipped. |
| 28 final bool skip; | 28 final bool skip; |
| 29 | 29 |
| 30 /// Whether to use verbose stack traces. | 30 /// Whether to use verbose stack traces. |
| 31 final bool verboseTrace; | 31 final bool verboseTrace; |
| 32 | 32 |
| 33 /// The reason the test or suite should be skipped, if given. | 33 /// The reason the test or suite should be skipped, if given. |
| 34 final String skipReason; | 34 final String skipReason; |
| 35 | 35 |
| 36 /// A set of tags attached to a test | |
| 37 final List<String> tags; | |
| 38 | |
| 36 /// Platform-specific metadata. | 39 /// Platform-specific metadata. |
| 37 /// | 40 /// |
| 38 /// Each key identifies a platform, and its value identifies the specific | 41 /// Each key identifies a platform, and its value identifies the specific |
| 39 /// metadata for that platform. These can be applied by calling [forPlatform]. | 42 /// metadata for that platform. These can be applied by calling [forPlatform]. |
| 40 final Map<PlatformSelector, Metadata> onPlatform; | 43 final Map<PlatformSelector, Metadata> onPlatform; |
| 41 | 44 |
| 42 /// Parses a user-provided map into the value for [onPlatform]. | 45 /// Parses a user-provided map into the value for [onPlatform]. |
| 43 static Map<PlatformSelector, Metadata> _parseOnPlatform( | 46 static Map<PlatformSelector, Metadata> _parseOnPlatform( |
| 44 Map<String, dynamic> onPlatform) { | 47 Map<String, dynamic> onPlatform) { |
| 45 if (onPlatform == null) return {}; | 48 if (onPlatform == null) return {}; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 result[selector] = new Metadata.parse(timeout: timeout, skip: skip); | 84 result[selector] = new Metadata.parse(timeout: timeout, skip: skip); |
| 82 }); | 85 }); |
| 83 return result; | 86 return result; |
| 84 } | 87 } |
| 85 | 88 |
| 86 /// Creates new Metadata. | 89 /// Creates new Metadata. |
| 87 /// | 90 /// |
| 88 /// [testOn] defaults to [PlatformSelector.all]. | 91 /// [testOn] defaults to [PlatformSelector.all]. |
| 89 Metadata({PlatformSelector testOn, Timeout timeout, bool skip: false, | 92 Metadata({PlatformSelector testOn, Timeout timeout, bool skip: false, |
| 90 this.verboseTrace: false, this.skipReason, | 93 this.verboseTrace: false, this.skipReason, |
| 91 Map<PlatformSelector, Metadata> onPlatform}) | 94 Map<PlatformSelector, Metadata> onPlatform, List<String> tags}) |
| 92 : testOn = testOn == null ? PlatformSelector.all : testOn, | 95 : testOn = testOn == null ? PlatformSelector.all : testOn, |
| 93 timeout = timeout == null ? const Timeout.factor(1) : timeout, | 96 timeout = timeout == null ? const Timeout.factor(1) : timeout, |
| 94 skip = skip, | 97 skip = skip, |
| 95 onPlatform = onPlatform == null | 98 onPlatform = onPlatform == null |
| 96 ? const {} | 99 ? const {} |
| 97 : new UnmodifiableMapView(onPlatform); | 100 : new UnmodifiableMapView(onPlatform), |
| 101 this.tags = tags ?? const <String>[]; | |
|
nweiz
2015/10/13 23:28:12
Unfortunately "??" isn't usable here. Anything tha
yjbanov
2015/10/30 20:13:59
Done.
| |
| 98 | 102 |
| 99 /// Creates a new Metadata, but with fields parsed from caller-friendly values | 103 /// Creates a new Metadata, but with fields parsed from caller-friendly values |
| 100 /// where applicable. | 104 /// where applicable. |
| 101 /// | 105 /// |
| 102 /// Throws a [FormatException] if any field is invalid. | 106 /// Throws a [FormatException] if any field is invalid. |
| 103 Metadata.parse({String testOn, Timeout timeout, skip, | 107 Metadata.parse({String testOn, Timeout timeout, skip, |
| 104 this.verboseTrace: false, Map<String, dynamic> onPlatform}) | 108 this.verboseTrace: false, Map<String, dynamic> onPlatform, |
| 109 List<String> tags}) | |
| 105 : testOn = testOn == null | 110 : testOn = testOn == null |
| 106 ? PlatformSelector.all | 111 ? PlatformSelector.all |
| 107 : new PlatformSelector.parse(testOn), | 112 : new PlatformSelector.parse(testOn), |
| 108 timeout = timeout == null ? const Timeout.factor(1) : timeout, | 113 timeout = timeout == null ? const Timeout.factor(1) : timeout, |
| 109 skip = skip != null && skip != false, | 114 skip = skip != null && skip != false, |
| 110 skipReason = skip is String ? skip : null, | 115 skipReason = skip is String ? skip : null, |
| 111 onPlatform = _parseOnPlatform(onPlatform) { | 116 onPlatform = _parseOnPlatform(onPlatform), |
| 117 this.tags = tags ?? const <String>[] { | |
| 112 if (skip != null && skip is! String && skip is! bool) { | 118 if (skip != null && skip is! String && skip is! bool) { |
| 113 throw new ArgumentError( | 119 throw new ArgumentError( |
| 114 '"skip" must be a String or a bool, was "$skip".'); | 120 '"skip" must be a String or a bool, was "$skip".'); |
| 115 } | 121 } |
| 116 } | 122 } |
| 117 | 123 |
| 118 /// Dezerializes the result of [Metadata.serialize] into a new [Metadata]. | 124 /// Dezerializes the result of [Metadata.serialize] into a new [Metadata]. |
| 119 Metadata.deserialize(serialized) | 125 Metadata.deserialize(serialized) |
| 120 : testOn = serialized['testOn'] == null | 126 : testOn = serialized['testOn'] == null |
| 121 ? PlatformSelector.all | 127 ? PlatformSelector.all |
| 122 : new PlatformSelector.parse(serialized['testOn']), | 128 : new PlatformSelector.parse(serialized['testOn']), |
| 123 timeout = _deserializeTimeout(serialized['timeout']), | 129 timeout = _deserializeTimeout(serialized['timeout']), |
| 124 skip = serialized['skip'], | 130 skip = serialized['skip'], |
| 125 skipReason = serialized['skipReason'], | 131 skipReason = serialized['skipReason'], |
| 126 verboseTrace = serialized['verboseTrace'], | 132 verboseTrace = serialized['verboseTrace'], |
| 133 tags = serialized['tags'] ?? const <String>[], | |
| 127 onPlatform = new Map.fromIterable(serialized['onPlatform'], | 134 onPlatform = new Map.fromIterable(serialized['onPlatform'], |
| 128 key: (pair) => new PlatformSelector.parse(pair.first), | 135 key: (pair) => new PlatformSelector.parse(pair.first), |
| 129 value: (pair) => new Metadata.deserialize(pair.last)); | 136 value: (pair) => new Metadata.deserialize(pair.last)); |
| 130 | 137 |
| 131 /// Deserializes timeout from the format returned by [_serializeTimeout]. | 138 /// Deserializes timeout from the format returned by [_serializeTimeout]. |
| 132 static _deserializeTimeout(serialized) { | 139 static _deserializeTimeout(serialized) { |
| 133 if (serialized == 'none') return Timeout.none; | 140 if (serialized == 'none') return Timeout.none; |
| 134 var scaleFactor = serialized['scaleFactor']; | 141 var scaleFactor = serialized['scaleFactor']; |
| 135 if (scaleFactor != null) return new Timeout.factor(scaleFactor); | 142 if (scaleFactor != null) return new Timeout.factor(scaleFactor); |
| 136 return new Timeout( | 143 return new Timeout( |
| 137 new Duration(microseconds: serialized['duration'])); | 144 new Duration(microseconds: serialized['duration'])); |
| 138 } | 145 } |
| 139 | 146 |
| 140 /// Return a new [Metadata] that merges [this] with [other]. | 147 /// Return a new [Metadata] that merges [this] with [other]. |
| 141 /// | 148 /// |
| 142 /// If the two [Metadata]s have conflicting properties, [other] wins. | 149 /// If the two [Metadata]s have conflicting properties, [other] wins. |
| 143 Metadata merge(Metadata other) => | 150 Metadata merge(Metadata other) => |
| 144 new Metadata( | 151 new Metadata( |
| 145 testOn: testOn.intersect(other.testOn), | 152 testOn: testOn.intersect(other.testOn), |
| 146 timeout: timeout.merge(other.timeout), | 153 timeout: timeout.merge(other.timeout), |
| 147 skip: skip || other.skip, | 154 skip: skip || other.skip, |
| 148 verboseTrace: verboseTrace || other.verboseTrace, | 155 verboseTrace: verboseTrace || other.verboseTrace, |
| 149 skipReason: other.skipReason == null ? skipReason : other.skipReason, | 156 skipReason: other.skipReason == null ? skipReason : other.skipReason, |
| 150 onPlatform: mergeMaps(onPlatform, other.onPlatform)); | 157 onPlatform: mergeMaps(onPlatform, other.onPlatform), |
| 158 tags: mergeLists(tags, other.tags)); | |
| 151 | 159 |
| 152 /// Returns a copy of [this] with the given fields changed. | 160 /// Returns a copy of [this] with the given fields changed. |
| 153 Metadata change({PlatformSelector testOn, Timeout timeout, bool skip, | 161 Metadata change({PlatformSelector testOn, Timeout timeout, bool skip, |
| 154 bool verboseTrace, String skipReason, | 162 bool verboseTrace, String skipReason, |
| 155 Map<PlatformSelector, Metadata> onPlatform}) { | 163 Map<PlatformSelector, Metadata> onPlatform}) { |
| 156 if (testOn == null) testOn = this.testOn; | 164 if (testOn == null) testOn = this.testOn; |
| 157 if (timeout == null) timeout = this.timeout; | 165 if (timeout == null) timeout = this.timeout; |
| 158 if (skip == null) skip = this.skip; | 166 if (skip == null) skip = this.skip; |
| 159 if (verboseTrace == null) verboseTrace = this.verboseTrace; | 167 if (verboseTrace == null) verboseTrace = this.verboseTrace; |
| 160 if (skipReason == null) skipReason = this.skipReason; | 168 if (skipReason == null) skipReason = this.skipReason; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 185 onPlatform.forEach((key, value) { | 193 onPlatform.forEach((key, value) { |
| 186 serializedOnPlatform.add([key.toString(), value.serialize()]); | 194 serializedOnPlatform.add([key.toString(), value.serialize()]); |
| 187 }); | 195 }); |
| 188 | 196 |
| 189 return { | 197 return { |
| 190 'testOn': testOn == PlatformSelector.all ? null : testOn.toString(), | 198 'testOn': testOn == PlatformSelector.all ? null : testOn.toString(), |
| 191 'timeout': _serializeTimeout(timeout), | 199 'timeout': _serializeTimeout(timeout), |
| 192 'skip': skip, | 200 'skip': skip, |
| 193 'skipReason': skipReason, | 201 'skipReason': skipReason, |
| 194 'verboseTrace': verboseTrace, | 202 'verboseTrace': verboseTrace, |
| 195 'onPlatform': serializedOnPlatform | 203 'onPlatform': serializedOnPlatform, |
| 204 'tags': tags.isEmpty ? null : tags, | |
|
nweiz
2015/10/13 23:28:12
Just pass an empty list here rather than adding a
yjbanov
2015/10/30 20:13:59
Done.
| |
| 196 }; | 205 }; |
| 197 } | 206 } |
| 198 | 207 |
| 199 /// Serializes timeout into a JSON-safe object. | 208 /// Serializes timeout into a JSON-safe object. |
| 200 _serializeTimeout(Timeout timeout) { | 209 _serializeTimeout(Timeout timeout) { |
| 201 if (timeout == Timeout.none) return 'none'; | 210 if (timeout == Timeout.none) return 'none'; |
| 202 return { | 211 return { |
| 203 'duration': timeout.duration == null | 212 'duration': timeout.duration == null |
| 204 ? null | 213 ? null |
| 205 : timeout.duration.inMicroseconds, | 214 : timeout.duration.inMicroseconds, |
| 206 'scaleFactor': timeout.scaleFactor | 215 'scaleFactor': timeout.scaleFactor |
| 207 }; | 216 }; |
| 208 } | 217 } |
| 209 } | 218 } |
| OLD | NEW |