Revert "re-write flutter analyze (the single-shot and --flutter-repo) to use the analysis server (#16281)" (#16482)

This reverts commit 2f41ea546f.
This commit is contained in:
Devon Carew
2018-04-11 16:49:38 -07:00
committed by GitHub
parent 2f41ea546f
commit 071485258f
17 changed files with 983 additions and 446 deletions

View File

@@ -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/dart/analysis.dart';
import 'package:flutter_tools/src/commands/analyze_continuously.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';

View File

@@ -0,0 +1,48 @@
// 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!'));
});
});
});
}

View File

@@ -17,6 +17,7 @@ import '../src/common.dart';
import '../src/context.dart';
void main() {
final String analyzerSeparator = platform.isWindows ? '-' : '•';
group('analyze once', () {
@@ -32,11 +33,7 @@ void main() {
});
tearDownAll(() {
try {
tempDir?.deleteSync(recursive: true);
} catch (e) {
// ignore errors deleting the temporary directory
}
tempDir?.deleteSync(recursive: true);
});
// Create a project to be analyzed
@@ -53,7 +50,7 @@ void main() {
}, timeout: allowForRemotePubInvocation);
// Analyze in the current directory - no arguments
testUsingContext('working directory', () async {
testUsingContext('flutter analyze working directory', () async {
await runCommand(
command: new AnalyzeCommand(workingDirectory: fs.directory(projectPath)),
arguments: <String>['analyze'],
@@ -62,17 +59,17 @@ void main() {
});
// Analyze a specific file outside the current directory
testUsingContext('passing one file throws', () async {
testUsingContext('flutter analyze one file', () async {
await runCommand(
command: new AnalyzeCommand(),
arguments: <String>['analyze', libMain.path],
toolExit: true,
exitMessageContains: 'is not a directory',
statusTextContains: <String>['No issues found!'],
);
});
// Analyze in the current directory - no arguments
testUsingContext('working directory with errors', () async {
testUsingContext('flutter analyze 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.
@@ -96,7 +93,22 @@ void main() {
statusTextContains: <String>[
'Analyzing',
'warning $analyzerSeparator The parameter \'onPressed\' is required',
'info $analyzerSeparator The method \'_incrementCounter\' isn\'t used',
'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',
'2 issues found.',
],
toolExit: true,
@@ -104,7 +116,8 @@ void main() {
});
// Analyze in the current directory - no arguments
testUsingContext('working directory with local options', () async {
testUsingContext('flutter analyze 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'));
@@ -122,15 +135,15 @@ void main() {
statusTextContains: <String>[
'Analyzing',
'warning $analyzerSeparator The parameter \'onPressed\' is required',
'info $analyzerSeparator The method \'_incrementCounter\' isn\'t used',
'info $analyzerSeparator Only throw instances of classes extending either Exception or Error',
'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('no duplicate issues', () async {
testUsingContext('flutter analyze no duplicate issues', () async {
final Directory tempDir = fs.systemTempDirectory.createTempSync('analyze_once_test_').absolute;
try {
@@ -164,6 +177,22 @@ 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');
@@ -221,23 +250,18 @@ 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 catch (e) {
} on ToolExit {
if (!toolExit) {
testLogger.clear();
rethrow;
}
if (exitMessageContains != null) {
expect(e.message, contains(exitMessageContains));
}
}
assertContains(testLogger.statusText, statusTextContains);
assertContains(testLogger.errorText, errorTextContains);
testLogger.clear();
}

View File

@@ -431,13 +431,14 @@ 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);
await _analyzeProject(dir.path, target: fs.path.join(dir.path, 'lib', 'flutter_project.dart'));
await _analyzeProject(fs.path.join(dir.path, 'example'));
} else {
await _analyzeProject(dir.path);
}
}
Future<Null> _analyzeProject(String workingDir) async {
Future<Null> _analyzeProject(String workingDir, {String target}) async {
final String flutterToolsPath = fs.path.absolute(fs.path.join(
'bin',
'flutter_tools.dart',
@@ -447,6 +448,8 @@ Future<Null> _analyzeProject(String workingDir) async {
..addAll(dartVmFlags)
..add(flutterToolsPath)
..add('analyze');
if (target != null)
args.add(target);
final ProcessResult exec = await Process.run(
'$dartSdkPath/bin/dart',