mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Add a command for running unit tests
This commit is contained in:
parent
f5ce556472
commit
fc8cdf4daf
@ -21,6 +21,7 @@ import 'src/commands/logs.dart';
|
||||
import 'src/commands/run_mojo.dart';
|
||||
import 'src/commands/start.dart';
|
||||
import 'src/commands/stop.dart';
|
||||
import 'src/commands/test.dart';
|
||||
import 'src/commands/trace.dart';
|
||||
import 'src/process.dart';
|
||||
|
||||
@ -54,6 +55,7 @@ Future main(List<String> args) async {
|
||||
..addCommand(new RunMojoCommand())
|
||||
..addCommand(new StartCommand())
|
||||
..addCommand(new StopCommand())
|
||||
..addCommand(new TestCommand())
|
||||
..addCommand(new TraceCommand());
|
||||
|
||||
return Chain.capture(() async {
|
||||
|
44
packages/flutter_tools/lib/src/commands/test.dart
Normal file
44
packages/flutter_tools/lib/src/commands/test.dart
Normal file
@ -0,0 +1,44 @@
|
||||
// Copyright 2015 The Chromium Authors. 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:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:test/src/executable.dart' as executable;
|
||||
|
||||
import 'flutter_command.dart';
|
||||
import '../test/loader.dart' as loader;
|
||||
|
||||
final Logger _logging = new Logger('sky_tools.test');
|
||||
|
||||
class TestCommand extends FlutterCommand {
|
||||
final String name = 'test';
|
||||
final String description = 'Runs Flutter unit tests for the current project (requires a local build of the engine).';
|
||||
|
||||
TestCommand() {
|
||||
argParser.addOption('build-dir', defaultsTo: '../../../engine/src/out/Debug');
|
||||
}
|
||||
|
||||
String get _shellPath {
|
||||
if (Platform.isLinux)
|
||||
return path.join(argResults['build-dir'], 'sky_shell');
|
||||
if (Platform.isMacOS)
|
||||
return path.join(argResults['build-dir'], 'SkyShell.app', 'Contents', 'MacOS', 'SkyShell');
|
||||
throw new Exception('Unsupported platform.');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int> runInProject() async {
|
||||
loader.shellPath = _shellPath;
|
||||
if (!FileSystemEntity.isFileSync(loader.shellPath)) {
|
||||
_logging.severe('Cannot find Flutter Shell at ${loader.shellPath}');
|
||||
return 1;
|
||||
}
|
||||
loader.installHook();
|
||||
await executable.main(argResults.rest);
|
||||
return exitCode;
|
||||
}
|
||||
}
|
@ -29,8 +29,10 @@ final String _kSkyShell = Platform.environment['SKY_SHELL'];
|
||||
const String _kHost = '127.0.0.1';
|
||||
const String _kPath = '/runner';
|
||||
|
||||
String shellPath;
|
||||
|
||||
// Right now a bunch of our tests crash or assert after the tests have finished running.
|
||||
// Mostly this is just because the test puts the framework in an inconsistent state with
|
||||
// Mostly this is just because the test puts the framework in an inconsistent state with
|
||||
// a scheduled microtask that verifies that state. Eventually we should fix all these
|
||||
// problems but for now we'll just paper over them.
|
||||
const bool kExpectAllTestsToCloseCleanly = false;
|
||||
@ -54,8 +56,8 @@ Future<_ServerInfo> _createServer() async {
|
||||
}
|
||||
|
||||
Future<Process> _startProcess(String path, { String packageRoot }) {
|
||||
assert(_kSkyShell != null); // Please provide the path to the shell in the SKY_SHELL environment variable.
|
||||
return Process.start(_kSkyShell, [
|
||||
assert(shellPath != null || _kSkyShell != null); // Please provide the path to the shell in the SKY_SHELL environment variable.
|
||||
return Process.start(shellPath ?? _kSkyShell, [
|
||||
'--enable-checked-mode',
|
||||
'--non-interactive',
|
||||
'--package-root=$packageRoot',
|
||||
@ -172,7 +174,7 @@ void main() {
|
||||
completer.complete(response["tests"].map((test) {
|
||||
var testMetadata = new Metadata.deserialize(test['metadata']);
|
||||
return new RemoteTest(test['name'], testMetadata, socket, test['index']);
|
||||
}));
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user