| 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.test.utils; | 5 library test.test.utils; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:test/src/backend/invoker.dart'; | 10 import 'package:test/src/backend/invoker.dart'; |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 /// Returns a local [LiveTest] that runs [body]. | 220 /// Returns a local [LiveTest] that runs [body]. |
| 221 LiveTest createTest(body()) { | 221 LiveTest createTest(body()) { |
| 222 var test = new LocalTest("test", new Metadata(), body); | 222 var test = new LocalTest("test", new Metadata(), body); |
| 223 var suite = new Suite([test]); | 223 var suite = new Suite([test]); |
| 224 return test.load(suite); | 224 return test.load(suite); |
| 225 } | 225 } |
| 226 | 226 |
| 227 /// Runs [body] as a test. | 227 /// Runs [body] as a test. |
| 228 /// | 228 /// |
| 229 /// Once it completes, returns the [LiveTest] used to run it. | 229 /// Once it completes, returns the [LiveTest] used to run it. |
| 230 Future<LiveTest> runTest(body()) { | 230 Future<LiveTest> runTestBody(body()) { |
| 231 var liveTest = createTest(body); | 231 var liveTest = createTest(body); |
| 232 return liveTest.run().then((_) => liveTest); | 232 return liveTest.run().then((_) => liveTest); |
| 233 } | 233 } |
| 234 | 234 |
| 235 /// Asserts that [liveTest] has completed and passed. | 235 /// Asserts that [liveTest] has completed and passed. |
| 236 /// | 236 /// |
| 237 /// If the test had any errors, they're surfaced nicely into the outer test. | 237 /// If the test had any errors, they're surfaced nicely into the outer test. |
| 238 void expectTestPassed(LiveTest liveTest) { | 238 void expectTestPassed(LiveTest liveTest) { |
| 239 // Since the test is expected to pass, we forward any current or future errors | 239 // Since the test is expected to pass, we forward any current or future errors |
| 240 // to the outer test, because they're definitely unexpected. | 240 // to the outer test, because they're definitely unexpected. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 }); | 273 }); |
| 274 }); | 274 }); |
| 275 | 275 |
| 276 return liveTest.run().then((_) { | 276 return liveTest.run().then((_) { |
| 277 expectTestPassed(liveTest); | 277 expectTestPassed(liveTest); |
| 278 // Ensure that the outer test doesn't complete until the inner future | 278 // Ensure that the outer test doesn't complete until the inner future |
| 279 // completes. | 279 // completes. |
| 280 return future; | 280 return future; |
| 281 }); | 281 }); |
| 282 } | 282 } |
| OLD | NEW |