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

Side by Side Diff: client/testing/unittest/unittestsuite.dart

Issue 8343009: Clean up UnitTestSuite a bit. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 2 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 | « no previous file | no next file » | 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 // TODO(rnystrom): This code is gradually moving from a Java/JUnit style to 5 // TODO(rnystrom): This code is gradually moving from a Java/JUnit style to
6 // something closer to JS/Jasmine. Eventually, the UnitTestSuite class can go 6 // something closer to JS/Jasmine. Eventually, the UnitTestSuite class can go
7 // away completely (or become private to this library) and the only exposed API 7 // away completely (or become private to this library) and the only exposed API
8 // will be group()/test()/expect(). Until then, both ways are supported, which 8 // will be group()/test()/expect(). Until then, both ways are supported, which
9 // is why things look a bit weird in here. 9 // is why things look a bit weird in here.
10 10
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 } catch(var e) { 82 } catch(var e) {
83 // TODO(jacobr): remove this horrible hack to work around dartc bugs. 83 // TODO(jacobr): remove this horrible hack to work around dartc bugs.
84 window.dynamic.addEventListener("DOMContentLoaded", listener, false); 84 window.dynamic.addEventListener("DOMContentLoaded", listener, false);
85 } 85 }
86 } 86 }
87 87
88 /** Subclasses should override this method to register tests. */ 88 /** Subclasses should override this method to register tests. */
89 void setUpTestSuite() {} 89 void setUpTestSuite() {}
90 90
91 /** Enqueues a synchronous test. */ 91 /** Enqueues a synchronous test. */
92 UnitTestSuite addTest(TestFunction body) { 92 void addTest(TestFunction body) {
93 test(null, body); 93 test(null, body);
94 } 94 }
95 95
96 /** Adds the tests defined by the given TestSet to this suite. */ 96 /** Adds the tests defined by the given TestSet to this suite. */
97 void addTestSet(TestSet test) { 97 void addTestSet(TestSet test) {
98 test._bindToSuite(this); 98 test._bindToSuite(this);
99 test.setup(); 99 test.setup();
100 } 100 }
101 101
102 /** Adds the tests defined by the given TestSets to this suite. */ 102 /** Adds the tests defined by the given TestSets to this suite. */
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 283
284 /** 284 /**
285 * Creates a new async test case with the given description and body. The 285 * Creates a new async test case with the given description and body. The
286 * description will include the descriptions of any surrounding group() 286 * description will include the descriptions of any surrounding group()
287 * calls. 287 * calls.
288 */ 288 */
289 void asyncTest(String spec, int callbacks, TestFunction body) { 289 void asyncTest(String spec, int callbacks, TestFunction body) {
290 _ensureActiveSuite(); 290 _ensureActiveSuite();
291 291
292 final testCase = new TestCase( 292 final testCase = new TestCase(
293 _currentSuite._tests.length + 1, _fullSpec(spec), body, callbacks); 293 _currentSuite._tests.length + 1, _fullSpec(spec), body, callbacks);
294 _currentSuite._tests.add(testCase); 294 _currentSuite._tests.add(testCase);
295 295
296 if (callbacks < 1) { 296 if (callbacks < 1) {
297 testCase.recordError( 297 testCase.recordError(
298 'Async tests must wait for at least one callback ', ''); 298 'Async tests must wait for at least one callback ', '');
299 } 299 }
300 } 300 }
301 301
302 /** 302 /**
303 * Creates a new named group of tests. Calls to group() or test() within the 303 * Creates a new named group of tests. Calls to group() or test() within the
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 if (spec === null) return '$_currentGroup'; 340 if (spec === null) return '$_currentGroup';
341 return _currentGroup != '' ? '$_currentGroup $spec' : spec; 341 return _currentGroup != '' ? '$_currentGroup $spec' : spec;
342 } 342 }
343 343
344 /** 344 /**
345 * Lazily creates a UnitTestSuite if there isn't already an active one. Returns 345 * Lazily creates a UnitTestSuite if there isn't already an active one. Returns
346 * whether or not one was created. 346 * whether or not one was created.
347 */ 347 */
348 _ensureActiveSuite() { 348 _ensureActiveSuite() {
349 if (_currentSuite != null) { 349 if (_currentSuite != null) {
350 return false; 350 return;
351 } 351 }
352 352
353 _currentSuite = new UnitTestSuite(); 353 _currentSuite = new UnitTestSuite();
354 return true;
355 } 354 }
356 355
357 /** 356 /**
358 * Wraps an value and provides an "==" operator that can be used to verify that 357 * Wraps an value and provides an "==" operator that can be used to verify that
359 * the value matches a given expectation. 358 * the value matches a given expectation.
360 */ 359 */
361 class Expectation { 360 class Expectation {
362 final _value; 361 final _value;
363 362
364 Expectation(this._value); 363 Expectation(this._value);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 </tr>"""; 512 </tr>""";
514 if (stackTrace != null) { 513 if (stackTrace != null) {
515 message += 514 message +=
516 "<tr><td></td><td colspan='2'><pre>${stackTrace}</pre></td></tr>"; 515 "<tr><td></td><td colspan='2'><pre>${stackTrace}</pre></td></tr>";
517 } 516 }
518 fail = true; 517 fail = true;
519 } 518 }
520 } 519 }
521 520
522 typedef void TestFunction(); 521 typedef void TestFunction();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698