Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 part of unittestTest; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 /** | 7 Future defer(void fn()) { |
| 8 * Schedule [fn] for future execution in an event handler. | 8 return new Future.sync(fn); |
|
nweiz
2014/09/10 21:04:43
This name is misleading, since [fn] is executed sy
kevmoo
2014/09/17 21:16:29
Done.
| |
| 9 */ | |
| 10 Future _defer(void fn()) { | |
| 11 return new Future(fn); | |
| 12 } | 9 } |
| 13 | |
| 14 String buildStatusString(int passed, int failed, int errors, | |
| 15 var results, | |
| 16 {int count: 0, | |
| 17 String setup: '', String teardown: '', | |
| 18 String uncaughtError: null, | |
| 19 String message: ''}) { | |
| 20 var totalTests = 0; | |
| 21 var testDetails = new StringBuffer(); | |
| 22 if (results == null) { | |
| 23 // no op | |
| 24 assert(message == ''); | |
| 25 } else if (results is String) { | |
| 26 totalTests = passed + failed + errors; | |
| 27 testDetails.write(':$results:$message'); | |
| 28 } else { | |
| 29 totalTests = results.length; | |
| 30 for (var i = 0; i < results.length; i++) { | |
| 31 testDetails.write(':${results[i].description}:' | |
| 32 '${collapseWhitespace(results[i].message)}'); | |
| 33 } | |
| 34 } | |
| 35 return '$passed:$failed:$errors:$totalTests:$count:' | |
| 36 '$setup:$teardown:$uncaughtError$testDetails'; | |
| 37 } | |
| 38 | |
| 39 class TestConfiguration extends Configuration { | |
| 40 | |
| 41 // Some test state that is captured. | |
| 42 int count = 0; // A count of callbacks. | |
| 43 String setup = ''; // The name of the test group setup function, if any. | |
| 44 String teardown = ''; // The name of the group teardown function, if any. | |
| 45 | |
| 46 // The port to communicate with the parent isolate | |
| 47 final SendPort _port; | |
| 48 String _result; | |
| 49 | |
| 50 TestConfiguration(this._port): super.blank(); | |
| 51 | |
| 52 void onSummary(int passed, int failed, int errors, List<TestCase> results, | |
| 53 String uncaughtError) { | |
| 54 _result = buildStatusString(passed, failed, errors, results, | |
| 55 count: count, setup: setup, teardown: teardown, | |
| 56 uncaughtError: uncaughtError); | |
| 57 } | |
| 58 | |
| 59 void onDone(bool success) { | |
| 60 _port.send(_result); | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 Function makeDelayedSetup(index, s) => () { | |
| 65 return new Future.delayed(new Duration(milliseconds: 1), () { | |
| 66 s.write('l$index U '); | |
| 67 }); | |
| 68 }; | |
| 69 | |
| 70 Function makeDelayedTeardown(index, s) => () { | |
| 71 return new Future.delayed(new Duration(milliseconds: 1), () { | |
| 72 s.write('l$index D '); | |
| 73 }); | |
| 74 }; | |
| 75 | |
| 76 Function makeImmediateSetup(index, s) => () { | |
| 77 s.write('l$index U '); | |
| 78 }; | |
| 79 | |
| 80 Function makeImmediateTeardown(index, s) => () { | |
| 81 s.write('l$index D '); | |
| 82 }; | |
| 83 | |
| 84 void runTestInIsolate(sendport) { | |
| 85 var testConfig = new TestConfiguration(sendport); | |
| 86 unittestConfiguration = testConfig; | |
| 87 testFunction(testConfig); | |
| 88 } | |
| 89 | |
| 90 void main() { | |
| 91 var replyPort = new ReceivePort(); | |
| 92 Isolate.spawn(runTestInIsolate, replyPort.sendPort); | |
| 93 replyPort.first.then((String msg) { | |
| 94 expect(msg.trim(), expected); | |
| 95 }); | |
| 96 } | |
| OLD | NEW |