| 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 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 | 745 |
| 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; |
| 756 try { |
| 757 final Duration timeout = unittestConfiguration.timeout; |
| 758 timer = new Timer(timeout, () { |
| 759 testCase.error("Test timed out after ${timeout.inSeconds} seconds."); |
| 760 }); |
| 761 } on UnsupportedError catch (e) { |
| 762 if (e.message != "Timer greater than 0.") rethrow; |
| 763 // Support running on d8 and jsshell which don't support timers. |
| 764 } |
| 755 f.whenComplete(() { | 765 f.whenComplete(() { |
| 766 if (timer != null) timer.cancel(); |
| 756 var now = new DateTime.now().millisecondsSinceEpoch; | 767 var now = new DateTime.now().millisecondsSinceEpoch; |
| 757 if ((now - _lastBreath) >= BREATH_INTERVAL) { | 768 if ((now - _lastBreath) >= BREATH_INTERVAL) { |
| 758 _lastBreath = now; | 769 _lastBreath = now; |
| 759 Timer.run(_nextTestCase); | 770 Timer.run(_nextTestCase); |
| 760 } else { | 771 } else { |
| 761 runAsync(_nextTestCase); // Schedule the next test. | 772 runAsync(_nextTestCase); // Schedule the next test. |
| 762 } | 773 } |
| 763 }); | 774 }); |
| 764 } | 775 } |
| 765 } | 776 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 | 877 |
| 867 if (!formatStacks) return trace; | 878 if (!formatStacks) return trace; |
| 868 | 879 |
| 869 // Format the stack trace by removing everything above TestCase._runTest, | 880 // Format the stack trace by removing everything above TestCase._runTest, |
| 870 // which is usually going to be irrelevant. Also fold together unittest and | 881 // which is usually going to be irrelevant. Also fold together unittest and |
| 871 // core library calls so only the function the user called is visible. | 882 // core library calls so only the function the user called is visible. |
| 872 return new Trace(trace.frames.takeWhile((frame) { | 883 return new Trace(trace.frames.takeWhile((frame) { |
| 873 return frame.package != 'unittest' || frame.member != 'TestCase._runTest'; | 884 return frame.package != 'unittest' || frame.member != 'TestCase._runTest'; |
| 874 })).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore); | 885 })).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore); |
| 875 } | 886 } |
| OLD | NEW |