Fix the output when running dart help pub. Process.runSync(..) is used since printUsage() is not an async method.
Bug: https://github.com/dart-lang/sdk/issues/41040 Change-Id: I9e4fbab333bbd67dcab2b1e0752fc0debb80be46 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/139833 Commit-Queue: Jaime Wren <jwren@google.com> Reviewed-by: Devon Carew <devoncarew@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
9a140bab87
commit
784b17dd24
@@ -15,6 +15,25 @@ class PubCommand extends DartdevCommand<int> {
|
||||
|
||||
final ArgParser argParser = ArgParser.allowAnything();
|
||||
|
||||
/// Override [printUsage] for invocations of 'dart help pub' which won't
|
||||
/// execute [run] below. Without this, the 'dart help pub' reports the
|
||||
/// command pub with no commands or flags.
|
||||
@override
|
||||
void printUsage() {
|
||||
final command = sdk.pub;
|
||||
final args = ['help'];
|
||||
|
||||
log.trace('$command ${args.first}');
|
||||
|
||||
// Call 'pub help'
|
||||
// Process.runSync(..) is used since [printUsage] is not an async method,
|
||||
// and we want to guarantee that the result (the help text for the console)
|
||||
// is printed before command exits.
|
||||
final result = Process.runSync(command, args);
|
||||
stderr.write(result.stderr);
|
||||
stdout.write(result.stdout);
|
||||
}
|
||||
|
||||
@override
|
||||
FutureOr<int> run() async {
|
||||
final command = sdk.pub;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright (c) 2020, 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 '../utils.dart';
|
||||
|
||||
void main() {
|
||||
group('help', help);
|
||||
}
|
||||
|
||||
void help() {
|
||||
TestProject p;
|
||||
|
||||
tearDown(() => p?.dispose());
|
||||
|
||||
test('pub', () {
|
||||
p = project();
|
||||
var result = p.runSync('help', ['pub']);
|
||||
|
||||
var pubHelpResult = p.runSync('pub', ['help']);
|
||||
expect(result.stdout, contains(pubHelpResult.stdout));
|
||||
expect(result.stderr, contains(pubHelpResult.stderr));
|
||||
});
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import 'commands/analyze_test.dart' as analyze;
|
||||
import 'commands/create_test.dart' as create;
|
||||
import 'commands/flag_test.dart' as flag;
|
||||
import 'commands/format_test.dart' as format;
|
||||
import 'commands/help_test.dart' as help;
|
||||
import 'commands/migrate_test.dart' as migrate;
|
||||
import 'commands/pub_test.dart' as pub;
|
||||
import 'commands/test_test.dart' as test;
|
||||
@@ -16,11 +17,12 @@ import 'sdk_test.dart' as sdk;
|
||||
import 'utils_test.dart' as utils;
|
||||
|
||||
main() {
|
||||
group('dartdev', () {
|
||||
group('dart', () {
|
||||
analyze.main();
|
||||
create.main();
|
||||
flag.main();
|
||||
format.main();
|
||||
help.main();
|
||||
migrate.main();
|
||||
pub.main();
|
||||
test.main();
|
||||
|
||||
Reference in New Issue
Block a user