Chromium Code Reviews| 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 * Support for writing Dart unit tests. | 6 * Support for writing Dart unit tests. |
| 7 * | 7 * |
| 8 * For information on installing and importing this library, see the | 8 * For information on installing and importing this library, see the |
| 9 * [unittest package on pub.dartlang.org] | 9 * [unittest package on pub.dartlang.org] |
| 10 * (http://pub.dartlang.org/packages/unittest). | 10 * (http://pub.dartlang.org/packages/unittest). |
| (...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 743 _completeTests(); | 743 _completeTests(); |
| 744 } else { | 744 } else { |
| 745 final testCase = testCases[_currentTestCaseIndex]; | 745 final testCase = testCases[_currentTestCaseIndex]; |
| 746 var f = _guardAsync(testCase._run, null, testCase); | 746 var f = _guardAsync(testCase._run, null, testCase); |
| 747 Timer timer; | 747 Timer timer; |
| 748 final Duration timeout = unittestConfiguration.timeout; | 748 final Duration timeout = unittestConfiguration.timeout; |
| 749 if (timeout != null) { | 749 if (timeout != null) { |
| 750 try { | 750 try { |
| 751 timer = new Timer(timeout, () { | 751 timer = new Timer(timeout, () { |
| 752 testCase.error("Test timed out after ${timeout.inSeconds} seconds."); | 752 testCase.error("Test timed out after ${timeout.inSeconds} seconds."); |
| 753 Timer.run(_nextTestCase); | |
|
Siggi Cherem (dart-lang)
2013/10/07 21:39:45
since this is already in a timer callback, it seem
devoncarew
2013/10/07 21:45:33
Done.
| |
| 753 }); | 754 }); |
| 754 } on UnsupportedError catch (e) { | 755 } on UnsupportedError catch (e) { |
| 755 if (e.message != "Timer greater than 0.") rethrow; | 756 if (e.message != "Timer greater than 0.") rethrow; |
| 756 // Support running on d8 and jsshell which don't support timers. | 757 // Support running on d8 and jsshell which don't support timers. |
| 757 } | 758 } |
| 758 } | 759 } |
| 759 f.whenComplete(() { | 760 f.whenComplete(() { |
| 760 if (timer != null) timer.cancel(); | 761 if (timer != null) timer.cancel(); |
| 761 var now = new DateTime.now().millisecondsSinceEpoch; | 762 var now = new DateTime.now().millisecondsSinceEpoch; |
| 762 if ((now - _lastBreath) >= BREATH_INTERVAL) { | 763 if ((now - _lastBreath) >= BREATH_INTERVAL) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 851 | 852 |
| 852 /** | 853 /** |
| 853 * A flag that controls whether we hide unittest and core library details in | 854 * A flag that controls whether we hide unittest and core library details in |
| 854 * exception stacks. | 855 * exception stacks. |
| 855 * | 856 * |
| 856 * Useful to disable when debugging unittest or matcher customizations. | 857 * Useful to disable when debugging unittest or matcher customizations. |
| 857 */ | 858 */ |
| 858 bool formatStacks = true; | 859 bool formatStacks = true; |
| 859 | 860 |
| 860 /** | 861 /** |
| 861 * A flag that controls whether we try to filter out irrelevant frames from | 862 * A flag that controls whether we try to filter out irrelevant frames from |
| 862 * the stack trace. Requires formatStacks to be set. | 863 * the stack trace. Requires formatStacks to be set. |
| 863 */ | 864 */ |
| 864 bool filterStacks = true; | 865 bool filterStacks = true; |
| 865 | 866 |
| 866 /** | 867 /** |
| 867 * Returns a Trace object from a StackTrace object or a String, or the | 868 * Returns a Trace object from a StackTrace object or a String, or the |
| 868 * unchanged input if formatStacks is false; | 869 * unchanged input if formatStacks is false; |
| 869 */ | 870 */ |
| 870 Trace _getTrace(stack) { | 871 Trace _getTrace(stack) { |
| 871 Trace trace; | 872 Trace trace; |
| 872 if (stack == null || !formatStacks) return null; | 873 if (stack == null || !formatStacks) return null; |
| 873 if (stack is String) { | 874 if (stack is String) { |
| 874 trace = new Trace.parse(stack); | 875 trace = new Trace.parse(stack); |
| 875 } else if (stack is StackTrace) { | 876 } else if (stack is StackTrace) { |
| 876 trace = new Trace.from(stack); | 877 trace = new Trace.from(stack); |
| 877 } else { | 878 } else { |
| 878 throw new Exception('Invalid stack type ${stack.runtimeType} for $stack.'); | 879 throw new Exception('Invalid stack type ${stack.runtimeType} for $stack.'); |
| 879 } | 880 } |
| 880 | 881 |
| 881 if (!filterStacks) return trace; | 882 if (!filterStacks) return trace; |
| 882 | 883 |
| 883 // Format the stack trace by removing everything above TestCase._runTest, | 884 // Format the stack trace by removing everything above TestCase._runTest, |
| 884 // which is usually going to be irrelevant. Also fold together unittest and | 885 // which is usually going to be irrelevant. Also fold together unittest and |
| 885 // core library calls so only the function the user called is visible. | 886 // core library calls so only the function the user called is visible. |
| 886 return new Trace(trace.frames.takeWhile((frame) { | 887 return new Trace(trace.frames.takeWhile((frame) { |
| 887 return frame.package != 'unittest' || frame.member != 'TestCase._runTest'; | 888 return frame.package != 'unittest' || frame.member != 'TestCase._runTest'; |
| 888 })).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore); | 889 })).terse.foldFrames((frame) => frame.package == 'unittest' || frame.isCore); |
| 889 } | 890 } |
| OLD | NEW |