Skip to content

Commit 3f20e25

Browse files
committed
Add tests for "pub run --list" command.
Issue dart-lang#1323
1 parent 6a88acc commit 3f20e25

File tree

4 files changed

+120
-13
lines changed

4 files changed

+120
-13
lines changed

lib/src/command/run.dart

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@ class RunCommand extends PubCommand {
2222
bool get allowTrailingOptions => false;
2323

2424
RunCommand() {
25-
argParser.addFlag("checked", abbr: "c",
26-
help: "Enable runtime type checks and assertions.");
25+
argParser.addFlag("checked",
26+
abbr: "c", help: "Enable runtime type checks and assertions.");
27+
argParser.addFlag('list',
28+
help: 'List all available executables.', negatable: false);
2729
argParser.addOption("mode",
2830
help: 'Mode to run transformers in.\n'
29-
'(defaults to "release" for dependencies, "debug" for '
30-
'entrypoint)');
31-
argParser.addFlag('list',
32-
help: 'List all executables that can by invoked with pub run',
33-
negatable: false);
31+
'(defaults to "release" for dependencies, "debug" for entrypoint)');
3432
}
3533

3634
Future run() async {
@@ -55,10 +53,10 @@ class RunCommand extends PubCommand {
5553
executable = components[1];
5654

5755
if (p.split(executable).length > 1) {
58-
// TODO(nweiz): Use adjacent strings when the new async/await compiler
59-
// lands.
60-
usageException("Cannot run an executable in a subdirectory of a " +
61-
"dependency.");
56+
// TODO(nweiz): Use adjacent strings when the new async/await compiler
57+
// lands.
58+
usageException(
59+
"Cannot run an executable in a subdirectory of a dependency.");
6260
}
6361
} else if (onlyIdentifierRegExp.hasMatch(executable)) {
6462
// "pub run foo" means the same thing as "pub run foo:foo" as long as
@@ -82,7 +80,8 @@ class RunCommand extends PubCommand {
8280

8381
/// Lists all executables reachable from [entrypoint].
8482
void _listExecutables() {
85-
var ownExecutables = _listExecutablesFor(entrypoint.root);
83+
var ownExecutables = _listExecutablesFor(entrypoint.root)
84+
.map((executable) => p.join('bin', executable));
8685

8786
var packageExecutables = entrypoint.root.immediateDependencies
8887
.map((dep) => entrypoint.packageGraph.packages[dep.name])
@@ -94,7 +93,7 @@ class RunCommand extends PubCommand {
9493
..addAll(packageExecutables)
9594
..sort();
9695

97-
log.message('Executables:\n ${allExecutables.join('\n ')}');
96+
log.message(log.bold(allExecutables.join('\n')));
9897
}
9998

10099
/// Lists all Dart files in the `bin` directory of the [package].

test/run/errors_if_no_executable_is_given_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Must specify an executable to run.
2020
Usage: pub run <executable> [args...]
2121
-h, --help Print this usage information.
2222
-c, --[no-]checked Enable runtime type checks and assertions.
23+
--list List all available executables.
2324
--mode Mode to run transformers in.
2425
(defaults to "release" for dependencies, "debug" for entrypoint)
2526

test/run/errors_if_path_in_dependency_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Cannot run an executable in a subdirectory of a dependency.
2727
Usage: pub run <executable> [args...]
2828
-h, --help Print this usage information.
2929
-c, --[no-]checked Enable runtime type checks and assertions.
30+
--list List all available executables.
3031
--mode Mode to run transformers in.
3132
(defaults to "release" for dependencies, "debug" for entrypoint)
3233

test/run/list_test.dart

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Copyright (c) 2016, 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+
import 'package:path/path.dart' as p;
6+
7+
import '../descriptor.dart' as d;
8+
import '../test_pub.dart';
9+
10+
main() {
11+
integration("lists executables in entrypoint's bin", () {
12+
d.dir(appPath, [
13+
d.appPubspec(),
14+
d.dir('bin', [
15+
d.file('foo.dart'),
16+
d.file('bar.dart'),
17+
d.dir('sub', [d.file('baz.dart')])
18+
])
19+
]).create();
20+
21+
schedulePub(
22+
args: ['run', '--list'],
23+
output: '''
24+
${p.join('bin', 'bar')}
25+
${p.join('bin', 'foo')}
26+
${p.join('bin', 'sub', 'baz')}
27+
''');
28+
});
29+
30+
integration('lists only Dart files', () {
31+
d.dir(appPath, [
32+
d.appPubspec(),
33+
d.dir('bin', [d.file('foo.dart'), d.file('bar.sh')])
34+
]).create();
35+
36+
schedulePub(args: ['run', '--list'], output: p.join('bin', 'foo'));
37+
});
38+
39+
integration('lists executables from a dependency', () {
40+
d.dir('foo', [
41+
d.libPubspec('foo', '1.0.0'),
42+
d.dir('bin', [
43+
d.file('bar.dart'),
44+
d.dir('sub', [d.file('baz.dart'),])
45+
])
46+
]).create();
47+
48+
d.dir(appPath, [
49+
d.appPubspec({
50+
'foo': {'path': '../foo'}
51+
})
52+
]).create();
53+
54+
pubGet();
55+
schedulePub(
56+
args: ['run', '--list'],
57+
output: '''
58+
foo:bar
59+
foo:${p.join('sub', 'baz')}
60+
''');
61+
});
62+
63+
integration('lists executables only from immediate dependencies', () {
64+
d.dir('foo', [
65+
d.libPubspec('foo', '1.0.0'),
66+
d.dir('bin', [d.file('baz.dart')])
67+
]).create();
68+
69+
d.dir('bar', [
70+
d.libPubspec('bar', '1.0.0', deps: {
71+
'foo': {'path': '../foo'}
72+
}),
73+
d.dir('bin', [d.file('baz.dart')])
74+
]).create();
75+
76+
d.dir(appPath, [
77+
d.appPubspec({
78+
'bar': {'path': '../bar'}
79+
})
80+
]).create();
81+
82+
pubGet();
83+
schedulePub(args: ['run', '--list'], output: 'bar:baz');
84+
});
85+
86+
integration('normilizes executable names', () {
87+
d.dir('foo', [
88+
d.libPubspec('foo', '1.0.0'),
89+
d.dir('bin', [d.file('foo.dart'), d.file('bar.dart')])
90+
]).create();
91+
92+
d.dir(appPath, [
93+
d.appPubspec({
94+
'foo': {'path': '../foo'}
95+
})
96+
]).create();
97+
98+
pubGet();
99+
schedulePub(
100+
args: ['run', '--list'],
101+
output: '''
102+
foo
103+
foo:bar
104+
''');
105+
});
106+
}

0 commit comments

Comments
 (0)