| 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 '../backend/operating_system.dart'; | 9 import '../backend/operating_system.dart'; |
| 10 import '../backend/test_platform.dart'; | 10 import '../backend/test_platform.dart'; |
| 11 import '../frontend/skip.dart'; | 11 import '../frontend/skip.dart'; |
| 12 import '../frontend/timeout.dart'; | 12 import '../frontend/timeout.dart'; |
| 13 import '../utils.dart'; | 13 import '../utils.dart'; |
| 14 import 'platform_selector.dart'; | 14 import 'platform_selector.dart'; |
| 15 | 15 |
| 16 /// Metadata for a test or test suite. | 16 /// Metadata for a test or test suite. |
| 17 /// | 17 /// |
| 18 /// This metadata comes from declarations on the test itself; it doesn't include | 18 /// This metadata comes from declarations on the test itself; it doesn't include |
| 19 /// configuration from the user. | 19 /// configuration from the user. |
| 20 class Metadata { | 20 class Metadata { |
| 21 /// The selector indicating which platforms the suite supports. | 21 /// The selector indicating which platforms the suite supports. |
| 22 final PlatformSelector testOn; | 22 final PlatformSelector testOn; |
| 23 | 23 |
| 24 /// The modification to the timeout for the test or suite. | 24 /// The modification to the timeout for the test or suite. |
| 25 final Timeout timeout; | 25 final Timeout timeout; |
| 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. |
| 31 final bool verboseTrace; |
| 32 |
| 30 /// The reason the test or suite should be skipped, if given. | 33 /// The reason the test or suite should be skipped, if given. |
| 31 final String skipReason; | 34 final String skipReason; |
| 32 | 35 |
| 33 /// Platform-specific metadata. | 36 /// Platform-specific metadata. |
| 34 /// | 37 /// |
| 35 /// Each key identifies a platform, and its value identifies the specific | 38 /// Each key identifies a platform, and its value identifies the specific |
| 36 /// metadata for that platform. These can be applied by calling [forPlatform]. | 39 /// metadata for that platform. These can be applied by calling [forPlatform]. |
| 37 final Map<PlatformSelector, Metadata> onPlatform; | 40 final Map<PlatformSelector, Metadata> onPlatform; |
| 38 | 41 |
| 39 /// Parses a user-provided map into the value for [onPlatform]. | 42 /// Parses a user-provided map into the value for [onPlatform]. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 80 |
| 78 result[selector] = new Metadata.parse(timeout: timeout, skip: skip); | 81 result[selector] = new Metadata.parse(timeout: timeout, skip: skip); |
| 79 }); | 82 }); |
| 80 return result; | 83 return result; |
| 81 } | 84 } |
| 82 | 85 |
| 83 /// Creates new Metadata. | 86 /// Creates new Metadata. |
| 84 /// | 87 /// |
| 85 /// [testOn] defaults to [PlatformSelector.all]. | 88 /// [testOn] defaults to [PlatformSelector.all]. |
| 86 Metadata({PlatformSelector testOn, Timeout timeout, bool skip: false, | 89 Metadata({PlatformSelector testOn, Timeout timeout, bool skip: false, |
| 87 this.skipReason, Map<PlatformSelector, Metadata> onPlatform}) | 90 this.verboseTrace: false, this.skipReason, |
| 91 Map<PlatformSelector, Metadata> onPlatform}) |
| 88 : testOn = testOn == null ? PlatformSelector.all : testOn, | 92 : testOn = testOn == null ? PlatformSelector.all : testOn, |
| 89 timeout = timeout == null ? const Timeout.factor(1) : timeout, | 93 timeout = timeout == null ? const Timeout.factor(1) : timeout, |
| 90 skip = skip, | 94 skip = skip, |
| 91 onPlatform = onPlatform == null | 95 onPlatform = onPlatform == null |
| 92 ? const {} | 96 ? const {} |
| 93 : new UnmodifiableMapView(onPlatform); | 97 : new UnmodifiableMapView(onPlatform); |
| 94 | 98 |
| 95 /// Creates a new Metadata, but with fields parsed from caller-friendly values | 99 /// Creates a new Metadata, but with fields parsed from caller-friendly values |
| 96 /// where applicable. | 100 /// where applicable. |
| 97 /// | 101 /// |
| 98 /// Throws a [FormatException] if any field is invalid. | 102 /// Throws a [FormatException] if any field is invalid. |
| 99 Metadata.parse({String testOn, Timeout timeout, skip, | 103 Metadata.parse({String testOn, Timeout timeout, skip, |
| 100 Map<String, dynamic> onPlatform}) | 104 this.verboseTrace: false, Map<String, dynamic> onPlatform}) |
| 101 : testOn = testOn == null | 105 : testOn = testOn == null |
| 102 ? PlatformSelector.all | 106 ? PlatformSelector.all |
| 103 : new PlatformSelector.parse(testOn), | 107 : new PlatformSelector.parse(testOn), |
| 104 timeout = timeout == null ? const Timeout.factor(1) : timeout, | 108 timeout = timeout == null ? const Timeout.factor(1) : timeout, |
| 105 skip = skip != null && skip != false, | 109 skip = skip != null && skip != false, |
| 106 skipReason = skip is String ? skip : null, | 110 skipReason = skip is String ? skip : null, |
| 107 onPlatform = _parseOnPlatform(onPlatform) { | 111 onPlatform = _parseOnPlatform(onPlatform) { |
| 108 if (skip != null && skip is! String && skip is! bool) { | 112 if (skip != null && skip is! String && skip is! bool) { |
| 109 throw new ArgumentError( | 113 throw new ArgumentError( |
| 110 '"skip" must be a String or a bool, was "$skip".'); | 114 '"skip" must be a String or a bool, was "$skip".'); |
| 111 } | 115 } |
| 112 } | 116 } |
| 113 | 117 |
| 114 /// Dezerializes the result of [Metadata.serialize] into a new [Metadata]. | 118 /// Dezerializes the result of [Metadata.serialize] into a new [Metadata]. |
| 115 Metadata.deserialize(serialized) | 119 Metadata.deserialize(serialized) |
| 116 : testOn = serialized['testOn'] == null | 120 : testOn = serialized['testOn'] == null |
| 117 ? PlatformSelector.all | 121 ? PlatformSelector.all |
| 118 : new PlatformSelector.parse(serialized['testOn']), | 122 : new PlatformSelector.parse(serialized['testOn']), |
| 119 timeout = serialized['timeout']['duration'] == null | 123 timeout = serialized['timeout']['duration'] == null |
| 120 ? new Timeout.factor(serialized['timeout']['scaleFactor']) | 124 ? new Timeout.factor(serialized['timeout']['scaleFactor']) |
| 121 : new Timeout(new Duration( | 125 : new Timeout(new Duration( |
| 122 microseconds: serialized['timeout']['duration'])), | 126 microseconds: serialized['timeout']['duration'])), |
| 123 skip = serialized['skip'], | 127 skip = serialized['skip'], |
| 124 skipReason = serialized['skipReason'], | 128 skipReason = serialized['skipReason'], |
| 129 verboseTrace = serialized['verboseTrace'], |
| 125 onPlatform = new Map.fromIterable(serialized['onPlatform'], | 130 onPlatform = new Map.fromIterable(serialized['onPlatform'], |
| 126 key: (pair) => new PlatformSelector.parse(pair.first), | 131 key: (pair) => new PlatformSelector.parse(pair.first), |
| 127 value: (pair) => new Metadata.deserialize(pair.last)); | 132 value: (pair) => new Metadata.deserialize(pair.last)); |
| 128 | 133 |
| 129 /// Return a new [Metadata] that merges [this] with [other]. | 134 /// Return a new [Metadata] that merges [this] with [other]. |
| 130 /// | 135 /// |
| 131 /// If the two [Metadata]s have conflicting properties, [other] wins. | 136 /// If the two [Metadata]s have conflicting properties, [other] wins. |
| 132 Metadata merge(Metadata other) => | 137 Metadata merge(Metadata other) => |
| 133 new Metadata( | 138 new Metadata( |
| 134 testOn: testOn.intersect(other.testOn), | 139 testOn: testOn.intersect(other.testOn), |
| 135 timeout: timeout.merge(other.timeout), | 140 timeout: timeout.merge(other.timeout), |
| 136 skip: skip || other.skip, | 141 skip: skip || other.skip, |
| 142 verboseTrace: verboseTrace || other.verboseTrace, |
| 137 skipReason: other.skipReason == null ? skipReason : other.skipReason, | 143 skipReason: other.skipReason == null ? skipReason : other.skipReason, |
| 138 onPlatform: mergeMaps(onPlatform, other.onPlatform)); | 144 onPlatform: mergeMaps(onPlatform, other.onPlatform)); |
| 139 | 145 |
| 140 /// Returns a copy of [this] with the given fields changed. | 146 /// Returns a copy of [this] with the given fields changed. |
| 141 Metadata change({PlatformSelector testOn, Timeout timeout, bool skip, | 147 Metadata change({PlatformSelector testOn, Timeout timeout, bool skip, |
| 142 String skipReason, Map<PlatformSelector, Metadata> onPlatform}) { | 148 bool verboseTrace, String skipReason, |
| 149 Map<PlatformSelector, Metadata> onPlatform}) { |
| 143 if (testOn == null) testOn = this.testOn; | 150 if (testOn == null) testOn = this.testOn; |
| 144 if (timeout == null) timeout = this.timeout; | 151 if (timeout == null) timeout = this.timeout; |
| 145 if (skip == null) skip = this.skip; | 152 if (skip == null) skip = this.skip; |
| 153 if (verboseTrace == null) verboseTrace = this.verboseTrace; |
| 146 if (skipReason == null) skipReason = this.skipReason; | 154 if (skipReason == null) skipReason = this.skipReason; |
| 147 if (onPlatform == null) onPlatform = this.onPlatform; | 155 if (onPlatform == null) onPlatform = this.onPlatform; |
| 148 return new Metadata(testOn: testOn, timeout: timeout, skip: skip, | 156 return new Metadata(testOn: testOn, timeout: timeout, skip: skip, |
| 149 skipReason: skipReason, onPlatform: onPlatform); | 157 verboseTrace: verboseTrace, skipReason: skipReason, |
| 158 onPlatform: onPlatform); |
| 150 } | 159 } |
| 151 | 160 |
| 152 /// Returns a copy of [this] with all platform-specific metadata from | 161 /// Returns a copy of [this] with all platform-specific metadata from |
| 153 /// [onPlatform] resolved. | 162 /// [onPlatform] resolved. |
| 154 Metadata forPlatform(TestPlatform platform, {OperatingSystem os}) { | 163 Metadata forPlatform(TestPlatform platform, {OperatingSystem os}) { |
| 155 var metadata = this; | 164 var metadata = this; |
| 156 onPlatform.forEach((platformSelector, platformMetadata) { | 165 onPlatform.forEach((platformSelector, platformMetadata) { |
| 157 if (!platformSelector.evaluate(platform, os: os)) return; | 166 if (!platformSelector.evaluate(platform, os: os)) return; |
| 158 metadata = metadata.merge(platformMetadata); | 167 metadata = metadata.merge(platformMetadata); |
| 159 }); | 168 }); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 172 return { | 181 return { |
| 173 'testOn': testOn == PlatformSelector.all ? null : testOn.toString(), | 182 'testOn': testOn == PlatformSelector.all ? null : testOn.toString(), |
| 174 'timeout': { | 183 'timeout': { |
| 175 'duration': timeout.duration == null | 184 'duration': timeout.duration == null |
| 176 ? null | 185 ? null |
| 177 : timeout.duration.inMicroseconds, | 186 : timeout.duration.inMicroseconds, |
| 178 'scaleFactor': timeout.scaleFactor | 187 'scaleFactor': timeout.scaleFactor |
| 179 }, | 188 }, |
| 180 'skip': skip, | 189 'skip': skip, |
| 181 'skipReason': skipReason, | 190 'skipReason': skipReason, |
| 191 'verboseTrace': verboseTrace, |
| 182 'onPlatform': serializedOnPlatform | 192 'onPlatform': serializedOnPlatform |
| 183 }; | 193 }; |
| 184 } | 194 } |
| 185 } | 195 } |
| OLD | NEW |