mirror of
https://github.com/flutter/packages.git
synced 2025-06-05 19:17:51 +08:00

Removes the legacy analysis options override and fixes all resulting issues. This is a combination of dart fix and manual changes (mostly mechanical, but some small restructuring to address warnings more cleanly, such as creating typed structs from args when they are used repeatedly to avoid repeated casting, or making things that were unnecessarily public private). One small opportunistic extra cleanup is that the handling of null-safety prerelease versions is removed, as any new plugin would be written null-safe from the start, so we no longer need to allow those versions. Part of flutter/flutter#76229
118 lines
3.9 KiB
Dart
118 lines
3.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 '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<void> runner;
|
|
|
|
setUp(() {
|
|
initializeFakePackages();
|
|
processRunner = RecordingProcessRunner();
|
|
final AnalyzeCommand analyzeCommand = AnalyzeCommand(
|
|
mockPackagesDir, mockFileSystem,
|
|
processRunner: processRunner);
|
|
|
|
runner = CommandRunner<void>('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 MockProcess mockProcess = MockProcess();
|
|
mockProcess.exitCodeCompleter.complete(0);
|
|
processRunner.processToReturn = mockProcess;
|
|
await runner.run(<String>['analyze']);
|
|
|
|
expect(
|
|
processRunner.recordedCalls,
|
|
orderedEquals(<ProcessCall>[
|
|
ProcessCall('pub', const <String>['global', 'activate', 'tuneup'],
|
|
mockPackagesDir.path),
|
|
ProcessCall(
|
|
'flutter', const <String>['packages', 'get'], plugin1Dir.path),
|
|
ProcessCall(
|
|
'flutter', const <String>['packages', 'get'], plugin2Dir.path),
|
|
ProcessCall('pub', const <String>['global', 'run', 'tuneup', 'check'],
|
|
plugin1Dir.path),
|
|
ProcessCall('pub', const <String>['global', 'run', 'tuneup', 'check'],
|
|
plugin2Dir.path),
|
|
]));
|
|
});
|
|
|
|
group('verifies analysis settings', () {
|
|
test('fails analysis_options.yaml', () async {
|
|
createFakePlugin('foo', withExtraFiles: <List<String>>[
|
|
<String>['analysis_options.yaml']
|
|
]);
|
|
|
|
await expectLater(() => runner.run(<String>['analyze']),
|
|
throwsA(const TypeMatcher<ToolExit>()));
|
|
});
|
|
|
|
test('fails .analysis_options', () async {
|
|
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 =
|
|
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', const <String>['global', 'activate', 'tuneup'],
|
|
mockPackagesDir.path),
|
|
ProcessCall(
|
|
'flutter', const <String>['packages', 'get'], pluginDir.path),
|
|
ProcessCall(
|
|
'pub',
|
|
const <String>['global', 'run', 'tuneup', 'check'],
|
|
pluginDir.path),
|
|
]));
|
|
});
|
|
|
|
// See: https://github.com/flutter/flutter/issues/78994
|
|
test('takes an empty allow list', () async {
|
|
createFakePlugin('foo', withExtraFiles: <List<String>>[
|
|
<String>['analysis_options.yaml']
|
|
]);
|
|
|
|
final MockProcess mockProcess = MockProcess();
|
|
mockProcess.exitCodeCompleter.complete(0);
|
|
processRunner.processToReturn = mockProcess;
|
|
|
|
await expectLater(
|
|
() => runner.run(<String>['analyze', '--custom-analysis', '']),
|
|
throwsA(const TypeMatcher<ToolExit>()));
|
|
});
|
|
});
|
|
}
|