5399dbf6f6
- split the Dart CLI tool out of the VM into it's own embedder which runs in AOT mode. The pure Dart VM executable is called 'dartvm' and has no Dart CLI functionality in it - the Dart CLI executable parses the CLI commands and invokes the rest of the AOT tools in the same process, for the 'run' and 'test' commands it execs a process which runs 'dartvm' to run - 'dart hello.dart' execs the 'dartvm' process and runs 'hello.dart' - the Dart CLI is not generated for ia32 as we are not shipping a Dart SDK for ia32 anymore (support to execute the 'dartvm' for ia32 architecture is retained) - the Dart CLI tool is not built in the internal Dart SDK builds TEST=ci Some performance improvement numbers 'dart format pkg/dartdev' goes from 1.17 secs to 0.22 secs 'dart doc pkg/dartdev' goes from 100.2 secs to 66.6 secs 'dart fix pkg/dartdev' goes from 19.3 secs to 14.5 secs Change-Id: I66984a26cb2ab014b34dc1873f1f3d2884e13518 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364202 Commit-Queue: Ben Konyi <bkonyi@google.com> Reviewed-by: Ben Konyi <bkonyi@google.com>
150 lines
4.5 KiB
Dart
150 lines
4.5 KiB
Dart
// 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 'dart:io';
|
|
|
|
import 'package:args/command_runner.dart';
|
|
import 'package:dartdev/dartdev.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import '../utils.dart';
|
|
|
|
void main() {
|
|
initGlobalState();
|
|
group('command', command, timeout: longTimeout);
|
|
group('flag', help, timeout: longTimeout);
|
|
group('invalid flags', invalidFlags, timeout: longTimeout);
|
|
}
|
|
|
|
void expectUsage(String msg) {
|
|
expect(msg, contains('Usage: dart <command|dart-file> [arguments]'));
|
|
expect(msg, contains('Global options:'));
|
|
expect(msg, contains('Available commands:'));
|
|
expect(msg, contains('analyze '));
|
|
expect(msg, contains('create '));
|
|
expect(msg, contains('compile '));
|
|
expect(msg, contains('format '));
|
|
}
|
|
|
|
void command() {
|
|
// For each command description, assert that the values are not empty, don't
|
|
// have trailing white space and end with a period.
|
|
test('description formatting', () {
|
|
DartdevRunner(['--suppress-analytics'])
|
|
.commands
|
|
.forEach((String commandKey, Command<int> command) {
|
|
expect(commandKey, isNotEmpty);
|
|
expect(command.description, isNotEmpty);
|
|
expect(command.description.split('\n').first, endsWith('.'));
|
|
expect(command.description.trim(), equals(command.description));
|
|
});
|
|
});
|
|
|
|
// Assert that all found usageLineLengths are the same and null
|
|
test('argParser usageLineLength', () {
|
|
DartdevRunner(['--suppress-analytics'])
|
|
.commands
|
|
.forEach((String commandKey, Command<int> command) {
|
|
if (command.name != 'help' &&
|
|
command.name != 'format' &&
|
|
command.name != 'pub' &&
|
|
command.name != 'test') {
|
|
expect(command.argParser.usageLineLength,
|
|
stdout.hasTerminal ? stdout.terminalColumns : null);
|
|
} else if (command.name == 'pub') {
|
|
// TODO(sigurdm): Avoid special casing here.
|
|
// https://github.com/dart-lang/pub/issues/2700
|
|
expect(command.argParser.usageLineLength,
|
|
stdout.hasTerminal ? stdout.terminalColumns : 80);
|
|
} else {
|
|
expect(command.argParser.usageLineLength, isNull);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
void help() {
|
|
late TestProject p;
|
|
|
|
test('--help', () async {
|
|
p = project();
|
|
var result = await p.run(['--help']);
|
|
|
|
expect(result.exitCode, 0);
|
|
expect(result.stderr, isEmpty);
|
|
expect(result.stdout, contains(DartdevRunner.dartdevDescription));
|
|
expectUsage(result.stdout);
|
|
});
|
|
|
|
test('--help --verbose', () async {
|
|
p = project();
|
|
var result = await p.run(['--help', '--verbose']);
|
|
|
|
expect(result.exitCode, 0);
|
|
expect(result.stderr, isEmpty);
|
|
expect(result.stdout,
|
|
contains('The following options are only used for VM development'));
|
|
});
|
|
|
|
test('--help -v', () async {
|
|
p = project();
|
|
var result = await p.run(['--help', '-v']);
|
|
|
|
expect(result.exitCode, 0);
|
|
expect(result.stderr, isEmpty);
|
|
expect(result.stdout,
|
|
contains('The following options are only used for VM development'));
|
|
});
|
|
|
|
test('print Dart CLI help on usage error', () async {
|
|
p = project();
|
|
var result = await p.run(['---help']);
|
|
expect(result.exitCode, 64);
|
|
expect(result.stderr, contains('Could not find an option named "---help"'));
|
|
expectUsage(result.stderr);
|
|
expect(result.stdout, isEmpty);
|
|
});
|
|
|
|
test('help', () async {
|
|
p = project();
|
|
var result = await p.run(['help']);
|
|
|
|
expect(result.exitCode, 0);
|
|
expect(result.stderr, isEmpty);
|
|
expect(result.stdout, contains(DartdevRunner.dartdevDescription));
|
|
expectUsage(result.stdout);
|
|
});
|
|
|
|
test('help --verbose', () async {
|
|
p = project();
|
|
var result = await p.run(['help', '--verbose']);
|
|
|
|
expect(result.exitCode, 0);
|
|
expect(result.stdout,
|
|
contains('Usage: dart [vm-options] <command|dart-file> [arguments]'));
|
|
});
|
|
|
|
test('help -v', () async {
|
|
p = project();
|
|
var result = await p.run(['help', '-v']);
|
|
|
|
expect(result.exitCode, 0);
|
|
expect(result.stdout,
|
|
contains('Usage: dart [vm-options] <command|dart-file> [arguments]'));
|
|
});
|
|
}
|
|
|
|
void invalidFlags() {
|
|
late TestProject p;
|
|
|
|
test('Regress #49437', () async {
|
|
// Regression test for https://github.com/dart-lang/sdk/issues/49437
|
|
p = project();
|
|
final result = await p.run(['-no-load-cse', 'hello.dart']);
|
|
expect(result.exitCode, 64);
|
|
expect(result.stdout, isNot(contains(DartdevRunner.dartdevDescription)));
|
|
expectUsage(result.stderr);
|
|
});
|
|
}
|