Commit 8084d3c6 authored by Adam Barth's avatar Adam Barth

Merge pull request #32 from abarth/flutter_test

Add a command for running unit tests
parents f5ce5564 fc8cdf4d
...@@ -21,6 +21,7 @@ import 'src/commands/logs.dart'; ...@@ -21,6 +21,7 @@ import 'src/commands/logs.dart';
import 'src/commands/run_mojo.dart'; import 'src/commands/run_mojo.dart';
import 'src/commands/start.dart'; import 'src/commands/start.dart';
import 'src/commands/stop.dart'; import 'src/commands/stop.dart';
import 'src/commands/test.dart';
import 'src/commands/trace.dart'; import 'src/commands/trace.dart';
import 'src/process.dart'; import 'src/process.dart';
...@@ -54,6 +55,7 @@ Future main(List<String> args) async { ...@@ -54,6 +55,7 @@ Future main(List<String> args) async {
..addCommand(new RunMojoCommand()) ..addCommand(new RunMojoCommand())
..addCommand(new StartCommand()) ..addCommand(new StartCommand())
..addCommand(new StopCommand()) ..addCommand(new StopCommand())
..addCommand(new TestCommand())
..addCommand(new TraceCommand()); ..addCommand(new TraceCommand());
return Chain.capture(() async { return Chain.capture(() async {
......
// 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,6 +29,8 @@ final String _kSkyShell = Platform.environment['SKY_SHELL']; ...@@ -29,6 +29,8 @@ final String _kSkyShell = Platform.environment['SKY_SHELL'];
const String _kHost = '127.0.0.1'; const String _kHost = '127.0.0.1';
const String _kPath = '/runner'; const String _kPath = '/runner';
String shellPath;
// Right now a bunch of our tests crash or assert after the tests have finished running. // 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 // a scheduled microtask that verifies that state. Eventually we should fix all these
...@@ -54,8 +56,8 @@ Future<_ServerInfo> _createServer() async { ...@@ -54,8 +56,8 @@ Future<_ServerInfo> _createServer() async {
} }
Future<Process> _startProcess(String path, { String packageRoot }) { Future<Process> _startProcess(String path, { String packageRoot }) {
assert(_kSkyShell != null); // Please provide the path to the shell in the SKY_SHELL environment variable. assert(shellPath != null || _kSkyShell != null); // Please provide the path to the shell in the SKY_SHELL environment variable.
return Process.start(_kSkyShell, [ return Process.start(shellPath ?? _kSkyShell, [
'--enable-checked-mode', '--enable-checked-mode',
'--non-interactive', '--non-interactive',
'--package-root=$packageRoot', '--package-root=$packageRoot',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment