Track which Widget objects were created by the local project. (#15041)

Make flutter test support the --track-widget-creation flag.
Add widget creation location tests. Tests are skipped when
--track-widget-creation flag is not passed.
This commit is contained in:
Jacob Richman
2018-03-09 08:09:49 -08:00
committed by GitHub
parent a9e2781132
commit 046c6d5f7f
5 changed files with 249 additions and 42 deletions

View File

@@ -23,54 +23,72 @@ class TestCommand extends FlutterCommand {
TestCommand({ bool verboseHelp: false }) {
requiresPubspecYaml();
usesPubOption();
argParser.addOption('name',
argParser.addOption(
'name',
help: 'A regular expression matching substrings of the names of tests to run.',
valueHelp: 'regexp',
allowMultiple: true,
splitCommas: false,
);
argParser.addOption('plain-name',
argParser.addOption(
'plain-name',
help: 'A plain-text substring of the names of tests to run.',
valueHelp: 'substring',
allowMultiple: true,
splitCommas: false,
);
argParser.addFlag('start-paused',
defaultsTo: false,
negatable: false,
help: 'Start in a paused mode and wait for a debugger to connect.\n'
'You must specify a single test file to run, explicitly.\n'
'Instructions for connecting with a debugger and printed to the\n'
'console once the test has started.'
);
argParser.addFlag('coverage',
argParser.addFlag(
'start-paused',
defaultsTo: false,
negatable: false,
help: 'Whether to collect coverage information.'
help: 'Start in a paused mode and wait for a debugger to connect.\n'
'You must specify a single test file to run, explicitly.\n'
'Instructions for connecting with a debugger and printed to the\n'
'console once the test has started.',
);
argParser.addFlag('merge-coverage',
argParser.addFlag(
'coverage',
defaultsTo: false,
negatable: false,
help: 'Whether to collect coverage information.',
);
argParser.addFlag(
'merge-coverage',
defaultsTo: false,
negatable: false,
help: 'Whether to merge coverage data with "coverage/lcov.base.info".\n'
'Implies collecting coverage data. (Requires lcov)'
'Implies collecting coverage data. (Requires lcov)',
);
argParser.addFlag('ipv6',
negatable: false,
hide: true,
help: 'Whether to use IPv6 for the test harness server socket.'
argParser.addFlag(
'ipv6',
negatable: false,
hide: true,
help: 'Whether to use IPv6 for the test harness server socket.',
);
argParser.addOption('coverage-path',
argParser.addOption(
'coverage-path',
defaultsTo: 'coverage/lcov.info',
help: 'Where to store coverage information (if coverage is enabled).'
help: 'Where to store coverage information (if coverage is enabled).',
);
argParser.addFlag(
'machine',
hide: !verboseHelp,
negatable: false,
help: 'Handle machine structured JSON command input\n'
'and provide output and progress in machine friendly format.',
);
argParser.addFlag(
'preview-dart-2',
hide: !verboseHelp,
help: 'Preview Dart 2.0 functionality.',
);
argParser.addFlag(
'track-widget-creation',
negatable: false,
hide: !verboseHelp,
help: 'Track widget creation locations.\n'
'This enables testing of features such as the widget inspector.',
);
argParser.addFlag('machine',
hide: !verboseHelp,
negatable: false,
help: 'Handle machine structured JSON command input\n'
'and provide output and progress in machine friendly format.');
argParser.addFlag('preview-dart-2',
hide: !verboseHelp,
help: 'Preview Dart 2.0 functionality.');
}
@override
@@ -200,17 +218,19 @@ class TestCommand extends FlutterCommand {
Cache.releaseLockEarly();
final int result = await runTests(files,
workDir: workDir,
names: names,
plainNames: plainNames,
watcher: watcher,
enableObservatory: collector != null || startPaused,
startPaused: startPaused,
ipv6: argResults['ipv6'],
machine: machine,
previewDart2: argResults['preview-dart-2'],
);
final int result = await runTests(
files,
workDir: workDir,
names: names,
plainNames: plainNames,
watcher: watcher,
enableObservatory: collector != null || startPaused,
startPaused: startPaused,
ipv6: argResults['ipv6'],
machine: machine,
previewDart2: argResults['preview-dart-2'],
trackWidgetCreation: argResults['track-widget-creation'],
);
if (collector != null) {
if (!await _collectCoverageData(collector, mergeCoverageData: argResults['merge-coverage']))

View File

@@ -61,6 +61,7 @@ void installHook({
bool previewDart2: false,
int port: 0,
String precompiledDillPath,
bool trackWidgetCreation: false,
int observatoryPort,
InternetAddressType serverType: InternetAddressType.IP_V4,
}) {
@@ -79,6 +80,7 @@ void installHook({
previewDart2: previewDart2,
port: port,
precompiledDillPath: precompiledDillPath,
trackWidgetCreation: trackWidgetCreation,
),
);
}
@@ -97,7 +99,7 @@ class _CompilationRequest {
// This class is a wrapper around compiler that allows multiple isolates to
// enqueue compilation requests, but ensures only one compilation at a time.
class _Compiler {
_Compiler() {
_Compiler(bool trackWidgetCreation) {
// Compiler maintains and updates single incremental dill file.
// Incremental compilation requests done for each test copy that file away
// for independent execution.
@@ -135,7 +137,8 @@ class _Compiler {
compiler = new ResidentCompiler(
artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
packagesPath: PackageMap.globalPackagesPath);
packagesPath: PackageMap.globalPackagesPath,
trackWidgetCreation: trackWidgetCreation);
}
final StreamController<_CompilationRequest> compilerController =
@@ -162,6 +165,7 @@ class _FlutterPlatform extends PlatformPlugin {
this.previewDart2,
this.port,
this.precompiledDillPath,
this.trackWidgetCreation,
}) : assert(shellPath != null);
final String shellPath;
@@ -174,6 +178,7 @@ class _FlutterPlatform extends PlatformPlugin {
final bool previewDart2;
final int port;
final String precompiledDillPath;
final bool trackWidgetCreation;
_Compiler compiler;
@@ -269,7 +274,7 @@ class _FlutterPlatform extends PlatformPlugin {
if (previewDart2 && precompiledDillPath == null) {
// Lazily instantiate compiler so it is built only if it is actually used.
compiler ??= new _Compiler();
compiler ??= new _Compiler(trackWidgetCreation);
mainDart = await compiler.compile(mainDart);
if (mainDart == null) {

View File

@@ -4,6 +4,7 @@
import 'dart:async';
import 'package:args/command_runner.dart';
// ignore: implementation_imports
import 'package:test/src/executable.dart' as test;
@@ -29,8 +30,16 @@ Future<int> runTests(
bool ipv6: false,
bool machine: false,
bool previewDart2: false,
bool trackWidgetCreation: false,
TestWatcher watcher,
}) async {
if (trackWidgetCreation && !previewDart2) {
throw new UsageException(
'--track-widget-creation is valid only when --preview-dart-2 is specified.',
null,
);
}
// Compute the command-line arguments for package:test.
final List<String> testArgs = <String>[];
if (!terminal.supportsColor)
@@ -77,6 +86,7 @@ Future<int> runTests(
startPaused: startPaused,
serverType: serverType,
previewDart2: previewDart2,
trackWidgetCreation: trackWidgetCreation,
);
// Make the global packages path absolute.