Commit 0a1385d9 authored by Ian Hickson's avatar Ian Hickson

Merge pull request #66 from Hixie/better-tests

Run 'pub get' the first time the tests are run
parents f0ebc2b0 bd69e2c4
...@@ -59,12 +59,12 @@ class InitCommand extends Command { ...@@ -59,12 +59,12 @@ class InitCommand extends Command {
if (argResults['pub']) { if (argResults['pub']) {
print("Running pub get..."); print("Running pub get...");
Process process = await Process.start( int code = await runCommandAndStreamOutput(
sdkBinaryName('pub'), ['get'], workingDirectory: out.path); [sdkBinaryName('pub'), 'get'],
stdout.addStream(process.stdout); workingDirectory: out.path
stderr.addStream(process.stderr); );
int code = await process.exitCode; if (code != 0)
if (code != 0) return code; return code;
} }
print(message); print(message);
......
...@@ -11,6 +11,7 @@ import 'package:test/src/executable.dart' as executable; ...@@ -11,6 +11,7 @@ import 'package:test/src/executable.dart' as executable;
import '../artifacts.dart'; import '../artifacts.dart';
import '../build_configuration.dart'; import '../build_configuration.dart';
import '../process.dart';
import '../test/loader.dart' as loader; import '../test/loader.dart' as loader;
import 'flutter_command.dart'; import 'flutter_command.dart';
...@@ -36,7 +37,8 @@ class TestCommand extends FlutterCommand { ...@@ -36,7 +37,8 @@ class TestCommand extends FlutterCommand {
@override @override
Future<int> runInProject() async { Future<int> runInProject() async {
List<String> testArgs = argResults.rest.toList(); List<String> testArgs = argResults.rest.toList();
Directory testDir = new Directory(path.join(ArtifactStore.flutterRoot, 'packages/unit/test')); Directory flutterDir = new Directory(path.join(ArtifactStore.flutterRoot, 'packages/unit')); // see https://github.com/flutter/flutter/issues/50
Directory testDir = new Directory(path.join(flutterDir.path, 'test'));
if (testArgs.isEmpty) { if (testArgs.isEmpty) {
testArgs.addAll(testDir.listSync(recursive: true, followLinks: false) testArgs.addAll(testDir.listSync(recursive: true, followLinks: false)
.where((FileSystemEntity entity) => entity.path.endsWith('_test.dart') && FileSystemEntity.isFileSync(entity.path)) .where((FileSystemEntity entity) => entity.path.endsWith('_test.dart') && FileSystemEntity.isFileSync(entity.path))
...@@ -47,9 +49,27 @@ class TestCommand extends FlutterCommand { ...@@ -47,9 +49,27 @@ class TestCommand extends FlutterCommand {
testArgs.insert(0, '--no-color'); testArgs.insert(0, '--no-color');
List<BuildConfiguration> configs = buildConfigurations; List<BuildConfiguration> configs = buildConfigurations;
bool foundOne = false; bool foundOne = false;
File pubSpecYaml = new File(path.join(flutterDir.path, 'pubspec.yaml'));
File pubSpecLock = new File(path.join(flutterDir.path, 'pubspec.lock'));
if (!pubSpecYaml.existsSync()) {
print('${flutterDir.path} has no pubspec.yaml');
return 1;
}
if (!pubSpecLock.existsSync() || pubSpecYaml.lastModifiedSync().isAfter(pubSpecLock.lastModifiedSync())) {
print("Running pub get...");
int code = await runCommandAndStreamOutput(
[sdkBinaryName('pub'), 'get'],
workingDirectory: flutterDir.path
);
if (code != 0)
return code;
}
String currentDirectory = Directory.current.path; String currentDirectory = Directory.current.path;
Directory.current = testDir.path; Directory.current = flutterDir.path;
// TODO(ianh): Verify that this directory has had 'pub get' run in it at least once.
loader.installHook(); loader.installHook();
for (BuildConfiguration config in configs) { for (BuildConfiguration config in configs) {
if (!config.testable) if (!config.testable)
......
...@@ -12,11 +12,17 @@ final Logger _logging = new Logger('sky_tools.process'); ...@@ -12,11 +12,17 @@ final Logger _logging = new Logger('sky_tools.process');
/// This runs the command and streams stdout/stderr from the child process to /// This runs the command and streams stdout/stderr from the child process to
/// this process' stdout/stderr. /// this process' stdout/stderr.
Future<int> runCommandAndStreamOutput(List<String> cmd, Future<int> runCommandAndStreamOutput(List<String> cmd, {
{String prefix: '', RegExp filter}) async { String prefix: '',
RegExp filter,
String workingDirectory
}) async {
_logging.info(cmd.join(' ')); _logging.info(cmd.join(' '));
Process proc = Process proc = await Process.start(
await Process.start(cmd[0], cmd.getRange(1, cmd.length).toList()); cmd[0],
cmd.getRange(1, cmd.length).toList(),
workingDirectory: workingDirectory
);
proc.stdout.transform(UTF8.decoder).listen((String data) { proc.stdout.transform(UTF8.decoder).listen((String data) {
List<String> dataLines = data.trimRight().split('\n'); List<String> dataLines = data.trimRight().split('\n');
if (filter != null) { if (filter != null) {
...@@ -65,7 +71,7 @@ String runSync(List<String> cmd) => _runWithLoggingSync(cmd); ...@@ -65,7 +71,7 @@ String runSync(List<String> cmd) => _runWithLoggingSync(cmd);
/// Return the platform specific name for the given Dart SDK binary. So, `pub` /// Return the platform specific name for the given Dart SDK binary. So, `pub`
/// ==> `pub.bat`. /// ==> `pub.bat`.
String sdkBinaryName(String name) { String sdkBinaryName(String name) {
return Platform.isWindows ? '${name}.bat' : name; return Platform.isWindows ? '$name.bat' : name;
} }
String _runWithLoggingSync(List<String> cmd, {bool checked: false}) { String _runWithLoggingSync(List<String> cmd, {bool checked: false}) {
......
...@@ -120,6 +120,9 @@ void main() { ...@@ -120,6 +120,9 @@ void main() {
case -0x0b: // ProcessSignal.SIGSEGV case -0x0b: // ProcessSignal.SIGSEGV
output += 'Segmentation fault in subprocess for: $path\n'; output += 'Segmentation fault in subprocess for: $path\n';
break; break;
case -0x06: // ProcessSignal.SIGABRT
output += 'Aborted while running: $path\n';
break;
default: default:
output += 'Unexpected exit code $exitCode from subprocess for: $path\n'; output += 'Unexpected exit code $exitCode from subprocess for: $path\n';
} }
......
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