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 unittest; | 5 part of unittest; |
6 | 6 |
7 // A custom failure handler for [expect] that routes expect failures | 7 // A custom failure handler for [expect] that routes expect failures |
8 // to the config. | 8 // to the config. |
9 class _ExpectFailureHandler extends DefaultFailureHandler { | 9 class _ExpectFailureHandler extends DefaultFailureHandler { |
10 final SimpleConfiguration _config; | 10 final SimpleConfiguration _config; |
(...skipping 28 matching lines...) Expand all Loading... |
39 /// [expect]. If false, failed [expect]s will not cause the test | 39 /// [expect]. If false, failed [expect]s will not cause the test |
40 /// to stop (other exceptions will still terminate the test). | 40 /// to stop (other exceptions will still terminate the test). |
41 bool stopTestOnExpectFailure = true; | 41 bool stopTestOnExpectFailure = true; |
42 | 42 |
43 // If stopTestOnExpectFailure is false, we need to capture failures, which | 43 // If stopTestOnExpectFailure is false, we need to capture failures, which |
44 // we do with this List. | 44 // we do with this List. |
45 final _testLogBuffer = <Pair<String, StackTrace>>[]; | 45 final _testLogBuffer = <Pair<String, StackTrace>>[]; |
46 | 46 |
47 /// The constructor sets up a failure handler for [expect] that redirects | 47 /// The constructor sets up a failure handler for [expect] that redirects |
48 /// [expect] failures to [onExpectFailure]. | 48 /// [expect] failures to [onExpectFailure]. |
49 SimpleConfiguration(): super.blank() { | 49 SimpleConfiguration() : super.blank() { |
50 configureExpectFailureHandler(new _ExpectFailureHandler(this)); | 50 configureExpectFailureHandler(new _ExpectFailureHandler(this)); |
51 } | 51 } |
52 | 52 |
53 void onInit() { | 53 void onInit() { |
54 // For Dart internal tests, we don't want stack frame filtering. | 54 // For Dart internal tests, we don't want stack frame filtering. |
55 // We turn it off here in the default config, but by default turn | 55 // We turn it off here in the default config, but by default turn |
56 // it back on in the vm and html configs. | 56 // it back on in the vm and html configs. |
57 filterStacks = false; | 57 filterStacks = false; |
58 _receivePort = new ReceivePort(); | 58 _receivePort = new ReceivePort(); |
59 _postMessage('unittest-suite-wait-for-done'); | 59 _postMessage('unittest-suite-wait-for-done'); |
60 } | 60 } |
61 | 61 |
62 /// Called when each test starts. Useful to show intermediate progress on | 62 /// Called when each test starts. Useful to show intermediate progress on |
63 /// a test suite. Derived classes should call this first before their own | 63 /// a test suite. Derived classes should call this first before their own |
64 /// override code. | 64 /// override code. |
65 void onTestStart(TestCase testCase) { | 65 void onTestStart(TestCase testCase) { |
66 assert(testCase != null); | 66 assert(testCase != null); |
67 _testLogBuffer.clear(); | 67 _testLogBuffer.clear(); |
68 } | 68 } |
69 | 69 |
70 /// Called when each test is first completed. Useful to show intermediate | 70 /// Called when each test is first completed. Useful to show intermediate |
71 /// progress on a test suite. Derived classes should call this first | 71 /// progress on a test suite. Derived classes should call this first |
72 /// before their own override code. | 72 /// before their own override code. |
73 void onTestResult(TestCase testCase) { | 73 void onTestResult(TestCase testCase) { |
74 assert(testCase != null); | 74 assert(testCase != null); |
75 if (!stopTestOnExpectFailure && _testLogBuffer.length > 0) { | 75 if (!stopTestOnExpectFailure && _testLogBuffer.length > 0) { |
76 // Write the message/stack pairs up to the last pairs. | 76 // Write the message/stack pairs up to the last pairs. |
77 var reason = new StringBuffer(); | 77 var reason = new StringBuffer(); |
78 for (var reasonAndTrace in | 78 for (var reasonAndTrace |
79 _testLogBuffer.take(_testLogBuffer.length - 1)) { | 79 in _testLogBuffer.take(_testLogBuffer.length - 1)) { |
80 reason.write(reasonAndTrace.first); | 80 reason.write(reasonAndTrace.first); |
81 reason.write('\n'); | 81 reason.write('\n'); |
82 reason.write(reasonAndTrace.last); | 82 reason.write(reasonAndTrace.last); |
83 reason.write('\n'); | 83 reason.write('\n'); |
84 } | 84 } |
85 var lastReasonAndTrace = _testLogBuffer.last; | 85 var lastReasonAndTrace = _testLogBuffer.last; |
86 // Write the last message. | 86 // Write the last message. |
87 reason.write(lastReasonAndTrace.first); | 87 reason.write(lastReasonAndTrace.first); |
88 if (testCase.result == PASS) { | 88 if (testCase.result == PASS) { |
89 testCase._result = FAIL; | 89 testCase._result = FAIL; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 } | 190 } |
191 } | 191 } |
192 } | 192 } |
193 | 193 |
194 void _postMessage(String message) { | 194 void _postMessage(String message) { |
195 // In dart2js browser tests, the JavaScript-based test controller | 195 // In dart2js browser tests, the JavaScript-based test controller |
196 // intercepts calls to print and listens for "secret" messages. | 196 // intercepts calls to print and listens for "secret" messages. |
197 print(message); | 197 print(message); |
198 } | 198 } |
199 } | 199 } |
OLD | NEW |