have flutter analyze support --preview-dart-2 (#14582)
* have flutter analyze support --preview-dart-2 * review comments
This commit is contained in:
@@ -69,6 +69,44 @@ void main() {
|
||||
}, overrides: <Type, Generator>{
|
||||
OperatingSystemUtils: () => os
|
||||
});
|
||||
|
||||
testUsingContext('--preview-dart-2', () async {
|
||||
final String contents = "StringBuffer bar = StringBuffer('baz');";
|
||||
tempDir.childFile('main.dart').writeAsStringSync(contents);
|
||||
server = new AnalysisServer(dartSdkPath, <String>[tempDir.path], previewDart2: true);
|
||||
|
||||
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);
|
||||
}, overrides: <Type, Generator>{
|
||||
OperatingSystemUtils: () => os
|
||||
});
|
||||
|
||||
testUsingContext('no --preview-dart-2 shows errors', () async {
|
||||
final String contents = "StringBuffer bar = StringBuffer('baz');";
|
||||
tempDir.childFile('main.dart').writeAsStringSync(contents);
|
||||
server = new AnalysisServer(dartSdkPath, <String>[tempDir.path], previewDart2: false);
|
||||
|
||||
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, 1);
|
||||
}, overrides: <Type, Generator>{
|
||||
OperatingSystemUtils: () => os
|
||||
});
|
||||
}
|
||||
|
||||
void _createSampleProject(Directory directory, { bool brokenCode: false }) {
|
||||
|
||||
@@ -192,6 +192,45 @@ void bar() {
|
||||
toolExit: true,
|
||||
);
|
||||
});
|
||||
|
||||
testUsingContext('--preview-dart-2', () async {
|
||||
final String contents = '''
|
||||
StringBuffer bar = StringBuffer('baz');
|
||||
''';
|
||||
|
||||
final Directory tempDir = fs.systemTempDirectory.createTempSync();
|
||||
tempDir.childFile('main.dart').writeAsStringSync(contents);
|
||||
|
||||
try {
|
||||
await runCommand(
|
||||
command: new AnalyzeCommand(workingDirectory: fs.directory(tempDir)),
|
||||
arguments: <String>['analyze', '--preview-dart-2'],
|
||||
statusTextContains: <String>['No issues found!'],
|
||||
);
|
||||
} finally {
|
||||
tempDir.deleteSync(recursive: true);
|
||||
}
|
||||
});
|
||||
|
||||
testUsingContext('no --preview-dart-2 shows errors', () async {
|
||||
final String contents = '''
|
||||
StringBuffer bar = StringBuffer('baz');
|
||||
''';
|
||||
|
||||
final Directory tempDir = fs.systemTempDirectory.createTempSync();
|
||||
tempDir.childFile('main.dart').writeAsStringSync(contents);
|
||||
|
||||
try {
|
||||
await runCommand(
|
||||
command: new AnalyzeCommand(workingDirectory: fs.directory(tempDir)),
|
||||
arguments: <String>['analyze'],
|
||||
statusTextContains: <String>['1 issue found.'],
|
||||
toolExit: true,
|
||||
);
|
||||
} finally {
|
||||
tempDir.deleteSync(recursive: true);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user