Flutter analyze watch improvements (#11143)
* flutter analyze --watch auto detect if in flutter repo * move isFlutterLibrary from AnalyzeOnce into AnalyzeBase for use by AnalyzeContinuously * pass --flutter-repo to analysis server when analyzing the flutter repository * enhance flutter analyze --watch to summarize public members lacking documentation
This commit is contained in:
@@ -23,51 +23,55 @@ void main() {
|
||||
tempDir = fs.systemTempDirectory.createTempSync('analysis_test');
|
||||
});
|
||||
|
||||
Future<AnalysisServer> analyzeWithServer({ bool brokenCode: false, bool flutterRepo: false, int expectedErrorCount: 0 }) async {
|
||||
_createSampleProject(tempDir, brokenCode: brokenCode);
|
||||
|
||||
await pubGet(directory: tempDir.path);
|
||||
|
||||
server = new AnalysisServer(dartSdkPath, <String>[tempDir.path], flutterRepo: flutterRepo);
|
||||
|
||||
final Future<bool> onDone = server.onAnalyzing.where((bool analyzing) => analyzing == false).first;
|
||||
final List<AnalysisError> errors = <AnalysisError>[];
|
||||
server.onErrors.listen((FileAnalysisErrors fileErrors) {
|
||||
errors.addAll(fileErrors.errors);
|
||||
});
|
||||
|
||||
await server.start();
|
||||
await onDone;
|
||||
|
||||
expect(errors, hasLength(expectedErrorCount));
|
||||
return server;
|
||||
}
|
||||
|
||||
tearDown(() {
|
||||
tempDir?.deleteSync(recursive: true);
|
||||
return server?.dispose();
|
||||
});
|
||||
|
||||
group('analyze --watch', () {
|
||||
testUsingContext('AnalysisServer success', () async {
|
||||
_createSampleProject(tempDir);
|
||||
});
|
||||
|
||||
await pubGet(directory: tempDir.path);
|
||||
|
||||
server = new AnalysisServer(dartSdkPath, <String>[tempDir.path]);
|
||||
|
||||
int errorCount = 0;
|
||||
final Future<bool> onDone = server.onAnalyzing.where((bool analyzing) => analyzing == false).first;
|
||||
server.onErrors.listen((FileAnalysisErrors errors) => errorCount += errors.errors.length);
|
||||
|
||||
await server.start();
|
||||
await onDone;
|
||||
|
||||
expect(errorCount, 0);
|
||||
group('AnalysisServer', () {
|
||||
testUsingContext('success', () async {
|
||||
server = await analyzeWithServer();
|
||||
}, overrides: <Type, Generator>{
|
||||
OperatingSystemUtils: () => os
|
||||
});
|
||||
});
|
||||
|
||||
testUsingContext('AnalysisServer errors', () async {
|
||||
_createSampleProject(tempDir, brokenCode: true);
|
||||
|
||||
await pubGet(directory: tempDir.path);
|
||||
|
||||
server = new AnalysisServer(dartSdkPath, <String>[tempDir.path]);
|
||||
|
||||
int errorCount = 0;
|
||||
final Future<bool> onDone = server.onAnalyzing.where((bool analyzing) => analyzing == false).first;
|
||||
server.onErrors.listen((FileAnalysisErrors errors) {
|
||||
errorCount += errors.errors.length;
|
||||
testUsingContext('errors', () async {
|
||||
server = await analyzeWithServer(brokenCode: true, expectedErrorCount: 1);
|
||||
}, overrides: <Type, Generator>{
|
||||
OperatingSystemUtils: () => os
|
||||
});
|
||||
|
||||
await server.start();
|
||||
await onDone;
|
||||
|
||||
expect(errorCount, greaterThan(0));
|
||||
}, overrides: <Type, Generator>{
|
||||
OperatingSystemUtils: () => os
|
||||
testUsingContext('--flutter-repo', () async {
|
||||
// When a Dart SDK containing support for the --flutter-repo startup flag
|
||||
// https://github.com/dart-lang/sdk/commit/def1ee6604c4b3385b567cb9832af0dbbaf32e0d
|
||||
// is rolled into Flutter, then the expectedErrorCount should be set to 1.
|
||||
server = await analyzeWithServer(flutterRepo: true, expectedErrorCount: 0);
|
||||
}, overrides: <Type, Generator>{
|
||||
OperatingSystemUtils: () => os
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -77,6 +81,13 @@ void _createSampleProject(Directory directory, { bool brokenCode: false }) {
|
||||
name: foo_project
|
||||
''');
|
||||
|
||||
final File analysisOptionsFile = fs.file(fs.path.join(directory.path, 'analysis_options.yaml'));
|
||||
analysisOptionsFile.writeAsStringSync('''
|
||||
linter:
|
||||
rules:
|
||||
- hash_and_equals
|
||||
''');
|
||||
|
||||
final File dartFile = fs.file(fs.path.join(directory.path, 'lib', 'main.dart'));
|
||||
dartFile.parent.createSync();
|
||||
dartFile.writeAsStringSync('''
|
||||
@@ -84,5 +95,7 @@ void main() {
|
||||
print('hello world');
|
||||
${brokenCode ? 'prints("hello world");' : ''}
|
||||
}
|
||||
|
||||
class SomeClassWithoutDartDoc { }
|
||||
''');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user