Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Side by Side Diff: pkg/unittest/lib/src/config.dart

Issue 22859009: Changes to how we handle fancy stacks: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/unittest/lib/html_config.dart ('k') | pkg/unittest/lib/src/test_case.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 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 Configuration _config; 10 Configuration _config;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 /** 49 /**
50 * If true (the default), then tests will stop after the first failed 50 * If true (the default), then tests will stop after the first failed
51 * [expect]. If false, failed [expect]s will not cause the test 51 * [expect]. If false, failed [expect]s will not cause the test
52 * to stop (other exceptions will still terminate the test). 52 * to stop (other exceptions will still terminate the test).
53 */ 53 */
54 bool stopTestOnExpectFailure = true; 54 bool stopTestOnExpectFailure = true;
55 55
56 // If stopTestOnExpectFailure is false, we need to capture failures, which 56 // If stopTestOnExpectFailure is false, we need to capture failures, which
57 // we do with this List. 57 // we do with this List.
58 final _testLogBuffer = <Pair<String, Trace>>[]; 58 final _testLogBuffer = <Pair<String, StackTrace>>[];
59 59
60 /** 60 /**
61 * The constructor sets up a failure handler for [expect] that redirects 61 * The constructor sets up a failure handler for [expect] that redirects
62 * [expect] failures to [onExpectFailure]. 62 * [expect] failures to [onExpectFailure].
63 */ 63 */
64 Configuration() { 64 Configuration() {
65 configureExpectFailureHandler(new _ExpectFailureHandler(this)); 65 configureExpectFailureHandler(new _ExpectFailureHandler(this));
66 } 66 }
67 /** 67 /**
68 * Called as soon as the unittest framework becomes initialized. This is done 68 * Called as soon as the unittest framework becomes initialized. This is done
69 * even before tests are added to the test framework. It might be used to 69 * even before tests are added to the test framework. It might be used to
70 * determine/debug errors that occur before the test harness starts executing. 70 * determine/debug errors that occur before the test harness starts executing.
71 * It is also used to tell the vm or browser that tests are going to be run 71 * It is also used to tell the vm or browser that tests are going to be run
72 * asynchronously and that the process should wait until they are done. 72 * asynchronously and that the process should wait until they are done.
73 */ 73 */
74 void onInit() { 74 void onInit() {
75 // For Dart internal tests, we don't want stack frame filtering.
76 // We turn it off here in the default config, but by default turn
77 // it back on in the vm and html configs.
78 filterStacks = false;
75 _receivePort = new ReceivePort(); 79 _receivePort = new ReceivePort();
76 _postMessage('unittest-suite-wait-for-done'); 80 _postMessage('unittest-suite-wait-for-done');
77 } 81 }
78 82
79 /** Called as soon as the unittest framework starts running. */ 83 /** Called as soon as the unittest framework starts running. */
80 void onStart() {} 84 void onStart() {}
81 85
82 /** 86 /**
83 * Called when each test starts. Useful to show intermediate progress on 87 * Called when each test starts. Useful to show intermediate progress on
84 * a test suite. Derived classes should call this first before their own 88 * a test suite. Derived classes should call this first before their own
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 * Handles failures from expect(). The default in 151 * Handles failures from expect(). The default in
148 * this base configuration is to throw an exception; 152 * this base configuration is to throw an exception;
149 */ 153 */
150 void onExpectFailure(String reason) { 154 void onExpectFailure(String reason) {
151 if (stopTestOnExpectFailure) { 155 if (stopTestOnExpectFailure) {
152 throw new TestFailure(reason); 156 throw new TestFailure(reason);
153 } else { 157 } else {
154 try { 158 try {
155 throw ''; 159 throw '';
156 } catch (_, stack) { 160 } catch (_, stack) {
157 _testLogBuffer.add( 161 var trace = _getTrace(stack);
158 new Pair<String, Trace>(reason, new Trace.from(stack))); 162 if (trace == null) trace = stack;
163 _testLogBuffer.add(new Pair<String, StackTrace>(reason, trace));
159 } 164 }
160 } 165 }
161 } 166 }
162 167
163 /** 168 /**
164 * Format a test result. 169 * Format a test result.
165 */ 170 */
166 String formatResult(TestCase testCase) { 171 String formatResult(TestCase testCase) {
167 var result = new StringBuffer(); 172 var result = new StringBuffer();
168 result.write(testCase.result.toUpperCase()); 173 result.write(testCase.result.toUpperCase());
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 // Currently e.message works in dartium, but not in dartc. 239 // Currently e.message works in dartium, but not in dartc.
235 void handleExternalError(e, String message, [stack]) => 240 void handleExternalError(e, String message, [stack]) =>
236 _reportTestError('$message\nCaught $e', stack); 241 _reportTestError('$message\nCaught $e', stack);
237 242
238 _postMessage(String message) { 243 _postMessage(String message) {
239 // In dart2js browser tests, the JavaScript-based test controller 244 // In dart2js browser tests, the JavaScript-based test controller
240 // intercepts calls to print and listens for "secret" messages. 245 // intercepts calls to print and listens for "secret" messages.
241 print(message); 246 print(message);
242 } 247 }
243 } 248 }
OLDNEW
« no previous file with comments | « pkg/unittest/lib/html_config.dart ('k') | pkg/unittest/lib/src/test_case.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698