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

Side by Side Diff: utils/tests/pub/pub_tests.dart

Issue 10214006: Refactor command code and add support for --help and --version. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
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('dart:io'); 7 #import('dart:io');
8 8
9 #import('test_pub.dart'); 9 #import('test_pub.dart');
10 #import('../../../lib/unittest/unittest.dart'); 10 #import('../../../lib/unittest/unittest.dart');
11 11
12 final USAGE_STRING = """
13 Pub is a package manager for Dart.
14
15 Usage:
16
17 pub command [arguments]
18
19 The commands are:
20
21 list print the contents of repositories
22 update update a package's dependencies
23 version print Pub version
nweiz 2012/04/25 20:49:41 Since this output isn't sorted, this test is poten
Bob Nystrom 2012/04/25 22:56:40 It is sorted. See pub.dart:98.
nweiz 2012/04/25 23:09:22 Oh, I see. I was confused by the TODO about the so
24
25 Use "pub help [command]" for more information about a command.
26 """;
27
28 final VERSION_STRING = '''
29 Pub 0.0.0
30 ''';
31
12 main() { 32 main() {
13 group('running pub with no command', () { 33 testPub('running pub with no command displays usage',
14 testPub('displays usage', 34 args: [],
15 args: [], 35 output: USAGE_STRING);
16 output: '''
17 Pub is a package manager for Dart.
18 36
19 Usage: 37 testPub('running pub with just --help displays usage',
38 args: ['--help'],
39 output: USAGE_STRING);
nweiz 2012/04/25 20:49:41 May as well test for just "help" too.
Bob Nystrom 2012/04/25 22:56:40 Help will be a full command (so you can do "help [
20 40
21 pub command [arguments] 41 testPub('running pub with just --version displays version',
22 42 args: ['--version'],
23 The commands are: 43 output: VERSION_STRING);
24
25 list print the contents of repositories
26 version print Pub version
27
28 Use "pub help [command]" for more information about a command.''');
29 });
30 44
31 group('an unknown command', () { 45 group('an unknown command', () {
32 testPub('displays an error message', 46 testPub('displays an error message',
33 args: ['quylthulg'], 47 args: ['quylthulg'],
34 output: ''' 48 output: '''
35 Unknown command "quylthulg". 49 Unknown command "quylthulg".
36 Run "pub help" to see available commands.''', 50 Run "pub help" to see available commands.
51 ''',
37 exitCode: 64); 52 exitCode: 64);
38 }); 53 });
39 54
40 listCommand(); 55 group('pub list', listCommand);
41 versionCommand(); 56 group('pub update', updateCommand);
57 group('pub version', versionCommand);
42 } 58 }
43 59
44 listCommand() { 60 listCommand() {
45 group('list cache', () { 61 group('cache', () {
46 testPub('treats an empty directory as a package', 62 testPub('treats an empty directory as a package',
47 cache: [ 63 cache: [
48 dir('apple'), 64 dir('apple'),
49 dir('banana'), 65 dir('banana'),
50 dir('cherry') 66 dir('cherry')
51 ], 67 ],
52 args: ['list', 'cache'], 68 args: ['list', 'cache'],
53 output: ''' 69 output: '''
54 apple 70 apple
55 banana 71 banana
56 cherry'''); 72 cherry
73 ''');
57 }); 74 });
58 } 75 }
59 76
77 updateCommand() {
78 testPub('adds a dependent package',
79 cache: [
80 dir('foo', [
81 file('foo.dart', 'main() => "foo";')
82 ])
83 ],
84 app: dir('myapp', [
85 file('pubspec', 'foo')
86 ]),
87 args: ['update'],
88 expectedPackageDir: [
89 dir('foo', [
90 file('foo.dart', 'main() => "foo";')
91 ])
92 ],
93 output: '');
94
95 testPub('adds a transitively dependent package',
96 cache: [
97 dir('foo', [
98 file('foo.dart', 'main() => "foo";'),
99 file('pubspec', 'bar')
100 ]),
101 dir('bar', [
102 file('bar.dart', 'main() => "bar";'),
103 ])
104 ],
105 app: dir('myapp', [
106 file('pubspec', 'foo')
107 ]),
108 args: ['update'],
109 expectedPackageDir: [
110 dir('foo', [
111 file('foo.dart', 'main() => "foo";')
112 ]),
113 dir('bar', [
114 file('bar.dart', 'main() => "bar";'),
115 ])
116 ],
117 output: '');
118 }
119
60 versionCommand() { 120 versionCommand() {
61 group('the version command', () { 121 testPub('displays the current version',
62 testPub('displays the current version', 122 args: ['version'],
63 args: ['version'], 123 output: VERSION_STRING);
64 output: 'Pub 0.0.0');
65 });
66 } 124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698