Commit 435fdbff authored by Devon Carew's avatar Devon Carew

move driver create test to the flutter_tools package (#3433)

* move driver create test to the flutter_tools package

* review comments
parent 25164e10
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async';
import 'dart:io'; import 'dart:io';
import 'package:args/command_runner.dart'; import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/artifacts.dart'; import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/process.dart';
import 'package:flutter_tools/src/commands/create.dart'; import 'package:flutter_tools/src/commands/create.dart';
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import 'package:test/test.dart'; import 'package:test/test.dart';
...@@ -26,28 +26,13 @@ void main() { ...@@ -26,28 +26,13 @@ void main() {
}); });
// Verify that we create a project that is well-formed. // Verify that we create a project that is well-formed.
testUsingContext('flutter-simple', () async { testUsingContext('project', () async {
ArtifactStore.flutterRoot = '../..'; return _createAndAnalyzeProject(temp, <String>[]);
CreateCommand command = new CreateCommand(); });
CommandRunner runner = new CommandRunner('test_flutter', '')
..addCommand(command);
await runner.run(['create', temp.path])
.then((int code) => expect(code, equals(0)));
String mainPath = path.join(temp.path, 'lib', 'main.dart'); testUsingContext('project with-driver-test', () async {
expect(new File(mainPath).existsSync(), true); return _createAndAnalyzeProject(temp, <String>['--with-driver-test']);
ProcessResult exec = Process.runSync( });
sdkBinaryName('dartanalyzer'), ['--fatal-warnings', mainPath],
workingDirectory: temp.path
);
if (exec.exitCode != 0) {
print(exec.stdout);
print(exec.stderr);
}
expect(exec.exitCode, 0);
},
// This test can take a while due to network requests.
timeout: new Timeout(new Duration(minutes: 2)));
// Verify that we can regenerate over an existing project. // Verify that we can regenerate over an existing project.
testUsingContext('can re-gen over existing project', () async { testUsingContext('can re-gen over existing project', () async {
...@@ -56,10 +41,11 @@ void main() { ...@@ -56,10 +41,11 @@ void main() {
CommandRunner runner = new CommandRunner('test_flutter', '') CommandRunner runner = new CommandRunner('test_flutter', '')
..addCommand(command); ..addCommand(command);
await runner.run(['create', '--no-pub', temp.path]) int code = await runner.run(<String>['create', '--no-pub', temp.path]);
.then((int code) => expect(code, equals(0))); expect(code, equals(0));
await runner.run(['create', '--no-pub', temp.path])
.then((int code) => expect(code, equals(0))); code = await runner.run(<String>['create', '--no-pub', temp.path]);
expect(code, equals(0));
}); });
// Verify that we fail with an error code when the file exists. // Verify that we fail with an error code when the file exists.
...@@ -70,8 +56,33 @@ void main() { ...@@ -70,8 +56,33 @@ void main() {
..addCommand(command); ..addCommand(command);
File existingFile = new File("${temp.path.toString()}/bad"); File existingFile = new File("${temp.path.toString()}/bad");
if (!existingFile.existsSync()) existingFile.createSync(); if (!existingFile.existsSync()) existingFile.createSync();
await runner.run(['create', existingFile.path]) int code = await runner.run(<String>['create', existingFile.path]);
.then((int code) => expect(code, equals(1))); expect(code, equals(1));
}); });
}); });
} }
Future<Null> _createAndAnalyzeProject(Directory dir, List<String> createArgs) async {
ArtifactStore.flutterRoot = '../..';
CreateCommand command = new CreateCommand();
CommandRunner runner = new CommandRunner('test_flutter', '')
..addCommand(command);
List<String> args = <String>['create'];
args.addAll(createArgs);
args.add(dir.path);
int code = await runner.run(args);
expect(code, equals(0));
String mainPath = path.join(dir.path, 'lib', 'main.dart');
expect(new File(mainPath).existsSync(), true);
String flutterToolsPath = path.absolute(path.join('bin', 'flutter_tools.dart'));
ProcessResult exec = Process.runSync(
'dart', <String>[flutterToolsPath, 'analyze'],
workingDirectory: dir.path
);
if (exec.exitCode != 0) {
print(exec.stdout);
print(exec.stderr);
}
expect(exec.exitCode, 0);
}
...@@ -4,7 +4,7 @@ set -ex ...@@ -4,7 +4,7 @@ set -ex
export PATH="$PWD/bin:$PATH" export PATH="$PWD/bin:$PATH"
# analyze all the Dart code in the repo # analyze all the Dart code in the repo
flutter analyze --flutter-repo --no-current-directory --no-current-package --congratulate flutter analyze --flutter-repo
# keep the rest of this file in sync with # keep the rest of this file in sync with
# //chrome_infra/build/scripts/slave/recipes/flutter/flutter.py # //chrome_infra/build/scripts/slave/recipes/flutter/flutter.py
...@@ -24,6 +24,3 @@ flutter analyze --flutter-repo --no-current-directory --no-current-package --con ...@@ -24,6 +24,3 @@ flutter analyze --flutter-repo --no-current-directory --no-current-package --con
(cd examples/layers; flutter test) (cd examples/layers; flutter test)
(cd examples/material_gallery; flutter test) (cd examples/material_gallery; flutter test)
(cd examples/stocks; flutter test) (cd examples/stocks; flutter test)
CREATE_TEST_DIR=`mktemp -d`
(cd $CREATE_TEST_DIR && flutter create --with-driver-test create_test && cd create_test && flutter analyze)
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