| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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("TestFramework"); | 5 #library("TestFramework"); |
| 6 #import("dart:coreimpl"); | 6 #import("dart:coreimpl"); |
| 7 | 7 |
| 8 | 8 |
| 9 typedef void AsynchronousTestFunction(TestExpectation check); | 9 typedef void AsynchronousTestFunction(TestExpectation check); |
| 10 | 10 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 setUp(); | 63 setUp(); |
| 64 result.runGuarded(this, () { | 64 result.runGuarded(this, () { |
| 65 performTest(); | 65 performTest(); |
| 66 tearDown(); | 66 tearDown(); |
| 67 }); | 67 }); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void addToTestSuite(TestSuite suite) { | 70 void addToTestSuite(TestSuite suite) { |
| 71 suite.addTestCase(this); | 71 suite.addTestCase(this); |
| 72 } | 72 } |
| 73 | |
| 74 } | 73 } |
| 75 | 74 |
| 76 | 75 |
| 77 class TestResult { | 76 class TestResult { |
| 78 | 77 |
| 79 TestResult(this.runner) : errors = [], failures = []; | 78 TestResult(this.runner) : errors = [], failures = []; |
| 80 | 79 |
| 81 void error(String message, TestCase testCase) { | 80 void error(String message, TestCase testCase) { |
| 82 errors.add([message, testCase]); | 81 errors.add([message, testCase]); |
| 83 } | 82 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 throw "must pass Promise or Future to TestFramework.completes"; | 180 throw "must pass Promise or Future to TestFramework.completes"; |
| 182 } | 181 } |
| 183 Completer completer = new Completer(); | 182 Completer completer = new Completer(); |
| 184 future.then(runs1((value) { | 183 future.then(runs1((value) { |
| 185 completer.complete(value); | 184 completer.complete(value); |
| 186 })); | 185 })); |
| 187 return completer.future; | 186 return completer.future; |
| 188 } | 187 } |
| 189 | 188 |
| 190 Promise completesWithValue(Promise promise, var expected) { | 189 Promise completesWithValue(Promise promise, var expected) { |
| 191 Promise result = new TestPromise(this); | 190 Promise promiseResult = new TestPromise(this); |
| 192 promise.then((value) { | 191 promise.then((value) { |
| 193 Expect.equals(expected, value); | 192 Expect.equals(expected, value); |
| 194 result.complete(value); | 193 promiseResult.complete(value); |
| 195 }); | 194 }); |
| 196 return result; | 195 return promiseResult; |
| 197 } | 196 } |
| 198 | 197 |
| 199 Function runs0(Function fn) { | 198 Function runs0(Function fn) { |
| 200 bool ran = false; // We only check that the function is executed once. | 199 bool ran = false; // We only check that the function is executed once. |
| 201 pendingCallbacks++; | 200 pendingCallbacks++; |
| 202 return () { | 201 return () { |
| 203 if (!ran) pendingCallbacks--; | 202 if (!ran) pendingCallbacks--; |
| 204 ran = true; | 203 ran = true; |
| 205 return result.runGuarded(testCase, () => fn()); | 204 return result.runGuarded(testCase, () => fn()); |
| 206 }; | 205 }; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 | 289 |
| 291 void addCompleteHandler(void completeHandler(T result)) { | 290 void addCompleteHandler(void completeHandler(T result)) { |
| 292 super.addCompleteHandler(expect.runs1((T result) { | 291 super.addCompleteHandler(expect.runs1((T result) { |
| 293 completeHandler(result); | 292 completeHandler(result); |
| 294 })); | 293 })); |
| 295 } | 294 } |
| 296 | 295 |
| 297 final TestExpectation expect; | 296 final TestExpectation expect; |
| 298 | 297 |
| 299 } | 298 } |
| OLD | NEW |