OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library dart_style.test.command_line; | 5 library dart_style.test.command_line; |
6 | 6 |
7 import 'dart:convert'; | 7 import 'dart:convert'; |
8 | 8 |
9 import 'package:path/path.dart' as p; | 9 import 'package:path/path.dart' as p; |
10 import 'package:scheduled_test/descriptor.dart' as d; | 10 import 'package:scheduled_test/descriptor.dart' as d; |
11 import 'package:scheduled_test/scheduled_test.dart'; | 11 import 'package:scheduled_test/scheduled_test.dart'; |
12 import 'package:scheduled_test/scheduled_stream.dart'; | 12 import 'package:scheduled_test/scheduled_stream.dart'; |
13 | 13 |
14 import 'utils.dart'; | 14 import 'utils.dart'; |
15 | 15 |
16 void main() { | 16 void main() { |
17 setUpTestSuite(); | 17 setUpTestSuite(); |
18 | 18 |
19 test("Exits with 0 on success.", () { | 19 test("Exits with 0 on success.", () { |
20 d.dir("code", [ | 20 d.dir("code", [d.file("a.dart", unformattedSource)]).create(); |
21 d.file("a.dart", unformattedSource) | |
22 ]).create(); | |
23 | 21 |
24 var process = runFormatterOnDir(); | 22 var process = runFormatterOnDir(); |
25 process.shouldExit(0); | 23 process.shouldExit(0); |
26 }); | 24 }); |
27 | 25 |
28 test("Exits with 64 on a command line argument error.", () { | 26 test("Exits with 64 on a command line argument error.", () { |
29 var process = runFormatterOnDir(["-wat"]); | 27 var process = runFormatterOnDir(["-wat"]); |
30 process.shouldExit(64); | 28 process.shouldExit(64); |
31 }); | 29 }); |
32 | 30 |
33 test("Exits with 65 on a parse error.", () { | 31 test("Exits with 65 on a parse error.", () { |
34 d.dir("code", [ | 32 d.dir("code", [d.file("a.dart", "herp derp i are a dart")]).create(); |
35 d.file("a.dart", "herp derp i are a dart") | |
36 ]).create(); | |
37 | 33 |
38 var process = runFormatterOnDir(); | 34 var process = runFormatterOnDir(); |
39 process.shouldExit(65); | 35 process.shouldExit(65); |
40 }); | 36 }); |
41 | 37 |
42 test("Errors if --dry-run and --overwrite are both passed.", () { | 38 test("Errors if --dry-run and --overwrite are both passed.", () { |
43 d.dir("code", [ | 39 d.dir("code", [d.file("a.dart", unformattedSource)]).create(); |
44 d.file("a.dart", unformattedSource) | |
45 ]).create(); | |
46 | 40 |
47 var process = runFormatterOnDir(["--dry-run", "--overwrite"]); | 41 var process = runFormatterOnDir(["--dry-run", "--overwrite"]); |
48 process.shouldExit(64); | 42 process.shouldExit(64); |
49 }); | 43 }); |
50 | 44 |
51 test("Errors if --dry-run and --machine are both passed.", () { | 45 test("Errors if --dry-run and --machine are both passed.", () { |
52 d.dir("code", [ | 46 d.dir("code", [d.file("a.dart", unformattedSource)]).create(); |
53 d.file("a.dart", unformattedSource) | |
54 ]).create(); | |
55 | 47 |
56 var process = runFormatterOnDir(["--dry-run", "--machine"]); | 48 var process = runFormatterOnDir(["--dry-run", "--machine"]); |
57 process.shouldExit(64); | 49 process.shouldExit(64); |
58 }); | 50 }); |
59 | 51 |
60 test("Errors if --machine and --overwrite are both passed.", () { | 52 test("Errors if --machine and --overwrite are both passed.", () { |
61 d.dir("code", [ | 53 d.dir("code", [d.file("a.dart", unformattedSource)]).create(); |
62 d.file("a.dart", unformattedSource) | |
63 ]).create(); | |
64 | 54 |
65 var process = runFormatterOnDir(["--machine", "--overwrite"]); | 55 var process = runFormatterOnDir(["--machine", "--overwrite"]); |
66 process.shouldExit(64); | 56 process.shouldExit(64); |
67 }); | 57 }); |
68 | 58 |
69 test("Errors if --dry-run and --machine are both passed.", () { | 59 test("Errors if --dry-run and --machine are both passed.", () { |
70 d.dir("code", [ | 60 d.dir("code", [d.file("a.dart", unformattedSource)]).create(); |
71 d.file("a.dart", unformattedSource) | |
72 ]).create(); | |
73 | 61 |
74 var process = runFormatter(["--dry-run", "--machine"]); | 62 var process = runFormatter(["--dry-run", "--machine"]); |
75 process.shouldExit(64); | 63 process.shouldExit(64); |
76 }); | 64 }); |
77 | 65 |
78 test("Errors if --machine and --overwrite are both passed.", () { | 66 test("Errors if --machine and --overwrite are both passed.", () { |
79 d.dir("code", [ | 67 d.dir("code", [d.file("a.dart", unformattedSource)]).create(); |
80 d.file("a.dart", unformattedSource) | |
81 ]).create(); | |
82 | 68 |
83 var process = runFormatter(["--machine", "--overwrite"]); | 69 var process = runFormatter(["--machine", "--overwrite"]); |
84 process.shouldExit(64); | 70 process.shouldExit(64); |
85 }); | 71 }); |
86 | 72 |
87 group("--dry-run", () { | 73 group("--dry-run", () { |
88 test("prints names of files that would change.", () { | 74 test("prints names of files that would change.", () { |
89 d.dir("code", [ | 75 d.dir("code", [ |
90 d.file("a_bad.dart", unformattedSource), | 76 d.file("a_bad.dart", unformattedSource), |
91 d.file("b_good.dart", formattedSource), | 77 d.file("b_good.dart", formattedSource), |
92 d.file("c_bad.dart", unformattedSource), | 78 d.file("c_bad.dart", unformattedSource), |
93 d.file("d_good.dart", formattedSource) | 79 d.file("d_good.dart", formattedSource) |
94 ]).create(); | 80 ]).create(); |
95 | 81 |
96 var aBad = p.join("code", "a_bad.dart"); | 82 var aBad = p.join("code", "a_bad.dart"); |
97 var cBad = p.join("code", "c_bad.dart"); | 83 var cBad = p.join("code", "c_bad.dart"); |
98 | 84 |
99 var process = runFormatterOnDir(["--dry-run"]); | 85 var process = runFormatterOnDir(["--dry-run"]); |
100 | 86 |
101 // The order isn't specified. | 87 // The order isn't specified. |
102 process.stdout.expect(either(aBad, cBad)); | 88 process.stdout.expect(either(aBad, cBad)); |
103 process.stdout.expect(either(aBad, cBad)); | 89 process.stdout.expect(either(aBad, cBad)); |
104 process.shouldExit(); | 90 process.shouldExit(); |
105 }); | 91 }); |
106 | 92 |
107 test("does not modify files.", () { | 93 test("does not modify files.", () { |
108 d.dir("code", [ | 94 d.dir("code", [d.file("a.dart", unformattedSource)]).create(); |
109 d.file("a.dart", unformattedSource) | |
110 ]).create(); | |
111 | 95 |
112 var process = runFormatterOnDir(["--dry-run"]); | 96 var process = runFormatterOnDir(["--dry-run"]); |
113 process.stdout.expect(p.join("code", "a.dart")); | 97 process.stdout.expect(p.join("code", "a.dart")); |
114 process.shouldExit(); | 98 process.shouldExit(); |
115 | 99 |
116 d.dir('code', [ | 100 d.dir('code', [d.file('a.dart', unformattedSource)]).validate(); |
117 d.file('a.dart', unformattedSource) | |
118 ]).validate(); | |
119 }); | 101 }); |
120 }); | 102 }); |
121 | 103 |
122 group("--machine", () { | 104 group("--machine", () { |
123 test("writes each output as json", () { | 105 test("writes each output as json", () { |
124 d.dir("code", [ | 106 d.dir("code", [ |
125 d.file("a.dart", unformattedSource), | 107 d.file("a.dart", unformattedSource), |
126 d.file("b.dart", unformattedSource) | 108 d.file("b.dart", unformattedSource) |
127 ]).create(); | 109 ]).create(); |
128 | 110 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 var process = runFormatter(); | 181 var process = runFormatter(); |
200 process.writeLine(unformattedSource); | 182 process.writeLine(unformattedSource); |
201 process.closeStdin(); | 183 process.closeStdin(); |
202 | 184 |
203 // No trailing newline at the end. | 185 // No trailing newline at the end. |
204 process.stdout.expect(formattedSource.trimRight()); | 186 process.stdout.expect(formattedSource.trimRight()); |
205 process.shouldExit(0); | 187 process.shouldExit(0); |
206 }); | 188 }); |
207 }); | 189 }); |
208 } | 190 } |
OLD | NEW |