OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 library testing.chain; | 5 library testing.chain; |
6 | 6 |
7 import 'dart:async' show | 7 import 'dart:async' show |
8 Future, | 8 Future, |
9 Stream; | 9 Stream; |
10 | 10 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 /// interleaving steps. | 172 /// interleaving steps. |
173 Future doStep(dynamic input) async { | 173 Future doStep(dynamic input) async { |
174 Future future; | 174 Future future; |
175 bool isAsync = false; | 175 bool isAsync = false; |
176 if (iterator.moveNext()) { | 176 if (iterator.moveNext()) { |
177 Step step = iterator.current; | 177 Step step = iterator.current; |
178 lastStepRun = step; | 178 lastStepRun = step; |
179 isAsync = step.isAsync; | 179 isAsync = step.isAsync; |
180 logStepStart(completed, unexpectedResults.length, descriptions.length, | 180 logStepStart(completed, unexpectedResults.length, descriptions.length, |
181 suite, description, step); | 181 suite, description, step); |
| 182 // TODO(ahe): It's important to share the zone error reporting zone |
| 183 // between all the tasks. Otherwise, if a future completes with an |
| 184 // error in one zone, and gets stored, it becomes an uncaught error |
| 185 // in other zones (this happened in createPlatform). |
182 future = runGuarded(() async { | 186 future = runGuarded(() async { |
183 try { | 187 try { |
184 return await step.run(input, this); | 188 return await step.run(input, this); |
185 } catch (error, trace) { | 189 } catch (error, trace) { |
186 return step.unhandledError(error, trace); | 190 return step.unhandledError(error, trace); |
187 } | 191 } |
188 }, printLineOnStdout: sb.writeln); | 192 }, printLineOnStdout: sb.writeln); |
189 } else { | 193 } else { |
190 future = new Future.value(null); | 194 future = new Future.value(null); |
191 } | 195 } |
(...skipping 19 matching lines...) Expand all Loading... |
211 } else if (result.outcome == Expectation.Fail) { | 215 } else if (result.outcome == Expectation.Fail) { |
212 result.addLog("Negative test reported an error as expeceted.\n"); | 216 result.addLog("Negative test reported an error as expeceted.\n"); |
213 } | 217 } |
214 result = toNegativeTestResult(result); | 218 result = toNegativeTestResult(result); |
215 } | 219 } |
216 if (!expectedOutcomes.contains(result.outcome)) { | 220 if (!expectedOutcomes.contains(result.outcome)) { |
217 result.addLog("$sb"); | 221 result.addLog("$sb"); |
218 unexpectedResults[description] = result; | 222 unexpectedResults[description] = result; |
219 unexpectedOutcomes[description] = expectedOutcomes; | 223 unexpectedOutcomes[description] = expectedOutcomes; |
220 logUnexpectedResult(suite, description, result, expectedOutcomes); | 224 logUnexpectedResult(suite, description, result, expectedOutcomes); |
| 225 exitCode = 1; |
221 } else { | 226 } else { |
222 logMessage(sb); | 227 logMessage(sb); |
223 } | 228 } |
224 logTestComplete(++completed, unexpectedResults.length, | 229 logTestComplete(++completed, unexpectedResults.length, |
225 descriptions.length, suite, description); | 230 descriptions.length, suite, description); |
226 }); | 231 }); |
227 if (isAsync) { | 232 if (isAsync) { |
228 futures.add(future); | 233 futures.add(future); |
229 return null; | 234 return null; |
230 } else { | 235 } else { |
231 return future; | 236 return future; |
232 } | 237 } |
233 } | 238 } |
234 // The input of the first step is [description]. | 239 // The input of the first step is [description]. |
235 await doStep(description); | 240 await doStep(description); |
236 } | 241 } |
237 await Future.wait(futures); | 242 await Future.wait(futures); |
238 logSuiteComplete(); | 243 logSuiteComplete(); |
239 if (unexpectedResults.isNotEmpty) { | 244 if (unexpectedResults.isNotEmpty) { |
240 unexpectedResults.forEach((TestDescription description, Result result) { | 245 unexpectedResults.forEach((TestDescription description, Result result) { |
241 exitCode = 1; | |
242 logUnexpectedResult(suite, description, result, | 246 logUnexpectedResult(suite, description, result, |
243 unexpectedOutcomes[description]); | 247 unexpectedOutcomes[description]); |
244 }); | 248 }); |
245 print("${unexpectedResults.length} failed:"); | 249 print("${unexpectedResults.length} failed:"); |
246 unexpectedResults.forEach((TestDescription description, Result result) { | 250 unexpectedResults.forEach((TestDescription description, Result result) { |
247 print("${suite.name}/${description.shortName}: ${result.outcome}"); | 251 print("${suite.name}/${description.shortName}: ${result.outcome}"); |
248 }); | 252 }); |
249 } | 253 } |
250 } | 254 } |
251 | 255 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 Future<Null> runChain( | 355 Future<Null> runChain( |
352 CreateContext f, Map<String, String> environment, Set<String> selectors, | 356 CreateContext f, Map<String, String> environment, Set<String> selectors, |
353 String json) { | 357 String json) { |
354 return withErrorHandling(() async { | 358 return withErrorHandling(() async { |
355 Chain suite = new Suite.fromJsonMap(Uri.base, JSON.decode(json)); | 359 Chain suite = new Suite.fromJsonMap(Uri.base, JSON.decode(json)); |
356 print("Running ${suite.name}"); | 360 print("Running ${suite.name}"); |
357 ChainContext context = await f(suite, environment); | 361 ChainContext context = await f(suite, environment); |
358 return context.run(suite, selectors); | 362 return context.run(suite, selectors); |
359 }); | 363 }); |
360 } | 364 } |
OLD | NEW |