Files
sdk/pkg/analysis_server/test/analysis/notification_analyzedFiles_test.dart
T
Paul Berry 105b170ddb Roll package test to 0.12.29+1 and stack_trace to 1.9.0
This required some changes to analysis_server, since analysis_server
used to have its own version of pumpEventQueue().  Since
pumpEventQueue() is now provided by the test package, I've removed
analysis_server's version, and I've updated some of the call sites to
pass in "times: 5000" to replicate the old analysis_server behavior.

This also required some changes to analyzer, since the fail() method
is now marked as @alwaysThrows, so no code may follow it without
producing a dead code hint.

Change-Id: Ie5ef3a5cc685c18da02de699e59f63f3bb8865f7
Reviewed-on: https://dart-review.googlesource.com/32683
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2018-01-07 14:22:23 +00:00

131 lines
3.8 KiB
Dart

// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'package:analysis_server/protocol/protocol.dart';
import 'package:analysis_server/protocol/protocol_constants.dart';
import 'package:analysis_server/protocol/protocol_generated.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../analysis_abstract.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(AnalysisNotificationAnalyzedFilesTest);
});
}
@reflectiveTest
class AnalysisNotificationAnalyzedFilesTest extends AbstractAnalysisTest {
List<String> analyzedFiles;
bool analyzedFilesReceived = false;
void assertHasFile(String filePath) {
expect(analyzedFilesReceived, isTrue);
expect(analyzedFiles, contains(filePath));
}
void assertHasNoFile(String filePath) {
expect(analyzedFilesReceived, isTrue);
expect(analyzedFiles, isNot(contains(filePath)));
}
Future<Null> prepareAnalyzedFiles() async {
addGeneralAnalysisSubscription(GeneralAnalysisService.ANALYZED_FILES);
await pumpEventQueue(times: 5000);
}
void processNotification(Notification notification) {
if (notification.event == ANALYSIS_NOTIFICATION_ANALYZED_FILES) {
AnalysisAnalyzedFilesParams params =
new AnalysisAnalyzedFilesParams.fromNotification(notification);
analyzedFilesReceived = true;
analyzedFiles = params.directories;
}
}
void setUp() {
generateSummaryFiles = true;
super.setUp();
createProject();
}
test_afterAnalysis() async {
addTestFile('''
class A {}
''');
await waitForTasksFinished();
await prepareAnalyzedFiles();
assertHasFile(testFile);
}
test_beforeAnalysis() async {
addTestFile('''
class A {}
''');
await prepareAnalyzedFiles();
assertHasFile(testFile);
}
test_beforeAnalysis_excludeYamlFiles() async {
File yamlFile = getFolder(projectPath).getChildAssumingFile('sample.yaml');
yamlFile.writeAsStringSync('');
addTestFile('''
class A {}
''');
await prepareAnalyzedFiles();
assertHasFile(testFile);
assertHasNoFile(yamlFile.path);
}
test_insignificant_change() async {
// Making a change that doesn't affect the set of reachable files should
// not trigger the notification to be re-sent.
addTestFile('class A {}');
await prepareAnalyzedFiles();
expect(analyzedFilesReceived, isTrue);
analyzedFilesReceived = false;
modifyTestFile('class B {}');
await prepareAnalyzedFiles();
expect(analyzedFilesReceived, isFalse);
}
test_resubscribe_no_changes() async {
// Unsubscribing and resubscribing should cause the notification to be
// re-sent, even if nothing has changed.
addTestFile('class A {}');
await prepareAnalyzedFiles();
expect(analyzedFilesReceived, isTrue);
unsubscribeAnalyzedFiles();
analyzedFilesReceived = false;
await prepareAnalyzedFiles();
expect(analyzedFilesReceived, isTrue);
assertHasFile(testFile);
}
test_significant_change() async {
// Making a change that *does* affect the set of reachable files should
// trigger the notification to be re-sent.
addTestFile('class A {}');
newFile('/foo.dart', content: 'library foo;');
await prepareAnalyzedFiles();
expect(analyzedFilesReceived, isTrue);
analyzedFilesReceived = false;
modifyTestFile('import "/foo.dart";');
await prepareAnalyzedFiles();
assertHasFile('/foo.dart');
}
void unsubscribeAnalyzedFiles() {
removeGeneralAnalysisSubscription(GeneralAnalysisService.ANALYZED_FILES);
}
}