re-write flutter analyze (the single-shot and --flutter-repo) to use the analysis server (#16281)
re-write flutter analyze (the single-shot and --flutter-repo) to use the analysis server
This commit is contained in:
@@ -6,7 +6,7 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/os.dart';
|
||||
import 'package:flutter_tools/src/commands/analyze_continuously.dart';
|
||||
import 'package:flutter_tools/src/dart/analysis.dart';
|
||||
import 'package:flutter_tools/src/dart/pub.dart';
|
||||
import 'package:flutter_tools/src/dart/sdk.dart';
|
||||
import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
// Copyright 2016 The Chromium 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:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/commands/analyze.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
import '../src/mocks.dart';
|
||||
|
||||
void main() {
|
||||
Directory tempDir;
|
||||
|
||||
setUpAll(() {
|
||||
Cache.disableLocking();
|
||||
});
|
||||
|
||||
setUp(() {
|
||||
tempDir = fs.systemTempDirectory.createTempSync('analysis_duplicate_names_test');
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
tempDir?.deleteSync(recursive: true);
|
||||
});
|
||||
|
||||
group('analyze', () {
|
||||
testUsingContext('flutter analyze with two files with the same name', () async {
|
||||
final File dartFileA = fs.file(fs.path.join(tempDir.path, 'a.dart'));
|
||||
dartFileA.parent.createSync();
|
||||
dartFileA.writeAsStringSync('library test;');
|
||||
final File dartFileB = fs.file(fs.path.join(tempDir.path, 'b.dart'));
|
||||
dartFileB.writeAsStringSync('library test;');
|
||||
|
||||
final AnalyzeCommand command = new AnalyzeCommand();
|
||||
applyMocksToCommand(command);
|
||||
return createTestCommandRunner(command).run(
|
||||
<String>['analyze', '--no-current-package', dartFileA.path, dartFileB.path]
|
||||
).then<Null>((Null value) {
|
||||
expect(testLogger.statusText, contains('Analyzing'));
|
||||
expect(testLogger.statusText, contains('No issues found!'));
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -17,7 +17,6 @@ import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
|
||||
void main() {
|
||||
|
||||
final String analyzerSeparator = platform.isWindows ? '-' : '•';
|
||||
|
||||
group('analyze once', () {
|
||||
@@ -33,7 +32,11 @@ void main() {
|
||||
});
|
||||
|
||||
tearDownAll(() {
|
||||
tempDir?.deleteSync(recursive: true);
|
||||
try {
|
||||
tempDir?.deleteSync(recursive: true);
|
||||
} catch (e) {
|
||||
// ignore errors deleting the temporary directory
|
||||
}
|
||||
});
|
||||
|
||||
// Create a project to be analyzed
|
||||
@@ -50,7 +53,7 @@ void main() {
|
||||
}, timeout: allowForRemotePubInvocation);
|
||||
|
||||
// Analyze in the current directory - no arguments
|
||||
testUsingContext('flutter analyze working directory', () async {
|
||||
testUsingContext('working directory', () async {
|
||||
await runCommand(
|
||||
command: new AnalyzeCommand(workingDirectory: fs.directory(projectPath)),
|
||||
arguments: <String>['analyze'],
|
||||
@@ -59,17 +62,17 @@ void main() {
|
||||
});
|
||||
|
||||
// Analyze a specific file outside the current directory
|
||||
testUsingContext('flutter analyze one file', () async {
|
||||
testUsingContext('passing one file throws', () async {
|
||||
await runCommand(
|
||||
command: new AnalyzeCommand(),
|
||||
arguments: <String>['analyze', libMain.path],
|
||||
statusTextContains: <String>['No issues found!'],
|
||||
toolExit: true,
|
||||
exitMessageContains: 'is not a directory',
|
||||
);
|
||||
});
|
||||
|
||||
// Analyze in the current directory - no arguments
|
||||
testUsingContext('flutter analyze working directory with errors', () async {
|
||||
|
||||
testUsingContext('working directory with errors', () async {
|
||||
// Break the code to produce the "The parameter 'onPressed' is required" hint
|
||||
// that is upgraded to a warning in package:flutter/analysis_options_user.yaml
|
||||
// to assert that we are using the default Flutter analysis options.
|
||||
@@ -93,22 +96,7 @@ void main() {
|
||||
statusTextContains: <String>[
|
||||
'Analyzing',
|
||||
'warning $analyzerSeparator The parameter \'onPressed\' is required',
|
||||
'hint $analyzerSeparator The method \'_incrementCounter\' isn\'t used',
|
||||
'2 issues found.',
|
||||
],
|
||||
toolExit: true,
|
||||
);
|
||||
});
|
||||
|
||||
// Analyze a specific file outside the current directory
|
||||
testUsingContext('flutter analyze one file with errors', () async {
|
||||
await runCommand(
|
||||
command: new AnalyzeCommand(),
|
||||
arguments: <String>['analyze', libMain.path],
|
||||
statusTextContains: <String>[
|
||||
'Analyzing',
|
||||
'warning $analyzerSeparator The parameter \'onPressed\' is required',
|
||||
'hint $analyzerSeparator The method \'_incrementCounter\' isn\'t used',
|
||||
'info $analyzerSeparator The method \'_incrementCounter\' isn\'t used',
|
||||
'2 issues found.',
|
||||
],
|
||||
toolExit: true,
|
||||
@@ -116,8 +104,7 @@ void main() {
|
||||
});
|
||||
|
||||
// Analyze in the current directory - no arguments
|
||||
testUsingContext('flutter analyze working directory with local options', () async {
|
||||
|
||||
testUsingContext('working directory with local options', () async {
|
||||
// Insert an analysis_options.yaml file in the project
|
||||
// which will trigger a lint for broken code that was inserted earlier
|
||||
final File optionsFile = fs.file(fs.path.join(projectPath, 'analysis_options.yaml'));
|
||||
@@ -135,15 +122,15 @@ void main() {
|
||||
statusTextContains: <String>[
|
||||
'Analyzing',
|
||||
'warning $analyzerSeparator The parameter \'onPressed\' is required',
|
||||
'hint $analyzerSeparator The method \'_incrementCounter\' isn\'t used',
|
||||
'lint $analyzerSeparator Only throw instances of classes extending either Exception or Error',
|
||||
'info $analyzerSeparator The method \'_incrementCounter\' isn\'t used',
|
||||
'info $analyzerSeparator Only throw instances of classes extending either Exception or Error',
|
||||
'3 issues found.',
|
||||
],
|
||||
toolExit: true,
|
||||
);
|
||||
});
|
||||
|
||||
testUsingContext('flutter analyze no duplicate issues', () async {
|
||||
testUsingContext('no duplicate issues', () async {
|
||||
final Directory tempDir = fs.systemTempDirectory.createTempSync('analyze_once_test_').absolute;
|
||||
|
||||
try {
|
||||
@@ -177,22 +164,6 @@ void bar() {
|
||||
}
|
||||
});
|
||||
|
||||
// Analyze a specific file outside the current directory
|
||||
testUsingContext('flutter analyze one file with local options', () async {
|
||||
await runCommand(
|
||||
command: new AnalyzeCommand(),
|
||||
arguments: <String>['analyze', libMain.path],
|
||||
statusTextContains: <String>[
|
||||
'Analyzing',
|
||||
'warning $analyzerSeparator The parameter \'onPressed\' is required',
|
||||
'hint $analyzerSeparator The method \'_incrementCounter\' isn\'t used',
|
||||
'lint $analyzerSeparator Only throw instances of classes extending either Exception or Error',
|
||||
'3 issues found.',
|
||||
],
|
||||
toolExit: true,
|
||||
);
|
||||
});
|
||||
|
||||
testUsingContext('--preview-dart-2', () async {
|
||||
const String contents = '''
|
||||
StringBuffer bar = StringBuffer('baz');
|
||||
@@ -250,18 +221,23 @@ Future<Null> runCommand({
|
||||
List<String> statusTextContains,
|
||||
List<String> errorTextContains,
|
||||
bool toolExit: false,
|
||||
String exitMessageContains,
|
||||
}) async {
|
||||
try {
|
||||
arguments.insert(0, '--flutter-root=${Cache.flutterRoot}');
|
||||
await createTestCommandRunner(command).run(arguments);
|
||||
expect(toolExit, isFalse, reason: 'Expected ToolExit exception');
|
||||
} on ToolExit {
|
||||
} on ToolExit catch (e) {
|
||||
if (!toolExit) {
|
||||
testLogger.clear();
|
||||
rethrow;
|
||||
}
|
||||
if (exitMessageContains != null) {
|
||||
expect(e.message, contains(exitMessageContains));
|
||||
}
|
||||
}
|
||||
assertContains(testLogger.statusText, statusTextContains);
|
||||
assertContains(testLogger.errorText, errorTextContains);
|
||||
|
||||
testLogger.clear();
|
||||
}
|
||||
|
||||
@@ -431,14 +431,13 @@ Future<Null> _createAndAnalyzeProject(
|
||||
{ List<String> unexpectedPaths = const <String>[], bool plugin = false }) async {
|
||||
await _createProject(dir, createArgs, expectedPaths, unexpectedPaths: unexpectedPaths, plugin: plugin);
|
||||
if (plugin) {
|
||||
await _analyzeProject(dir.path, target: fs.path.join(dir.path, 'lib', 'flutter_project.dart'));
|
||||
await _analyzeProject(fs.path.join(dir.path, 'example'));
|
||||
await _analyzeProject(dir.path);
|
||||
} else {
|
||||
await _analyzeProject(dir.path);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Null> _analyzeProject(String workingDir, {String target}) async {
|
||||
Future<Null> _analyzeProject(String workingDir) async {
|
||||
final String flutterToolsPath = fs.path.absolute(fs.path.join(
|
||||
'bin',
|
||||
'flutter_tools.dart',
|
||||
@@ -448,8 +447,6 @@ Future<Null> _analyzeProject(String workingDir, {String target}) async {
|
||||
..addAll(dartVmFlags)
|
||||
..add(flutterToolsPath)
|
||||
..add('analyze');
|
||||
if (target != null)
|
||||
args.add(target);
|
||||
|
||||
final ProcessResult exec = await Process.run(
|
||||
'$dartSdkPath/bin/dart',
|
||||
|
||||
Reference in New Issue
Block a user