OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS d.file |
| 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. |
| 4 |
| 5 import 'package:scheduled_test/scheduled_test.dart'; |
| 6 |
| 7 import '../../lib/src/exit_codes.dart' as exit_codes; |
| 8 import '../test_pub.dart'; |
| 9 |
| 10 /// Runs separate integration tests for "pub build", "pub serve", and |
| 11 /// "pub build --format json" and validates that in all cases, it fails with |
| 12 /// an expected error message and exits with [exitCode]. |
| 13 /// |
| 14 /// The integrations assume set up is already done, so you will likely want to |
| 15 /// call [setUp] before this. |
| 16 /// |
| 17 /// If [error] is provided, then both pub build and pub serve should exit with |
| 18 /// that message. Otherwise, [buildError] is the expected error from pub build |
| 19 /// and [serveError] from pub serve. |
| 20 void pubBuildAndServeShouldFail(String description, {List<String> args, |
| 21 String error, String buildError, String serveError, int exitCode}) { |
| 22 |
| 23 if (error != null) { |
| 24 assert(buildError == null); |
| 25 buildError = error; |
| 26 |
| 27 assert(serveError == null); |
| 28 serveError = error; |
| 29 } |
| 30 |
| 31 // Usage errors also print the usage, so validate that. |
| 32 var buildExpectation = buildError; |
| 33 var serveExpectation = serveError; |
| 34 if (exitCode == exit_codes.USAGE) { |
| 35 buildExpectation = allOf( |
| 36 startsWith(buildExpectation), contains("Usage: pub build")); |
| 37 serveExpectation = allOf( |
| 38 startsWith(serveExpectation), contains("Usage: pub serve")); |
| 39 } |
| 40 |
| 41 integration("build fails $description", () { |
| 42 schedulePub(args: ["build"]..addAll(args), |
| 43 error: buildExpectation, |
| 44 exitCode: exitCode); |
| 45 }); |
| 46 |
| 47 integration("build --format json fails $description", () { |
| 48 schedulePub(args: ["build", "--format", "json"]..addAll(args), |
| 49 outputJson: { |
| 50 "error": buildError // No usage in JSON output. |
| 51 }, |
| 52 exitCode: exitCode); |
| 53 }); |
| 54 |
| 55 integration("serve fails $description", () { |
| 56 schedulePub(args: ["serve"]..addAll(args), |
| 57 error: serveExpectation, |
| 58 exitCode: exitCode); |
| 59 }); |
| 60 } |
OLD | NEW |