| 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 '../frontend/timeout.dart'; | 7 import '../frontend/timeout.dart'; |
| 8 import 'platform_selector.dart'; | 8 import 'platform_selector.dart'; |
| 9 | 9 |
| 10 /// Metadata for a test or test suite. | 10 /// Metadata for a test or test suite. |
| 11 /// | 11 /// |
| 12 /// This metadata comes from declarations on the test itself; it doesn't include | 12 /// This metadata comes from declarations on the test itself; it doesn't include |
| 13 /// configuration from the user. | 13 /// configuration from the user. |
| 14 class Metadata { | 14 class Metadata { |
| 15 /// The selector indicating which platforms the suite supports. | 15 /// The selector indicating which platforms the suite supports. |
| 16 final PlatformSelector testOn; | 16 final PlatformSelector testOn; |
| 17 | 17 |
| 18 /// The modification to the timeout for the test or suite. | 18 /// The modification to the timeout for the test or suite. |
| 19 final Timeout timeout; | 19 final Timeout timeout; |
| 20 | 20 |
| 21 /// Whether the test or suite should be skipped. |
| 22 final bool skip; |
| 23 |
| 24 /// The reason the test or suite should be skipped, if given. |
| 25 final String skipReason; |
| 26 |
| 21 /// Creates new Metadata. | 27 /// Creates new Metadata. |
| 22 /// | 28 /// |
| 23 /// [testOn] defaults to [PlatformSelector.all]. | 29 /// [testOn] defaults to [PlatformSelector.all]. |
| 24 Metadata({PlatformSelector testOn, Timeout timeout}) | 30 Metadata({PlatformSelector testOn, Timeout timeout, bool skip: false, |
| 31 this.skipReason}) |
| 25 : testOn = testOn == null ? PlatformSelector.all : testOn, | 32 : testOn = testOn == null ? PlatformSelector.all : testOn, |
| 26 timeout = timeout == null ? const Timeout.factor(1) : timeout; | 33 timeout = timeout == null ? const Timeout.factor(1) : timeout, |
| 34 skip = skip; |
| 27 | 35 |
| 28 /// Creates a new Metadata, but with fields parsed from strings where | 36 /// Creates a new Metadata, but with fields parsed from strings where |
| 29 /// applicable. | 37 /// applicable. |
| 30 /// | 38 /// |
| 31 /// Throws a [FormatException] if any field is invalid. | 39 /// Throws a [FormatException] if any field is invalid. |
| 32 Metadata.parse({String testOn, Timeout timeout}) | 40 Metadata.parse({String testOn, Timeout timeout, skip}) |
| 33 : this( | 41 : testOn = testOn == null |
| 34 testOn: testOn == null ? null : new PlatformSelector.parse(testOn), | 42 ? PlatformSelector.all |
| 35 timeout: timeout); | 43 : new PlatformSelector.parse(testOn), |
| 44 timeout = timeout == null ? const Timeout.factor(1) : timeout, |
| 45 skip = skip != null && skip != false, |
| 46 skipReason = skip is String ? skip : null { |
| 47 if (skip != null && skip is! String && skip is! bool) { |
| 48 throw new ArgumentError( |
| 49 '"skip" must be a String or a bool, was "$skip".'); |
| 50 } |
| 51 } |
| 36 | 52 |
| 37 /// Dezerializes the result of [Metadata.serialize] into a new [Metadata]. | 53 /// Dezerializes the result of [Metadata.serialize] into a new [Metadata]. |
| 38 Metadata.deserialize(serialized) | 54 Metadata.deserialize(serialized) |
| 39 : this.parse( | 55 : this.parse( |
| 40 testOn: serialized['testOn'], | 56 testOn: serialized['testOn'], |
| 41 timeout: serialized['timeout']['duration'] == null | 57 timeout: serialized['timeout']['duration'] == null |
| 42 ? new Timeout.factor(serialized['timeout']['scaleFactor']) | 58 ? new Timeout.factor(serialized['timeout']['scaleFactor']) |
| 43 : new Timeout(new Duration( | 59 : new Timeout(new Duration( |
| 44 microseconds: serialized['timeout']['duration']))); | 60 microseconds: serialized['timeout']['duration'])), |
| 61 skip: serialized['skipReason'] == null |
| 62 ? serialized['skip'] |
| 63 : serialized['skipReason']); |
| 45 | 64 |
| 46 /// Return a new [Metadata] that merges [this] with [other]. | 65 /// Return a new [Metadata] that merges [this] with [other]. |
| 47 /// | 66 /// |
| 48 /// If the two [Metadata]s have conflicting properties, [other] wins. | 67 /// If the two [Metadata]s have conflicting properties, [other] wins. |
| 49 Metadata merge(Metadata other) => | 68 Metadata merge(Metadata other) => |
| 50 new Metadata( | 69 new Metadata( |
| 51 testOn: testOn.intersect(other.testOn), | 70 testOn: testOn.intersect(other.testOn), |
| 52 timeout: timeout.merge(other.timeout)); | 71 timeout: timeout.merge(other.timeout), |
| 72 skip: skip || other.skip, |
| 73 skipReason: other.skipReason == null ? skipReason : other.skipReason); |
| 53 | 74 |
| 54 /// Serializes [this] into a JSON-safe object that can be deserialized using | 75 /// Serializes [this] into a JSON-safe object that can be deserialized using |
| 55 /// [new Metadata.deserialize]. | 76 /// [new Metadata.deserialize]. |
| 56 serialize() => { | 77 serialize() => { |
| 57 'testOn': testOn == PlatformSelector.all ? null : testOn.toString(), | 78 'testOn': testOn == PlatformSelector.all ? null : testOn.toString(), |
| 58 'timeout': { | 79 'timeout': { |
| 59 'duration': timeout.duration == null | 80 'duration': timeout.duration == null |
| 60 ? null | 81 ? null |
| 61 : timeout.duration.inMicroseconds, | 82 : timeout.duration.inMicroseconds, |
| 62 'scaleFactor': timeout.scaleFactor | 83 'scaleFactor': timeout.scaleFactor |
| 63 } | 84 }, |
| 85 'skip': skip, |
| 86 'skipReason': skipReason |
| 64 }; | 87 }; |
| 65 } | 88 } |
| OLD | NEW |