-
Notifications
You must be signed in to change notification settings - Fork 231
Add "pub run --list" command to show all available executables #2 #1680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,225 @@ | ||
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:test/test.dart'; | ||
|
||
import '../descriptor.dart' as d; | ||
import '../test_pub.dart'; | ||
|
||
const _validMain = 'main() {}'; | ||
|
||
main() { | ||
_testExecutablesOutput(output, {bool dev: true}) => () async { | ||
await pubGet(); | ||
await runPub( | ||
args: ['deps', '--executables'] | ||
..addAll(dev ? ['--dev'] : ['--no-dev']), | ||
output: output); | ||
}; | ||
|
||
_testAllDepsOutput(output) => _testExecutablesOutput(output); | ||
_testNonDevDepsOutput(output) => _testExecutablesOutput(output, dev: false); | ||
|
||
group("lists nothing when no executables found", () { | ||
setUp(() async { | ||
await d.dir(appPath, [d.appPubspec()]).create(); | ||
}); | ||
|
||
test("all dependencies", _testAllDepsOutput('\n')); | ||
test("non-dev dependencies", _testNonDevDepsOutput('\n')); | ||
}); | ||
|
||
group("skips non-Dart executables", () { | ||
setUp(() async { | ||
await d.dir(appPath, [ | ||
d.appPubspec(), | ||
d.dir('bin', [d.file('foo.py'), d.file('bar.sh')]) | ||
]).create(); | ||
}); | ||
|
||
test("all dependencies", _testAllDepsOutput('\n')); | ||
test("non-dev dependencies", _testNonDevDepsOutput('\n')); | ||
}); | ||
|
||
group("skips Dart executables which are not parsable", () { | ||
setUp(() async { | ||
await d.dir(appPath, [ | ||
d.appPubspec(), | ||
d.dir('bin', [d.file('foo.dart', 'main() {')]) | ||
]).create(); | ||
}); | ||
|
||
test("all dependencies", _testAllDepsOutput('\n')); | ||
test("non-dev dependencies", _testNonDevDepsOutput('\n')); | ||
}); | ||
|
||
group("skips Dart executables without entrypoints", () { | ||
setUp(() async { | ||
await d.dir(appPath, [ | ||
d.appPubspec(), | ||
d.dir( | ||
'bin', [d.file('foo.dart'), d.file('bar.dart', 'main(x, y, z) {}')]) | ||
]).create(); | ||
}); | ||
|
||
test("all dependencies", _testAllDepsOutput('\n')); | ||
test("non-dev dependencies", _testNonDevDepsOutput('\n')); | ||
}); | ||
|
||
group("lists valid Dart executables with entrypoints", () { | ||
setUp(() async { | ||
await d.dir(appPath, [ | ||
d.appPubspec(), | ||
d.dir('bin', | ||
[d.file('foo.dart', _validMain), d.file('bar.dart', _validMain)]) | ||
]).create(); | ||
}); | ||
|
||
test("all dependencies", _testAllDepsOutput('myapp: bar, foo')); | ||
test("non-dev dependencies", _testNonDevDepsOutput('myapp: bar, foo')); | ||
}); | ||
|
||
group("skips executables in sub directories", () { | ||
setUp(() async { | ||
await d.dir(appPath, [ | ||
d.appPubspec(), | ||
d.dir('bin', [ | ||
d.file('foo.dart', _validMain), | ||
d.dir('sub', [d.file('bar.dart', _validMain)]) | ||
]) | ||
]).create(); | ||
}); | ||
|
||
test("all dependencies", _testAllDepsOutput('myapp:foo')); | ||
test("non-dev dependencies", _testNonDevDepsOutput('myapp:foo')); | ||
}); | ||
|
||
group("lists executables from a dependency", () { | ||
setUp(() async { | ||
await d.dir('foo', [ | ||
d.libPubspec('foo', '1.0.0'), | ||
d.dir('bin', [d.file('bar.dart', _validMain)]) | ||
]).create(); | ||
|
||
await d.dir(appPath, [ | ||
d.appPubspec({ | ||
'foo': {'path': '../foo'} | ||
}) | ||
]).create(); | ||
}); | ||
|
||
test("all dependencies", _testAllDepsOutput('foo:bar')); | ||
test("non-dev dependencies", _testNonDevDepsOutput('foo:bar')); | ||
}); | ||
|
||
group("lists executables only from immediate dependencies", () { | ||
setUp(() async { | ||
await d.dir(appPath, [ | ||
d.appPubspec({ | ||
'foo': {'path': '../foo'} | ||
}) | ||
]).create(); | ||
|
||
await d.dir('foo', [ | ||
d.libPubspec('foo', '1.0.0', deps: { | ||
'baz': {'path': '../baz'} | ||
}), | ||
d.dir('bin', [d.file('bar.dart', _validMain)]) | ||
]).create(); | ||
|
||
await d.dir('baz', [ | ||
d.libPubspec('baz', '1.0.0'), | ||
d.dir('bin', [d.file('qux.dart', _validMain)]) | ||
]).create(); | ||
}); | ||
|
||
test("all dependencies", _testAllDepsOutput('foo:bar')); | ||
test("non-dev dependencies", _testNonDevDepsOutput('foo:bar')); | ||
}); | ||
|
||
group("applies formatting before printing executables", () { | ||
setUp(() async { | ||
await d.dir(appPath, [ | ||
d.appPubspec({ | ||
'foo': {'path': '../foo'}, | ||
'bar': {'path': '../bar'} | ||
}), | ||
d.dir('bin', [d.file('myapp.dart', _validMain)]) | ||
]).create(); | ||
|
||
await d.dir('foo', [ | ||
d.libPubspec('foo', '1.0.0'), | ||
d.dir('bin', | ||
[d.file('baz.dart', _validMain), d.file('foo.dart', _validMain)]) | ||
]).create(); | ||
|
||
await d.dir('bar', [ | ||
d.libPubspec('bar', '1.0.0'), | ||
d.dir('bin', [d.file('qux.dart', _validMain)]) | ||
]).create(); | ||
}); | ||
|
||
test("all dependencies", _testAllDepsOutput(''' | ||
myapp | ||
bar:qux | ||
foo: foo, baz''')); | ||
test("non-dev dependencies", _testNonDevDepsOutput(''' | ||
myapp | ||
bar:qux | ||
foo: foo, baz''')); | ||
}); | ||
|
||
group("dev dependencies", () { | ||
setUp(() async { | ||
await d.dir('foo', [ | ||
d.libPubspec('foo', '1.0.0'), | ||
d.dir('bin', [d.file('bar.dart', _validMain)]) | ||
]).create(); | ||
|
||
await d.dir(appPath, [ | ||
d.pubspec({ | ||
'name': 'myapp', | ||
'dev_dependencies': { | ||
'foo': {'path': '../foo'} | ||
} | ||
}) | ||
]).create(); | ||
}); | ||
|
||
test("are listed if --dev flag is set", _testAllDepsOutput('foo:bar')); | ||
test("are skipped if --no-dev flag is set", _testNonDevDepsOutput('\n')); | ||
}); | ||
|
||
group("overriden dependencies executables", () { | ||
setUp(() async { | ||
await d.dir('foo-1.0', [ | ||
d.libPubspec('foo', '1.0.0'), | ||
d.dir('bin', [d.file('bar.dart', _validMain)]) | ||
]).create(); | ||
|
||
await d.dir('foo-2.0', [ | ||
d.libPubspec('foo', '2.0.0'), | ||
d.dir('bin', | ||
[d.file('bar.dart', _validMain), d.file('baz.dart', _validMain)]) | ||
]).create(); | ||
|
||
await d.dir(appPath, [ | ||
d.pubspec({ | ||
'name': 'myapp', | ||
'dependencies': { | ||
'foo': {'path': '../foo-1.0'} | ||
}, | ||
'dependency_overrides': { | ||
'foo': {'path': '../foo-2.0'} | ||
} | ||
}) | ||
]).create(); | ||
}); | ||
|
||
test( | ||
'are listed if --dev flag is set', _testAllDepsOutput('foo: bar, baz')); | ||
test('are listed if --no-dev flag is set', | ||
_testNonDevDepsOutput('foo: bar, baz')); | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't found a good way to test the same things.
I was choosing between:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could consider wrapping multiple calls to
test
in_testExecutablesOutput
, something like this:Up to you though, that pattern can make it hard to support the named args to
test
methods etc.