From cb220c85beffd9424a5892608af58ca9dfb83544 Mon Sep 17 00:00:00 2001 From: Mikkel Nygaard Ravn Date: Wed, 19 Apr 2017 00:00:39 +0200 Subject: [PATCH] Add test of flutter create --plugin (#9459) --- packages/flutter_tools/README.md | 6 +-- packages/flutter_tools/test/create_test.dart | 54 +++++++++++++++----- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/packages/flutter_tools/README.md b/packages/flutter_tools/README.md index 9c091436f9..3fe19e378d 100644 --- a/packages/flutter_tools/README.md +++ b/packages/flutter_tools/README.md @@ -2,9 +2,9 @@ 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 -pub get -FLUTTER_ROOT=$PWD/../.. dart --checked test/all.dart +../../bin/cache/dart-sdk/bin/pub run test ``` diff --git a/packages/flutter_tools/test/create_test.dart b/packages/flutter_tools/test/create_test.dart index 0d3287464d..1a3bfd5547 100644 --- a/packages/flutter_tools/test/create_test.dart +++ b/packages/flutter_tools/test/create_test.dart @@ -35,11 +35,27 @@ void main() { // Verify that we create a project that is well-formed. testUsingContext('project', () async { - return _createAndAnalyzeProject(temp, []); + return _createAndAnalyzeProject( + temp, + [], + fs.path.join(temp.path, 'lib', 'main.dart'), + ); }); testUsingContext('project with-driver-test', () async { - return _createAndAnalyzeProject(temp, ['--with-driver-test']); + return _createAndAnalyzeProject( + temp, + ['--with-driver-test'], + fs.path.join(temp.path, 'lib', 'main.dart'), + ); + }); + + testUsingContext('plugin project', () async { + return _createAndAnalyzeProject( + temp, + ['--plugin'], + fs.path.join(temp.path, 'example', 'lib', 'main.dart'), + ); }); // Verify content and formatting @@ -54,27 +70,30 @@ void main() { void expectExists(String relPath) { expect(fs.isFileSync('${temp.path}/$relPath'), true); } + expectExists('lib/main.dart'); for (FileSystemEntity file in temp.listSync(recursive: true)) { if (file is File && file.path.endsWith('.dart')) { - final String original= file.readAsStringSync(); + final String original = file.readAsStringSync(); final Process process = await Process.start( - sdkBinaryName('dartfmt'), - [file.path], - workingDirectory: temp.path, + sdkBinaryName('dartfmt'), + [file.path], + workingDirectory: temp.path, ); final String formatted = - await process.stdout.transform(UTF8.decoder).join(); + await process.stdout.transform(UTF8.decoder).join(); expect(original, formatted, reason: file.path); } } // 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); - 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(); expect(xcodeConfig, contains('FLUTTER_ROOT=')); expect(xcodeConfig, contains('FLUTTER_APPLICATION_PATH=')); @@ -127,7 +146,11 @@ void main() { }); } -Future _createAndAnalyzeProject(Directory dir, List createArgs) async { +Future _createAndAnalyzeProject( + Directory dir, + List createArgs, + String mainPath, +) async { Cache.flutterRoot = '../..'; final CreateCommand command = new CreateCommand(); final CommandRunner runner = createTestCommandRunner(command); @@ -136,12 +159,15 @@ Future _createAndAnalyzeProject(Directory dir, List createArgs) as args.add(dir.path); await runner.run(args); - final String mainPath = fs.path.join(dir.path, 'lib', 'main.dart'); 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( - '$dartSdkPath/bin/dart', [flutterToolsPath, 'analyze'], - workingDirectory: dir.path + '$dartSdkPath/bin/dart', + [flutterToolsPath, 'analyze'], + workingDirectory: dir.path, ); if (exec.exitCode != 0) { print(exec.stdout);