Index: packages/dart_style/test/command_line_test.dart |
diff --git a/packages/dart_style/test/command_line_test.dart b/packages/dart_style/test/command_line_test.dart |
index de644490e4d69c44a6b85014eb722c4b6a346d47..425143d01d4f1adc865756f7fdc4522beb594d9b 100644 |
--- a/packages/dart_style/test/command_line_test.dart |
+++ b/packages/dart_style/test/command_line_test.dart |
@@ -16,62 +16,85 @@ import 'utils.dart'; |
void main() { |
setUpTestSuite(); |
- test("Exits with 0 on success.", () { |
+ test("exits with 0 on success", () { |
d.dir("code", [d.file("a.dart", unformattedSource)]).create(); |
var process = runFormatterOnDir(); |
process.shouldExit(0); |
}); |
- test("Exits with 64 on a command line argument error.", () { |
+ test("exits with 64 on a command line argument error", () { |
var process = runFormatterOnDir(["-wat"]); |
process.shouldExit(64); |
}); |
- test("Exits with 65 on a parse error.", () { |
+ test("exits with 65 on a parse error", () { |
d.dir("code", [d.file("a.dart", "herp derp i are a dart")]).create(); |
var process = runFormatterOnDir(); |
process.shouldExit(65); |
}); |
- test("Errors if --dry-run and --overwrite are both passed.", () { |
+ test("errors if --dry-run and --overwrite are both passed", () { |
d.dir("code", [d.file("a.dart", unformattedSource)]).create(); |
var process = runFormatterOnDir(["--dry-run", "--overwrite"]); |
process.shouldExit(64); |
}); |
- test("Errors if --dry-run and --machine are both passed.", () { |
+ test("errors if --dry-run and --machine are both passed", () { |
d.dir("code", [d.file("a.dart", unformattedSource)]).create(); |
var process = runFormatterOnDir(["--dry-run", "--machine"]); |
process.shouldExit(64); |
}); |
- test("Errors if --machine and --overwrite are both passed.", () { |
+ test("errors if --machine and --overwrite are both passed", () { |
d.dir("code", [d.file("a.dart", unformattedSource)]).create(); |
var process = runFormatterOnDir(["--machine", "--overwrite"]); |
process.shouldExit(64); |
}); |
- test("Errors if --dry-run and --machine are both passed.", () { |
+ test("errors if --dry-run and --machine are both passed", () { |
d.dir("code", [d.file("a.dart", unformattedSource)]).create(); |
var process = runFormatter(["--dry-run", "--machine"]); |
process.shouldExit(64); |
}); |
- test("Errors if --machine and --overwrite are both passed.", () { |
+ test("errors if --machine and --overwrite are both passed", () { |
d.dir("code", [d.file("a.dart", unformattedSource)]).create(); |
var process = runFormatter(["--machine", "--overwrite"]); |
process.shouldExit(64); |
}); |
+ test("--version prints the version number", () { |
+ var process = runFormatter(["--version"]); |
+ |
+ // Match something roughly semver-like. |
+ process.stdout.expect(matches(r"\d+\.\d+\.\d+.*")); |
+ process.shouldExit(0); |
+ }); |
+ |
+ test("only prints a hidden directory once", () { |
+ d.dir('code', [ |
+ d.dir('.skip', [ |
+ d.file('a.dart', unformattedSource), |
+ d.file('b.dart', unformattedSource) |
+ ]) |
+ ]).create(); |
+ |
+ var process = runFormatterOnDir(); |
+ |
+ process.stdout.expect(startsWith("Formatting directory")); |
+ process.stdout.expect("Skipping hidden path ${p.join("code", ".skip")}"); |
+ process.shouldExit(); |
+ }); |
+ |
group("--dry-run", () { |
- test("prints names of files that would change.", () { |
+ test("prints names of files that would change", () { |
d.dir("code", [ |
d.file("a_bad.dart", unformattedSource), |
d.file("b_good.dart", formattedSource), |
@@ -90,7 +113,7 @@ void main() { |
process.shouldExit(); |
}); |
- test("does not modify files.", () { |
+ test("does not modify files", () { |
d.dir("code", [d.file("a.dart", unformattedSource)]).create(); |
var process = runFormatterOnDir(["--dry-run"]); |
@@ -130,12 +153,12 @@ void main() { |
}); |
group("--preserve", () { |
- test("errors if given paths.", () { |
+ test("errors if given paths", () { |
var process = runFormatter(["--preserve", "path", "another"]); |
process.shouldExit(64); |
}); |
- test("errors on wrong number of components.", () { |
+ test("errors on wrong number of components", () { |
var process = runFormatter(["--preserve", "1"]); |
process.shouldExit(64); |
@@ -143,12 +166,12 @@ void main() { |
process.shouldExit(64); |
}); |
- test("errors on non-integer component.", () { |
+ test("errors on non-integer component", () { |
var process = runFormatter(["--preserve", "1:2.3"]); |
process.shouldExit(64); |
}); |
- test("updates selection.", () { |
+ test("updates selection", () { |
var process = runFormatter(["--preserve", "6:10", "-m"]); |
process.writeLine(unformattedSource); |
process.closeStdin(); |
@@ -164,20 +187,43 @@ void main() { |
}); |
}); |
+ group("--indent", () { |
+ test("sets the leading indentation of the output", () { |
+ var process = runFormatter(["--indent", "3"]); |
+ process.writeLine("main() {'''"); |
+ process.writeLine("a flush left multi-line string''';}"); |
+ process.closeStdin(); |
+ |
+ process.stdout.expect(" main() {"); |
+ process.stdout.expect(" '''"); |
+ process.stdout.expect("a flush left multi-line string''';"); |
+ process.stdout.expect(" }"); |
+ process.shouldExit(0); |
+ }); |
+ |
+ test("errors if the indent is not a non-negative number", () { |
+ var process = runFormatter(["--indent", "notanum"]); |
+ process.shouldExit(64); |
+ |
+ process = runFormatter(["--preserve", "-4"]); |
+ process.shouldExit(64); |
+ }); |
+ }); |
+ |
group("with no paths", () { |
- test("errors on --overwrite.", () { |
+ test("errors on --overwrite", () { |
var process = runFormatter(["--overwrite"]); |
process.shouldExit(64); |
}); |
- test("exits with 65 on parse error.", () { |
+ test("exits with 65 on parse error", () { |
var process = runFormatter(); |
process.writeLine("herp derp i are a dart"); |
process.closeStdin(); |
process.shouldExit(65); |
}); |
- test("reads from stdin.", () { |
+ test("reads from stdin", () { |
var process = runFormatter(); |
process.writeLine(unformattedSource); |
process.closeStdin(); |