OLD | NEW |
| 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 |
1 import 'package:scheduled_test/scheduled_test.dart'; | 5 import 'package:scheduled_test/scheduled_test.dart'; |
| 6 |
2 import '../../lib/src/exit_codes.dart' as exit_codes; | 7 import '../../lib/src/exit_codes.dart' as exit_codes; |
3 import '../test_pub.dart'; | 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. |
4 void pubBuildAndServeShouldFail(String description, {List<String> args, | 20 void pubBuildAndServeShouldFail(String description, {List<String> args, |
5 String error, String buildError, String serveError, int exitCode}) { | 21 String error, String buildError, String serveError, int exitCode}) { |
| 22 |
6 if (error != null) { | 23 if (error != null) { |
7 assert(buildError == null); | 24 assert(buildError == null); |
8 buildError = error; | 25 buildError = error; |
| 26 |
9 assert(serveError == null); | 27 assert(serveError == null); |
10 serveError = error; | 28 serveError = error; |
11 } | 29 } |
| 30 |
| 31 // Usage errors also print the usage, so validate that. |
12 var buildExpectation = buildError; | 32 var buildExpectation = buildError; |
13 var serveExpectation = serveError; | 33 var serveExpectation = serveError; |
14 if (exitCode == exit_codes.USAGE) { | 34 if (exitCode == exit_codes.USAGE) { |
15 buildExpectation = | 35 buildExpectation = |
16 allOf(startsWith(buildExpectation), contains("Usage: pub build")); | 36 allOf(startsWith(buildExpectation), contains("Usage: pub build")); |
17 serveExpectation = | 37 serveExpectation = |
18 allOf(startsWith(serveExpectation), contains("Usage: pub serve")); | 38 allOf(startsWith(serveExpectation), contains("Usage: pub serve")); |
19 } | 39 } |
| 40 |
20 integration("build fails $description", () { | 41 integration("build fails $description", () { |
21 schedulePub( | 42 schedulePub( |
22 args: ["build"]..addAll(args), | 43 args: ["build"]..addAll(args), |
23 error: buildExpectation, | 44 error: buildExpectation, |
24 exitCode: exitCode); | 45 exitCode: exitCode); |
25 }); | 46 }); |
| 47 |
26 integration("build --format json fails $description", () { | 48 integration("build --format json fails $description", () { |
27 schedulePub(args: ["build", "--format", "json"]..addAll(args), outputJson: { | 49 schedulePub(args: ["build", "--format", "json"]..addAll(args), outputJson: { |
28 "error": buildError | 50 "error": buildError // No usage in JSON output. |
29 }, exitCode: exitCode); | 51 }, exitCode: exitCode); |
30 }); | 52 }); |
| 53 |
31 integration("serve fails $description", () { | 54 integration("serve fails $description", () { |
32 schedulePub( | 55 schedulePub( |
33 args: ["serve"]..addAll(args), | 56 args: ["serve"]..addAll(args), |
34 error: serveExpectation, | 57 error: serveExpectation, |
35 exitCode: exitCode); | 58 exitCode: exitCode); |
36 }); | 59 }); |
37 } | 60 } |
OLD | NEW |