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; |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 203 |
204 test("errors if the indent is not a non-negative number", () { | 204 test("errors if the indent is not a non-negative number", () { |
205 var process = runFormatter(["--indent", "notanum"]); | 205 var process = runFormatter(["--indent", "notanum"]); |
206 process.shouldExit(64); | 206 process.shouldExit(64); |
207 | 207 |
208 process = runFormatter(["--preserve", "-4"]); | 208 process = runFormatter(["--preserve", "-4"]); |
209 process.shouldExit(64); | 209 process.shouldExit(64); |
210 }); | 210 }); |
211 }); | 211 }); |
212 | 212 |
| 213 group("--set-exit-if-changed", () { |
| 214 test("gives exit code 0 if there are no changes", () { |
| 215 d.dir("code", [d.file("a.dart", formattedSource)]).create(); |
| 216 |
| 217 var process = runFormatterOnDir(["--set-exit-if-changed"]); |
| 218 process.shouldExit(0); |
| 219 }); |
| 220 |
| 221 test("gives exit code 1 if there are changes", () { |
| 222 d.dir("code", [d.file("a.dart", unformattedSource)]).create(); |
| 223 |
| 224 var process = runFormatterOnDir(["--set-exit-if-changed"]); |
| 225 process.shouldExit(1); |
| 226 }); |
| 227 |
| 228 test("gives exit code 1 if there are changes even in dry run", () { |
| 229 d.dir("code", [d.file("a.dart", unformattedSource)]).create(); |
| 230 |
| 231 var process = runFormatterOnDir(["--set-exit-if-changed", "--dry-run"]); |
| 232 process.shouldExit(1); |
| 233 }); |
| 234 }); |
| 235 |
213 group("with no paths", () { | 236 group("with no paths", () { |
214 test("errors on --overwrite", () { | 237 test("errors on --overwrite", () { |
215 var process = runFormatter(["--overwrite"]); | 238 var process = runFormatter(["--overwrite"]); |
216 process.shouldExit(64); | 239 process.shouldExit(64); |
217 }); | 240 }); |
218 | 241 |
219 test("exits with 65 on parse error", () { | 242 test("exits with 65 on parse error", () { |
220 var process = runFormatter(); | 243 var process = runFormatter(); |
221 process.writeLine("herp derp i are a dart"); | 244 process.writeLine("herp derp i are a dart"); |
222 process.closeStdin(); | 245 process.closeStdin(); |
223 process.shouldExit(65); | 246 process.shouldExit(65); |
224 }); | 247 }); |
225 | 248 |
226 test("reads from stdin", () { | 249 test("reads from stdin", () { |
227 var process = runFormatter(); | 250 var process = runFormatter(); |
228 process.writeLine(unformattedSource); | 251 process.writeLine(unformattedSource); |
229 process.closeStdin(); | 252 process.closeStdin(); |
230 | 253 |
231 // No trailing newline at the end. | 254 // No trailing newline at the end. |
232 process.stdout.expect(formattedSource.trimRight()); | 255 process.stdout.expect(formattedSource.trimRight()); |
233 process.shouldExit(0); | 256 process.shouldExit(0); |
234 }); | 257 }); |
235 }); | 258 }); |
236 } | 259 } |
OLD | NEW |