mirror of
https://github.com/flutter/packages.git
synced 2025-05-24 12:16:44 +08:00

Currently the tool accepts `--custom-analysis` to allow a list of packages for which custom `analysis_options.yaml` are allowed, and `--exclude` to exclude a set of packages when running a command against all, or all changed, packages. This results in these exception lists being embedded into CI configuration files (e.g., .cirrus.yaml) or scripts, which makes them harder to maintain, and harder to re-use in other contexts (local runs, new CI systems). This adds support for both flags to accept paths to YAML files that contain the lists, so that they can be maintained separately, and with inline comments about the reasons things are on the lists. Also updates the CI to use this new support, eliminating those lists from `.cirrus.yaml` and `tool_runner.sh` Fixes https://github.com/flutter/flutter/issues/86799
255 lines
7.9 KiB
Dart
255 lines
7.9 KiB
Dart
// Copyright 2013 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
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/analyze_command.dart';
|
|
import 'package:flutter_plugin_tools/src/common/core.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'mocks.dart';
|
|
import 'util.dart';
|
|
|
|
void main() {
|
|
late FileSystem fileSystem;
|
|
late MockPlatform mockPlatform;
|
|
late Directory packagesDir;
|
|
late RecordingProcessRunner processRunner;
|
|
late CommandRunner<void> runner;
|
|
|
|
setUp(() {
|
|
fileSystem = MemoryFileSystem();
|
|
mockPlatform = MockPlatform();
|
|
packagesDir = createPackagesDirectory(fileSystem: fileSystem);
|
|
processRunner = RecordingProcessRunner();
|
|
final AnalyzeCommand analyzeCommand = AnalyzeCommand(
|
|
packagesDir,
|
|
processRunner: processRunner,
|
|
platform: mockPlatform,
|
|
);
|
|
|
|
runner = CommandRunner<void>('analyze_command', 'Test for analyze_command');
|
|
runner.addCommand(analyzeCommand);
|
|
});
|
|
|
|
test('analyzes all packages', () async {
|
|
final Directory plugin1Dir = createFakePlugin('a', packagesDir);
|
|
final Directory plugin2Dir = createFakePlugin('b', packagesDir);
|
|
|
|
await runCapturingPrint(runner, <String>['analyze']);
|
|
|
|
expect(
|
|
processRunner.recordedCalls,
|
|
orderedEquals(<ProcessCall>[
|
|
ProcessCall(
|
|
'flutter', const <String>['packages', 'get'], plugin1Dir.path),
|
|
ProcessCall(
|
|
'flutter', const <String>['packages', 'get'], plugin2Dir.path),
|
|
ProcessCall('dart', const <String>['analyze', '--fatal-infos'],
|
|
plugin1Dir.path),
|
|
ProcessCall('dart', const <String>['analyze', '--fatal-infos'],
|
|
plugin2Dir.path),
|
|
]));
|
|
});
|
|
|
|
test('skips flutter pub get for examples', () async {
|
|
final Directory plugin1Dir = createFakePlugin('a', packagesDir);
|
|
|
|
await runCapturingPrint(runner, <String>['analyze']);
|
|
|
|
expect(
|
|
processRunner.recordedCalls,
|
|
orderedEquals(<ProcessCall>[
|
|
ProcessCall(
|
|
'flutter', const <String>['packages', 'get'], plugin1Dir.path),
|
|
ProcessCall('dart', const <String>['analyze', '--fatal-infos'],
|
|
plugin1Dir.path),
|
|
]));
|
|
});
|
|
|
|
test('don\'t elide a non-contained example package', () async {
|
|
final Directory plugin1Dir = createFakePlugin('a', packagesDir);
|
|
final Directory plugin2Dir = createFakePlugin('example', packagesDir);
|
|
|
|
await runCapturingPrint(runner, <String>['analyze']);
|
|
|
|
expect(
|
|
processRunner.recordedCalls,
|
|
orderedEquals(<ProcessCall>[
|
|
ProcessCall(
|
|
'flutter', const <String>['packages', 'get'], plugin1Dir.path),
|
|
ProcessCall(
|
|
'flutter', const <String>['packages', 'get'], plugin2Dir.path),
|
|
ProcessCall('dart', const <String>['analyze', '--fatal-infos'],
|
|
plugin1Dir.path),
|
|
ProcessCall('dart', const <String>['analyze', '--fatal-infos'],
|
|
plugin2Dir.path),
|
|
]));
|
|
});
|
|
|
|
test('uses a separate analysis sdk', () async {
|
|
final Directory pluginDir = createFakePlugin('a', packagesDir);
|
|
|
|
await runCapturingPrint(
|
|
runner, <String>['analyze', '--analysis-sdk', 'foo/bar/baz']);
|
|
|
|
expect(
|
|
processRunner.recordedCalls,
|
|
orderedEquals(<ProcessCall>[
|
|
ProcessCall(
|
|
'flutter',
|
|
const <String>['packages', 'get'],
|
|
pluginDir.path,
|
|
),
|
|
ProcessCall(
|
|
'foo/bar/baz/bin/dart',
|
|
const <String>['analyze', '--fatal-infos'],
|
|
pluginDir.path,
|
|
),
|
|
]),
|
|
);
|
|
});
|
|
|
|
group('verifies analysis settings', () {
|
|
test('fails analysis_options.yaml', () async {
|
|
createFakePlugin('foo', packagesDir,
|
|
extraFiles: <String>['analysis_options.yaml']);
|
|
|
|
Error? commandError;
|
|
final List<String> output = await runCapturingPrint(
|
|
runner, <String>['analyze'], errorHandler: (Error e) {
|
|
commandError = e;
|
|
});
|
|
|
|
expect(commandError, isA<ToolExit>());
|
|
expect(
|
|
output,
|
|
containsAllInOrder(<Matcher>[
|
|
contains(
|
|
'Found an extra analysis_options.yaml at /packages/foo/analysis_options.yaml'),
|
|
contains(' foo:\n'
|
|
' Unexpected local analysis options'),
|
|
]),
|
|
);
|
|
});
|
|
|
|
test('fails .analysis_options', () async {
|
|
createFakePlugin('foo', packagesDir,
|
|
extraFiles: <String>['.analysis_options']);
|
|
|
|
Error? commandError;
|
|
final List<String> output = await runCapturingPrint(
|
|
runner, <String>['analyze'], errorHandler: (Error e) {
|
|
commandError = e;
|
|
});
|
|
|
|
expect(commandError, isA<ToolExit>());
|
|
expect(
|
|
output,
|
|
containsAllInOrder(<Matcher>[
|
|
contains(
|
|
'Found an extra analysis_options.yaml at /packages/foo/.analysis_options'),
|
|
contains(' foo:\n'
|
|
' Unexpected local analysis options'),
|
|
]),
|
|
);
|
|
});
|
|
|
|
test('takes an allow list', () async {
|
|
final Directory pluginDir = createFakePlugin('foo', packagesDir,
|
|
extraFiles: <String>['analysis_options.yaml']);
|
|
|
|
await runCapturingPrint(
|
|
runner, <String>['analyze', '--custom-analysis', 'foo']);
|
|
|
|
expect(
|
|
processRunner.recordedCalls,
|
|
orderedEquals(<ProcessCall>[
|
|
ProcessCall(
|
|
'flutter', const <String>['packages', 'get'], pluginDir.path),
|
|
ProcessCall('dart', const <String>['analyze', '--fatal-infos'],
|
|
pluginDir.path),
|
|
]));
|
|
});
|
|
|
|
test('takes an allow config file', () async {
|
|
final Directory pluginDir = createFakePlugin('foo', packagesDir,
|
|
extraFiles: <String>['analysis_options.yaml']);
|
|
final File allowFile = packagesDir.childFile('custom.yaml');
|
|
allowFile.writeAsStringSync('- foo');
|
|
|
|
await runCapturingPrint(
|
|
runner, <String>['analyze', '--custom-analysis', allowFile.path]);
|
|
|
|
expect(
|
|
processRunner.recordedCalls,
|
|
orderedEquals(<ProcessCall>[
|
|
ProcessCall(
|
|
'flutter', const <String>['packages', 'get'], pluginDir.path),
|
|
ProcessCall('dart', const <String>['analyze', '--fatal-infos'],
|
|
pluginDir.path),
|
|
]));
|
|
});
|
|
|
|
// See: https://github.com/flutter/flutter/issues/78994
|
|
test('takes an empty allow list', () async {
|
|
createFakePlugin('foo', packagesDir,
|
|
extraFiles: <String>['analysis_options.yaml']);
|
|
|
|
await expectLater(
|
|
() => runCapturingPrint(
|
|
runner, <String>['analyze', '--custom-analysis', '']),
|
|
throwsA(isA<ToolExit>()));
|
|
});
|
|
});
|
|
|
|
test('fails if "packages get" fails', () async {
|
|
createFakePlugin('foo', packagesDir);
|
|
|
|
processRunner.mockProcessesForExecutable['flutter'] = <io.Process>[
|
|
MockProcess.failing() // flutter packages get
|
|
];
|
|
|
|
Error? commandError;
|
|
final List<String> output = await runCapturingPrint(
|
|
runner, <String>['analyze'], errorHandler: (Error e) {
|
|
commandError = e;
|
|
});
|
|
|
|
expect(commandError, isA<ToolExit>());
|
|
expect(
|
|
output,
|
|
containsAllInOrder(<Matcher>[
|
|
contains('Unable to get dependencies'),
|
|
]),
|
|
);
|
|
});
|
|
|
|
test('fails if "analyze" fails', () async {
|
|
createFakePlugin('foo', packagesDir);
|
|
|
|
processRunner.mockProcessesForExecutable['dart'] = <io.Process>[
|
|
MockProcess.failing() // dart analyze
|
|
];
|
|
|
|
Error? commandError;
|
|
final List<String> output = await runCapturingPrint(
|
|
runner, <String>['analyze'], errorHandler: (Error e) {
|
|
commandError = e;
|
|
});
|
|
|
|
expect(commandError, isA<ToolExit>());
|
|
expect(
|
|
output,
|
|
containsAllInOrder(<Matcher>[
|
|
contains('The following packages had errors:'),
|
|
contains(' foo'),
|
|
]),
|
|
);
|
|
});
|
|
}
|