Support flutter test with prebuilt binaries

Now you can run tests with and without --flutter-repo with a prebuilt binary on
Linux.

Fixes #307
This commit is contained in:
Adam Barth
2015-12-03 10:02:13 -08:00
parent 17533e1d74
commit fb98a387aa
6 changed files with 33 additions and 57 deletions

View File

@@ -49,8 +49,9 @@ class BuildConfiguration {
BuildConfiguration.prebuilt({
this.hostPlatform,
this.targetPlatform,
this.deviceId
}) : type = BuildType.prebuilt, buildDir = null, testable = false;
this.deviceId,
this.testable: false
}) : type = BuildType.prebuilt, buildDir = null;
BuildConfiguration.local({
this.type,

View File

@@ -26,14 +26,20 @@ class TestCommand extends FlutterCommand {
'any test paths. Otherwise, run this command from the root of your project.';
}
String getShellPath(TargetPlatform platform, String buildPath) {
switch (platform) {
case TargetPlatform.linux:
return path.join(buildPath, 'sky_shell');
case TargetPlatform.mac:
return path.join(buildPath, 'SkyShell.app', 'Contents', 'MacOS', 'SkyShell');
default:
throw new Exception('Unsupported platform.');
Future<String> _getShellPath(BuildConfiguration config) async {
if (config.type == BuildType.prebuilt) {
Artifact artifact = ArtifactStore.getArtifact(
type: ArtifactType.shell, targetPlatform: config.targetPlatform);
return await ArtifactStore.getPath(artifact);
} else {
switch (config.targetPlatform) {
case TargetPlatform.linux:
return path.join(config.buildDir, 'sky_shell');
case TargetPlatform.mac:
return path.join(config.buildDir, 'SkyShell.app', 'Contents', 'MacOS', 'SkyShell');
default:
throw new Exception('Unsupported platform.');
}
}
}
@@ -69,6 +75,11 @@ class TestCommand extends FlutterCommand {
if (!runFlutterTests && !validateProjectRoot())
return 1;
// If we're running the flutter tests, we want to use the packages directory
// from the unit package in order to find the proper shell binary.
if (runFlutterTests && ArtifactStore.packageRoot == 'packages')
ArtifactStore.packageRoot = path.join(ArtifactStore.flutterRoot, 'packages', 'unit', 'packages');
Directory testDir = runFlutterTests ? _flutterUnitTestDir : Directory.current;
if (testArgs.isEmpty)
@@ -84,7 +95,7 @@ class TestCommand extends FlutterCommand {
if (!config.testable)
continue;
foundOne = true;
loader.shellPath = path.join(Directory.current.path, getShellPath(config.targetPlatform, config.buildDir));
loader.shellPath = path.absolute(await _getShellPath(config));
if (!FileSystemEntity.isFileSync(loader.shellPath)) {
logging.severe('Cannot find Flutter shell at ${loader.shellPath}');
return 1;

View File

@@ -218,6 +218,14 @@ class FlutterCommandRunner extends CommandRunner {
targetPlatform: TargetPlatform.android,
deviceId: globalResults['android-device-id']
));
if (hostPlatform == HostPlatform.linux) {
configs.add(new BuildConfiguration.prebuilt(
hostPlatform: HostPlatform.linux,
targetPlatform: TargetPlatform.linux,
testable: true
));
}
} else {
if (!FileSystemEntity.isDirectorySync(enginePath))
logging.warning('$enginePath is not a valid directory');