have flutter analyze support --preview-dart-2 (#14582)

* have flutter analyze support --preview-dart-2

* review comments
This commit is contained in:
Devon Carew
2018-02-14 16:00:29 -08:00
committed by GitHub
parent 59fe5d0f46
commit 53b348a50d
5 changed files with 106 additions and 6 deletions

View File

@@ -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 }) {

View File

@@ -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);
}
});
});
}