| OLD | NEW |
| 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 /** | 5 /** |
| 6 * A library for writing dart unit tests. | 6 * A library for writing dart unit tests. |
| 7 * | 7 * |
| 8 * To import this library, specify the relative path to | 8 * To import this library, specify the relative path to |
| 9 * lib/unittest/unittest.dart. | 9 * lib/unittest/unittest.dart. |
| 10 * | 10 * |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 if (result == false) { | 235 if (result == false) { |
| 236 _fail('Exception:\n$e\ndid not match expectation.'); | 236 _fail('Exception:\n$e\ndid not match expectation.'); |
| 237 } | 237 } |
| 238 } | 238 } |
| 239 } | 239 } |
| 240 | 240 |
| 241 if (threw != true) _fail('An expected exception was not thrown.'); | 241 if (threw != true) _fail('An expected exception was not thrown.'); |
| 242 } | 242 } |
| 243 | 243 |
| 244 /** | 244 /** |
| 245 * The regexp pattern filter which constrains which tests to run |
| 246 * based on their descriptions. |
| 247 */ |
| 248 |
| 249 String filter = null; |
| 250 |
| 251 /** |
| 245 * Creates a new test case with the given description and body. The | 252 * Creates a new test case with the given description and body. The |
| 246 * description will include the descriptions of any surrounding group() | 253 * description will include the descriptions of any surrounding group() |
| 247 * calls. | 254 * calls. |
| 248 */ | 255 */ |
| 249 void test(String spec, TestFunction body) { | 256 void test(String spec, TestFunction body) { |
| 250 ensureInitialized(); | 257 ensureInitialized(); |
| 251 | 258 |
| 252 _tests.add(new TestCase(_tests.length + 1, _fullSpec(spec), body, 0)); | 259 _tests.add(new TestCase(_tests.length + 1, _fullSpec(spec), body, 0)); |
| 253 } | 260 } |
| 254 | 261 |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 }); | 641 }); |
| 635 port.toSendPort().send(null, null); | 642 port.toSendPort().send(null, null); |
| 636 } | 643 } |
| 637 | 644 |
| 638 /** Runs all queued tests, one at a time. */ | 645 /** Runs all queued tests, one at a time. */ |
| 639 _runTests() { | 646 _runTests() { |
| 640 // If we are soloing a test, remove all the others. | 647 // If we are soloing a test, remove all the others. |
| 641 if (_soloTest != null) { | 648 if (_soloTest != null) { |
| 642 _tests = _tests.filter((t) => t == _soloTest); | 649 _tests = _tests.filter((t) => t == _soloTest); |
| 643 } | 650 } |
| 651 if (filter != null) { |
| 652 RegExp re = new RegExp(filter); |
| 653 _tests = _tests.filter((t) => re.hasMatch(t.description)); |
| 654 } |
| 644 | 655 |
| 645 _config.onStart(); | 656 _config.onStart(); |
| 646 | 657 |
| 647 _defer(() { | 658 _defer(() { |
| 648 assert (_currentTest == 0); | 659 assert (_currentTest == 0); |
| 649 _testRunner(); | 660 _testRunner(); |
| 650 }); | 661 }); |
| 651 } | 662 } |
| 652 | 663 |
| 653 /** | 664 /** |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 _config.onInit(); | 767 _config.onInit(); |
| 757 | 768 |
| 758 // Immediately queue the suite up. It will run after a timeout (i.e. after | 769 // Immediately queue the suite up. It will run after a timeout (i.e. after |
| 759 // main() has returned). | 770 // main() has returned). |
| 760 _defer(_runTests); | 771 _defer(_runTests); |
| 761 } | 772 } |
| 762 | 773 |
| 763 /** Signature for a test function. */ | 774 /** Signature for a test function. */ |
| 764 typedef void TestFunction(); | 775 typedef void TestFunction(); |
| 765 | 776 |
| OLD | NEW |