mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 08:44:27 +00:00
Fix producing errors from bytes to update the latest signature.
This should fix analyzer-mac-release bot. Change-Id: Ia61f5c33a21d703f20fb7a275bbffa4511a122c9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/346941 Reviewed-by: Phil Quitslund <pquitslund@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
f6c0da24d0
commit
b6d2662a82
4 changed files with 100 additions and 10 deletions
|
@ -28,34 +28,29 @@ void f() {
|
|||
await standardAnalysisSetup();
|
||||
|
||||
// The contents on disk (badText) are missing a semicolon.
|
||||
await analysisFinished;
|
||||
expect(currentAnalysisErrors[path], isNotEmpty);
|
||||
expect(await waitForFileErrors(path), isNotEmpty);
|
||||
|
||||
// There should be no errors now because the contents on disk have been
|
||||
// overridden with goodText.
|
||||
await sendAnalysisUpdateContent({path: AddContentOverlay(goodText)});
|
||||
await analysisFinished;
|
||||
expect(currentAnalysisErrors[path], isEmpty);
|
||||
expect(await waitForFileErrors(path), isEmpty);
|
||||
|
||||
// There should be errors now because we've removed the semicolon.
|
||||
await sendAnalysisUpdateContent({
|
||||
path: ChangeContentOverlay([SourceEdit(goodText.indexOf(';'), 1, '')])
|
||||
});
|
||||
await analysisFinished;
|
||||
expect(currentAnalysisErrors[path], isNotEmpty);
|
||||
expect(await waitForFileErrors(path), isNotEmpty);
|
||||
|
||||
// There should be no errors now because we've added the semicolon back.
|
||||
await sendAnalysisUpdateContent({
|
||||
path: ChangeContentOverlay([SourceEdit(goodText.indexOf(';'), 0, ';')])
|
||||
});
|
||||
await analysisFinished;
|
||||
expect(currentAnalysisErrors[path], isEmpty);
|
||||
expect(await waitForFileErrors(path), isEmpty);
|
||||
|
||||
// Now there should be errors again, because the contents on disk are no
|
||||
// longer overridden.
|
||||
await sendAnalysisUpdateContent({path: RemoveContentOverlay()});
|
||||
await analysisFinished;
|
||||
expect(currentAnalysisErrors[path], isNotEmpty);
|
||||
expect(await waitForFileErrors(path), isNotEmpty);
|
||||
}
|
||||
|
||||
Future<void> test_updateContent_multipleAdds() async {
|
||||
|
|
|
@ -249,6 +249,20 @@ abstract class AbstractAnalysisServerIntegrationTest extends IntegrationTest {
|
|||
});
|
||||
}
|
||||
|
||||
/// Returns the latest set of errors for the file.
|
||||
///
|
||||
/// If there are no errors received from the server yet, waits for them.
|
||||
/// Removes the set from the storage, so will wait again next time.
|
||||
Future<List<AnalysisError>> waitForFileErrors(String path) async {
|
||||
while (true) {
|
||||
var result = currentAnalysisErrors.remove(path);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
await pumpEventQueue();
|
||||
}
|
||||
}
|
||||
|
||||
/// Write a source file with the given absolute [pathname] and [contents].
|
||||
///
|
||||
/// If the file didn't previously exist, it is created. If it did, it is
|
||||
|
|
|
@ -1878,6 +1878,7 @@ class AnalysisDriver {
|
|||
if (bytes != null) {
|
||||
var result = _createErrorsResultFromBytes(file, library, bytes);
|
||||
_fileTracker.fileWasAnalyzed(path);
|
||||
_lastProducedSignatures[path] = signature;
|
||||
_scheduler.eventsController.add(result);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1022,6 +1022,86 @@ import 'a.dart';
|
|||
''');
|
||||
}
|
||||
|
||||
test_changeFile_notPriority_errorsFromBytes() async {
|
||||
final a = newFile('$testPackageLibPath/a.dart', '');
|
||||
|
||||
final driver = driverFor(a);
|
||||
final collector = DriverEventCollector(driver);
|
||||
|
||||
driver.addFile2(a);
|
||||
|
||||
// Initial analysis, no errors.
|
||||
await assertEventsText(collector, r'''
|
||||
[status] analyzing
|
||||
[operation] analyzeFile
|
||||
file: /home/test/lib/a.dart
|
||||
library: /home/test/lib/a.dart
|
||||
[stream]
|
||||
ResolvedUnitResult #0
|
||||
path: /home/test/lib/a.dart
|
||||
uri: package:test/a.dart
|
||||
flags: exists isLibrary
|
||||
[status] idle
|
||||
''');
|
||||
|
||||
// Update the file, has an error.
|
||||
// Note, we analyze the file.
|
||||
modifyFile2(a, ';');
|
||||
driver.changeFile2(a);
|
||||
await assertEventsText(collector, r'''
|
||||
[status] analyzing
|
||||
[operation] analyzeFile
|
||||
file: /home/test/lib/a.dart
|
||||
library: /home/test/lib/a.dart
|
||||
[stream]
|
||||
ResolvedUnitResult #1
|
||||
path: /home/test/lib/a.dart
|
||||
uri: package:test/a.dart
|
||||
flags: exists isLibrary
|
||||
errors
|
||||
0 +1 UNEXPECTED_TOKEN
|
||||
[status] idle
|
||||
''');
|
||||
|
||||
// Update the file, no errors.
|
||||
// Note, we return errors from bytes.
|
||||
// We must update latest signatures, not reflected in the text.
|
||||
// If we don't, the next assert will fail.
|
||||
modifyFile2(a, '');
|
||||
driver.changeFile2(a);
|
||||
await assertEventsText(collector, r'''
|
||||
[status] analyzing
|
||||
[operation] getErrorsFromBytes
|
||||
file: /home/test/lib/a.dart
|
||||
library: /home/test/lib/a.dart
|
||||
[stream]
|
||||
ErrorsResult #2
|
||||
path: /home/test/lib/a.dart
|
||||
uri: package:test/a.dart
|
||||
flags: isLibrary
|
||||
[status] idle
|
||||
''');
|
||||
|
||||
// Update the file, has an error.
|
||||
// Note, we return errors from bytes.
|
||||
modifyFile2(a, ';');
|
||||
driver.changeFile2(a);
|
||||
await assertEventsText(collector, r'''
|
||||
[status] analyzing
|
||||
[operation] getErrorsFromBytes
|
||||
file: /home/test/lib/a.dart
|
||||
library: /home/test/lib/a.dart
|
||||
[stream]
|
||||
ErrorsResult #3
|
||||
path: /home/test/lib/a.dart
|
||||
uri: package:test/a.dart
|
||||
flags: isLibrary
|
||||
errors
|
||||
0 +1 UNEXPECTED_TOKEN
|
||||
[status] idle
|
||||
''');
|
||||
}
|
||||
|
||||
test_changeFile_notUsed() async {
|
||||
final a = newFile('$testPackageLibPath/a.dart', '');
|
||||
final b = newFile('$testPackageLibPath/b.dart', 'class B1 {}');
|
||||
|
|
Loading…
Reference in a new issue