Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: packages/dart_style/test/command_line_test.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « packages/dart_style/pubspec.yaml ('k') | packages/dart_style/test/comments/classes.unit » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library dart_style.test.command_line;
6
7 import 'dart:convert';
8
9 import 'package:path/path.dart' as p;
10 import 'package:scheduled_test/descriptor.dart' as d;
11 import 'package:scheduled_test/scheduled_test.dart';
12 import 'package:scheduled_test/scheduled_stream.dart';
13
14 import 'utils.dart';
15
16 void main() {
17 setUpTestSuite();
18
19 test("Exits with 0 on success.", () {
20 d.dir("code", [d.file("a.dart", unformattedSource)]).create();
21
22 var process = runFormatterOnDir();
23 process.shouldExit(0);
24 });
25
26 test("Exits with 64 on a command line argument error.", () {
27 var process = runFormatterOnDir(["-wat"]);
28 process.shouldExit(64);
29 });
30
31 test("Exits with 65 on a parse error.", () {
32 d.dir("code", [d.file("a.dart", "herp derp i are a dart")]).create();
33
34 var process = runFormatterOnDir();
35 process.shouldExit(65);
36 });
37
38 test("Errors if --dry-run and --overwrite are both passed.", () {
39 d.dir("code", [d.file("a.dart", unformattedSource)]).create();
40
41 var process = runFormatterOnDir(["--dry-run", "--overwrite"]);
42 process.shouldExit(64);
43 });
44
45 test("Errors if --dry-run and --machine are both passed.", () {
46 d.dir("code", [d.file("a.dart", unformattedSource)]).create();
47
48 var process = runFormatterOnDir(["--dry-run", "--machine"]);
49 process.shouldExit(64);
50 });
51
52 test("Errors if --machine and --overwrite are both passed.", () {
53 d.dir("code", [d.file("a.dart", unformattedSource)]).create();
54
55 var process = runFormatterOnDir(["--machine", "--overwrite"]);
56 process.shouldExit(64);
57 });
58
59 test("Errors if --dry-run and --machine are both passed.", () {
60 d.dir("code", [d.file("a.dart", unformattedSource)]).create();
61
62 var process = runFormatter(["--dry-run", "--machine"]);
63 process.shouldExit(64);
64 });
65
66 test("Errors if --machine and --overwrite are both passed.", () {
67 d.dir("code", [d.file("a.dart", unformattedSource)]).create();
68
69 var process = runFormatter(["--machine", "--overwrite"]);
70 process.shouldExit(64);
71 });
72
73 group("--dry-run", () {
74 test("prints names of files that would change.", () {
75 d.dir("code", [
76 d.file("a_bad.dart", unformattedSource),
77 d.file("b_good.dart", formattedSource),
78 d.file("c_bad.dart", unformattedSource),
79 d.file("d_good.dart", formattedSource)
80 ]).create();
81
82 var aBad = p.join("code", "a_bad.dart");
83 var cBad = p.join("code", "c_bad.dart");
84
85 var process = runFormatterOnDir(["--dry-run"]);
86
87 // The order isn't specified.
88 process.stdout.expect(either(aBad, cBad));
89 process.stdout.expect(either(aBad, cBad));
90 process.shouldExit();
91 });
92
93 test("does not modify files.", () {
94 d.dir("code", [d.file("a.dart", unformattedSource)]).create();
95
96 var process = runFormatterOnDir(["--dry-run"]);
97 process.stdout.expect(p.join("code", "a.dart"));
98 process.shouldExit();
99
100 d.dir('code', [d.file('a.dart', unformattedSource)]).validate();
101 });
102 });
103
104 group("--machine", () {
105 test("writes each output as json", () {
106 d.dir("code", [
107 d.file("a.dart", unformattedSource),
108 d.file("b.dart", unformattedSource)
109 ]).create();
110
111 var jsonA = JSON.encode({
112 "path": p.join("code", "a.dart"),
113 "source": formattedSource,
114 "selection": {"offset": -1, "length": -1}
115 });
116
117 var jsonB = JSON.encode({
118 "path": p.join("code", "b.dart"),
119 "source": formattedSource,
120 "selection": {"offset": -1, "length": -1}
121 });
122
123 var process = runFormatterOnDir(["--machine"]);
124
125 // The order isn't specified.
126 process.stdout.expect(either(jsonA, jsonB));
127 process.stdout.expect(either(jsonA, jsonB));
128 process.shouldExit();
129 });
130 });
131
132 group("--preserve", () {
133 test("errors if given paths.", () {
134 var process = runFormatter(["--preserve", "path", "another"]);
135 process.shouldExit(64);
136 });
137
138 test("errors on wrong number of components.", () {
139 var process = runFormatter(["--preserve", "1"]);
140 process.shouldExit(64);
141
142 process = runFormatter(["--preserve", "1:2:3"]);
143 process.shouldExit(64);
144 });
145
146 test("errors on non-integer component.", () {
147 var process = runFormatter(["--preserve", "1:2.3"]);
148 process.shouldExit(64);
149 });
150
151 test("updates selection.", () {
152 var process = runFormatter(["--preserve", "6:10", "-m"]);
153 process.writeLine(unformattedSource);
154 process.closeStdin();
155
156 var json = JSON.encode({
157 "path": "<stdin>",
158 "source": formattedSource,
159 "selection": {"offset": 5, "length": 9}
160 });
161
162 process.stdout.expect(json);
163 process.shouldExit();
164 });
165 });
166
167 group("with no paths", () {
168 test("errors on --overwrite.", () {
169 var process = runFormatter(["--overwrite"]);
170 process.shouldExit(64);
171 });
172
173 test("exits with 65 on parse error.", () {
174 var process = runFormatter();
175 process.writeLine("herp derp i are a dart");
176 process.closeStdin();
177 process.shouldExit(65);
178 });
179
180 test("reads from stdin.", () {
181 var process = runFormatter();
182 process.writeLine(unformattedSource);
183 process.closeStdin();
184
185 // No trailing newline at the end.
186 process.stdout.expect(formattedSource.trimRight());
187 process.shouldExit(0);
188 });
189 });
190 }
OLDNEW
« no previous file with comments | « packages/dart_style/pubspec.yaml ('k') | packages/dart_style/test/comments/classes.unit » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698