Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Move plugin tool tests over #3606

Merged
merged 4 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ task:
- flutter channel master
- flutter upgrade
- git fetch origin master
submodules_script:
- git submodule init
- git submodule update
matrix:
- name: plugin_tools_tests
script:
- cd script/tool
- pub get
- CIRRUS_BUILD_ID=null pub run test
- name: publishable
script:
- flutter channel master
Expand Down Expand Up @@ -132,9 +134,6 @@ task:
- flutter channel master
- flutter upgrade
- git fetch origin master
submodules_script:
- git submodule init
- git submodule update
matrix:
- name: build-linux+drive-examples
install_script:
Expand All @@ -161,9 +160,6 @@ task:
- flutter channel master
- flutter upgrade
- git fetch origin master
submodules_script:
- git submodule init
- git submodule update
create_simulator_script:
- xcrun simctl list
- xcrun simctl create Flutter-iPhone com.apple.CoreSimulator.SimDeviceType.iPhone-11 com.apple.CoreSimulator.SimRuntime.iOS-14-3 | xargs xcrun simctl boot
Expand Down Expand Up @@ -222,9 +218,6 @@ task:
- flutter channel master
- flutter upgrade
- git fetch origin master
submodules_script:
- git submodule init
- git submodule update
create_simulator_script:
- xcrun simctl list
- xcrun simctl create Flutter-iPhone com.apple.CoreSimulator.SimDeviceType.iPhone-X com.apple.CoreSimulator.SimRuntime.iOS-13-3 | xargs xcrun simctl boot
Expand Down Expand Up @@ -254,9 +247,6 @@ task:
- flutter channel master
- flutter upgrade
- git fetch origin master
submodules_script:
- git submodule init
- git submodule update
matrix:
- name: build_all_plugins_app
script:
Expand Down
5 changes: 5 additions & 0 deletions script/tool/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@ dependencies:
http_multi_server: ^2.2.0
collection: 1.14.13

dev_dependencies:
matcher: ^0.12.6
mockito: ^4.1.1
pedantic: 1.8.0

environment:
sdk: ">=2.3.0 <3.0.0"
93 changes: 93 additions & 0 deletions script/tool/test/analyze_command_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import 'package:args/command_runner.dart';
import 'package:file/file.dart';
import 'package:flutter_plugin_tools/src/analyze_command.dart';
import 'package:flutter_plugin_tools/src/common.dart';
import 'package:test/test.dart';

import 'mocks.dart';
import 'util.dart';

void main() {
RecordingProcessRunner processRunner;
CommandRunner runner;

setUp(() {
initializeFakePackages();
processRunner = RecordingProcessRunner();
final AnalyzeCommand analyzeCommand = AnalyzeCommand(
mockPackagesDir, mockFileSystem,
processRunner: processRunner);

runner = CommandRunner<Null>('analyze_command', 'Test for analyze_command');
runner.addCommand(analyzeCommand);
});

tearDown(() {
mockPackagesDir.deleteSync(recursive: true);
});

test('analyzes all packages', () async {
final Directory plugin1Dir = await createFakePlugin('a');
final Directory plugin2Dir = await createFakePlugin('b');

final MockProcess mockProcess = MockProcess();
mockProcess.exitCodeCompleter.complete(0);
processRunner.processToReturn = mockProcess;
await runner.run(<String>['analyze']);

expect(
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
ProcessCall('pub', <String>['global', 'activate', 'tuneup'],
mockPackagesDir.path),
ProcessCall('flutter', <String>['packages', 'get'], plugin1Dir.path),
ProcessCall('flutter', <String>['packages', 'get'], plugin2Dir.path),
ProcessCall('pub', <String>['global', 'run', 'tuneup', 'check'],
plugin1Dir.path),
ProcessCall('pub', <String>['global', 'run', 'tuneup', 'check'],
plugin2Dir.path),
]));
});

group('verifies analysis settings', () {
test('fails analysis_options.yaml', () async {
await createFakePlugin('foo', withExtraFiles: <List<String>>[
<String>['analysis_options.yaml']
]);

await expectLater(() => runner.run(<String>['analyze']),
throwsA(const TypeMatcher<ToolExit>()));
});

test('fails .analysis_options', () async {
await createFakePlugin('foo', withExtraFiles: <List<String>>[
<String>['.analysis_options']
]);

await expectLater(() => runner.run(<String>['analyze']),
throwsA(const TypeMatcher<ToolExit>()));
});

test('takes an allow list', () async {
final Directory pluginDir =
await createFakePlugin('foo', withExtraFiles: <List<String>>[
<String>['analysis_options.yaml']
]);

final MockProcess mockProcess = MockProcess();
mockProcess.exitCodeCompleter.complete(0);
processRunner.processToReturn = mockProcess;
await runner.run(<String>['analyze', '--custom-analysis', 'foo']);

expect(
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
ProcessCall('pub', <String>['global', 'activate', 'tuneup'],
mockPackagesDir.path),
ProcessCall('flutter', <String>['packages', 'get'], pluginDir.path),
ProcessCall('pub', <String>['global', 'run', 'tuneup', 'check'],
pluginDir.path),
]));
});
});
}
Loading