OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 pub_tests; | 5 library pub_tests; |
6 | 6 |
7 import 'package:scheduled_test/scheduled_test.dart'; | 7 import 'package:scheduled_test/scheduled_test.dart'; |
8 | 8 |
9 import '../lib/src/exit_codes.dart' as exit_codes; | 9 import '../lib/src/exit_codes.dart' as exit_codes; |
10 import 'test_pub.dart'; | 10 import 'test_pub.dart'; |
11 | 11 |
12 final USAGE_STRING = """ | |
13 Pub is a package manager for Dart. | |
14 | |
15 Usage: pub <command> [arguments] | |
16 | |
17 Global options: | |
18 -h, --help Print this usage information. | |
19 --version Print pub version. | |
20 --[no-]trace Print debugging information when an error occurs. | |
21 --verbosity Control output verbosity. | |
22 | |
23 [all] Show all output including internal tracing messages. | |
24 [io] Also show IO operations. | |
25 [normal] Show errors, warnings, and user messages. | |
26 [solver] Show steps during version resolution. | |
27 | |
28 -v, --verbose Shortcut for "--verbosity=all". | |
29 | |
30 Available commands: | |
31 build Apply transformers to build a package. | |
32 cache Work with the system cache. | |
33 deps Print package dependencies. | |
34 downgrade Downgrade the current package's dependencies to oldest version
s. | |
35 get Get the current package's dependencies. | |
36 global Work with global packages. | |
37 help Display help information for Pub. | |
38 publish Publish the current package to pub.dartlang.org. | |
39 run Run an executable from a package. | |
40 serve Run a local web development server. | |
41 upgrade Upgrade the current package's dependencies to latest versions. | |
42 uploader Manage uploaders for a package on pub.dartlang.org. | |
43 version Print pub version. | |
44 | |
45 Run "pub help [command]" for more information about a command. | |
46 See http://dartlang.org/tools/pub for detailed documentation. | |
47 """; | |
48 | |
49 final VERSION_STRING = ''' | |
50 Pub 0.1.2+3 | |
51 '''; | |
52 | |
53 main() { | 12 main() { |
54 initConfig(); | 13 initConfig(); |
55 | 14 |
56 integration('running pub with no command displays usage', () { | 15 integration('running pub with no command displays usage', () { |
57 schedulePub(args: [], output: USAGE_STRING); | 16 schedulePub(args: [], output: """ |
58 }); | 17 Pub is a package manager for Dart. |
59 | 18 |
60 integration('running pub with just --help displays usage', () { | 19 Usage: pub <command> [arguments] |
61 schedulePub(args: ['--help'], output: USAGE_STRING); | |
62 }); | |
63 | 20 |
64 integration('running pub with just -h displays usage', () { | 21 Global options: |
65 schedulePub(args: ['-h'], output: USAGE_STRING); | 22 -h, --help Print this usage information. |
66 }); | 23 --version Print pub version. |
| 24 --[no-]trace Print debugging information when an error occurs. |
| 25 --verbosity Control output verbosity. |
67 | 26 |
68 integration('running pub with --with-prejudice upcases everything', () { | 27 [all] Show all output including internal tracing message
s. |
69 schedulePub(args: ['--with-prejudice'], output: USAGE_STRING.toUpperCase()); | 28 [io] Also show IO operations. |
70 }); | 29 [normal] Show errors, warnings, and user messages. |
| 30 [solver] Show steps during version resolution. |
71 | 31 |
72 integration('running pub with --help after command shows command usage', () { | 32 -v, --verbose Shortcut for "--verbosity=all". |
73 schedulePub(args: ['get', '--help'], | |
74 output: ''' | |
75 Get the current package's dependencies. | |
76 | |
77 Usage: pub get | |
78 -h, --help Print usage information for this command. | |
79 --[no-]offline Use cached packages instead of accessing the net
work. | |
80 -n, --dry-run Report what dependencies would change but don't
change any. | |
81 | |
82 Run "pub help" to see global options. | |
83 See http://dartlang.org/tools/pub/cmd/pub-get.html for detailed docume
ntation. | |
84 '''); | |
85 }); | |
86 | |
87 integration('running pub with -h after command shows command usage', () { | |
88 schedulePub(args: ['get', '-h'], | |
89 output: ''' | |
90 Get the current package's dependencies. | |
91 | |
92 Usage: pub get | |
93 -h, --help Print usage information for this command. | |
94 --[no-]offline Use cached packages instead of accessing the net
work. | |
95 -n, --dry-run Report what dependencies would change but don't
change any. | |
96 | |
97 Run "pub help" to see global options. | |
98 See http://dartlang.org/tools/pub/cmd/pub-get.html for detailed docume
ntation. | |
99 '''); | |
100 }); | |
101 | |
102 integration('running pub with --help after a command with subcommands shows ' | |
103 'command usage', () { | |
104 schedulePub(args: ['cache', '--help'], | |
105 output: ''' | |
106 Work with the system cache. | |
107 | |
108 Usage: pub cache <subcommand> | |
109 -h, --help Print usage information for this command. | |
110 | |
111 Available subcommands: | |
112 add Install a package. | |
113 repair Reinstall cached packages. | |
114 | |
115 Run "pub help" to see global options. | |
116 See http://dartlang.org/tools/pub/cmd/pub-cache.html for detailed docu
mentation. | |
117 '''); | |
118 }); | |
119 | |
120 | |
121 integration('running pub with just --version displays version', () { | |
122 schedulePub(args: ['--version'], output: VERSION_STRING); | |
123 }); | |
124 | |
125 integration('an unknown command displays an error message', () { | |
126 schedulePub(args: ['quylthulg'], | |
127 error: ''' | |
128 Could not find a command named "quylthulg". | |
129 | 33 |
130 Available commands: | 34 Available commands: |
131 build Apply transformers to build a package. | 35 build Apply transformers to build a package. |
132 cache Work with the system cache. | 36 cache Work with the system cache. |
133 deps Print package dependencies. | 37 deps Print package dependencies. |
134 downgrade Downgrade the current package's dependencies to oldest ver
sions. | 38 downgrade Downgrade the current package's dependencies to oldest ver
sions. |
135 get Get the current package's dependencies. | 39 get Get the current package's dependencies. |
136 global Work with global packages. | 40 global Work with global packages. |
137 help Display help information for Pub. | 41 help Display help information for pub. |
138 publish Publish the current package to pub.dartlang.org. | 42 publish Publish the current package to pub.dartlang.org. |
139 run Run an executable from a package. | 43 run Run an executable from a package. |
140 serve Run a local web development server. | 44 serve Run a local web development server. |
141 upgrade Upgrade the current package's dependencies to latest versi
ons. | 45 upgrade Upgrade the current package's dependencies to latest versi
ons. |
142 uploader Manage uploaders for a package on pub.dartlang.org. | 46 uploader Manage uploaders for a package on pub.dartlang.org. |
143 version Print pub version. | 47 version Print pub version. |
144 ''', | 48 |
145 exitCode: exit_codes.USAGE); | 49 Run "pub help <command>" for more information about a command. |
| 50 See http://dartlang.org/tools/pub for detailed documentation. |
| 51 """); |
146 }); | 52 }); |
147 | 53 |
148 integration('an unknown subcommand displays an error message', () { | 54 integration('running pub with just --version displays version', () { |
149 schedulePub(args: ['cache', 'quylthulg'], | 55 schedulePub(args: ['--version'], output: 'Pub 0.1.2+3'); |
150 error: ''' | |
151 Could not find a subcommand named "quylthulg" for "pub cache". | |
152 | |
153 Usage: pub cache <subcommand> | |
154 -h, --help Print usage information for this command. | |
155 | |
156 Available subcommands: | |
157 add Install a package. | |
158 repair Reinstall cached packages. | |
159 | |
160 Run "pub help" to see global options. | |
161 See http://dartlang.org/tools/pub/cmd/pub-cache.html for detailed docume
ntation. | |
162 ''', | |
163 exitCode: exit_codes.USAGE); | |
164 }); | |
165 | |
166 integration('an unknown option displays an error message', () { | |
167 schedulePub(args: ['--blorf'], | |
168 error: ''' | |
169 Could not find an option named "blorf". | |
170 Run "pub help" to see available options. | |
171 ''', | |
172 exitCode: exit_codes.USAGE); | |
173 }); | |
174 | |
175 integration('an unknown command option displays an error message', () { | |
176 // TODO(rnystrom): When pub has command-specific options, a more precise | |
177 // error message would be good here. | |
178 schedulePub(args: ['version', '--blorf'], | |
179 error: ''' | |
180 Could not find an option named "blorf". | |
181 Run "pub help" to see available options. | |
182 ''', | |
183 exitCode: exit_codes.USAGE); | |
184 }); | |
185 | |
186 integration('an unexpected argument displays an error message', () { | |
187 schedulePub(args: ['version', 'unexpected'], | |
188 error: ''' | |
189 Command "version" does not take any arguments. | |
190 | |
191 Usage: pub version | |
192 -h, --help Print usage information for this command. | |
193 | |
194 Run "pub help" to see global options. | |
195 ''', | |
196 exitCode: exit_codes.USAGE); | |
197 }); | |
198 | |
199 integration('a missing subcommand displays an error message', () { | |
200 schedulePub(args: ['cache'], | |
201 error: ''' | |
202 Missing subcommand for "pub cache". | |
203 | |
204 Usage: pub cache <subcommand> | |
205 -h, --help Print usage information for this command. | |
206 | |
207 Available subcommands: | |
208 add Install a package. | |
209 repair Reinstall cached packages. | |
210 | |
211 Run "pub help" to see global options. | |
212 See http://dartlang.org/tools/pub/cmd/pub-cache.html for detailed docume
ntation. | |
213 ''', | |
214 exitCode: exit_codes.USAGE); | |
215 }); | |
216 | |
217 group('help', () { | |
218 integration('shows global help if no command is given', () { | |
219 schedulePub(args: ['help'], output: USAGE_STRING); | |
220 }); | |
221 | |
222 integration('shows help for a command', () { | |
223 schedulePub(args: ['help', 'get'], | |
224 output: ''' | |
225 Get the current package's dependencies. | |
226 | |
227 Usage: pub get | |
228 -h, --help Print usage information for this command. | |
229 --[no-]offline Use cached packages instead of accessing the n
etwork. | |
230 -n, --dry-run Report what dependencies would change but don'
t change any. | |
231 | |
232 Run "pub help" to see global options. | |
233 See http://dartlang.org/tools/pub/cmd/pub-get.html for detailed docu
mentation. | |
234 '''); | |
235 }); | |
236 | |
237 integration('shows help for a command', () { | |
238 schedulePub(args: ['help', 'publish'], | |
239 output: ''' | |
240 Publish the current package to pub.dartlang.org. | |
241 | |
242 Usage: pub publish [options] | |
243 -h, --help Print usage information for this command. | |
244 -n, --dry-run Validate but do not publish the package. | |
245 -f, --force Publish without confirmation if there are no errors
. | |
246 --server The package server to which to upload this package. | |
247 (defaults to "https://pub.dartlang.org") | |
248 | |
249 Run "pub help" to see global options. | |
250 See http://dartlang.org/tools/pub/cmd/pub-lish.html for detailed doc
umentation. | |
251 '''); | |
252 }); | |
253 | |
254 integration('shows non-truncated help', () { | |
255 schedulePub(args: ['help', 'serve'], | |
256 output: ''' | |
257 Run a local web development server. | |
258 | |
259 By default, this serves "web/" and "test/", but an explicit list of | |
260 directories to serve can be provided as well. | |
261 | |
262 Usage: pub serve [directories...] | |
263 -h, --help Print usage information for this command. | |
264 --mode Mode to run transformers in. | |
265 (defaults to "debug") | |
266 | |
267 --all Use all default source directories. | |
268 --hostname The hostname to listen on. | |
269 (defaults to "localhost") | |
270 | |
271 --port The base port to listen on. | |
272 (defaults to "8080") | |
273 | |
274 --[no-]dart2js Compile Dart to JavaScript. | |
275 (defaults to on) | |
276 | |
277 --[no-]force-poll Force the use of a polling filesystem watch
er. | |
278 | |
279 Run "pub help" to see global options. | |
280 See http://dartlang.org/tools/pub/cmd/pub-serve.html for detailed do
cumentation. | |
281 '''); | |
282 }); | |
283 | |
284 integration('shows help for a subcommand', () { | |
285 schedulePub(args: ['help', 'cache', 'list'], | |
286 output: ''' | |
287 List packages in the system cache. | |
288 | |
289 Usage: pub cache list | |
290 -h, --help Print usage information for this command. | |
291 | |
292 Run "pub help" to see global options. | |
293 '''); | |
294 }); | |
295 | |
296 integration('an unknown help command displays an error message', () { | |
297 schedulePub(args: ['help', 'quylthulg'], | |
298 error: ''' | |
299 Could not find a command named "quylthulg". | |
300 | |
301 Available commands: | |
302 build Apply transformers to build a package. | |
303 cache Work with the system cache. | |
304 deps Print package dependencies. | |
305 downgrade Downgrade the current package's dependencies to oldest
versions. | |
306 get Get the current package's dependencies. | |
307 global Work with global packages. | |
308 help Display help information for Pub. | |
309 publish Publish the current package to pub.dartlang.org. | |
310 run Run an executable from a package. | |
311 serve Run a local web development server. | |
312 upgrade Upgrade the current package's dependencies to latest v
ersions. | |
313 uploader Manage uploaders for a package on pub.dartlang.org. | |
314 version Print pub version. | |
315 ''', | |
316 exitCode: exit_codes.USAGE); | |
317 }); | |
318 | |
319 integration('an unknown help subcommand displays an error message', () { | |
320 schedulePub(args: ['help', 'cache', 'quylthulg'], | |
321 error: ''' | |
322 Could not find a subcommand named "quylthulg" for "pub cache". | |
323 | |
324 Usage: pub cache <subcommand> | |
325 -h, --help Print usage information for this command. | |
326 | |
327 Available subcommands: | |
328 add Install a package. | |
329 repair Reinstall cached packages. | |
330 | |
331 Run "pub help" to see global options. | |
332 See http://dartlang.org/tools/pub/cmd/pub-cache.html for detailed do
cumentation. | |
333 ''', | |
334 exitCode: exit_codes.USAGE); | |
335 }); | |
336 | |
337 integration('an unexpected help subcommand displays an error message', () { | |
338 schedulePub(args: ['help', 'version', 'badsubcommand'], | |
339 error: ''' | |
340 Command "pub version" does not expect a subcommand. | |
341 | |
342 Usage: pub version | |
343 -h, --help Print usage information for this command. | |
344 | |
345 Run "pub help" to see global options. | |
346 ''', | |
347 exitCode: exit_codes.USAGE); | |
348 }); | |
349 }); | |
350 | |
351 group('version', () { | |
352 integration('displays the current version', () { | |
353 schedulePub(args: ['version'], output: VERSION_STRING); | |
354 }); | |
355 }); | 56 }); |
356 } | 57 } |
OLD | NEW |