diff --git a/packages/flutter_tools/lib/src/commands/init.dart b/packages/flutter_tools/lib/src/commands/init.dart index 9adcc0d29a..85ef4415cd 100644 --- a/packages/flutter_tools/lib/src/commands/init.dart +++ b/packages/flutter_tools/lib/src/commands/init.dart @@ -59,12 +59,12 @@ class InitCommand extends Command { if (argResults['pub']) { print("Running pub get..."); - Process process = await Process.start( - sdkBinaryName('pub'), ['get'], workingDirectory: out.path); - stdout.addStream(process.stdout); - stderr.addStream(process.stderr); - int code = await process.exitCode; - if (code != 0) return code; + int code = await runCommandAndStreamOutput( + [sdkBinaryName('pub'), 'get'], + workingDirectory: out.path + ); + if (code != 0) + return code; } print(message); diff --git a/packages/flutter_tools/lib/src/commands/test.dart b/packages/flutter_tools/lib/src/commands/test.dart index 6cbc9a92be..0decb1c513 100644 --- a/packages/flutter_tools/lib/src/commands/test.dart +++ b/packages/flutter_tools/lib/src/commands/test.dart @@ -11,6 +11,7 @@ import 'package:test/src/executable.dart' as executable; import '../artifacts.dart'; import '../build_configuration.dart'; +import '../process.dart'; import '../test/loader.dart' as loader; import 'flutter_command.dart'; @@ -36,7 +37,8 @@ class TestCommand extends FlutterCommand { @override Future runInProject() async { List 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) { testArgs.addAll(testDir.listSync(recursive: true, followLinks: false) .where((FileSystemEntity entity) => entity.path.endsWith('_test.dart') && FileSystemEntity.isFileSync(entity.path)) @@ -47,9 +49,27 @@ class TestCommand extends FlutterCommand { testArgs.insert(0, '--no-color'); List configs = buildConfigurations; 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; - Directory.current = testDir.path; - // TODO(ianh): Verify that this directory has had 'pub get' run in it at least once. + Directory.current = flutterDir.path; loader.installHook(); for (BuildConfiguration config in configs) { if (!config.testable) diff --git a/packages/flutter_tools/lib/src/process.dart b/packages/flutter_tools/lib/src/process.dart index 2fd8a7a360..d1db6547c4 100644 --- a/packages/flutter_tools/lib/src/process.dart +++ b/packages/flutter_tools/lib/src/process.dart @@ -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 process' stdout/stderr. -Future runCommandAndStreamOutput(List cmd, - {String prefix: '', RegExp filter}) async { +Future runCommandAndStreamOutput(List cmd, { + String prefix: '', + RegExp filter, + String workingDirectory +}) async { _logging.info(cmd.join(' ')); - Process proc = - await Process.start(cmd[0], cmd.getRange(1, cmd.length).toList()); + Process proc = await Process.start( + cmd[0], + cmd.getRange(1, cmd.length).toList(), + workingDirectory: workingDirectory + ); proc.stdout.transform(UTF8.decoder).listen((String data) { List dataLines = data.trimRight().split('\n'); if (filter != null) { @@ -65,7 +71,7 @@ String runSync(List cmd) => _runWithLoggingSync(cmd); /// Return the platform specific name for the given Dart SDK binary. So, `pub` /// ==> `pub.bat`. String sdkBinaryName(String name) { - return Platform.isWindows ? '${name}.bat' : name; + return Platform.isWindows ? '$name.bat' : name; } String _runWithLoggingSync(List cmd, {bool checked: false}) { diff --git a/packages/flutter_tools/lib/src/test/loader.dart b/packages/flutter_tools/lib/src/test/loader.dart index 4ad9583ecf..cf54c0a976 100644 --- a/packages/flutter_tools/lib/src/test/loader.dart +++ b/packages/flutter_tools/lib/src/test/loader.dart @@ -120,6 +120,9 @@ void main() { case -0x0b: // ProcessSignal.SIGSEGV output += 'Segmentation fault in subprocess for: $path\n'; break; + case -0x06: // ProcessSignal.SIGABRT + output += 'Aborted while running: $path\n'; + break; default: output += 'Unexpected exit code $exitCode from subprocess for: $path\n'; }