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

Side by Side Diff: pkg/unittest/lib/interactive_html_config.dart

Issue 19684006: Roll back "Use package:stack_trace in unittest." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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_enhanced_config.dart ('k') | pkg/unittest/lib/src/config.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) 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 /** 5 /**
6 * This configuration can be used to rerun selected tests, as well 6 * This configuration can be used to rerun selected tests, as well
7 * as see diagnostic output from tests. It runs each test in its own 7 * as see diagnostic output from tests. It runs each test in its own
8 * IFrame, so the configuration consists of two parts - a 'parent' 8 * IFrame, so the configuration consists of two parts - a 'parent'
9 * config that manages all the tests, and a 'child' config for the 9 * config that manages all the tests, and a 'child' config for the
10 * IFrame that runs the individual tests. 10 * IFrame that runs the individual tests.
11 * 11 *
12 * Note: this unit test configuration will not work with the debugger (the tests 12 * Note: this unit test configuration will not work with the debugger (the tests
13 * are executed in a separate IFrame). 13 * are executed in a separate IFrame).
14 */ 14 */
15 library unittest_interactive_html_config; 15 library unittest_interactive_html_config;
16 16
17 // TODO(gram) - add options for: remove IFrame on done/keep 17 // TODO(gram) - add options for: remove IFrame on done/keep
18 // IFrame for failed tests/keep IFrame for all tests. 18 // IFrame for failed tests/keep IFrame for all tests.
19 19
20 import 'dart:html'; 20 import 'dart:html';
21 import 'dart:async'; 21 import 'dart:async';
22 import 'dart:math'; 22 import 'dart:math';
23
24 import 'package:stack_trace/stack_trace.dart';
25
26 import 'unittest.dart'; 23 import 'unittest.dart';
27 24
28 /** The messages exchanged between parent and child. */ 25 /** The messages exchanged between parent and child. */
29 class _Message { 26 class _Message {
30 static const START = 'start'; 27 static const START = 'start';
31 static const LOG = 'log'; 28 static const LOG = 'log';
32 static const STACK = 'stack'; 29 static const STACK = 'stack';
33 static const PASS = 'pass'; 30 static const PASS = 'pass';
34 static const FAIL = 'fail'; 31 static const FAIL = 'fail';
35 static const ERROR = 'error'; 32 static const ERROR = 'error';
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 elapsed = -1; 145 elapsed = -1;
149 } else { 146 } else {
150 DateTime end = new DateTime.now(); 147 DateTime end = new DateTime.now();
151 elapsed = end.difference(_testStarts[testCase.id]).inMilliseconds; 148 elapsed = end.difference(_testStarts[testCase.id]).inMilliseconds;
152 } 149 }
153 _parentWindow.postMessage( 150 _parentWindow.postMessage(
154 _Message.text(_Message.LOG, elapsed, message).toString(), '*'); 151 _Message.text(_Message.LOG, elapsed, message).toString(), '*');
155 } 152 }
156 153
157 /** 154 /**
158 * Get the elapsed time for the test, and post the test result back to the 155 * Get the elapsed time for the test, anbd post the test result
159 * parent window. If the test failed due to an exception the stack is posted 156 * back to the parent window. If the test failed due to an exception
160 * back too (before the test result). 157 * the stack is posted back too (before the test result).
161 */ 158 */
162 void onTestResult(TestCase testCase) { 159 void onTestResult(TestCase testCase) {
163 super.onTestResult(testCase); 160 super.onTestResult(testCase);
164 DateTime end = new DateTime.now(); 161 DateTime end = new DateTime.now();
165 int elapsed = end.difference(_testStarts[testCase.id]).inMilliseconds; 162 int elapsed = end.difference(_testStarts[testCase.id]).inMilliseconds;
166 if (testCase.stackTrace != null) { 163 if (testCase.stackTrace != null) {
167 var message = json.stringify(testCase.stackTrace.frames.map((frame) {
168 return <String>{
169 "uri": frame.uri.toString(),
170 "line": frame.line,
171 "column": frame.column,
172 "member": frame.member
173 };
174 }).toList());
175 _parentWindow.postMessage( 164 _parentWindow.postMessage(
176 _Message.text(_Message.STACK, elapsed, message), '*'); 165 _Message.text(_Message.STACK, elapsed, testCase.stackTrace), '*');
177 } 166 }
178 _parentWindow.postMessage( 167 _parentWindow.postMessage(
179 _Message.text(testCase.result, elapsed, testCase.message), '*'); 168 _Message.text(testCase.result, elapsed, testCase.message), '*');
180 } 169 }
181 void onSummary(int passed, int failed, int errors, List<TestCase> results, 170 void onSummary(int passed, int failed, int errors, List<TestCase> results,
182 String uncaughtError) { 171 String uncaughtError) {
183 } 172 }
184 173
185 void onDone(bool success) { 174 void onDone(bool success) {
186 _uninstallErrorHandler(); 175 _uninstallErrorHandler();
187 } 176 }
188 } 177 }
189 178
190 /** 179 /**
191 * The parent configuration runs in the top-level window; it wraps the tests 180 * The parent configuration runs in the top-level window; it wraps the tests
192 * in new functions that create child IFrames and run the real tests. 181 * in new functions that create child IFrames and run the real tests.
193 */ 182 */
194 class ParentInteractiveHtmlConfiguration extends HtmlConfiguration { 183 class ParentInteractiveHtmlConfiguration extends HtmlConfiguration {
195 final Map<int,DateTime> _testStarts; 184 final Map<int,DateTime> _testStarts;
196 185
197 186
198 /** The stack that was posted back from the child, if any. */ 187 /** The stack that was posted back from the child, if any. */
199 Trace _stack; 188 String _stack;
200 189
201 int _testTime; 190 int _testTime;
202 /** 191 /**
203 * Whether or not we have already wrapped the TestCase test functions 192 * Whether or not we have already wrapped the TestCase test functions
204 * in new closures that instead create an IFrame and get it to run the 193 * in new closures that instead create an IFrame and get it to run the
205 * test. 194 * test.
206 */ 195 */
207 bool _doneWrap = false; 196 bool _doneWrap = false;
208 197
209 StreamSubscription _messageSubscription; 198 StreamSubscription _messageSubscription;
(...skipping 27 matching lines...) Expand all
237 void _handleMessage(MessageEvent e) { 226 void _handleMessage(MessageEvent e) {
238 // Get the result, do any logging, then do a pass/fail. 227 // Get the result, do any logging, then do a pass/fail.
239 var msg = new _Message.fromString(e.data); 228 var msg = new _Message.fromString(e.data);
240 229
241 if(msg == null) { 230 if(msg == null) {
242 return; 231 return;
243 } 232 }
244 if (msg.messageType == _Message.LOG) { 233 if (msg.messageType == _Message.LOG) {
245 logMessage(e.data); 234 logMessage(e.data);
246 } else if (msg.messageType == _Message.STACK) { 235 } else if (msg.messageType == _Message.STACK) {
247 _stack = new Trace(json.parse(msg.body).map((frame) { 236 _stack = msg.body;
248 return new Frame(
249 Uri.parse(frame['uri']),
250 frame['line'],
251 frame['column'],
252 frame['member']);
253 }));
254 } else { 237 } else {
255 _testTime = msg.elapsed; 238 _testTime = msg.elapsed;
256 logMessage(_Message.text(_Message.LOG, _testTime, 'Complete')); 239 logMessage(_Message.text(_Message.LOG, _testTime, 'Complete'));
257 if (msg.messageType == _Message.PASS) { 240 if (msg.messageType == _Message.PASS) {
258 currentTestCase.pass(); 241 currentTestCase.pass();
259 } else if (msg.messageType == _Message.FAIL) { 242 } else if (msg.messageType == _Message.FAIL) {
260 currentTestCase.fail(msg.body, _stack); 243 currentTestCase.fail(msg.body, _stack);
261 } else if (msg.messageType == _Message.ERROR) { 244 } else if (msg.messageType == _Message.ERROR) {
262 currentTestCase.error(msg.body, _stack); 245 currentTestCase.error(msg.body, _stack);
263 } 246 }
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 ul, menu, dir { 683 ul, menu, dir {
701 display: block; 684 display: block;
702 list-style-type: disc; 685 list-style-type: disc;
703 -webkit-margin-before: 1em; 686 -webkit-margin-before: 1em;
704 -webkit-margin-after: 1em; 687 -webkit-margin-after: 1em;
705 -webkit-margin-start: 0px; 688 -webkit-margin-start: 0px;
706 -webkit-margin-end: 0px; 689 -webkit-margin-end: 0px;
707 -webkit-padding-start: 40px; 690 -webkit-padding-start: 40px;
708 } 691 }
709 """; 692 """;
OLDNEW
« no previous file with comments | « pkg/unittest/lib/html_enhanced_config.dart ('k') | pkg/unittest/lib/src/config.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698