Commit fb98a387 authored by Adam Barth's avatar Adam Barth

Support `flutter test` with prebuilt binaries

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

Fixes #307
parent 17533e1d
......@@ -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,
......
......@@ -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;
......
......@@ -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');
......
#!/usr/bin/env python
# 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 argparse
import os
import subprocess
import sys
import zipfile
def download(base_url, out_dir, name):
url = '%s/%s' % (base_url, name)
dst = os.path.join(out_dir, name)
print 'Downloading', url
subprocess.call([ 'curl', '-o', dst, url ])
def main():
parser = argparse.ArgumentParser(description='Downloads test artifacts from Google storage')
parser.add_argument('revision_file')
parser.add_argument('out_dir')
args = parser.parse_args()
out_dir = args.out_dir
if not os.path.exists(out_dir):
os.makedirs(out_dir)
revision = None
with open(args.revision_file, 'r') as f:
revision = f.read()
base_url = 'https://storage.googleapis.com/mojo/flutter/%s/linux-x64' % revision
download(base_url, out_dir, 'artifacts.zip')
artifacts_zip = zipfile.ZipFile(os.path.join(out_dir, 'artifacts.zip'))
artifacts_zip.extractall(out_dir)
artifacts_zip.close()
subprocess.call([ 'chmod', 'a+x', os.path.join(out_dir, 'sky_shell' )])
subprocess.call([ 'chmod', 'a+x', os.path.join(out_dir, 'sky_snapshot' )])
if __name__ == '__main__':
sys.exit(main())
......@@ -2,5 +2,4 @@
set -ex
dart dev/update_packages.dart
./travis/download_tester.py packages/unit/packages/sky_engine/REVISION bin/cache/travis/out/Debug
(cd packages/unit; ../../bin/flutter cache populate)
......@@ -5,7 +5,7 @@ set -ex
./bin/flutter analyze --flutter-repo --no-current-directory --no-current-package --congratulate
# flutter package tests
./bin/flutter test --flutter-repo --engine-src-path bin/cache/travis
./bin/flutter test --flutter-repo
(cd packages/cassowary; pub run test -j1)
# (cd packages/flutter_sprites; ) # No tests to run.
......
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