OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library unittest.state; |
| 6 |
| 7 /// The state of a [LiveTest]. |
| 8 /// |
| 9 /// A test's state is made up of two components, its [status] and its [result]. |
| 10 /// The [status] represents where the test is in its process of running; the |
| 11 /// [result] represents the outcome as far as its known. |
| 12 class State { |
| 13 /// Where the test is in its process of running. |
| 14 final Status status; |
| 15 |
| 16 /// The outcome of the test, as far as it's known. |
| 17 /// |
| 18 /// Note that if [status] is [Status.pending], [result] will always be |
| 19 /// [Result.success] since the test hasn't yet had a chance to fail. |
| 20 final Result result; |
| 21 |
| 22 const State(this.status, this.result); |
| 23 |
| 24 bool operator==(other) => other is State && status == other.status && |
| 25 result == other.result; |
| 26 |
| 27 int get hashCode => status.hashCode ^ (7 * result.hashCode); |
| 28 |
| 29 String toString() { |
| 30 if (status == Status.pending) return "pending"; |
| 31 if (status == Status.complete) return result.toString(); |
| 32 if (result == Result.success) return "running"; |
| 33 return "running with $result"; |
| 34 } |
| 35 } |
| 36 |
| 37 /// Where the test is in its process of running. |
| 38 class Status { |
| 39 /// The test has not yet begun running. |
| 40 static const pending = const Status._("pending"); |
| 41 |
| 42 /// The test is currently running. |
| 43 static const running = const Status._("running"); |
| 44 |
| 45 /// The test has finished running. |
| 46 /// |
| 47 /// Note that even if the test is marked [complete], it may still be running |
| 48 /// code asynchronously. A test is considered complete either once it hits its |
| 49 /// first error or when all [expectAsync] callbacks have been called and any |
| 50 /// returned [Future] has completed, but it's possible for further processing |
| 51 /// to happen, which may cause further errors. |
| 52 static const complete = const Status._("complete"); |
| 53 |
| 54 /// The name of the status. |
| 55 final String name; |
| 56 |
| 57 factory Status.parse(String name) { |
| 58 switch (name) { |
| 59 case "pending": return Status.pending; |
| 60 case "running": return Status.running; |
| 61 case "complete": return Status.complete; |
| 62 default: |
| 63 throw new ArgumentError('Invalid status name "$name".'); |
| 64 } |
| 65 } |
| 66 |
| 67 const Status._(this.name); |
| 68 |
| 69 String toString() => name; |
| 70 } |
| 71 |
| 72 /// The outcome of the test, as far as it's known. |
| 73 class Result { |
| 74 /// The test has not yet failed in any way. |
| 75 /// |
| 76 /// Note that this doesn't mean that the test won't fail in the future. |
| 77 static const success = const Result._("success"); |
| 78 |
| 79 /// The test has failed. |
| 80 /// |
| 81 /// A failure is specifically caused by a [TestFailure] being thrown; any |
| 82 /// other exception causes an error. |
| 83 static const failure = const Result._("failure"); |
| 84 |
| 85 /// The test has crashed. |
| 86 /// |
| 87 /// Any exception other than a [TestFailure] is considered to be an error. |
| 88 static const error = const Result._("error"); |
| 89 |
| 90 /// The name of the result. |
| 91 final String name; |
| 92 |
| 93 factory Result.parse(String name) { |
| 94 switch (name) { |
| 95 case "success": return Result.success; |
| 96 case "failure": return Result.failure; |
| 97 case "error": return Result.error; |
| 98 default: |
| 99 throw new ArgumentError('Invalid result name "$name".'); |
| 100 } |
| 101 } |
| 102 |
| 103 const Result._(this.name); |
| 104 |
| 105 String toString() => name; |
| 106 } |
OLD | NEW |