| 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 /// The state of a [LiveTest]. | 5 /// The state of a [LiveTest]. |
| 6 /// | 6 /// |
| 7 /// A test's state is made up of two components, its [status] and its [result]. | 7 /// A test's state is made up of two components, its [status] and its [result]. |
| 8 /// The [status] represents where the test is in its process of running; the | 8 /// The [status] represents where the test is in its process of running; the |
| 9 /// [result] represents the outcome as far as its known. | 9 /// [result] represents the outcome as far as its known. |
| 10 class State { | 10 class State { |
| 11 /// Where the test is in its process of running. | 11 /// Where the test is in its process of running. |
| 12 final Status status; | 12 final Status status; |
| 13 | 13 |
| 14 /// The outcome of the test, as far as it's known. | 14 /// The outcome of the test, as far as it's known. |
| 15 /// | 15 /// |
| 16 /// Note that if [status] is [Status.pending], [result] will always be | 16 /// Note that if [status] is [Status.pending], [result] will always be |
| 17 /// [Result.success] since the test hasn't yet had a chance to fail. | 17 /// [Result.success] since the test hasn't yet had a chance to fail. |
| 18 final Result result; | 18 final Result result; |
| 19 | 19 |
| 20 /// Whether a test in this state is expected to be done running code. |
| 21 /// |
| 22 /// If [status] is [Status.complete] and [result] doesn't indicate an error, a |
| 23 /// properly-written test case should not be running any more code. However, |
| 24 /// it may have started asynchronous processes without notifying the test |
| 25 /// runner. |
| 26 bool get shouldBeDone => status == Status.complete && result.isPassing; |
| 27 |
| 20 const State(this.status, this.result); | 28 const State(this.status, this.result); |
| 21 | 29 |
| 22 bool operator==(other) => other is State && status == other.status && | 30 bool operator==(other) => other is State && status == other.status && |
| 23 result == other.result; | 31 result == other.result; |
| 24 | 32 |
| 25 int get hashCode => status.hashCode ^ (7 * result.hashCode); | 33 int get hashCode => status.hashCode ^ (7 * result.hashCode); |
| 26 | 34 |
| 27 String toString() { | 35 String toString() { |
| 28 if (status == Status.pending) return "pending"; | 36 if (status == Status.pending) return "pending"; |
| 29 if (status == Status.complete) return result.toString(); | 37 if (status == Status.complete) return result.toString(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 String toString() => name; | 75 String toString() => name; |
| 68 } | 76 } |
| 69 | 77 |
| 70 /// The outcome of the test, as far as it's known. | 78 /// The outcome of the test, as far as it's known. |
| 71 class Result { | 79 class Result { |
| 72 /// The test has not yet failed in any way. | 80 /// The test has not yet failed in any way. |
| 73 /// | 81 /// |
| 74 /// Note that this doesn't mean that the test won't fail in the future. | 82 /// Note that this doesn't mean that the test won't fail in the future. |
| 75 static const success = const Result._("success"); | 83 static const success = const Result._("success"); |
| 76 | 84 |
| 85 /// The test, or some part of it, has been skipped. |
| 86 /// |
| 87 /// This implies that the test hasn't failed *yet*. However, it this doesn't |
| 88 /// mean that the test won't fail in the future. |
| 89 static const skipped = const Result._("skipped"); |
| 90 |
| 77 /// The test has failed. | 91 /// The test has failed. |
| 78 /// | 92 /// |
| 79 /// A failure is specifically caused by a [TestFailure] being thrown; any | 93 /// A failure is specifically caused by a [TestFailure] being thrown; any |
| 80 /// other exception causes an error. | 94 /// other exception causes an error. |
| 81 static const failure = const Result._("failure"); | 95 static const failure = const Result._("failure"); |
| 82 | 96 |
| 83 /// The test has crashed. | 97 /// The test has crashed. |
| 84 /// | 98 /// |
| 85 /// Any exception other than a [TestFailure] is considered to be an error. | 99 /// Any exception other than a [TestFailure] is considered to be an error. |
| 86 static const error = const Result._("error"); | 100 static const error = const Result._("error"); |
| 87 | 101 |
| 88 /// The name of the result. | 102 /// The name of the result. |
| 89 final String name; | 103 final String name; |
| 90 | 104 |
| 105 /// Whether this is a passing result. |
| 106 /// |
| 107 /// A test is considered to have passed if it's a success or if it was |
| 108 /// skipped. |
| 109 bool get isPassing => this == success || this == skipped; |
| 110 |
| 111 /// Whether this is a failing result. |
| 112 /// |
| 113 /// A test is considered to have failed if it experiences a failure or an |
| 114 /// error. |
| 115 bool get isFailing => !isPassing; |
| 116 |
| 91 factory Result.parse(String name) { | 117 factory Result.parse(String name) { |
| 92 switch (name) { | 118 switch (name) { |
| 93 case "success": return Result.success; | 119 case "success": return Result.success; |
| 120 case "skipped": return Result.skipped; |
| 94 case "failure": return Result.failure; | 121 case "failure": return Result.failure; |
| 95 case "error": return Result.error; | 122 case "error": return Result.error; |
| 96 default: | 123 default: |
| 97 throw new ArgumentError('Invalid result name "$name".'); | 124 throw new ArgumentError('Invalid result name "$name".'); |
| 98 } | 125 } |
| 99 } | 126 } |
| 100 | 127 |
| 101 const Result._(this.name); | 128 const Result._(this.name); |
| 102 | 129 |
| 103 String toString() => name; | 130 String toString() => name; |
| 104 } | 131 } |
| OLD | NEW |