Skip to content
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

Include bare pub --help command in help_test #4112

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 51 additions & 8 deletions test/embedding/embedding_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

import 'dart:io';

import 'package:args/command_runner.dart';
import 'package:path/path.dart' as p;
import 'package:pub/src/command_runner.dart';
import 'package:pub/src/exit_codes.dart';
import 'package:pub/src/io.dart' show EnvironmentKeys;
import 'package:test/test.dart';
Expand Down Expand Up @@ -66,7 +68,7 @@ extension on GoldenTestContext {
Future<void> runEmbedding(
List<String> args, {
String? workingDirectory,
Map<String, String>? environment,
Map<String, String?>? environment,
dynamic exitCode = 0,
}) async {
final buffer = StringBuffer();
Expand Down Expand Up @@ -196,13 +198,22 @@ main() {
expect(buffer.toString(), contains('FINE: Pub 3.1.2+3'));
});

testWithGolden('--help', (context) async {
await servePackages();
await context.runEmbedding(
['pub', '--help'],
workingDirectory: d.path('.'),
);
});
final cmds = _extractCommands();
for (final c in cmds) {
testWithGolden(c.join(' '), (ctx) async {
await servePackages();
await ctx.runEmbedding(
c.toList(),
environment: {
// Use more columns to avoid unintended line breaking.
'_PUB_TEST_TERMINAL_COLUMNS': '200',
'HOME': null,
'PUB_CACHE': null,
},
workingDirectory: d.path('.'),
);
});
}

testWithGolden('--color forces colors', (context) async {
final server = await servePackages();
Expand Down Expand Up @@ -501,3 +512,35 @@ String _filter(String input) {
(match) => match[1]!,
);
}

/// Extract all commands and subcommands.
///
/// Result will be an iterable of lists, illustrated as follows:
/// ```
/// [
/// [pub, --help]
/// [pub, get, --help]
/// ...
/// ]
/// ```
Iterable<List<String>> _extractCommands() sync* {
// dedup aliases.
Set visitedCommands = <Command>{};
final stack = [PubCommandRunner().commands.values.toList()];
final parents = <String>[];
while (true) {
final commands = stack.last;
if (commands.isEmpty) {
stack.removeLast();
yield ['pub', ...parents, '--help'];
if (parents.isEmpty) break;
parents.removeLast();
} else {
final command = commands.removeLast();
if (!visitedCommands.add(command)) continue;
if (command.hidden) continue;
stack.add(command.subcommands.values.toList());
parents.add(command.name);
}
}
}
56 changes: 0 additions & 56 deletions test/help_test.dart

This file was deleted.

32 changes: 32 additions & 0 deletions test/testdata/goldens/embedding/embedding_test/pub --help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# GENERATED BY: test/embedding/embedding_test.dart

$ tool/test-bin/pub_command_runner.dart pub --help
Work with packages.

Usage: pub_command_runner pub [arguments...]
-h, --help Print this usage information.
-v, --verbose Print detailed logging.
--[no-]color Use colors in terminal output.
Defaults to color when connected to a terminal, and no-color otherwise.
-C, --directory=<dir> Run the subcommand in the directory<dir>.
(defaults to ".")

Available subcommands:
add Add dependencies to `pubspec.yaml`.
cache Work with the system cache.
deps Print package dependencies.
downgrade Downgrade the current package's dependencies to oldest versions.
fail Throws an exception
get Get the current package's dependencies.
global Work with global packages.
login Log into pub.dev.
logout Log out of pub.dev.
outdated Analyze your dependencies to find which ones can be upgraded.
publish Publish the current package to pub.dev.
remove Removes dependencies from `pubspec.yaml`.
token Manage authentication tokens for hosted pub repositories.
upgrade Upgrade the current package's dependencies to latest versions.

Run "pub_command_runner help" to see global options.
See https://dart.dev/tools/pub/cmd/pub-global for detailed documentation.

48 changes: 48 additions & 0 deletions test/testdata/goldens/embedding/embedding_test/pub add --help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# GENERATED BY: test/embedding/embedding_test.dart

$ tool/test-bin/pub_command_runner.dart pub add --help
Add dependencies to `pubspec.yaml`.

Invoking `dart pub add foo bar` will add `foo` and `bar` to `pubspec.yaml`
with a default constraint derived from latest compatible version.

Add to dev_dependencies by prefixing with "dev:".

Make dependency overrides by prefixing with "override:".

Add packages with specific constraints or other sources by giving a descriptor
after a colon.

For example:
* Add a hosted dependency at newest compatible stable version:
`dart pub add foo`
* Add a hosted dev dependency at newest compatible stable version:
`dart pub add dev:foo`
* Add a hosted dependency with the given constraint
`dart pub add foo:^1.2.3`
* Add multiple dependencies:
`dart pub add foo dev:bar`
* Add a path dependency:
`dart pub add 'foo:{"path":"../foo"}'`
* Add a hosted dependency:
`dart pub add 'foo:{"hosted":"my-pub.dev"}'`
* Add an sdk dependency:
`dart pub add 'foo:{"sdk":"flutter"}'`
* Add a git dependency:
`dart pub add 'foo:{"git":"https://github.com/foo/foo"}'`
* Add a dependency override:
`dart pub add 'override:foo:1.0.0'`
* Add a git dependency with a path and ref specified:
`dart pub add \
'foo:{"git":{"url":"../foo.git","ref":"<branch>","path":"<subdir>"}}'`

Usage: pub_command_runner pub add [options] [<section>:]<package>[:descriptor] [<section>:]<package2>[:descriptor] ...]
-h, --help Print this usage information.
--[no-]offline Use cached packages instead of accessing the network.
-n, --dry-run Report what dependencies would change but don't change any.
--[no-]precompile Build executables in immediate dependencies.
-C, --directory=<dir> Run this in the directory <dir>.

Run "pub_command_runner help" to see global options.
See https://dart.dev/tools/pub/cmd/pub-add for detailed documentation.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# GENERATED BY: test/embedding/embedding_test.dart

$ tool/test-bin/pub_command_runner.dart pub cache --help
Work with the system cache.

Usage: pub_command_runner pub cache [arguments...]
-h, --help Print this usage information.

Available subcommands:
add Install a package.
clean Clears the global PUB_CACHE.
repair Reinstall cached packages.

Run "pub_command_runner help" to see global options.
See https://dart.dev/tools/pub/cmd/pub-cache for detailed documentation.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# GENERATED BY: test/embedding/embedding_test.dart

$ tool/test-bin/pub_command_runner.dart pub cache add --help
Install a package.

Usage: pub_command_runner pub cache add <package> [--version <constraint>] [--all]
-h, --help Print this usage information.
--all Install all matching versions.
-v, --version Version constraint.

Run "pub_command_runner help" to see global options.
See https://dart.dev/tools/pub/cmd/pub-cache for detailed documentation.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# GENERATED BY: test/embedding/embedding_test.dart

$ tool/test-bin/pub_command_runner.dart pub cache clean --help
Clears the global PUB_CACHE.

Usage: pub_command_runner pub cache clean <subcommand> [arguments...]
-h, --help Print this usage information.
-f, --force Don't ask for confirmation.

Run "pub_command_runner help" to see global options.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# GENERATED BY: test/embedding/embedding_test.dart

$ tool/test-bin/pub_command_runner.dart pub cache repair --help
Reinstall cached packages.

Usage: pub_command_runner pub cache repair <subcommand> [arguments...]
-h, --help Print this usage information.

Run "pub_command_runner help" to see global options.
See https://dart.dev/tools/pub/cmd/pub-cache for detailed documentation.

18 changes: 18 additions & 0 deletions test/testdata/goldens/embedding/embedding_test/pub deps --help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# GENERATED BY: test/embedding/embedding_test.dart

$ tool/test-bin/pub_command_runner.dart pub deps --help
Print package dependencies.

Usage: pub_command_runner pub deps [arguments...]
-h, --help Print this usage information.
-s, --style How output should be displayed.
[compact, tree (default), list]
--[no-]dev Whether to include dev dependencies.
(defaults to on)
--executables List all available executables.
--json Output dependency information in a json format.
-C, --directory=<dir> Run this in the directory <dir>.

Run "pub_command_runner help" to see global options.
See https://dart.dev/tools/pub/cmd/pub-deps for detailed documentation.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# GENERATED BY: test/embedding/embedding_test.dart

$ tool/test-bin/pub_command_runner.dart pub downgrade --help
Downgrade the current package's dependencies to oldest versions.



Usage: pub_command_runner pub downgrade [dependencies...]
-h, --help Print this usage information.
--[no-]offline Use cached packages instead of accessing the network.
-n, --dry-run Report what dependencies would change but don't change any.
-C, --directory=<dir> Run this in the directory <dir>.

Run "pub_command_runner help" to see global options.
See https://dart.dev/tools/pub/cmd/pub-downgrade for detailed documentation.

16 changes: 16 additions & 0 deletions test/testdata/goldens/embedding/embedding_test/pub get --help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# GENERATED BY: test/embedding/embedding_test.dart

$ tool/test-bin/pub_command_runner.dart pub get --help
Get the current package's dependencies.

Usage: pub_command_runner pub get
-h, --help Print this usage information.
--[no-]offline Use cached packages instead of accessing the network.
-n, --dry-run Report what dependencies would change but don't change any.
--enforce-lockfile Enforce pubspec.lock. Fail resolution if pubspec.lock does not satisfy pubspec.yaml
--[no-]precompile Build executables in immediate dependencies.
-C, --directory=<dir> Run this in the directory <dir>.

Run "pub_command_runner help" to see global options.
See https://dart.dev/tools/pub/cmd/pub-get for detailed documentation.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# GENERATED BY: test/embedding/embedding_test.dart

$ tool/test-bin/pub_command_runner.dart pub global --help
Work with global packages.

Usage: pub_command_runner pub global [arguments...]
-h, --help Print this usage information.

Available subcommands:
activate Make a package's executables globally available.
deactivate Remove a previously activated package.
list List globally activated packages.
run Run an executable from a globally activated package.

Run "pub_command_runner help" to see global options.
See https://dart.dev/tools/pub/cmd/pub-global for detailed documentation.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# GENERATED BY: test/embedding/embedding_test.dart

$ tool/test-bin/pub_command_runner.dart pub global activate --help
Make a package's executables globally available.

Usage: pub_command_runner pub global activate <package> [version-constraint]
-h, --help Print this usage information.
-s, --source The source used to find the package.
[git, hosted (default), path]
--git-path Path of git package in repository
--git-ref Git branch or commit to be retrieved
--no-executables Do not put executables on PATH.
-x, --executable Executable(s) to place on PATH.
--overwrite Overwrite executables from other packages with the same name.
-u, --hosted-url A custom pub server URL for the package. Only applies when using the `hosted` source.

Run "pub_command_runner help" to see global options.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# GENERATED BY: test/embedding/embedding_test.dart

$ tool/test-bin/pub_command_runner.dart pub global deactivate --help
Remove a previously activated package.

Usage: pub_command_runner pub global deactivate <package>
-h, --help Print this usage information.

Run "pub_command_runner help" to see global options.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# GENERATED BY: test/embedding/embedding_test.dart

$ tool/test-bin/pub_command_runner.dart pub global list --help
List globally activated packages.

Usage: pub_command_runner pub global list <subcommand> [arguments...]
-h, --help Print this usage information.

Run "pub_command_runner help" to see global options.

Loading
Loading