Commit cb220c85 authored by Mikkel Nygaard Ravn's avatar Mikkel Nygaard Ravn Committed by GitHub

Add test of flutter create --plugin (#9459)

parent a6a8d997
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
Tools for building Flutter applications. Tools for building Flutter applications.
To run the tests, ensure that no devices are connected and run: To run the tests, ensure that no devices are connected,
then navigate to `flutter_tools` and execute:
```shell ```shell
pub get ../../bin/cache/dart-sdk/bin/pub run test
FLUTTER_ROOT=$PWD/../.. dart --checked test/all.dart
``` ```
...@@ -35,11 +35,27 @@ void main() { ...@@ -35,11 +35,27 @@ void main() {
// Verify that we create a project that is well-formed. // Verify that we create a project that is well-formed.
testUsingContext('project', () async { testUsingContext('project', () async {
return _createAndAnalyzeProject(temp, <String>[]); return _createAndAnalyzeProject(
temp,
<String>[],
fs.path.join(temp.path, 'lib', 'main.dart'),
);
}); });
testUsingContext('project with-driver-test', () async { testUsingContext('project with-driver-test', () async {
return _createAndAnalyzeProject(temp, <String>['--with-driver-test']); return _createAndAnalyzeProject(
temp,
<String>['--with-driver-test'],
fs.path.join(temp.path, 'lib', 'main.dart'),
);
});
testUsingContext('plugin project', () async {
return _createAndAnalyzeProject(
temp,
<String>['--plugin'],
fs.path.join(temp.path, 'example', 'lib', 'main.dart'),
);
}); });
// Verify content and formatting // Verify content and formatting
...@@ -54,27 +70,30 @@ void main() { ...@@ -54,27 +70,30 @@ void main() {
void expectExists(String relPath) { void expectExists(String relPath) {
expect(fs.isFileSync('${temp.path}/$relPath'), true); expect(fs.isFileSync('${temp.path}/$relPath'), true);
} }
expectExists('lib/main.dart'); expectExists('lib/main.dart');
for (FileSystemEntity file in temp.listSync(recursive: true)) { for (FileSystemEntity file in temp.listSync(recursive: true)) {
if (file is File && file.path.endsWith('.dart')) { if (file is File && file.path.endsWith('.dart')) {
final String original= file.readAsStringSync(); final String original = file.readAsStringSync();
final Process process = await Process.start( final Process process = await Process.start(
sdkBinaryName('dartfmt'), sdkBinaryName('dartfmt'),
<String>[file.path], <String>[file.path],
workingDirectory: temp.path, workingDirectory: temp.path,
); );
final String formatted = final String formatted =
await process.stdout.transform(UTF8.decoder).join(); await process.stdout.transform(UTF8.decoder).join();
expect(original, formatted, reason: file.path); expect(original, formatted, reason: file.path);
} }
} }
// Generated Xcode settings // Generated Xcode settings
final String xcodeConfigPath = fs.path.join('ios', 'Flutter', 'Generated.xcconfig'); final String xcodeConfigPath =
fs.path.join('ios', 'Flutter', 'Generated.xcconfig');
expectExists(xcodeConfigPath); expectExists(xcodeConfigPath);
final File xcodeConfigFile = fs.file(fs.path.join(temp.path, xcodeConfigPath)); final File xcodeConfigFile =
fs.file(fs.path.join(temp.path, xcodeConfigPath));
final String xcodeConfig = xcodeConfigFile.readAsStringSync(); final String xcodeConfig = xcodeConfigFile.readAsStringSync();
expect(xcodeConfig, contains('FLUTTER_ROOT=')); expect(xcodeConfig, contains('FLUTTER_ROOT='));
expect(xcodeConfig, contains('FLUTTER_APPLICATION_PATH=')); expect(xcodeConfig, contains('FLUTTER_APPLICATION_PATH='));
...@@ -127,7 +146,11 @@ void main() { ...@@ -127,7 +146,11 @@ void main() {
}); });
} }
Future<Null> _createAndAnalyzeProject(Directory dir, List<String> createArgs) async { Future<Null> _createAndAnalyzeProject(
Directory dir,
List<String> createArgs,
String mainPath,
) async {
Cache.flutterRoot = '../..'; Cache.flutterRoot = '../..';
final CreateCommand command = new CreateCommand(); final CreateCommand command = new CreateCommand();
final CommandRunner<Null> runner = createTestCommandRunner(command); final CommandRunner<Null> runner = createTestCommandRunner(command);
...@@ -136,12 +159,15 @@ Future<Null> _createAndAnalyzeProject(Directory dir, List<String> createArgs) as ...@@ -136,12 +159,15 @@ Future<Null> _createAndAnalyzeProject(Directory dir, List<String> createArgs) as
args.add(dir.path); args.add(dir.path);
await runner.run(args); await runner.run(args);
final String mainPath = fs.path.join(dir.path, 'lib', 'main.dart');
expect(fs.file(mainPath).existsSync(), true); expect(fs.file(mainPath).existsSync(), true);
final String flutterToolsPath = fs.path.absolute(fs.path.join('bin', 'flutter_tools.dart')); final String flutterToolsPath = fs.path.absolute(fs.path.join(
'bin',
'flutter_tools.dart',
));
final ProcessResult exec = Process.runSync( final ProcessResult exec = Process.runSync(
'$dartSdkPath/bin/dart', <String>[flutterToolsPath, 'analyze'], '$dartSdkPath/bin/dart',
workingDirectory: dir.path <String>[flutterToolsPath, 'analyze'],
workingDirectory: dir.path,
); );
if (exec.exitCode != 0) { if (exec.exitCode != 0) {
print(exec.stdout); print(exec.stdout);
......
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