From 74d03857f862d340d1fc9b910986f16e02b69af1 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Mon, 7 Jun 2021 10:04:43 -0700 Subject: [PATCH] [flutter_plugin_tools] Remove global state from tests (#4018) Eliminates the global test filesystem and global test packages directory, in favor of local versions. This guarantees that each test runs with a clean filesystem state, rather than relying on cleanup. It also simplifies understanding the tests, since everything is done via params and return values instead of needing to know about the magic global variables and which methods mutate them. --- script/tool/test/analyze_command_test.dart | 33 +++-- .../test/build_examples_command_test.dart | 113 +++++++-------- script/tool/test/common_test.dart | 137 +++++++----------- .../create_all_plugins_app_command_test.dart | 14 +- .../test/drive_examples_command_test.dart | 82 ++++++----- script/tool/test/firebase_test_lab_test.dart | 33 ++--- script/tool/test/java_test_command_test.dart | 18 ++- .../tool/test/lint_podspecs_command_test.dart | 50 +++---- script/tool/test/list_command_test.dart | 52 +++---- .../tool/test/publish_check_command_test.dart | 44 +++--- .../test/publish_plugin_command_test.dart | 115 +++++++-------- .../tool/test/pubspec_check_command_test.dart | 42 +++--- script/tool/test/test_command_test.dart | 59 ++++---- script/tool/test/util.dart | 47 +++--- script/tool/test/version_check_test.dart | 101 +++++++------ script/tool/test/xctest_command_test.dart | 53 ++++--- 16 files changed, 456 insertions(+), 537 deletions(-) diff --git a/script/tool/test/analyze_command_test.dart b/script/tool/test/analyze_command_test.dart index 28cfeaaf39..ec627f2586 100644 --- a/script/tool/test/analyze_command_test.dart +++ b/script/tool/test/analyze_command_test.dart @@ -4,6 +4,7 @@ import 'package:args/command_runner.dart'; import 'package:file/file.dart'; +import 'package:file/memory.dart'; import 'package:flutter_plugin_tools/src/analyze_command.dart'; import 'package:flutter_plugin_tools/src/common.dart'; import 'package:test/test.dart'; @@ -12,26 +13,25 @@ import 'mocks.dart'; import 'util.dart'; void main() { + late FileSystem fileSystem; + late Directory packagesDir; late RecordingProcessRunner processRunner; late CommandRunner runner; setUp(() { - initializeFakePackages(); + fileSystem = MemoryFileSystem(); + packagesDir = createPackagesDirectory(fileSystem: fileSystem); processRunner = RecordingProcessRunner(); final AnalyzeCommand analyzeCommand = - AnalyzeCommand(mockPackagesDir, processRunner: processRunner); + AnalyzeCommand(packagesDir, processRunner: processRunner); runner = CommandRunner('analyze_command', 'Test for analyze_command'); runner.addCommand(analyzeCommand); }); - tearDown(() { - mockPackagesDir.deleteSync(recursive: true); - }); - test('analyzes all packages', () async { - final Directory plugin1Dir = createFakePlugin('a'); - final Directory plugin2Dir = createFakePlugin('b'); + final Directory plugin1Dir = createFakePlugin('a', packagesDir); + final Directory plugin2Dir = createFakePlugin('b', packagesDir); final MockProcess mockProcess = MockProcess(); mockProcess.exitCodeCompleter.complete(0); @@ -53,7 +53,8 @@ void main() { }); test('skips flutter pub get for examples', () async { - final Directory plugin1Dir = createFakePlugin('a', withSingleExample: true); + final Directory plugin1Dir = + createFakePlugin('a', packagesDir, withSingleExample: true); final MockProcess mockProcess = MockProcess(); mockProcess.exitCodeCompleter.complete(0); @@ -71,8 +72,8 @@ void main() { }); test('don\'t elide a non-contained example package', () async { - final Directory plugin1Dir = createFakePlugin('a'); - final Directory plugin2Dir = createFakePlugin('example'); + final Directory plugin1Dir = createFakePlugin('a', packagesDir); + final Directory plugin2Dir = createFakePlugin('example', packagesDir); final MockProcess mockProcess = MockProcess(); mockProcess.exitCodeCompleter.complete(0); @@ -94,7 +95,7 @@ void main() { }); test('uses a separate analysis sdk', () async { - final Directory pluginDir = createFakePlugin('a'); + final Directory pluginDir = createFakePlugin('a', packagesDir); final MockProcess mockProcess = MockProcess(); mockProcess.exitCodeCompleter.complete(0); @@ -120,7 +121,7 @@ void main() { group('verifies analysis settings', () { test('fails analysis_options.yaml', () async { - createFakePlugin('foo', withExtraFiles: >[ + createFakePlugin('foo', packagesDir, withExtraFiles: >[ ['analysis_options.yaml'] ]); @@ -129,7 +130,7 @@ void main() { }); test('fails .analysis_options', () async { - createFakePlugin('foo', withExtraFiles: >[ + createFakePlugin('foo', packagesDir, withExtraFiles: >[ ['.analysis_options'] ]); @@ -139,7 +140,7 @@ void main() { test('takes an allow list', () async { final Directory pluginDir = - createFakePlugin('foo', withExtraFiles: >[ + createFakePlugin('foo', packagesDir, withExtraFiles: >[ ['analysis_options.yaml'] ]); @@ -160,7 +161,7 @@ void main() { // See: https://github.com/flutter/flutter/issues/78994 test('takes an empty allow list', () async { - createFakePlugin('foo', withExtraFiles: >[ + createFakePlugin('foo', packagesDir, withExtraFiles: >[ ['analysis_options.yaml'] ]); diff --git a/script/tool/test/build_examples_command_test.dart b/script/tool/test/build_examples_command_test.dart index d162806ab2..2ad17b374b 100644 --- a/script/tool/test/build_examples_command_test.dart +++ b/script/tool/test/build_examples_command_test.dart @@ -4,6 +4,7 @@ import 'package:args/command_runner.dart'; import 'package:file/file.dart'; +import 'package:file/memory.dart'; import 'package:flutter_plugin_tools/src/build_examples_command.dart'; import 'package:path/path.dart' as p; import 'package:platform/platform.dart'; @@ -13,40 +14,42 @@ import 'util.dart'; void main() { group('test build_example_command', () { + late FileSystem fileSystem; + late Directory packagesDir; late CommandRunner runner; late RecordingProcessRunner processRunner; final String flutterCommand = const LocalPlatform().isWindows ? 'flutter.bat' : 'flutter'; setUp(() { - initializeFakePackages(); + fileSystem = MemoryFileSystem(); + packagesDir = createPackagesDirectory(fileSystem: fileSystem); processRunner = RecordingProcessRunner(); final BuildExamplesCommand command = - BuildExamplesCommand(mockPackagesDir, processRunner: processRunner); + BuildExamplesCommand(packagesDir, processRunner: processRunner); runner = CommandRunner( 'build_examples_command', 'Test for build_example_command'); runner.addCommand(command); - cleanupPackages(); }); test('building for iOS when plugin is not set up for iOS results in no-op', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test'], ], isLinuxPlugin: false); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); final List output = await runCapturingPrint( runner, ['build-examples', '--ipa', '--no-macos']); final String packageName = - p.relative(pluginExampleDirectory.path, from: mockPackagesDir.path); + p.relative(pluginExampleDirectory.path, from: packagesDir.path); expect( output, @@ -61,18 +64,17 @@ void main() { // Output should be empty since running build-examples --macos with no macos // implementation is a no-op. expect(processRunner.recordedCalls, orderedEquals([])); - cleanupPackages(); }); test('building for ios', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test'], ], isIosPlugin: true); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); @@ -83,7 +85,7 @@ void main() { '--enable-experiment=exp1' ]); final String packageName = - p.relative(pluginExampleDirectory.path, from: mockPackagesDir.path); + p.relative(pluginExampleDirectory.path, from: packagesDir.path); expect( output, @@ -107,27 +109,26 @@ void main() { ], pluginExampleDirectory.path), ])); - cleanupPackages(); }); test( 'building for Linux when plugin is not set up for Linux results in no-op', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test'], ], isLinuxPlugin: false); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); final List output = await runCapturingPrint( runner, ['build-examples', '--no-ipa', '--linux']); final String packageName = - p.relative(pluginExampleDirectory.path, from: mockPackagesDir.path); + p.relative(pluginExampleDirectory.path, from: packagesDir.path); expect( output, @@ -142,25 +143,24 @@ void main() { // Output should be empty since running build-examples --linux with no // Linux implementation is a no-op. expect(processRunner.recordedCalls, orderedEquals([])); - cleanupPackages(); }); test('building for Linux', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test'], ], isLinuxPlugin: true); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); final List output = await runCapturingPrint( runner, ['build-examples', '--no-ipa', '--linux']); final String packageName = - p.relative(pluginExampleDirectory.path, from: mockPackagesDir.path); + p.relative(pluginExampleDirectory.path, from: packagesDir.path); expect( output, @@ -177,24 +177,24 @@ void main() { ProcessCall(flutterCommand, const ['build', 'linux'], pluginExampleDirectory.path), ])); - cleanupPackages(); }); test('building for macos with no implementation results in no-op', () async { - createFakePlugin('plugin', withExtraFiles: >[ - ['example', 'test'], - ]); + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, + withExtraFiles: >[ + ['example', 'test'], + ]); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); final List output = await runCapturingPrint( runner, ['build-examples', '--no-ipa', '--macos']); final String packageName = - p.relative(pluginExampleDirectory.path, from: mockPackagesDir.path); + p.relative(pluginExampleDirectory.path, from: packagesDir.path); expect( output, @@ -209,11 +209,10 @@ void main() { // Output should be empty since running build-examples --macos with no macos // implementation is a no-op. expect(processRunner.recordedCalls, orderedEquals([])); - cleanupPackages(); }); test('building for macos', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test'], ['example', 'macos', 'macos.swift'], @@ -221,14 +220,14 @@ void main() { isMacOsPlugin: true); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); final List output = await runCapturingPrint( runner, ['build-examples', '--no-ipa', '--macos']); final String packageName = - p.relative(pluginExampleDirectory.path, from: mockPackagesDir.path); + p.relative(pluginExampleDirectory.path, from: packagesDir.path); expect( output, @@ -245,23 +244,23 @@ void main() { ProcessCall(flutterCommand, const ['build', 'macos'], pluginExampleDirectory.path), ])); - cleanupPackages(); }); test('building for web with no implementation results in no-op', () async { - createFakePlugin('plugin', withExtraFiles: >[ - ['example', 'test'], - ]); + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, + withExtraFiles: >[ + ['example', 'test'], + ]); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); final List output = await runCapturingPrint( runner, ['build-examples', '--no-ipa', '--web']); final String packageName = - p.relative(pluginExampleDirectory.path, from: mockPackagesDir.path); + p.relative(pluginExampleDirectory.path, from: packagesDir.path); expect( output, @@ -276,11 +275,10 @@ void main() { // Output should be empty since running build-examples --macos with no macos // implementation is a no-op. expect(processRunner.recordedCalls, orderedEquals([])); - cleanupPackages(); }); test('building for web', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test'], ['example', 'web', 'index.html'], @@ -288,14 +286,14 @@ void main() { isWebPlugin: true); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); final List output = await runCapturingPrint( runner, ['build-examples', '--no-ipa', '--web']); final String packageName = - p.relative(pluginExampleDirectory.path, from: mockPackagesDir.path); + p.relative(pluginExampleDirectory.path, from: packagesDir.path); expect( output, @@ -312,27 +310,26 @@ void main() { ProcessCall(flutterCommand, const ['build', 'web'], pluginExampleDirectory.path), ])); - cleanupPackages(); }); test( 'building for Windows when plugin is not set up for Windows results in no-op', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test'], ], isWindowsPlugin: false); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); final List output = await runCapturingPrint( runner, ['build-examples', '--no-ipa', '--windows']); final String packageName = - p.relative(pluginExampleDirectory.path, from: mockPackagesDir.path); + p.relative(pluginExampleDirectory.path, from: packagesDir.path); expect( output, @@ -347,25 +344,24 @@ void main() { // Output should be empty since running build-examples --macos with no macos // implementation is a no-op. expect(processRunner.recordedCalls, orderedEquals([])); - cleanupPackages(); }); test('building for windows', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test'], ], isWindowsPlugin: true); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); final List output = await runCapturingPrint( runner, ['build-examples', '--no-ipa', '--windows']); final String packageName = - p.relative(pluginExampleDirectory.path, from: mockPackagesDir.path); + p.relative(pluginExampleDirectory.path, from: packagesDir.path); expect( output, @@ -382,27 +378,26 @@ void main() { ProcessCall(flutterCommand, const ['build', 'windows'], pluginExampleDirectory.path), ])); - cleanupPackages(); }); test( 'building for Android when plugin is not set up for Android results in no-op', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test'], ], isLinuxPlugin: false); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); final List output = await runCapturingPrint( runner, ['build-examples', '--apk', '--no-ipa']); final String packageName = - p.relative(pluginExampleDirectory.path, from: mockPackagesDir.path); + p.relative(pluginExampleDirectory.path, from: packagesDir.path); expect( output, @@ -417,18 +412,17 @@ void main() { // Output should be empty since running build-examples --macos with no macos // implementation is a no-op. expect(processRunner.recordedCalls, orderedEquals([])); - cleanupPackages(); }); test('building for android', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test'], ], isAndroidPlugin: true); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); @@ -439,7 +433,7 @@ void main() { '--no-macos', ]); final String packageName = - p.relative(pluginExampleDirectory.path, from: mockPackagesDir.path); + p.relative(pluginExampleDirectory.path, from: packagesDir.path); expect( output, @@ -456,18 +450,17 @@ void main() { ProcessCall(flutterCommand, const ['build', 'apk'], pluginExampleDirectory.path), ])); - cleanupPackages(); }); test('enable-experiment flag for Android', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test'], ], isAndroidPlugin: true); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); @@ -487,18 +480,17 @@ void main() { const ['build', 'apk', '--enable-experiment=exp1'], pluginExampleDirectory.path), ])); - cleanupPackages(); }); test('enable-experiment flag for ios', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test'], ], isIosPlugin: true); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); @@ -521,7 +513,6 @@ void main() { ], pluginExampleDirectory.path), ])); - cleanupPackages(); }); }); } diff --git a/script/tool/test/common_test.dart b/script/tool/test/common_test.dart index 53fd0ec472..2f497963d2 100644 --- a/script/tool/test/common_test.dart +++ b/script/tool/test/common_test.dart @@ -34,7 +34,7 @@ void main() { setUp(() { fileSystem = MemoryFileSystem(); - packagesDir = fileSystem.currentDirectory.childDirectory('packages'); + packagesDir = createPackagesDirectory(fileSystem: fileSystem); thirdPartyPackagesDir = packagesDir.parent .childDirectory('third_party') .childDirectory('packages'); @@ -52,7 +52,6 @@ void main() { } return Future.value(mockProcessResult); }); - initializeFakePackages(parentDir: packagesDir.parent); processRunner = RecordingProcessRunner(); plugins = []; final SamplePluginCommand samplePluginCommand = SamplePluginCommand( @@ -67,47 +66,40 @@ void main() { }); test('all plugins from file system', () async { - final Directory plugin1 = - createFakePlugin('plugin1', packagesDirectory: packagesDir); - final Directory plugin2 = - createFakePlugin('plugin2', packagesDirectory: packagesDir); + final Directory plugin1 = createFakePlugin('plugin1', packagesDir); + final Directory plugin2 = createFakePlugin('plugin2', packagesDir); await runner.run(['sample']); expect(plugins, unorderedEquals([plugin1.path, plugin2.path])); }); test('all plugins includes third_party/packages', () async { - final Directory plugin1 = - createFakePlugin('plugin1', packagesDirectory: packagesDir); - final Directory plugin2 = - createFakePlugin('plugin2', packagesDirectory: packagesDir); + final Directory plugin1 = createFakePlugin('plugin1', packagesDir); + final Directory plugin2 = createFakePlugin('plugin2', packagesDir); final Directory plugin3 = - createFakePlugin('plugin3', packagesDirectory: thirdPartyPackagesDir); + createFakePlugin('plugin3', thirdPartyPackagesDir); await runner.run(['sample']); expect(plugins, unorderedEquals([plugin1.path, plugin2.path, plugin3.path])); }); test('exclude plugins when plugins flag is specified', () async { - createFakePlugin('plugin1', packagesDirectory: packagesDir); - final Directory plugin2 = - createFakePlugin('plugin2', packagesDirectory: packagesDir); + createFakePlugin('plugin1', packagesDir); + final Directory plugin2 = createFakePlugin('plugin2', packagesDir); await runner.run( ['sample', '--plugins=plugin1,plugin2', '--exclude=plugin1']); expect(plugins, unorderedEquals([plugin2.path])); }); test('exclude plugins when plugins flag isn\'t specified', () async { - createFakePlugin('plugin1', packagesDirectory: packagesDir); - createFakePlugin('plugin2', packagesDirectory: packagesDir); + createFakePlugin('plugin1', packagesDir); + createFakePlugin('plugin2', packagesDir); await runner.run(['sample', '--exclude=plugin1,plugin2']); expect(plugins, unorderedEquals([])); }); test('exclude federated plugins when plugins flag is specified', () async { - createFakePlugin('plugin1', - parentDirectoryName: 'federated', packagesDirectory: packagesDir); - final Directory plugin2 = - createFakePlugin('plugin2', packagesDirectory: packagesDir); + createFakePlugin('plugin1', packagesDir, parentDirectoryName: 'federated'); + final Directory plugin2 = createFakePlugin('plugin2', packagesDir); await runner.run([ 'sample', '--plugins=federated/plugin1,plugin2', @@ -118,10 +110,8 @@ void main() { test('exclude entire federated plugins when plugins flag is specified', () async { - createFakePlugin('plugin1', - parentDirectoryName: 'federated', packagesDirectory: packagesDir); - final Directory plugin2 = - createFakePlugin('plugin2', packagesDirectory: packagesDir); + createFakePlugin('plugin1', packagesDir, parentDirectoryName: 'federated'); + final Directory plugin2 = createFakePlugin('plugin2', packagesDir); await runner.run([ 'sample', '--plugins=federated/plugin1,plugin2', @@ -132,10 +122,8 @@ void main() { group('test run-on-changed-packages', () { test('all plugins should be tested if there are no changes.', () async { - final Directory plugin1 = - createFakePlugin('plugin1', packagesDirectory: packagesDir); - final Directory plugin2 = - createFakePlugin('plugin2', packagesDirectory: packagesDir); + final Directory plugin1 = createFakePlugin('plugin1', packagesDir); + final Directory plugin2 = createFakePlugin('plugin2', packagesDir); await runner.run( ['sample', '--base-sha=master', '--run-on-changed-packages']); @@ -145,10 +133,8 @@ void main() { test('all plugins should be tested if there are no plugin related changes.', () async { gitDiffResponse = 'AUTHORS'; - final Directory plugin1 = - createFakePlugin('plugin1', packagesDirectory: packagesDir); - final Directory plugin2 = - createFakePlugin('plugin2', packagesDirectory: packagesDir); + final Directory plugin1 = createFakePlugin('plugin1', packagesDir); + final Directory plugin2 = createFakePlugin('plugin2', packagesDir); await runner.run( ['sample', '--base-sha=master', '--run-on-changed-packages']); @@ -160,10 +146,8 @@ void main() { .cirrus.yml packages/plugin1/CHANGELOG '''; - final Directory plugin1 = - createFakePlugin('plugin1', packagesDirectory: packagesDir); - final Directory plugin2 = - createFakePlugin('plugin2', packagesDirectory: packagesDir); + final Directory plugin1 = createFakePlugin('plugin1', packagesDir); + final Directory plugin2 = createFakePlugin('plugin2', packagesDir); await runner.run( ['sample', '--base-sha=master', '--run-on-changed-packages']); @@ -175,10 +159,8 @@ packages/plugin1/CHANGELOG .ci.yaml packages/plugin1/CHANGELOG '''; - final Directory plugin1 = - createFakePlugin('plugin1', packagesDirectory: packagesDir); - final Directory plugin2 = - createFakePlugin('plugin2', packagesDirectory: packagesDir); + final Directory plugin1 = createFakePlugin('plugin1', packagesDir); + final Directory plugin2 = createFakePlugin('plugin2', packagesDir); await runner.run( ['sample', '--base-sha=master', '--run-on-changed-packages']); @@ -190,10 +172,8 @@ packages/plugin1/CHANGELOG .ci/Dockerfile packages/plugin1/CHANGELOG '''; - final Directory plugin1 = - createFakePlugin('plugin1', packagesDirectory: packagesDir); - final Directory plugin2 = - createFakePlugin('plugin2', packagesDirectory: packagesDir); + final Directory plugin1 = createFakePlugin('plugin1', packagesDir); + final Directory plugin2 = createFakePlugin('plugin2', packagesDir); await runner.run( ['sample', '--base-sha=master', '--run-on-changed-packages']); @@ -206,10 +186,8 @@ packages/plugin1/CHANGELOG script/tool_runner.sh packages/plugin1/CHANGELOG '''; - final Directory plugin1 = - createFakePlugin('plugin1', packagesDirectory: packagesDir); - final Directory plugin2 = - createFakePlugin('plugin2', packagesDirectory: packagesDir); + final Directory plugin1 = createFakePlugin('plugin1', packagesDir); + final Directory plugin2 = createFakePlugin('plugin2', packagesDir); await runner.run( ['sample', '--base-sha=master', '--run-on-changed-packages']); @@ -222,10 +200,8 @@ packages/plugin1/CHANGELOG analysis_options.yaml packages/plugin1/CHANGELOG '''; - final Directory plugin1 = - createFakePlugin('plugin1', packagesDirectory: packagesDir); - final Directory plugin2 = - createFakePlugin('plugin2', packagesDirectory: packagesDir); + final Directory plugin1 = createFakePlugin('plugin1', packagesDir); + final Directory plugin2 = createFakePlugin('plugin2', packagesDir); await runner.run( ['sample', '--base-sha=master', '--run-on-changed-packages']); @@ -238,10 +214,8 @@ packages/plugin1/CHANGELOG .clang-format packages/plugin1/CHANGELOG '''; - final Directory plugin1 = - createFakePlugin('plugin1', packagesDirectory: packagesDir); - final Directory plugin2 = - createFakePlugin('plugin2', packagesDirectory: packagesDir); + final Directory plugin1 = createFakePlugin('plugin1', packagesDir); + final Directory plugin2 = createFakePlugin('plugin2', packagesDir); await runner.run( ['sample', '--base-sha=master', '--run-on-changed-packages']); @@ -250,9 +224,8 @@ packages/plugin1/CHANGELOG test('Only changed plugin should be tested.', () async { gitDiffResponse = 'packages/plugin1/plugin1.dart'; - final Directory plugin1 = - createFakePlugin('plugin1', packagesDirectory: packagesDir); - createFakePlugin('plugin2', packagesDirectory: packagesDir); + final Directory plugin1 = createFakePlugin('plugin1', packagesDir); + createFakePlugin('plugin2', packagesDir); await runner.run( ['sample', '--base-sha=master', '--run-on-changed-packages']); @@ -264,9 +237,8 @@ packages/plugin1/CHANGELOG packages/plugin1/plugin1.dart packages/plugin1/ios/plugin1.m '''; - final Directory plugin1 = - createFakePlugin('plugin1', packagesDirectory: packagesDir); - createFakePlugin('plugin2', packagesDirectory: packagesDir); + final Directory plugin1 = createFakePlugin('plugin1', packagesDir); + createFakePlugin('plugin2', packagesDir); await runner.run( ['sample', '--base-sha=master', '--run-on-changed-packages']); @@ -279,11 +251,9 @@ packages/plugin1/ios/plugin1.m packages/plugin1/plugin1.dart packages/plugin2/ios/plugin2.m '''; - final Directory plugin1 = - createFakePlugin('plugin1', packagesDirectory: packagesDir); - final Directory plugin2 = - createFakePlugin('plugin2', packagesDirectory: packagesDir); - createFakePlugin('plugin3', packagesDirectory: packagesDir); + final Directory plugin1 = createFakePlugin('plugin1', packagesDir); + final Directory plugin2 = createFakePlugin('plugin2', packagesDir); + createFakePlugin('plugin3', packagesDir); await runner.run( ['sample', '--base-sha=master', '--run-on-changed-packages']); @@ -298,10 +268,10 @@ packages/plugin1/plugin1/plugin1.dart packages/plugin1/plugin1_platform_interface/plugin1_platform_interface.dart packages/plugin1/plugin1_web/plugin1_web.dart '''; - final Directory plugin1 = createFakePlugin('plugin1', - parentDirectoryName: 'plugin1', packagesDirectory: packagesDir); - createFakePlugin('plugin2', packagesDirectory: packagesDir); - createFakePlugin('plugin3', packagesDirectory: packagesDir); + final Directory plugin1 = createFakePlugin('plugin1', packagesDir, + parentDirectoryName: 'plugin1'); + createFakePlugin('plugin2', packagesDir); + createFakePlugin('plugin3', packagesDir); await runner.run( ['sample', '--base-sha=master', '--run-on-changed-packages']); @@ -315,11 +285,10 @@ packages/plugin1/plugin1.dart packages/plugin2/ios/plugin2.m packages/plugin3/plugin3.dart '''; - final Directory plugin1 = createFakePlugin('plugin1', - parentDirectoryName: 'plugin1', packagesDirectory: packagesDir); - final Directory plugin2 = - createFakePlugin('plugin2', packagesDirectory: packagesDir); - createFakePlugin('plugin3', packagesDirectory: packagesDir); + final Directory plugin1 = createFakePlugin('plugin1', packagesDir, + parentDirectoryName: 'plugin1'); + final Directory plugin2 = createFakePlugin('plugin2', packagesDir); + createFakePlugin('plugin3', packagesDir); await runner.run([ 'sample', '--plugins=plugin1,plugin2', @@ -336,10 +305,10 @@ packages/plugin1/plugin1.dart packages/plugin2/ios/plugin2.m packages/plugin3/plugin3.dart '''; - final Directory plugin1 = createFakePlugin('plugin1', - parentDirectoryName: 'plugin1', packagesDirectory: packagesDir); - createFakePlugin('plugin2', packagesDirectory: packagesDir); - createFakePlugin('plugin3', packagesDirectory: packagesDir); + final Directory plugin1 = createFakePlugin('plugin1', packagesDir, + parentDirectoryName: 'plugin1'); + createFakePlugin('plugin2', packagesDir); + createFakePlugin('plugin3', packagesDir); await runner.run([ 'sample', '--exclude=plugin2,plugin3', @@ -352,12 +321,15 @@ packages/plugin3/plugin3.dart }); group('$GitVersionFinder', () { + late FileSystem fileSystem; late List?> gitDirCommands; late String gitDiffResponse; String? mergeBaseResponse; late MockGitDir gitDir; setUp(() { + fileSystem = MemoryFileSystem(); + createPackagesDirectory(fileSystem: fileSystem); gitDirCommands = ?>[]; gitDiffResponse = ''; gitDir = MockGitDir(); @@ -374,14 +346,9 @@ packages/plugin3/plugin3.dart } return Future.value(mockProcessResult); }); - initializeFakePackages(); processRunner = RecordingProcessRunner(); }); - tearDown(() { - cleanupPackages(); - }); - test('No git diff should result no files changed', () async { final GitVersionFinder finder = GitVersionFinder(gitDir, 'some base sha'); final List changedFiles = await finder.getChangedFiles(); diff --git a/script/tool/test/create_all_plugins_app_command_test.dart b/script/tool/test/create_all_plugins_app_command_test.dart index e9da3cb1ef..b3cbd592a6 100644 --- a/script/tool/test/create_all_plugins_app_command_test.dart +++ b/script/tool/test/create_all_plugins_app_command_test.dart @@ -43,9 +43,9 @@ void main() { }); test('pubspec includes all plugins', () async { - createFakePlugin('plugina', packagesDirectory: packagesDir); - createFakePlugin('pluginb', packagesDirectory: packagesDir); - createFakePlugin('pluginc', packagesDirectory: packagesDir); + createFakePlugin('plugina', packagesDir); + createFakePlugin('pluginb', packagesDir); + createFakePlugin('pluginc', packagesDir); await runner.run(['all-plugins-app']); final List pubspec = @@ -61,9 +61,9 @@ void main() { }); test('pubspec has overrides for all plugins', () async { - createFakePlugin('plugina', packagesDirectory: packagesDir); - createFakePlugin('pluginb', packagesDirectory: packagesDir); - createFakePlugin('pluginc', packagesDirectory: packagesDir); + createFakePlugin('plugina', packagesDir); + createFakePlugin('pluginb', packagesDir); + createFakePlugin('pluginc', packagesDir); await runner.run(['all-plugins-app']); final List pubspec = @@ -80,7 +80,7 @@ void main() { }); test('pubspec is compatible with null-safe app code', () async { - createFakePlugin('plugina', packagesDirectory: packagesDir); + createFakePlugin('plugina', packagesDir); await runner.run(['all-plugins-app']); final String pubspec = diff --git a/script/tool/test/drive_examples_command_test.dart b/script/tool/test/drive_examples_command_test.dart index 85bd4f019a..c9a8b9d90a 100644 --- a/script/tool/test/drive_examples_command_test.dart +++ b/script/tool/test/drive_examples_command_test.dart @@ -4,6 +4,7 @@ import 'package:args/command_runner.dart'; import 'package:file/file.dart'; +import 'package:file/memory.dart'; import 'package:flutter_plugin_tools/src/common.dart'; import 'package:flutter_plugin_tools/src/drive_examples_command.dart'; import 'package:path/path.dart' as p; @@ -14,27 +15,27 @@ import 'util.dart'; void main() { group('test drive_example_command', () { + late FileSystem fileSystem; + late Directory packagesDir; late CommandRunner runner; late RecordingProcessRunner processRunner; final String flutterCommand = const LocalPlatform().isWindows ? 'flutter.bat' : 'flutter'; + setUp(() { - initializeFakePackages(); + fileSystem = MemoryFileSystem(); + packagesDir = createPackagesDirectory(fileSystem: fileSystem); processRunner = RecordingProcessRunner(); final DriveExamplesCommand command = - DriveExamplesCommand(mockPackagesDir, processRunner: processRunner); + DriveExamplesCommand(packagesDir, processRunner: processRunner); runner = CommandRunner( 'drive_examples_command', 'Test for drive_example_command'); runner.addCommand(command); }); - tearDown(() { - cleanupPackages(); - }); - test('driving under folder "test"', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test_driver', 'plugin_test.dart'], ['example', 'test', 'plugin.dart'], @@ -43,7 +44,7 @@ void main() { isAndroidPlugin: true); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); @@ -79,7 +80,7 @@ void main() { }); test('driving under folder "test_driver"', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test_driver', 'plugin_test.dart'], ['example', 'test_driver', 'plugin.dart'], @@ -88,7 +89,7 @@ void main() { isIosPlugin: true); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); @@ -125,7 +126,7 @@ void main() { test('driving under folder "test_driver" when test files are missing"', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test_driver', 'plugin_test.dart'], ], @@ -133,7 +134,7 @@ void main() { isIosPlugin: true); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); @@ -144,7 +145,7 @@ void main() { test('a plugin without any integration test files is reported as an error', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'lib', 'main.dart'], ], @@ -152,7 +153,7 @@ void main() { isIosPlugin: true); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); @@ -164,7 +165,7 @@ void main() { test( 'driving under folder "test_driver" when targets are under "integration_test"', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test_driver', 'integration_test.dart'], ['example', 'integration_test', 'bar_test.dart'], @@ -175,7 +176,7 @@ void main() { isIosPlugin: true); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); @@ -221,7 +222,7 @@ void main() { }); test('driving when plugin does not support Linux is a no-op', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test_driver', 'plugin_test.dart'], ['example', 'test_driver', 'plugin.dart'], @@ -229,7 +230,7 @@ void main() { isMacOsPlugin: false); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); @@ -254,7 +255,7 @@ void main() { }); test('driving on a Linux plugin', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test_driver', 'plugin_test.dart'], ['example', 'test_driver', 'plugin.dart'], @@ -262,7 +263,7 @@ void main() { isLinuxPlugin: true); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); @@ -301,13 +302,14 @@ void main() { }); test('driving when plugin does not suppport macOS is a no-op', () async { - createFakePlugin('plugin', withExtraFiles: >[ - ['example', 'test_driver', 'plugin_test.dart'], - ['example', 'test_driver', 'plugin.dart'], - ]); + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, + withExtraFiles: >[ + ['example', 'test_driver', 'plugin_test.dart'], + ['example', 'test_driver', 'plugin.dart'], + ]); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); @@ -331,7 +333,7 @@ void main() { expect(processRunner.recordedCalls, []); }); test('driving on a macOS plugin', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test_driver', 'plugin_test.dart'], ['example', 'test_driver', 'plugin.dart'], @@ -340,7 +342,7 @@ void main() { isMacOsPlugin: true); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); @@ -379,7 +381,7 @@ void main() { }); test('driving when plugin does not suppport web is a no-op', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test_driver', 'plugin_test.dart'], ['example', 'test_driver', 'plugin.dart'], @@ -387,7 +389,7 @@ void main() { isWebPlugin: false); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); @@ -412,7 +414,7 @@ void main() { }); test('driving a web plugin', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test_driver', 'plugin_test.dart'], ['example', 'test_driver', 'plugin.dart'], @@ -420,7 +422,7 @@ void main() { isWebPlugin: true); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); @@ -461,7 +463,7 @@ void main() { }); test('driving when plugin does not suppport Windows is a no-op', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test_driver', 'plugin_test.dart'], ['example', 'test_driver', 'plugin.dart'], @@ -469,7 +471,7 @@ void main() { isWindowsPlugin: false); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); @@ -494,7 +496,7 @@ void main() { }); test('driving on a Windows plugin', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test_driver', 'plugin_test.dart'], ['example', 'test_driver', 'plugin.dart'], @@ -502,7 +504,7 @@ void main() { isWindowsPlugin: true); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); @@ -541,7 +543,7 @@ void main() { }); test('driving when plugin does not support mobile is no-op', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test_driver', 'plugin_test.dart'], ['example', 'test_driver', 'plugin.dart'], @@ -549,7 +551,7 @@ void main() { isMacOsPlugin: true); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); @@ -573,7 +575,7 @@ void main() { }); test('platform interface plugins are silently skipped', () async { - createFakePlugin('aplugin_platform_interface'); + createFakePlugin('aplugin_platform_interface', packagesDir); final List output = await runCapturingPrint(runner, [ 'drive-examples', @@ -593,7 +595,7 @@ void main() { }); test('enable-experiment flag', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test_driver', 'plugin_test.dart'], ['example', 'test', 'plugin.dart'], @@ -602,7 +604,7 @@ void main() { isAndroidPlugin: true); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); diff --git a/script/tool/test/firebase_test_lab_test.dart b/script/tool/test/firebase_test_lab_test.dart index f8ddc9fa47..74809007c2 100644 --- a/script/tool/test/firebase_test_lab_test.dart +++ b/script/tool/test/firebase_test_lab_test.dart @@ -7,6 +7,8 @@ import 'dart:io'; import 'package:args/command_runner.dart'; +import 'package:file/file.dart'; +import 'package:file/memory.dart'; import 'package:flutter_plugin_tools/src/common.dart'; import 'package:flutter_plugin_tools/src/firebase_test_lab_command.dart'; import 'package:test/test.dart'; @@ -16,15 +18,18 @@ import 'util.dart'; void main() { group('$FirebaseTestLabCommand', () { - final List printedMessages = []; + FileSystem fileSystem; + Directory packagesDir; + List printedMessages; CommandRunner runner; RecordingProcessRunner processRunner; setUp(() { - initializeFakePackages(); + fileSystem = MemoryFileSystem(); + packagesDir = createPackagesDirectory(fileSystem: fileSystem); + printedMessages = []; processRunner = RecordingProcessRunner(); - final FirebaseTestLabCommand command = FirebaseTestLabCommand( - mockPackagesDir, + final FirebaseTestLabCommand command = FirebaseTestLabCommand(packagesDir, processRunner: processRunner, print: (Object message) => printedMessages.add(message.toString())); @@ -33,15 +38,11 @@ void main() { runner.addCommand(command); }); - tearDown(() { - printedMessages.clear(); - }); - test('retries gcloud set', () async { final MockProcess mockProcess = MockProcess(); mockProcess.exitCodeCompleter.complete(1); processRunner.processToReturn = mockProcess; - createFakePlugin('plugin', withExtraFiles: >[ + createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['lib/test/should_not_run_e2e.dart'], ['example', 'test_driver', 'plugin_e2e.dart'], ['example', 'test_driver', 'plugin_e2e_test.dart'], @@ -66,7 +67,7 @@ void main() { }); test('runs e2e tests', () async { - createFakePlugin('plugin', withExtraFiles: >[ + createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['test', 'plugin_test.dart'], ['test', 'plugin_e2e.dart'], ['should_not_run_e2e.dart'], @@ -134,7 +135,7 @@ void main() { '/packages/plugin/example'), ProcessCall( '/packages/plugin/example/android/gradlew', - 'app:assembleDebug -Pverbose=true -Ptarget=/packages/plugin/example/test_driver/plugin_e2e.dart' + 'app:assembleDebug -Pverbose=true -Ptarget=/packages/plugin/example/test/plugin_e2e.dart' .split(' '), '/packages/plugin/example/android'), ProcessCall( @@ -144,7 +145,7 @@ void main() { '/packages/plugin/example'), ProcessCall( '/packages/plugin/example/android/gradlew', - 'app:assembleDebug -Pverbose=true -Ptarget=/packages/plugin/example/test/plugin_e2e.dart' + 'app:assembleDebug -Pverbose=true -Ptarget=/packages/plugin/example/test_driver/plugin_e2e.dart' .split(' '), '/packages/plugin/example/android'), ProcessCall( @@ -167,7 +168,7 @@ void main() { }); test('experimental flag', () async { - createFakePlugin('plugin', withExtraFiles: >[ + createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['test', 'plugin_test.dart'], ['test', 'plugin_e2e.dart'], ['should_not_run_e2e.dart'], @@ -225,7 +226,7 @@ void main() { '/packages/plugin/example'), ProcessCall( '/packages/plugin/example/android/gradlew', - 'app:assembleDebug -Pverbose=true -Ptarget=/packages/plugin/example/test_driver/plugin_e2e.dart -Pextra-front-end-options=--enable-experiment%3Dexp1 -Pextra-gen-snapshot-options=--enable-experiment%3Dexp1' + 'app:assembleDebug -Pverbose=true -Ptarget=/packages/plugin/example/test/plugin_e2e.dart -Pextra-front-end-options=--enable-experiment%3Dexp1 -Pextra-gen-snapshot-options=--enable-experiment%3Dexp1' .split(' '), '/packages/plugin/example/android'), ProcessCall( @@ -235,7 +236,7 @@ void main() { '/packages/plugin/example'), ProcessCall( '/packages/plugin/example/android/gradlew', - 'app:assembleDebug -Pverbose=true -Ptarget=/packages/plugin/example/test/plugin_e2e.dart -Pextra-front-end-options=--enable-experiment%3Dexp1 -Pextra-gen-snapshot-options=--enable-experiment%3Dexp1' + 'app:assembleDebug -Pverbose=true -Ptarget=/packages/plugin/example/test_driver/plugin_e2e.dart -Pextra-front-end-options=--enable-experiment%3Dexp1 -Pextra-gen-snapshot-options=--enable-experiment%3Dexp1' .split(' '), '/packages/plugin/example/android'), ProcessCall( @@ -255,8 +256,6 @@ void main() { '/packages/plugin/example'), ]), ); - - cleanupPackages(); }); }); } diff --git a/script/tool/test/java_test_command_test.dart b/script/tool/test/java_test_command_test.dart index 24e85429c1..a1c2d3b864 100644 --- a/script/tool/test/java_test_command_test.dart +++ b/script/tool/test/java_test_command_test.dart @@ -4,6 +4,7 @@ import 'package:args/command_runner.dart'; import 'package:file/file.dart'; +import 'package:file/memory.dart'; import 'package:flutter_plugin_tools/src/java_test_command.dart'; import 'package:path/path.dart' as p; import 'package:test/test.dart'; @@ -12,27 +13,27 @@ import 'util.dart'; void main() { group('$JavaTestCommand', () { + late FileSystem fileSystem; + late Directory packagesDir; late CommandRunner runner; - final RecordingProcessRunner processRunner = RecordingProcessRunner(); + late RecordingProcessRunner processRunner; setUp(() { - initializeFakePackages(); + fileSystem = MemoryFileSystem(); + packagesDir = createPackagesDirectory(fileSystem: fileSystem); + processRunner = RecordingProcessRunner(); final JavaTestCommand command = - JavaTestCommand(mockPackagesDir, processRunner: processRunner); + JavaTestCommand(packagesDir, processRunner: processRunner); runner = CommandRunner('java_test_test', 'Test for $JavaTestCommand'); runner.addCommand(command); }); - tearDown(() { - cleanupPackages(); - processRunner.recordedCalls.clear(); - }); - test('Should run Java tests in Android implementation folder', () async { final Directory plugin = createFakePlugin( 'plugin1', + packagesDir, isAndroidPlugin: true, isFlutter: true, withSingleExample: true, @@ -59,6 +60,7 @@ void main() { test('Should run Java tests in example folder', () async { final Directory plugin = createFakePlugin( 'plugin1', + packagesDir, isAndroidPlugin: true, isFlutter: true, withSingleExample: true, diff --git a/script/tool/test/lint_podspecs_command_test.dart b/script/tool/test/lint_podspecs_command_test.dart index 4cb416f0ba..349607b0ca 100644 --- a/script/tool/test/lint_podspecs_command_test.dart +++ b/script/tool/test/lint_podspecs_command_test.dart @@ -6,6 +6,7 @@ import 'package:args/command_runner.dart'; import 'package:file/file.dart'; +import 'package:file/memory.dart'; import 'package:flutter_plugin_tools/src/lint_podspecs_command.dart'; import 'package:mockito/mockito.dart'; import 'package:path/path.dart' as p; @@ -17,19 +18,22 @@ import 'util.dart'; void main() { group('$LintPodspecsCommand', () { + FileSystem fileSystem; + Directory packagesDir; CommandRunner runner; MockPlatform mockPlatform; final RecordingProcessRunner processRunner = RecordingProcessRunner(); List printedMessages; setUp(() { - initializeFakePackages(); + fileSystem = MemoryFileSystem(); + packagesDir = createPackagesDirectory(fileSystem: fileSystem); printedMessages = []; mockPlatform = MockPlatform(); when(mockPlatform.isMacOS).thenReturn(true); final LintPodspecsCommand command = LintPodspecsCommand( - mockPackagesDir, + packagesDir, processRunner: processRunner, platform: mockPlatform, print: (Object message) => printedMessages.add(message.toString()), @@ -44,12 +48,8 @@ void main() { processRunner.recordedCalls.clear(); }); - tearDown(() { - cleanupPackages(); - }); - test('only runs on macOS', () async { - createFakePlugin('plugin1', withExtraFiles: >[ + createFakePlugin('plugin1', packagesDir, withExtraFiles: >[ ['plugin1.podspec'], ]); @@ -63,11 +63,11 @@ void main() { }); test('runs pod lib lint on a podspec', () async { - final Directory plugin1Dir = - createFakePlugin('plugin1', withExtraFiles: >[ - ['ios', 'plugin1.podspec'], - ['bogus.dart'], // Ignore non-podspecs. - ]); + final Directory plugin1Dir = createFakePlugin('plugin1', packagesDir, + withExtraFiles: >[ + ['ios', 'plugin1.podspec'], + ['bogus.dart'], // Ignore non-podspecs. + ]); processRunner.resultStdout = 'Foo'; processRunner.resultStderr = 'Bar'; @@ -77,7 +77,7 @@ void main() { expect( processRunner.recordedCalls, orderedEquals([ - ProcessCall('which', const ['pod'], mockPackagesDir.path), + ProcessCall('which', const ['pod'], packagesDir.path), ProcessCall( 'pod', [ @@ -89,7 +89,7 @@ void main() { '--use-modular-headers', '--use-libraries' ], - mockPackagesDir.path), + packagesDir.path), ProcessCall( 'pod', [ @@ -100,7 +100,7 @@ void main() { '--skip-tests', '--use-modular-headers', ], - mockPackagesDir.path), + packagesDir.path), ]), ); @@ -110,10 +110,10 @@ void main() { }); test('skips podspecs with known issues', () async { - createFakePlugin('plugin1', withExtraFiles: >[ + createFakePlugin('plugin1', packagesDir, withExtraFiles: >[ ['plugin1.podspec'] ]); - createFakePlugin('plugin2', withExtraFiles: >[ + createFakePlugin('plugin2', packagesDir, withExtraFiles: >[ ['plugin2.podspec'] ]); @@ -123,23 +123,23 @@ void main() { expect( processRunner.recordedCalls, orderedEquals([ - ProcessCall('which', const ['pod'], mockPackagesDir.path), + ProcessCall('which', const ['pod'], packagesDir.path), ]), ); }); test('allow warnings for podspecs with known warnings', () async { - final Directory plugin1Dir = - createFakePlugin('plugin1', withExtraFiles: >[ - ['plugin1.podspec'], - ]); + final Directory plugin1Dir = createFakePlugin('plugin1', packagesDir, + withExtraFiles: >[ + ['plugin1.podspec'], + ]); await runner.run(['podspecs', '--ignore-warnings=plugin1']); expect( processRunner.recordedCalls, orderedEquals([ - ProcessCall('which', const ['pod'], mockPackagesDir.path), + ProcessCall('which', const ['pod'], packagesDir.path), ProcessCall( 'pod', [ @@ -152,7 +152,7 @@ void main() { '--allow-warnings', '--use-libraries' ], - mockPackagesDir.path), + packagesDir.path), ProcessCall( 'pod', [ @@ -164,7 +164,7 @@ void main() { '--use-modular-headers', '--allow-warnings', ], - mockPackagesDir.path), + packagesDir.path), ]), ); diff --git a/script/tool/test/list_command_test.dart b/script/tool/test/list_command_test.dart index ca0dbc614e..02b898c5c3 100644 --- a/script/tool/test/list_command_test.dart +++ b/script/tool/test/list_command_test.dart @@ -4,6 +4,7 @@ import 'package:args/command_runner.dart'; import 'package:file/file.dart'; +import 'package:file/memory.dart'; import 'package:flutter_plugin_tools/src/list_command.dart'; import 'package:test/test.dart'; @@ -11,19 +12,22 @@ import 'util.dart'; void main() { group('$ListCommand', () { + late FileSystem fileSystem; + late Directory packagesDir; late CommandRunner runner; setUp(() { - initializeFakePackages(); - final ListCommand command = ListCommand(mockPackagesDir); + fileSystem = MemoryFileSystem(); + packagesDir = createPackagesDirectory(fileSystem: fileSystem); + final ListCommand command = ListCommand(packagesDir); runner = CommandRunner('list_test', 'Test for $ListCommand'); runner.addCommand(command); }); test('lists plugins', () async { - createFakePlugin('plugin1'); - createFakePlugin('plugin2'); + createFakePlugin('plugin1', packagesDir); + createFakePlugin('plugin2', packagesDir); final List plugins = await runCapturingPrint(runner, ['list', '--type=plugin']); @@ -35,15 +39,13 @@ void main() { '/packages/plugin2', ]), ); - - cleanupPackages(); }); test('lists examples', () async { - createFakePlugin('plugin1', withSingleExample: true); - createFakePlugin('plugin2', + createFakePlugin('plugin1', packagesDir, withSingleExample: true); + createFakePlugin('plugin2', packagesDir, withExamples: ['example1', 'example2']); - createFakePlugin('plugin3'); + createFakePlugin('plugin3', packagesDir); final List examples = await runCapturingPrint(runner, ['list', '--type=example']); @@ -56,15 +58,13 @@ void main() { '/packages/plugin2/example/example2', ]), ); - - cleanupPackages(); }); test('lists packages', () async { - createFakePlugin('plugin1', withSingleExample: true); - createFakePlugin('plugin2', + createFakePlugin('plugin1', packagesDir, withSingleExample: true); + createFakePlugin('plugin2', packagesDir, withExamples: ['example1', 'example2']); - createFakePlugin('plugin3'); + createFakePlugin('plugin3', packagesDir); final List packages = await runCapturingPrint(runner, ['list', '--type=package']); @@ -80,15 +80,13 @@ void main() { '/packages/plugin3', ]), ); - - cleanupPackages(); }); test('lists files', () async { - createFakePlugin('plugin1', withSingleExample: true); - createFakePlugin('plugin2', + createFakePlugin('plugin1', packagesDir, withSingleExample: true); + createFakePlugin('plugin2', packagesDir, withExamples: ['example1', 'example2']); - createFakePlugin('plugin3'); + createFakePlugin('plugin3', packagesDir); final List examples = await runCapturingPrint(runner, ['list', '--type=file']); @@ -104,17 +102,15 @@ void main() { '/packages/plugin3/pubspec.yaml', ]), ); - - cleanupPackages(); }); test('lists plugins using federated plugin layout', () async { - createFakePlugin('plugin1'); + createFakePlugin('plugin1', packagesDir); // Create a federated plugin by creating a directory under the packages // directory with several packages underneath. - final Directory federatedPlugin = - mockPackagesDir.childDirectory('my_plugin')..createSync(); + final Directory federatedPlugin = packagesDir.childDirectory('my_plugin') + ..createSync(); final Directory clientLibrary = federatedPlugin.childDirectory('my_plugin')..createSync(); createFakePubspec(clientLibrary); @@ -138,17 +134,15 @@ void main() { '/packages/my_plugin/my_plugin_macos', ]), ); - - cleanupPackages(); }); test('can filter plugins with the --plugins argument', () async { - createFakePlugin('plugin1'); + createFakePlugin('plugin1', packagesDir); // Create a federated plugin by creating a directory under the packages // directory with several packages underneath. - final Directory federatedPlugin = - mockPackagesDir.childDirectory('my_plugin')..createSync(); + final Directory federatedPlugin = packagesDir.childDirectory('my_plugin') + ..createSync(); final Directory clientLibrary = federatedPlugin.childDirectory('my_plugin')..createSync(); createFakePubspec(clientLibrary); diff --git a/script/tool/test/publish_check_command_test.dart b/script/tool/test/publish_check_command_test.dart index cccff19de5..6d36031a26 100644 --- a/script/tool/test/publish_check_command_test.dart +++ b/script/tool/test/publish_check_command_test.dart @@ -10,6 +10,7 @@ import 'dart:io' as io; import 'package:args/command_runner.dart'; import 'package:file/file.dart'; +import 'package:file/memory.dart'; import 'package:flutter_plugin_tools/src/common.dart'; import 'package:flutter_plugin_tools/src/publish_check_command.dart'; import 'package:http/http.dart' as http; @@ -21,14 +22,17 @@ import 'util.dart'; void main() { group('$PublishCheckProcessRunner tests', () { + FileSystem fileSystem; + Directory packagesDir; PublishCheckProcessRunner processRunner; CommandRunner runner; setUp(() { - initializeFakePackages(); + fileSystem = MemoryFileSystem(); + packagesDir = createPackagesDirectory(fileSystem: fileSystem); processRunner = PublishCheckProcessRunner(); final PublishCheckCommand publishCheckCommand = - PublishCheckCommand(mockPackagesDir, processRunner: processRunner); + PublishCheckCommand(packagesDir, processRunner: processRunner); runner = CommandRunner( 'publish_check_command', @@ -37,13 +41,9 @@ void main() { runner.addCommand(publishCheckCommand); }); - tearDown(() { - mockPackagesDir.deleteSync(recursive: true); - }); - test('publish check all packages', () async { - final Directory plugin1Dir = createFakePlugin('a'); - final Directory plugin2Dir = createFakePlugin('b'); + final Directory plugin1Dir = createFakePlugin('a', packagesDir); + final Directory plugin2Dir = createFakePlugin('b', packagesDir); processRunner.processesToReturn.add( MockProcess()..exitCodeCompleter.complete(0), @@ -68,7 +68,7 @@ void main() { }); test('fail on negative test', () async { - createFakePlugin('a'); + createFakePlugin('a', packagesDir); final MockProcess process = MockProcess(); process.stdoutController.close(); // ignore: unawaited_futures @@ -84,7 +84,7 @@ void main() { }); test('fail on bad pubspec', () async { - final Directory dir = createFakePlugin('c'); + final Directory dir = createFakePlugin('c', packagesDir); await dir.childFile('pubspec.yaml').writeAsString('bad-yaml'); final MockProcess process = MockProcess(); @@ -95,7 +95,7 @@ void main() { }); test('pass on prerelease if --allow-pre-release flag is on', () async { - createFakePlugin('d'); + createFakePlugin('d', packagesDir); const String preReleaseOutput = 'Package has 1 warning.' 'Packages with an SDK constraint on a pre-release of the Dart SDK should themselves be published as a pre-release version.'; @@ -114,7 +114,7 @@ void main() { }); test('fail on prerelease if --allow-pre-release flag is off', () async { - createFakePlugin('d'); + createFakePlugin('d', packagesDir); const String preReleaseOutput = 'Package has 1 warning.' 'Packages with an SDK constraint on a pre-release of the Dart SDK should themselves be published as a pre-release version.'; @@ -132,7 +132,7 @@ void main() { }); test('Success message on stderr is not printed as an error', () async { - createFakePlugin('d'); + createFakePlugin('d', packagesDir); const String publishOutput = 'Package has 0 warnings.'; @@ -179,7 +179,7 @@ void main() { } return null; }); - final PublishCheckCommand command = PublishCheckCommand(mockPackagesDir, + final PublishCheckCommand command = PublishCheckCommand(packagesDir, processRunner: processRunner, httpClient: mockClient); runner = CommandRunner( @@ -189,9 +189,9 @@ void main() { runner.addCommand(command); final Directory plugin1Dir = - createFakePlugin('no_publish_a', includeVersion: true); + createFakePlugin('no_publish_a', packagesDir, includeVersion: true); final Directory plugin2Dir = - createFakePlugin('no_publish_b', includeVersion: true); + createFakePlugin('no_publish_b', packagesDir, includeVersion: true); createFakePubspec(plugin1Dir, name: 'no_publish_a', includeVersion: true, version: '0.1.0'); @@ -245,7 +245,7 @@ void main() { } return null; }); - final PublishCheckCommand command = PublishCheckCommand(mockPackagesDir, + final PublishCheckCommand command = PublishCheckCommand(packagesDir, processRunner: processRunner, httpClient: mockClient); runner = CommandRunner( @@ -255,9 +255,9 @@ void main() { runner.addCommand(command); final Directory plugin1Dir = - createFakePlugin('no_publish_a', includeVersion: true); + createFakePlugin('no_publish_a', packagesDir, includeVersion: true); final Directory plugin2Dir = - createFakePlugin('no_publish_b', includeVersion: true); + createFakePlugin('no_publish_b', packagesDir, includeVersion: true); createFakePubspec(plugin1Dir, name: 'no_publish_a', includeVersion: true, version: '0.1.0'); @@ -314,7 +314,7 @@ void main() { } return null; }); - final PublishCheckCommand command = PublishCheckCommand(mockPackagesDir, + final PublishCheckCommand command = PublishCheckCommand(packagesDir, processRunner: processRunner, httpClient: mockClient); runner = CommandRunner( @@ -324,9 +324,9 @@ void main() { runner.addCommand(command); final Directory plugin1Dir = - createFakePlugin('no_publish_a', includeVersion: true); + createFakePlugin('no_publish_a', packagesDir, includeVersion: true); final Directory plugin2Dir = - createFakePlugin('no_publish_b', includeVersion: true); + createFakePlugin('no_publish_b', packagesDir, includeVersion: true); createFakePubspec(plugin1Dir, name: 'no_publish_a', includeVersion: true, version: '0.1.0'); diff --git a/script/tool/test/publish_plugin_command_test.dart b/script/tool/test/publish_plugin_command_test.dart index 1bf6ab7bbe..570ceb234a 100644 --- a/script/tool/test/publish_plugin_command_test.dart +++ b/script/tool/test/publish_plugin_command_test.dart @@ -22,9 +22,10 @@ import 'util.dart'; void main() { const String testPluginName = 'foo'; - final List printedMessages = []; + List printedMessages; - Directory parentDir; + Directory testRoot; + Directory packagesDir; Directory pluginDir; GitDir gitDir; TestProcessRunner processRunner; @@ -43,34 +44,34 @@ void main() { } setUp(() async { - parentDir = fileSystem.systemTempDirectory + testRoot = fileSystem.systemTempDirectory .createTempSync('publish_plugin_command_test-'); // The temp directory can have symbolic links, which won't match git output; // use a fully resolved version to avoid potential path comparison issues. - parentDir = fileSystem.directory(parentDir.resolveSymbolicLinksSync()); - initializeFakePackages(parentDir: parentDir); - pluginDir = createFakePlugin(testPluginName, - withSingleExample: false, packagesDirectory: parentDir); + testRoot = fileSystem.directory(testRoot.resolveSymbolicLinksSync()); + packagesDir = createPackagesDirectory(parentDir: testRoot); + pluginDir = + createFakePlugin(testPluginName, packagesDir, withSingleExample: false); assert(pluginDir != null && pluginDir.existsSync()); createFakePubspec(pluginDir, includeVersion: true); io.Process.runSync('git', ['init'], - workingDirectory: parentDir.path); - gitDir = await GitDir.fromExisting(parentDir.path); + workingDirectory: testRoot.path); + gitDir = await GitDir.fromExisting(testRoot.path); await gitDir.runCommand(['add', '-A']); await gitDir.runCommand(['commit', '-m', 'Initial commit']); processRunner = TestProcessRunner(); mockStdin = MockStdin(); + printedMessages = []; commandRunner = CommandRunner('tester', '') - ..addCommand(PublishPluginCommand(parentDir, + ..addCommand(PublishPluginCommand(packagesDir, processRunner: processRunner, print: (Object message) => printedMessages.add(message.toString()), stdinput: mockStdin, - gitDir: await GitDir.fromExisting(parentDir.path))); + gitDir: gitDir)); }); tearDown(() { - parentDir.deleteSync(recursive: true); - printedMessages.clear(); + testRoot.deleteSync(recursive: true); }); group('Initial validation', () { @@ -109,7 +110,7 @@ void main() { expect( printedMessages, containsAllInOrder([ - 'There are files in the package directory that haven\'t been saved in git. Refusing to publish these files:\n\n?? foo/tmp\n\nIf the directory should be clean, you can run `git clean -xdf && git reset --hard HEAD` to wipe all local changes.', + 'There are files in the package directory that haven\'t been saved in git. Refusing to publish these files:\n\n?? packages/foo/tmp\n\nIf the directory should be clean, you can run `git clean -xdf && git reset --hard HEAD` to wipe all local changes.', 'Failed, see above for details.', ])); }); @@ -140,8 +141,8 @@ void main() { test('can publish non-flutter package', () async { createFakePubspec(pluginDir, includeVersion: true, isFlutter: false); io.Process.runSync('git', ['init'], - workingDirectory: parentDir.path); - gitDir = await GitDir.fromExisting(parentDir.path); + workingDirectory: testRoot.path); + gitDir = await GitDir.fromExisting(testRoot.path); await gitDir.runCommand(['add', '-A']); await gitDir.runCommand(['commit', '-m', 'Initial commit']); // Immediately return 0 when running `pub publish`. @@ -420,21 +421,19 @@ void main() { group('Auto release (all-changed flag)', () { setUp(() async { io.Process.runSync('git', ['init'], - workingDirectory: parentDir.path); - gitDir = await GitDir.fromExisting(parentDir.path); + workingDirectory: testRoot.path); + gitDir = await GitDir.fromExisting(testRoot.path); await gitDir.runCommand( ['remote', 'add', 'upstream', 'http://localhost:8000']); }); test('can release newly created plugins', () async { // Non-federated - final Directory pluginDir1 = createFakePlugin('plugin1', - withSingleExample: true, packagesDirectory: parentDir); + final Directory pluginDir1 = + createFakePlugin('plugin1', packagesDir, withSingleExample: true); // federated - final Directory pluginDir2 = createFakePlugin('plugin2', - withSingleExample: true, - parentDirectoryName: 'plugin2', - packagesDirectory: parentDir); + final Directory pluginDir2 = createFakePlugin('plugin2', packagesDir, + withSingleExample: true, parentDirectoryName: 'plugin2'); createFakePubspec(pluginDir1, name: 'plugin1', includeVersion: true, @@ -475,8 +474,8 @@ void main() { test('can release newly created plugins, while there are existing plugins', () async { // Prepare an exiting plugin and tag it - final Directory pluginDir0 = createFakePlugin('plugin0', - withSingleExample: true, packagesDirectory: parentDir); + final Directory pluginDir0 = + createFakePlugin('plugin0', packagesDir, withSingleExample: true); createFakePubspec(pluginDir0, name: 'plugin0', includeVersion: true, @@ -492,13 +491,11 @@ void main() { processRunner.pushTagsArgs.clear(); // Non-federated - final Directory pluginDir1 = createFakePlugin('plugin1', - withSingleExample: true, packagesDirectory: parentDir); + final Directory pluginDir1 = + createFakePlugin('plugin1', packagesDir, withSingleExample: true); // federated - final Directory pluginDir2 = createFakePlugin('plugin2', - withSingleExample: true, - parentDirectoryName: 'plugin2', - packagesDirectory: parentDir); + final Directory pluginDir2 = createFakePlugin('plugin2', packagesDir, + withSingleExample: true, parentDirectoryName: 'plugin2'); createFakePubspec(pluginDir1, name: 'plugin1', includeVersion: true, @@ -536,13 +533,11 @@ void main() { test('can release newly created plugins, dry run', () async { // Non-federated - final Directory pluginDir1 = createFakePlugin('plugin1', - withSingleExample: true, packagesDirectory: parentDir); + final Directory pluginDir1 = + createFakePlugin('plugin1', packagesDir, withSingleExample: true); // federated - final Directory pluginDir2 = createFakePlugin('plugin2', - withSingleExample: true, - parentDirectoryName: 'plugin2', - packagesDirectory: parentDir); + final Directory pluginDir2 = createFakePlugin('plugin2', packagesDir, + withSingleExample: true, parentDirectoryName: 'plugin2'); createFakePubspec(pluginDir1, name: 'plugin1', includeVersion: true, @@ -585,13 +580,11 @@ void main() { test('version change triggers releases.', () async { // Non-federated - final Directory pluginDir1 = createFakePlugin('plugin1', - withSingleExample: true, packagesDirectory: parentDir); + final Directory pluginDir1 = + createFakePlugin('plugin1', packagesDir, withSingleExample: true); // federated - final Directory pluginDir2 = createFakePlugin('plugin2', - withSingleExample: true, - parentDirectoryName: 'plugin2', - packagesDirectory: parentDir); + final Directory pluginDir2 = createFakePlugin('plugin2', packagesDir, + withSingleExample: true, parentDirectoryName: 'plugin2'); createFakePubspec(pluginDir1, name: 'plugin1', includeVersion: true, @@ -676,13 +669,11 @@ void main() { 'delete package will not trigger publish but exit the command successfully.', () async { // Non-federated - final Directory pluginDir1 = createFakePlugin('plugin1', - withSingleExample: true, packagesDirectory: parentDir); + final Directory pluginDir1 = + createFakePlugin('plugin1', packagesDir, withSingleExample: true); // federated - final Directory pluginDir2 = createFakePlugin('plugin2', - withSingleExample: true, - parentDirectoryName: 'plugin2', - packagesDirectory: parentDir); + final Directory pluginDir2 = createFakePlugin('plugin2', packagesDir, + withSingleExample: true, parentDirectoryName: 'plugin2'); createFakePubspec(pluginDir1, name: 'plugin1', includeVersion: true, @@ -764,13 +755,11 @@ void main() { 'versions revert do not trigger releases. Also prints out warning message.', () async { // Non-federated - final Directory pluginDir1 = createFakePlugin('plugin1', - withSingleExample: true, packagesDirectory: parentDir); + final Directory pluginDir1 = + createFakePlugin('plugin1', packagesDir, withSingleExample: true); // federated - final Directory pluginDir2 = createFakePlugin('plugin2', - withSingleExample: true, - parentDirectoryName: 'plugin2', - packagesDirectory: parentDir); + final Directory pluginDir2 = createFakePlugin('plugin2', packagesDir, + withSingleExample: true, parentDirectoryName: 'plugin2'); createFakePubspec(pluginDir1, name: 'plugin1', includeVersion: true, @@ -846,13 +835,11 @@ void main() { test('No version change does not release any plugins', () async { // Non-federated - final Directory pluginDir1 = createFakePlugin('plugin1', - withSingleExample: true, packagesDirectory: parentDir); + final Directory pluginDir1 = + createFakePlugin('plugin1', packagesDir, withSingleExample: true); // federated - final Directory pluginDir2 = createFakePlugin('plugin2', - withSingleExample: true, - parentDirectoryName: 'plugin2', - packagesDirectory: parentDir); + final Directory pluginDir2 = createFakePlugin('plugin2', packagesDir, + withSingleExample: true, parentDirectoryName: 'plugin2'); createFakePubspec(pluginDir1, name: 'plugin1', includeVersion: true, @@ -865,8 +852,8 @@ void main() { version: '0.0.1'); io.Process.runSync('git', ['init'], - workingDirectory: parentDir.path); - gitDir = await GitDir.fromExisting(parentDir.path); + workingDirectory: testRoot.path); + gitDir = await GitDir.fromExisting(testRoot.path); await gitDir.runCommand(['add', '-A']); await gitDir.runCommand(['commit', '-m', 'Add plugins']); diff --git a/script/tool/test/pubspec_check_command_test.dart b/script/tool/test/pubspec_check_command_test.dart index e1b1d36497..576060d23a 100644 --- a/script/tool/test/pubspec_check_command_test.dart +++ b/script/tool/test/pubspec_check_command_test.dart @@ -21,7 +21,7 @@ void main() { setUp(() { fileSystem = MemoryFileSystem(); packagesDir = fileSystem.currentDirectory.childDirectory('packages'); - initializeFakePackages(parentDir: packagesDir.parent); + createPackagesDirectory(parentDir: packagesDir.parent); processRunner = RecordingProcessRunner(); final PubspecCheckCommand command = PubspecCheckCommand(packagesDir, processRunner: processRunner); @@ -88,8 +88,8 @@ dev_dependencies: } test('passes for a plugin following conventions', () async { - final Directory pluginDirectory = createFakePlugin('plugin', - withSingleExample: true, packagesDirectory: packagesDir); + final Directory pluginDirectory = + createFakePlugin('plugin', packagesDir, withSingleExample: true); pluginDirectory.childFile('pubspec.yaml').writeAsStringSync(''' ${headerSection('plugin', isPlugin: true)} @@ -114,8 +114,8 @@ ${devDependenciesSection()} }); test('passes for a Flutter package following conventions', () async { - final Directory pluginDirectory = createFakePlugin('plugin', - withSingleExample: true, packagesDirectory: packagesDir); + final Directory pluginDirectory = + createFakePlugin('plugin', packagesDir, withSingleExample: true); pluginDirectory.childFile('pubspec.yaml').writeAsStringSync(''' ${headerSection('plugin')} @@ -163,8 +163,8 @@ ${dependenciesSection()} }); test('fails when homepage is included', () async { - final Directory pluginDirectory = createFakePlugin('plugin', - withSingleExample: true, packagesDirectory: packagesDir); + final Directory pluginDirectory = + createFakePlugin('plugin', packagesDir, withSingleExample: true); pluginDirectory.childFile('pubspec.yaml').writeAsStringSync(''' ${headerSection('plugin', isPlugin: true, includeHomepage: true)} @@ -184,8 +184,8 @@ ${devDependenciesSection()} }); test('fails when repository is missing', () async { - final Directory pluginDirectory = createFakePlugin('plugin', - withSingleExample: true, packagesDirectory: packagesDir); + final Directory pluginDirectory = + createFakePlugin('plugin', packagesDir, withSingleExample: true); pluginDirectory.childFile('pubspec.yaml').writeAsStringSync(''' ${headerSection('plugin', isPlugin: true, includeRepository: false)} @@ -205,8 +205,8 @@ ${devDependenciesSection()} }); test('fails when homepage is given instead of repository', () async { - final Directory pluginDirectory = createFakePlugin('plugin', - withSingleExample: true, packagesDirectory: packagesDir); + final Directory pluginDirectory = + createFakePlugin('plugin', packagesDir, withSingleExample: true); pluginDirectory.childFile('pubspec.yaml').writeAsStringSync(''' ${headerSection('plugin', isPlugin: true, includeHomepage: true, includeRepository: false)} @@ -226,8 +226,8 @@ ${devDependenciesSection()} }); test('fails when issue tracker is missing', () async { - final Directory pluginDirectory = createFakePlugin('plugin', - withSingleExample: true, packagesDirectory: packagesDir); + final Directory pluginDirectory = + createFakePlugin('plugin', packagesDir, withSingleExample: true); pluginDirectory.childFile('pubspec.yaml').writeAsStringSync(''' ${headerSection('plugin', isPlugin: true, includeIssueTracker: false)} @@ -247,8 +247,8 @@ ${devDependenciesSection()} }); test('fails when environment section is out of order', () async { - final Directory pluginDirectory = createFakePlugin('plugin', - withSingleExample: true, packagesDirectory: packagesDir); + final Directory pluginDirectory = + createFakePlugin('plugin', packagesDir, withSingleExample: true); pluginDirectory.childFile('pubspec.yaml').writeAsStringSync(''' ${headerSection('plugin', isPlugin: true)} @@ -268,8 +268,8 @@ ${environmentSection()} }); test('fails when flutter section is out of order', () async { - final Directory pluginDirectory = createFakePlugin('plugin', - withSingleExample: true, packagesDirectory: packagesDir); + final Directory pluginDirectory = + createFakePlugin('plugin', packagesDir, withSingleExample: true); pluginDirectory.childFile('pubspec.yaml').writeAsStringSync(''' ${headerSection('plugin', isPlugin: true)} @@ -289,8 +289,8 @@ ${devDependenciesSection()} }); test('fails when dependencies section is out of order', () async { - final Directory pluginDirectory = createFakePlugin('plugin', - withSingleExample: true, packagesDirectory: packagesDir); + final Directory pluginDirectory = + createFakePlugin('plugin', packagesDir, withSingleExample: true); pluginDirectory.childFile('pubspec.yaml').writeAsStringSync(''' ${headerSection('plugin', isPlugin: true)} @@ -310,8 +310,8 @@ ${dependenciesSection()} }); test('fails when devDependencies section is out of order', () async { - final Directory pluginDirectory = createFakePlugin('plugin', - withSingleExample: true, packagesDirectory: packagesDir); + final Directory pluginDirectory = + createFakePlugin('plugin', packagesDir, withSingleExample: true); pluginDirectory.childFile('pubspec.yaml').writeAsStringSync(''' ${headerSection('plugin', isPlugin: true)} diff --git a/script/tool/test/test_command_test.dart b/script/tool/test/test_command_test.dart index 61c06e0af1..5cbbdf5b8d 100644 --- a/script/tool/test/test_command_test.dart +++ b/script/tool/test/test_command_test.dart @@ -4,6 +4,7 @@ import 'package:args/command_runner.dart'; import 'package:file/file.dart'; +import 'package:file/memory.dart'; import 'package:flutter_plugin_tools/src/test_command.dart'; import 'package:test/test.dart'; @@ -11,32 +12,31 @@ import 'util.dart'; void main() { group('$TestCommand', () { + late FileSystem fileSystem; + late Directory packagesDir; late CommandRunner runner; - final RecordingProcessRunner processRunner = RecordingProcessRunner(); + late RecordingProcessRunner processRunner; setUp(() { - initializeFakePackages(); + fileSystem = MemoryFileSystem(); + packagesDir = createPackagesDirectory(fileSystem: fileSystem); + processRunner = RecordingProcessRunner(); final TestCommand command = - TestCommand(mockPackagesDir, processRunner: processRunner); + TestCommand(packagesDir, processRunner: processRunner); runner = CommandRunner('test_test', 'Test for $TestCommand'); runner.addCommand(command); }); - tearDown(() { - cleanupPackages(); - processRunner.recordedCalls.clear(); - }); - test('runs flutter test on each plugin', () async { - final Directory plugin1Dir = - createFakePlugin('plugin1', withExtraFiles: >[ - ['test', 'empty_test.dart'], - ]); - final Directory plugin2Dir = - createFakePlugin('plugin2', withExtraFiles: >[ - ['test', 'empty_test.dart'], - ]); + final Directory plugin1Dir = createFakePlugin('plugin1', packagesDir, + withExtraFiles: >[ + ['test', 'empty_test.dart'], + ]); + final Directory plugin2Dir = createFakePlugin('plugin2', packagesDir, + withExtraFiles: >[ + ['test', 'empty_test.dart'], + ]); await runner.run(['test']); @@ -49,16 +49,14 @@ void main() { 'flutter', const ['test', '--color'], plugin2Dir.path), ]), ); - - cleanupPackages(); }); test('skips testing plugins without test directory', () async { - createFakePlugin('plugin1'); - final Directory plugin2Dir = - createFakePlugin('plugin2', withExtraFiles: >[ - ['test', 'empty_test.dart'], - ]); + createFakePlugin('plugin1', packagesDir); + final Directory plugin2Dir = createFakePlugin('plugin2', packagesDir, + withExtraFiles: >[ + ['test', 'empty_test.dart'], + ]); await runner.run(['test']); @@ -69,17 +67,15 @@ void main() { 'flutter', const ['test', '--color'], plugin2Dir.path), ]), ); - - cleanupPackages(); }); test('runs pub run test on non-Flutter packages', () async { - final Directory plugin1Dir = createFakePlugin('plugin1', + final Directory plugin1Dir = createFakePlugin('plugin1', packagesDir, isFlutter: true, withExtraFiles: >[ ['test', 'empty_test.dart'], ]); - final Directory plugin2Dir = createFakePlugin('plugin2', + final Directory plugin2Dir = createFakePlugin('plugin2', packagesDir, isFlutter: false, withExtraFiles: >[ ['test', 'empty_test.dart'], @@ -101,13 +97,12 @@ void main() { plugin2Dir.path), ]), ); - - cleanupPackages(); }); test('runs on Chrome for web plugins', () async { final Directory pluginDir = createFakePlugin( 'plugin', + packagesDir, withExtraFiles: >[ ['test', 'empty_test.dart'], ], @@ -129,12 +124,12 @@ void main() { }); test('enable-experiment flag', () async { - final Directory plugin1Dir = createFakePlugin('plugin1', + final Directory plugin1Dir = createFakePlugin('plugin1', packagesDir, isFlutter: true, withExtraFiles: >[ ['test', 'empty_test.dart'], ]); - final Directory plugin2Dir = createFakePlugin('plugin2', + final Directory plugin2Dir = createFakePlugin('plugin2', packagesDir, isFlutter: false, withExtraFiles: >[ ['test', 'empty_test.dart'], @@ -156,8 +151,6 @@ void main() { plugin2Dir.path), ]), ); - - cleanupPackages(); }); }); } diff --git a/script/tool/test/util.dart b/script/tool/test/util.dart index 7d4278f68c..a0a316f95d 100644 --- a/script/tool/test/util.dart +++ b/script/tool/test/util.dart @@ -11,32 +11,29 @@ import 'package:file/file.dart'; import 'package:file/memory.dart'; import 'package:flutter_plugin_tools/src/common.dart'; import 'package:meta/meta.dart'; -import 'package:platform/platform.dart'; import 'package:quiver/collection.dart'; -// TODO(stuartmorgan): Eliminate this in favor of setting up a clean filesystem -// for each test, to eliminate the chance of files from one test interfering -// with another test. -FileSystem mockFileSystem = MemoryFileSystem( - style: const LocalPlatform().isWindows - ? FileSystemStyle.windows - : FileSystemStyle.posix); -late Directory mockPackagesDir; - -/// Creates a mock packages directory in the mock file system. +/// Creates a packages directory in the given location. /// -/// If [parentDir] is set the mock packages dir will be creates as a child of -/// it. If not [mockFileSystem] will be used instead. -void initializeFakePackages({Directory? parentDir}) { - mockPackagesDir = - (parentDir ?? mockFileSystem.currentDirectory).childDirectory('packages'); - mockPackagesDir.createSync(); +/// If [parentDir] is set the packages directory will be created there, +/// otherwise [fileSystem] must be provided and it will be created an arbitrary +/// location in that filesystem. +Directory createPackagesDirectory( + {Directory? parentDir, FileSystem? fileSystem}) { + assert(parentDir != null || fileSystem != null, + 'One of parentDir or fileSystem must be provided'); + assert(fileSystem == null || fileSystem is MemoryFileSystem, + 'If using a real filesystem, parentDir must be provided'); + final Directory packagesDir = + (parentDir ?? fileSystem!.currentDirectory).childDirectory('packages'); + packagesDir.createSync(); + return packagesDir; } -/// Creates a plugin package with the given [name] in [packagesDirectory], -/// defaulting to [mockPackagesDir]. +/// Creates a plugin package with the given [name] in [packagesDirectory]. Directory createFakePlugin( - String name, { + String name, + Directory packagesDirectory, { bool withSingleExample = false, List withExamples = const [], List> withExtraFiles = const >[], @@ -51,12 +48,11 @@ Directory createFakePlugin( bool includeVersion = false, String version = '0.0.1', String parentDirectoryName = '', - Directory? packagesDirectory, }) { assert(!(withSingleExample && withExamples.isNotEmpty), 'cannot pass withSingleExample and withExamples simultaneously'); - Directory parentDirectory = packagesDirectory ?? mockPackagesDir; + Directory parentDirectory = packagesDirectory; if (parentDirectoryName != '') { parentDirectory = parentDirectory.childDirectory(parentDirectoryName); } @@ -198,13 +194,6 @@ publish_to: $publishTo # Hardcoded safeguard to prevent this from somehow being parent.childFile('pubspec.yaml').writeAsStringSync(yaml); } -/// Cleans up the mock packages directory, making it an empty directory again. -void cleanupPackages() { - mockPackagesDir.listSync().forEach((FileSystemEntity entity) { - entity.deleteSync(recursive: true); - }); -} - typedef _ErrorHandler = void Function(Error error); /// Run the command [runner] with the given [args] and return diff --git a/script/tool/test/version_check_test.dart b/script/tool/test/version_check_test.dart index 600d9a08c3..ec76ceba8e 100644 --- a/script/tool/test/version_check_test.dart +++ b/script/tool/test/version_check_test.dart @@ -10,6 +10,7 @@ import 'dart:io' as io; import 'package:args/command_runner.dart'; import 'package:file/file.dart'; +import 'package:file/memory.dart'; import 'package:flutter_plugin_tools/src/common.dart'; import 'package:flutter_plugin_tools/src/version_check_command.dart'; import 'package:git/git.dart'; @@ -55,6 +56,8 @@ String _redColorString(String string) { void main() { const String indentation = ' '; group('$VersionCheckCommand', () { + FileSystem fileSystem; + Directory packagesDir; CommandRunner runner; RecordingProcessRunner processRunner; List> gitDirCommands; @@ -63,6 +66,8 @@ void main() { MockGitDir gitDir; setUp(() { + fileSystem = MemoryFileSystem(); + packagesDir = createPackagesDirectory(fileSystem: fileSystem); gitDirCommands = >[]; gitDiffResponse = ''; gitShowResponses = {}; @@ -86,9 +91,8 @@ void main() { } return Future.value(mockProcessResult); }); - initializeFakePackages(); processRunner = RecordingProcessRunner(); - final VersionCheckCommand command = VersionCheckCommand(mockPackagesDir, + final VersionCheckCommand command = VersionCheckCommand(packagesDir, processRunner: processRunner, gitDir: gitDir); runner = CommandRunner( @@ -96,12 +100,9 @@ void main() { runner.addCommand(command); }); - tearDown(() { - cleanupPackages(); - }); - test('allows valid version', () async { - createFakePlugin('plugin', includeChangeLog: true, includeVersion: true); + createFakePlugin('plugin', packagesDir, + includeChangeLog: true, includeVersion: true); gitDiffResponse = 'packages/plugin/pubspec.yaml'; gitShowResponses = { 'master:packages/plugin/pubspec.yaml': 'version: 1.0.0', @@ -127,7 +128,8 @@ void main() { }); test('denies invalid version', () async { - createFakePlugin('plugin', includeChangeLog: true, includeVersion: true); + createFakePlugin('plugin', packagesDir, + includeChangeLog: true, includeVersion: true); gitDiffResponse = 'packages/plugin/pubspec.yaml'; gitShowResponses = { 'master:packages/plugin/pubspec.yaml': 'version: 0.0.1', @@ -151,7 +153,8 @@ void main() { }); test('allows valid version without explicit base-sha', () async { - createFakePlugin('plugin', includeChangeLog: true, includeVersion: true); + createFakePlugin('plugin', packagesDir, + includeChangeLog: true, includeVersion: true); gitDiffResponse = 'packages/plugin/pubspec.yaml'; gitShowResponses = { 'abc123:packages/plugin/pubspec.yaml': 'version: 1.0.0', @@ -169,7 +172,8 @@ void main() { }); test('allows valid version for new package.', () async { - createFakePlugin('plugin', includeChangeLog: true, includeVersion: true); + createFakePlugin('plugin', packagesDir, + includeChangeLog: true, includeVersion: true); gitDiffResponse = 'packages/plugin/pubspec.yaml'; gitShowResponses = { 'HEAD:packages/plugin/pubspec.yaml': 'version: 1.0.0', @@ -187,7 +191,8 @@ void main() { }); test('allows likely reverts.', () async { - createFakePlugin('plugin', includeChangeLog: true, includeVersion: true); + createFakePlugin('plugin', packagesDir, + includeChangeLog: true, includeVersion: true); gitDiffResponse = 'packages/plugin/pubspec.yaml'; gitShowResponses = { 'abc123:packages/plugin/pubspec.yaml': 'version: 0.6.2', @@ -205,7 +210,8 @@ void main() { }); test('denies lower version that could not be a simple revert', () async { - createFakePlugin('plugin', includeChangeLog: true, includeVersion: true); + createFakePlugin('plugin', packagesDir, + includeChangeLog: true, includeVersion: true); gitDiffResponse = 'packages/plugin/pubspec.yaml'; gitShowResponses = { 'abc123:packages/plugin/pubspec.yaml': 'version: 0.6.2', @@ -221,7 +227,8 @@ void main() { }); test('denies invalid version without explicit base-sha', () async { - createFakePlugin('plugin', includeChangeLog: true, includeVersion: true); + createFakePlugin('plugin', packagesDir, + includeChangeLog: true, includeVersion: true); gitDiffResponse = 'packages/plugin/pubspec.yaml'; gitShowResponses = { 'abc123:packages/plugin/pubspec.yaml': 'version: 0.0.1', @@ -237,7 +244,7 @@ void main() { }); test('gracefully handles missing pubspec.yaml', () async { - final Directory pluginDir = createFakePlugin('plugin', + final Directory pluginDir = createFakePlugin('plugin', packagesDir, includeChangeLog: true, includeVersion: true); gitDiffResponse = 'packages/plugin/pubspec.yaml'; pluginDir.childFile('pubspec.yaml').deleteSync(); @@ -259,7 +266,7 @@ void main() { }); test('allows minor changes to platform interfaces', () async { - createFakePlugin('plugin_platform_interface', + createFakePlugin('plugin_platform_interface', packagesDir, includeChangeLog: true, includeVersion: true); gitDiffResponse = 'packages/plugin_platform_interface/pubspec.yaml'; gitShowResponses = { @@ -293,7 +300,7 @@ void main() { }); test('disallows breaking changes to platform interfaces', () async { - createFakePlugin('plugin_platform_interface', + createFakePlugin('plugin_platform_interface', packagesDir, includeChangeLog: true, includeVersion: true); gitDiffResponse = 'packages/plugin_platform_interface/pubspec.yaml'; gitShowResponses = { @@ -326,10 +333,8 @@ void main() { test('Allow empty lines in front of the first version in CHANGELOG', () async { - createFakePlugin('plugin', includeChangeLog: true, includeVersion: true); - - final Directory pluginDirectory = - mockPackagesDir.childDirectory('plugin'); + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, + includeChangeLog: true, includeVersion: true); createFakePubspec(pluginDirectory, isFlutter: true, includeVersion: true, version: '1.0.1'); @@ -355,10 +360,8 @@ void main() { }); test('Throws if versions in changelog and pubspec do not match', () async { - createFakePlugin('plugin', includeChangeLog: true, includeVersion: true); - - final Directory pluginDirectory = - mockPackagesDir.childDirectory('plugin'); + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, + includeChangeLog: true, includeVersion: true); createFakePubspec(pluginDirectory, isFlutter: true, includeVersion: true, version: '1.0.1'); @@ -392,10 +395,8 @@ The first version listed in CHANGELOG.md is 1.0.2. }); test('Success if CHANGELOG and pubspec versions match', () async { - createFakePlugin('plugin', includeChangeLog: true, includeVersion: true); - - final Directory pluginDirectory = - mockPackagesDir.childDirectory('plugin'); + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, + includeChangeLog: true, includeVersion: true); createFakePubspec(pluginDirectory, isFlutter: true, includeVersion: true, version: '1.0.1'); @@ -420,10 +421,8 @@ The first version listed in CHANGELOG.md is 1.0.2. test( 'Fail if pubspec version only matches an older version listed in CHANGELOG', () async { - createFakePlugin('plugin', includeChangeLog: true, includeVersion: true); - - final Directory pluginDirectory = - mockPackagesDir.childDirectory('plugin'); + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, + includeChangeLog: true, includeVersion: true); createFakePubspec(pluginDirectory, isFlutter: true, includeVersion: true, version: '1.0.0'); @@ -464,10 +463,8 @@ The first version listed in CHANGELOG.md is 1.0.1. test('Allow NEXT as a placeholder for gathering CHANGELOG entries', () async { - createFakePlugin('plugin', includeChangeLog: true, includeVersion: true); - - final Directory pluginDirectory = - mockPackagesDir.childDirectory('plugin'); + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, + includeChangeLog: true, includeVersion: true); createFakePubspec(pluginDirectory, isFlutter: true, includeVersion: true, version: '1.0.0'); @@ -495,10 +492,8 @@ The first version listed in CHANGELOG.md is 1.0.1. test('Fail if NEXT is left in the CHANGELOG when adding a version bump', () async { - createFakePlugin('plugin', includeChangeLog: true, includeVersion: true); - - final Directory pluginDirectory = - mockPackagesDir.childDirectory('plugin'); + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, + includeChangeLog: true, includeVersion: true); createFakePubspec(pluginDirectory, isFlutter: true, includeVersion: true, version: '1.0.1'); @@ -541,10 +536,8 @@ into the new version's release notes. }); test('Fail if the version changes without replacing NEXT', () async { - createFakePlugin('plugin', includeChangeLog: true, includeVersion: true); - - final Directory pluginDirectory = - mockPackagesDir.childDirectory('plugin'); + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, + includeChangeLog: true, includeVersion: true); createFakePubspec(pluginDirectory, isFlutter: true, includeVersion: true, version: '1.0.1'); @@ -596,14 +589,15 @@ The first version listed in CHANGELOG.md is 1.0.0. final MockClient mockClient = MockClient((http.Request request) async { return http.Response(json.encode(httpResponse), 200); }); - final VersionCheckCommand command = VersionCheckCommand(mockPackagesDir, + final VersionCheckCommand command = VersionCheckCommand(packagesDir, processRunner: processRunner, gitDir: gitDir, httpClient: mockClient); runner = CommandRunner( 'version_check_command', 'Test for $VersionCheckCommand'); runner.addCommand(command); - createFakePlugin('plugin', includeChangeLog: true, includeVersion: true); + createFakePlugin('plugin', packagesDir, + includeChangeLog: true, includeVersion: true); gitDiffResponse = 'packages/plugin/pubspec.yaml'; gitShowResponses = { 'master:packages/plugin/pubspec.yaml': 'version: 1.0.0', @@ -632,14 +626,15 @@ The first version listed in CHANGELOG.md is 1.0.0. final MockClient mockClient = MockClient((http.Request request) async { return http.Response(json.encode(httpResponse), 200); }); - final VersionCheckCommand command = VersionCheckCommand(mockPackagesDir, + final VersionCheckCommand command = VersionCheckCommand(packagesDir, processRunner: processRunner, gitDir: gitDir, httpClient: mockClient); runner = CommandRunner( 'version_check_command', 'Test for $VersionCheckCommand'); runner.addCommand(command); - createFakePlugin('plugin', includeChangeLog: true, includeVersion: true); + createFakePlugin('plugin', packagesDir, + includeChangeLog: true, includeVersion: true); gitDiffResponse = 'packages/plugin/pubspec.yaml'; gitShowResponses = { 'master:packages/plugin/pubspec.yaml': 'version: 1.0.0', @@ -676,14 +671,15 @@ ${indentation}Allowed versions: {1.0.0: NextVersionType.BREAKING_MAJOR, 0.1.0: N final MockClient mockClient = MockClient((http.Request request) async { return http.Response('xx', 400); }); - final VersionCheckCommand command = VersionCheckCommand(mockPackagesDir, + final VersionCheckCommand command = VersionCheckCommand(packagesDir, processRunner: processRunner, gitDir: gitDir, httpClient: mockClient); runner = CommandRunner( 'version_check_command', 'Test for $VersionCheckCommand'); runner.addCommand(command); - createFakePlugin('plugin', includeChangeLog: true, includeVersion: true); + createFakePlugin('plugin', packagesDir, + includeChangeLog: true, includeVersion: true); gitDiffResponse = 'packages/plugin/pubspec.yaml'; gitShowResponses = { 'master:packages/plugin/pubspec.yaml': 'version: 1.0.0', @@ -719,14 +715,15 @@ ${indentation}HTTP response: xx final MockClient mockClient = MockClient((http.Request request) async { return http.Response('xx', 404); }); - final VersionCheckCommand command = VersionCheckCommand(mockPackagesDir, + final VersionCheckCommand command = VersionCheckCommand(packagesDir, processRunner: processRunner, gitDir: gitDir, httpClient: mockClient); runner = CommandRunner( 'version_check_command', 'Test for $VersionCheckCommand'); runner.addCommand(command); - createFakePlugin('plugin', includeChangeLog: true, includeVersion: true); + createFakePlugin('plugin', packagesDir, + includeChangeLog: true, includeVersion: true); gitDiffResponse = 'packages/plugin/pubspec.yaml'; gitShowResponses = { 'master:packages/plugin/pubspec.yaml': 'version: 1.0.0', diff --git a/script/tool/test/xctest_command_test.dart b/script/tool/test/xctest_command_test.dart index 0b25a5b015..174dba1d5a 100644 --- a/script/tool/test/xctest_command_test.dart +++ b/script/tool/test/xctest_command_test.dart @@ -8,6 +8,7 @@ import 'dart:convert'; import 'package:args/command_runner.dart'; import 'package:file/file.dart'; +import 'package:file/memory.dart'; import 'package:flutter_plugin_tools/src/xctest_command.dart'; import 'package:test/test.dart'; @@ -85,31 +86,31 @@ void main() { const String _kSkip = '--skip'; group('test xctest_command', () { + FileSystem fileSystem; + Directory packagesDir; CommandRunner runner; RecordingProcessRunner processRunner; setUp(() { - initializeFakePackages(); + fileSystem = MemoryFileSystem(); + packagesDir = createPackagesDirectory(fileSystem: fileSystem); processRunner = RecordingProcessRunner(); final XCTestCommand command = - XCTestCommand(mockPackagesDir, processRunner: processRunner); + XCTestCommand(packagesDir, processRunner: processRunner); runner = CommandRunner('xctest_command', 'Test for xctest_command'); runner.addCommand(command); - cleanupPackages(); }); test('skip if ios is not supported', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test'], ], isIosPlugin: false); - final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); - - createFakePubspec(pluginExampleDirectory, isFlutter: true); + createFakePubspec(pluginDirectory.childDirectory('example'), + isFlutter: true); final MockProcess mockProcess = MockProcess(); mockProcess.exitCodeCompleter.complete(0); @@ -118,27 +119,27 @@ void main() { runner, ['xctest', _kDestination, 'foo_destination']); expect(output, contains('iOS is not supported by this plugin.')); expect(processRunner.recordedCalls, orderedEquals([])); - - cleanupPackages(); }); test('running with correct destination, skip 1 plugin', () async { - createFakePlugin('plugin1', - withExtraFiles: >[ - ['example', 'test'], - ], - isIosPlugin: true); - createFakePlugin('plugin2', - withExtraFiles: >[ - ['example', 'test'], - ], - isIosPlugin: true); + final Directory pluginDirectory1 = + createFakePlugin('plugin1', packagesDir, + withExtraFiles: >[ + ['example', 'test'], + ], + isIosPlugin: true); + final Directory pluginDirectory2 = + createFakePlugin('plugin2', packagesDir, + withExtraFiles: >[ + ['example', 'test'], + ], + isIosPlugin: true); final Directory pluginExampleDirectory1 = - mockPackagesDir.childDirectory('plugin1').childDirectory('example'); + pluginDirectory1.childDirectory('example'); createFakePubspec(pluginExampleDirectory1, isFlutter: true); final Directory pluginExampleDirectory2 = - mockPackagesDir.childDirectory('plugin2').childDirectory('example'); + pluginDirectory2.childDirectory('example'); createFakePubspec(pluginExampleDirectory2, isFlutter: true); final MockProcess mockProcess = MockProcess(); @@ -178,20 +179,18 @@ void main() { ], pluginExampleDirectory2.path), ])); - - cleanupPackages(); }); test('Not specifying --ios-destination assigns an available simulator', () async { - createFakePlugin('plugin', + final Directory pluginDirectory = createFakePlugin('plugin', packagesDir, withExtraFiles: >[ ['example', 'test'], ], isIosPlugin: true); final Directory pluginExampleDirectory = - mockPackagesDir.childDirectory('plugin').childDirectory('example'); + pluginDirectory.childDirectory('example'); createFakePubspec(pluginExampleDirectory, isFlutter: true); @@ -234,8 +233,6 @@ void main() { ], pluginExampleDirectory.path), ])); - - cleanupPackages(); }); }); }