| 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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 logStepComplete(completed, unexpectedResults.length, | 189 logStepComplete(completed, unexpectedResults.length, |
| 190 descriptions.length, suite, description, lastStepRun); | 190 descriptions.length, suite, description, lastStepRun); |
| 191 result = currentResult; | 191 result = currentResult; |
| 192 if (currentResult.outcome == Expectation.PASS) { | 192 if (currentResult.outcome == Expectation.PASS) { |
| 193 // The input to the next step is the output of this step. | 193 // The input to the next step is the output of this step. |
| 194 return doStep(result.output); | 194 return doStep(result.output); |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 if (description.multitestExpectations != null) { | 197 if (description.multitestExpectations != null) { |
| 198 if (isError(description.multitestExpectations)) { | 198 if (isError(description.multitestExpectations)) { |
| 199 result = result.toNegativeTestResult(); | 199 result = toNegativeTestResult( |
| 200 result, description.multitestExpectations); |
| 200 } | 201 } |
| 201 } else if (lastStep == lastStepRun && | 202 } else if (lastStep == lastStepRun && |
| 202 description.shortName.endsWith("negative_test")) { | 203 description.shortName.endsWith("negative_test")) { |
| 203 if (result.outcome == Expectation.PASS) { | 204 if (result.outcome == Expectation.PASS) { |
| 204 result.addLog("Negative test didn't report an error.\n"); | 205 result.addLog("Negative test didn't report an error.\n"); |
| 205 } else if (result.outcome == Expectation.FAIL) { | 206 } else if (result.outcome == Expectation.FAIL) { |
| 206 result.addLog("Negative test reported an error as expeceted.\n"); | 207 result.addLog("Negative test reported an error as expeceted.\n"); |
| 207 } | 208 } |
| 208 result = result.toNegativeTestResult(); | 209 result = toNegativeTestResult(result); |
| 209 } | 210 } |
| 210 if (!expectedOutcomes.contains(result.outcome)) { | 211 if (!expectedOutcomes.contains(result.outcome)) { |
| 211 result.addLog("$sb"); | 212 result.addLog("$sb"); |
| 212 unexpectedResults[description] = result; | 213 unexpectedResults[description] = result; |
| 213 unexpectedOutcomes[description] = expectedOutcomes; | 214 unexpectedOutcomes[description] = expectedOutcomes; |
| 214 logUnexpectedResult(suite, description, result, expectedOutcomes); | 215 logUnexpectedResult(suite, description, result, expectedOutcomes); |
| 215 } else { | 216 } else { |
| 216 logMessage(sb); | 217 logMessage(sb); |
| 217 } | 218 } |
| 218 logTestComplete(++completed, unexpectedResults.length, | 219 logTestComplete(++completed, unexpectedResults.length, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 | 310 |
| 310 Result.fail(O output, [error, StackTrace trace]) | 311 Result.fail(O output, [error, StackTrace trace]) |
| 311 : this(output, Expectation.FAIL, error, trace); | 312 : this(output, Expectation.FAIL, error, trace); |
| 312 | 313 |
| 313 String get log => logs.join(); | 314 String get log => logs.join(); |
| 314 | 315 |
| 315 void addLog(String log) { | 316 void addLog(String log) { |
| 316 logs.add(log); | 317 logs.add(log); |
| 317 } | 318 } |
| 318 | 319 |
| 319 Result<O> toNegativeTestResult() { | 320 Result<O> copyWithOutcome(Expectation outcome) { |
| 320 Expectation outcome = this.outcome; | |
| 321 if (outcome == Expectation.PASS) { | |
| 322 outcome = Expectation.FAIL; | |
| 323 } else if (outcome == Expectation.FAIL) { | |
| 324 outcome = Expectation.PASS; | |
| 325 } | |
| 326 return new Result<O>(output, outcome, error, trace) | 321 return new Result<O>(output, outcome, error, trace) |
| 327 ..logs.addAll(logs); | 322 ..logs.addAll(logs); |
| 328 } | 323 } |
| 329 } | 324 } |
| 330 | 325 |
| 331 /// This is called from generated code. | 326 /// This is called from generated code. |
| 332 Future<Null> runChain( | 327 Future<Null> runChain( |
| 333 CreateContext f, Map<String, String> environment, Set<String> selectors, | 328 CreateContext f, Map<String, String> environment, Set<String> selectors, |
| 334 String json) { | 329 String json) { |
| 335 return withErrorHandling(() async { | 330 return withErrorHandling(() async { |
| 336 Chain suite = new Suite.fromJsonMap(Uri.base, JSON.decode(json)); | 331 Chain suite = new Suite.fromJsonMap(Uri.base, JSON.decode(json)); |
| 337 print("Running ${suite.name}"); | 332 print("Running ${suite.name}"); |
| 338 ChainContext context = await f(suite, environment); | 333 ChainContext context = await f(suite, environment); |
| 339 return context.run(suite, selectors); | 334 return context.run(suite, selectors); |
| 340 }); | 335 }); |
| 341 } | 336 } |
| 337 |
| 338 Result toNegativeTestResult(Result result, [Set<String> expectations]) { |
| 339 Expectation outcome = result.outcome; |
| 340 if (outcome == Expectation.PASS) { |
| 341 if (expectations == null) { |
| 342 outcome = Expectation.FAIL; |
| 343 } else if (expectations.contains("compile-time error")) { |
| 344 outcome = Expectation.MISSING_COMPILETIME_ERROR; |
| 345 } else if (expectations.contains("runtime error") || |
| 346 expectations.contains("dynamic type error")) { |
| 347 outcome = Expectation.MISSING_RUNTIME_ERROR; |
| 348 } else { |
| 349 outcome = Expectation.FAIL; |
| 350 } |
| 351 } else if (outcome == Expectation.FAIL) { |
| 352 outcome = Expectation.PASS; |
| 353 } |
| 354 return result.copyWithOutcome(outcome); |
| 355 } |
| OLD | NEW |