Merge pull request #66 from Hixie/better-tests
Run 'pub get' the first time the tests are run
This commit is contained in:
commit
0a1385d9a9
@ -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);
|
||||
|
@ -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<int> runInProject() async {
|
||||
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) {
|
||||
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<BuildConfiguration> 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)
|
||||
|
@ -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<int> runCommandAndStreamOutput(List<String> cmd,
|
||||
{String prefix: '', RegExp filter}) async {
|
||||
Future<int> runCommandAndStreamOutput(List<String> 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<String> dataLines = data.trimRight().split('\n');
|
||||
if (filter != null) {
|
||||
@ -65,7 +71,7 @@ String runSync(List<String> 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<String> cmd, {bool checked: false}) {
|
||||
|
@ -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';
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user