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

Side by Side Diff: pkg/unittest/lib/src/test_case.dart

Issue 18384002: pkg/unittest: no need to expose the errorHandler helper (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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) 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 part of unittest; 5 part of unittest;
6 6
7 /** 7 /**
8 * Represents the state for an individual unit test. 8 * Represents the state for an individual unit test.
9 * 9 *
10 * Create by calling [test] or [solo_test]. 10 * Create by calling [test] or [solo_test].
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 Completer _testComplete; 61 Completer _testComplete;
62 62
63 TestCase._internal(this.id, this.description, this.testFunction) 63 TestCase._internal(this.id, this.description, this.testFunction)
64 : currentGroup = _currentContext.fullName, 64 : currentGroup = _currentContext.fullName,
65 setUp = _currentContext.testSetup, 65 setUp = _currentContext.testSetup,
66 tearDown = _currentContext.testTeardown; 66 tearDown = _currentContext.testTeardown;
67 67
68 bool get isComplete => !enabled || result != null; 68 bool get isComplete => !enabled || result != null;
69 69
70 errorHandler(stage) => (e) { 70 Function _errorHandler(String stage) => (e) {
71 var stack = getAttachedStackTrace(e); 71 var stack = getAttachedStackTrace(e);
72 stack = (stack == null) ? '' : '$stack'; 72 stack = (stack == null) ? '' : '$stack';
73 if (result == null || result == PASS) { 73 if (result == null || result == PASS) {
74 if (e is TestFailure) { 74 if (e is TestFailure) {
75 fail("$e", stack); 75 fail("$e", stack);
76 } else { 76 } else {
77 error("$stage failed: Caught $e", stack); 77 error("$stage failed: Caught $e", stack);
78 } 78 }
79 } 79 }
80 }; 80 };
81 81
82 /** 82 /**
83 * Perform any associated [_setUp] function and run the test. Returns 83 * Perform any associated [_setUp] function and run the test. Returns
84 * a [Future] that can be used to schedule the next test. If the test runs 84 * a [Future] that can be used to schedule the next test. If the test runs
85 * to completion synchronously, or is disabled, null is returned, to 85 * to completion synchronously, or is disabled, null is returned, to
86 * tell unittest to schedule the next test immediately. 86 * tell unittest to schedule the next test immediately.
87 */ 87 */
88 Future _run() { 88 Future _run() {
89 if (!enabled) return new Future.value(); 89 if (!enabled) return new Future.value();
90 90
91 _result = _stackTrace = null; 91 _result = _stackTrace = null;
92 _message = ''; 92 _message = '';
93 93
94 var f = (setUp == null) ? new Future.value() : new Future(setUp); 94 var f = (setUp == null) ? new Future.value() : new Future(setUp);
95 return f.catchError(errorHandler('Setup')) 95 return f.catchError(_errorHandler('Setup'))
96 .then((_) { 96 .then((_) {
97 // Skip the test if setup failed. 97 // Skip the test if setup failed.
98 if (result != null) return new Future.value(); 98 if (result != null) return new Future.value();
99 _config.onTestStart(this); 99 _config.onTestStart(this);
100 _startTime = new DateTime.now(); 100 _startTime = new DateTime.now();
101 _runningTime = null; 101 _runningTime = null;
102 ++_callbackFunctionsOutstanding; 102 ++_callbackFunctionsOutstanding;
103 return testFunction(); 103 return testFunction();
104 }) 104 })
105 .catchError(errorHandler('Test')) 105 .catchError(_errorHandler('Test'))
106 .then((_) { 106 .then((_) {
107 _markCallbackComplete(); 107 _markCallbackComplete();
108 if (result == null) { 108 if (result == null) {
109 // Outstanding callbacks exist; we need to return a Future. 109 // Outstanding callbacks exist; we need to return a Future.
110 _testComplete = new Completer(); 110 _testComplete = new Completer();
111 return _testComplete.future.whenComplete(() { 111 return _testComplete.future.whenComplete(() {
112 if (tearDown != null) { 112 if (tearDown != null) {
113 return tearDown(); 113 return tearDown();
114 } 114 }
115 }).catchError(errorHandler('Teardown')); 115 }).catchError(_errorHandler('Teardown'));
116 } else if (tearDown != null) { 116 } else if (tearDown != null) {
117 return tearDown(); 117 return tearDown();
118 } 118 }
119 }) 119 })
120 .catchError(errorHandler('Teardown')); 120 .catchError(_errorHandler('Teardown'));
121 } 121 }
122 122
123 // Set the results, notify the config, and return true if this 123 // Set the results, notify the config, and return true if this
124 // is the first time the result is being set. 124 // is the first time the result is being set.
125 void _setResult(String testResult, String messageText, String stack) { 125 void _setResult(String testResult, String messageText, String stack) {
126 _message = messageText; 126 _message = messageText;
127 _stackTrace = _formatStack(stack); 127 _stackTrace = _formatStack(stack);
128 if (result == null) { 128 if (result == null) {
129 _result = testResult; 129 _result = testResult;
130 _config.onTestResult(this); 130 _config.onTestResult(this);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 assert(stack != null); 175 assert(stack != null);
176 _complete(ERROR, messageText, stack); 176 _complete(ERROR, messageText, stack);
177 } 177 }
178 178
179 void _markCallbackComplete() { 179 void _markCallbackComplete() {
180 if (--_callbackFunctionsOutstanding == 0 && !isComplete) { 180 if (--_callbackFunctionsOutstanding == 0 && !isComplete) {
181 pass(); 181 pass();
182 } 182 }
183 } 183 }
184 } 184 }
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