| 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 /** | 5 /** |
| 6 * A library for writing dart unit tests. | 6 * A library for writing dart unit tests. |
| 7 * | 7 * |
| 8 * ## Installing ## | 8 * ## Installing ## |
| 9 * | 9 * |
| 10 * Use [pub][] to install this package. Add the following to your `pubspec.yaml` | 10 * Use [pub][] to install this package. Add the following to your `pubspec.yaml` |
| (...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 /** | 746 /** |
| 747 * Runs the next test. | 747 * Runs the next test. |
| 748 */ | 748 */ |
| 749 void _runTest() { | 749 void _runTest() { |
| 750 if (_currentTestCaseIndex >= testCases.length) { | 750 if (_currentTestCaseIndex >= testCases.length) { |
| 751 _completeTests(); | 751 _completeTests(); |
| 752 } else { | 752 } else { |
| 753 final testCase = testCases[_currentTestCaseIndex]; | 753 final testCase = testCases[_currentTestCaseIndex]; |
| 754 var f = _guardAsync(testCase._run, null, testCase); | 754 var f = _guardAsync(testCase._run, null, testCase); |
| 755 Timer timer; | 755 Timer timer; |
| 756 try { | 756 final Duration timeout = unittestConfiguration.timeout; |
| 757 final Duration timeout = unittestConfiguration.timeout; | 757 if (timeout != null) { |
| 758 timer = new Timer(timeout, () { | 758 try { |
| 759 testCase.error("Test timed out after ${timeout.inSeconds} seconds."); | 759 timer = new Timer(timeout, () { |
| 760 }); | 760 testCase.error("Test timed out after ${timeout.inSeconds} seconds."); |
| 761 } on UnsupportedError catch (e) { | 761 }); |
| 762 if (e.message != "Timer greater than 0.") rethrow; | 762 } on UnsupportedError catch (e) { |
| 763 // Support running on d8 and jsshell which don't support timers. | 763 if (e.message != "Timer greater than 0.") rethrow; |
| 764 // Support running on d8 and jsshell which don't support timers. |
| 765 } |
| 764 } | 766 } |
| 765 f.whenComplete(() { | 767 f.whenComplete(() { |
| 766 if (timer != null) timer.cancel(); | 768 if (timer != null) timer.cancel(); |
| 767 var now = new DateTime.now().millisecondsSinceEpoch; | 769 var now = new DateTime.now().millisecondsSinceEpoch; |
| 768 if ((now - _lastBreath) >= BREATH_INTERVAL) { | 770 if ((now - _lastBreath) >= BREATH_INTERVAL) { |
| 769 _lastBreath = now; | 771 _lastBreath = now; |
| 770 Timer.run(_nextTestCase); | 772 Timer.run(_nextTestCase); |
| 771 } else { | 773 } else { |
| 772 runAsync(_nextTestCase); // Schedule the next test. | 774 runAsync(_nextTestCase); // Schedule the next test. |
| 773 } | 775 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 | 888 |
| 887 if (!filterStacks) return trace; | 889 if (!filterStacks) return trace; |
| 888 | 890 |
| 889 // Format the stack trace by removing everything above TestCase._runTest, | 891 // Format the stack trace by removing everything above TestCase._runTest, |
| 890 // which is usually going to be irrelevant. Also fold together unittest and | 892 // which is usually going to be irrelevant. Also fold together unittest and |
| 891 // core library calls so only the function the user called is visible. | 893 // core library calls so only the function the user called is visible. |
| 892 return new Trace(trace.frames.takeWhile((frame) { | 894 return new Trace(trace.frames.takeWhile((frame) { |
| 893 return frame.package != 'unittest' || frame.member != 'TestCase._runTest'; | 895 return frame.package != 'unittest' || frame.member != 'TestCase._runTest'; |
| 894 })).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore); | 896 })).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore); |
| 895 } | 897 } |
| OLD | NEW |