OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of unittestTest; |
6 | 6 |
7 Future _defer(void fn()) { | 7 Future _defer(void fn()) { |
8 return new Future.sync(fn); | 8 return new Future.sync(fn); |
9 } | 9 } |
10 | 10 |
11 String buildStatusString(int passed, int failed, int errors, | 11 String buildStatusString(int passed, int failed, int errors, |
12 var results, | 12 var results, |
13 {int count: 0, | 13 {int count: 0, |
14 String setup: '', String teardown: '', | 14 String setup: '', String teardown: '', |
15 String uncaughtError: null, | 15 String uncaughtError: null, |
16 String message: ''}) { | 16 String message: ''}) { |
17 var totalTests = 0; | 17 var totalTests = 0; |
18 var testDetails = new StringBuffer(); | 18 var testDetails = new StringBuffer(); |
19 if (results == null) { | 19 if(results == null) { |
20 // no op | 20 // no op |
21 assert(message == ''); | 21 assert(message == ''); |
22 } else if (results is String) { | 22 } else if (results is String) { |
23 totalTests = passed + failed + errors; | 23 totalTests = passed + failed + errors; |
24 testDetails.write(':$results:$message'); | 24 testDetails.write(':$results:$message'); |
25 } else { | 25 } else { |
26 totalTests = results.length; | 26 totalTests = results.length; |
27 for (var i = 0; i < results.length; i++) { | 27 for (var i = 0; i < results.length; i++) { |
28 testDetails.write(':${results[i].description}:' | 28 testDetails.write(':${results[i].description}:' |
29 '${collapseWhitespace(results[i].message)}'); | 29 '${collapseWhitespace(results[i].message)}'); |
30 } | 30 } |
31 } | 31 } |
32 return '$passed:$failed:$errors:$totalTests:$count:' | 32 return '$passed:$failed:$errors:$totalTests:$count:' |
33 '$setup:$teardown:$uncaughtError$testDetails'; | 33 '$setup:$teardown:$uncaughtError$testDetails'; |
34 } | 34 } |
35 | 35 |
36 class TestConfiguration extends Configuration { | 36 class TestConfiguration extends Configuration { |
37 | 37 |
38 // Some test state that is captured. | 38 // Some test state that is captured. |
39 int count = 0; // A count of callbacks. | 39 int count = 0; // A count of callbacks. |
40 String setup = ''; // The name of the test group setup function, if any. | 40 String setup = ''; // The name of the test group setup function, if any. |
41 String teardown = ''; // The name of the group teardown function, if any. | 41 String teardown = ''; // The name of the group teardown function, if any. |
42 | 42 |
43 // The port to communicate with the parent isolate | 43 // The port to communicate with the parent isolate |
44 final SendPort _port; | 44 final SendPort _port; |
45 String _result; | 45 String _result; |
46 | 46 |
47 TestConfiguration(this._port): super.blank(); | 47 TestConfiguration(this._port) : super.blank(); |
48 | 48 |
49 void onSummary(int passed, int failed, int errors, List<TestCase> results, | 49 void onSummary(int passed, int failed, int errors, List<TestCase> results, |
50 String uncaughtError) { | 50 String uncaughtError) { |
51 _result = buildStatusString(passed, failed, errors, results, | 51 _result = buildStatusString(passed, failed, errors, results, |
52 count: count, setup: setup, teardown: teardown, | 52 count: count, setup: setup, teardown: teardown, |
53 uncaughtError: uncaughtError); | 53 uncaughtError: uncaughtError); |
54 } | 54 } |
55 | 55 |
56 void onDone(bool success) { | 56 void onDone(bool success) { |
57 _port.send(_result); | 57 _port.send(_result); |
(...skipping 23 matching lines...) Expand all Loading... |
81 runTestInIsolate(sendport) { | 81 runTestInIsolate(sendport) { |
82 var testConfig = new TestConfiguration(sendport); | 82 var testConfig = new TestConfiguration(sendport); |
83 unittestConfiguration = testConfig; | 83 unittestConfiguration = testConfig; |
84 testFunction(testConfig); | 84 testFunction(testConfig); |
85 } | 85 } |
86 | 86 |
87 main() { | 87 main() { |
88 var replyPort = new ReceivePort(); | 88 var replyPort = new ReceivePort(); |
89 Isolate.spawn(runTestInIsolate, replyPort.sendPort); | 89 Isolate.spawn(runTestInIsolate, replyPort.sendPort); |
90 replyPort.first.then((String msg) { | 90 replyPort.first.then((String msg) { |
91 expect(msg.trim(), expected); | 91 expect(msg.trim(), equals(expected)); |
92 }); | 92 }); |
93 } | 93 } |
OLD | NEW |