Migrate AnalysisDriverCachingTest to PubPackageResolutionTest.

R=brianwilkerson@google.com

Change-Id: Iafcc25686d1eb70f638347ed4af06e09eb965cc5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/158023
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2020-08-10 20:12:13 +00:00 committed by commit-bot@chromium.org
parent 276f10aaf6
commit 287c796412
4 changed files with 36 additions and 33 deletions

View file

@ -8,6 +8,7 @@ import 'package:analyzer/dart/analysis/context_locator.dart';
import 'package:analyzer/dart/analysis/declared_variables.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/file_system/physical_file_system.dart';
import 'package:analyzer/src/dart/analysis/byte_store.dart';
import 'package:analyzer/src/dart/analysis/context_builder.dart';
import 'package:cli_util/cli_util.dart';
import 'package:meta/meta.dart';
@ -23,6 +24,7 @@ class AnalysisContextCollectionImpl implements AnalysisContextCollection {
/// Initialize a newly created analysis context manager.
AnalysisContextCollectionImpl({
ByteStore byteStore,
Map<String, String> declaredVariables,
bool enableIndex = false,
@required List<String> includedPaths,
@ -50,6 +52,7 @@ class AnalysisContextCollectionImpl implements AnalysisContextCollection {
resourceProvider: this.resourceProvider,
);
var context = contextBuilder.createContext(
byteStore: byteStore,
contextRoot: root,
declaredVariables: DeclaredVariables.fromMap(declaredVariables ?? {}),
enableIndex: enableIndex,

View file

@ -12,7 +12,7 @@ import 'package:analyzer/src/context/builder.dart' as old
show ContextBuilder, ContextBuilderOptions;
import 'package:analyzer/src/context/context_root.dart' as old;
import 'package:analyzer/src/dart/analysis/byte_store.dart'
show MemoryByteStore;
show ByteStore, MemoryByteStore;
import 'package:analyzer/src/dart/analysis/driver.dart'
show AnalysisDriver, AnalysisDriverScheduler;
import 'package:analyzer/src/dart/analysis/driver_based_analysis_context.dart';
@ -39,7 +39,8 @@ class ContextBuilderImpl implements ContextBuilder {
@override
AnalysisContext createContext(
{@required ContextRoot contextRoot,
{ByteStore byteStore,
@required ContextRoot contextRoot,
DeclaredVariables declaredVariables,
bool enableIndex = false,
List<String> librarySummaryPaths,
@ -51,7 +52,7 @@ class ContextBuilderImpl implements ContextBuilder {
sdkPath ??= getSdkPath();
ArgumentError.checkNotNull(sdkPath, 'sdkPath');
var byteStore = MemoryByteStore();
byteStore ??= MemoryByteStore();
var fileContentOverlay = FileContentOverlay();
performanceLog ??= PerformanceLog(StringBuffer());

View file

@ -4,13 +4,10 @@
import 'package:analyzer/error/error.dart';
import 'package:analyzer/src/dart/error/lint_codes.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/lint/registry.dart';
import 'package:linter/src/rules.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../resolution/driver_resolution.dart';
import '../resolution/context_collection_resolution.dart';
main() {
defineReflectiveSuite(() {
@ -19,55 +16,47 @@ main() {
}
@reflectiveTest
class AnalysisDriverCachingTest extends DriverResolutionTest {
class AnalysisDriverCachingTest extends PubPackageResolutionTest {
List<Set<String>> get _linkedCycles {
var driver = driverFor(testFilePath);
return driver.test.libraryContext.linkedCycles;
}
@override
void setUp() {
super.setUp();
registerLintRules();
}
test_lints() async {
var path = convertPath('/test/lib/test.dart');
newFile(path, content: r'''
newFile(testFilePath, content: r'''
void f() {
![0].isEmpty;
}
''');
// We don't have any lints configured, so no errors.
assertErrorsInList(
(await driver.getErrors(path)).errors,
[],
);
await resolveTestFile();
assertErrorsInResult([]);
// The summary for the library was linked.
_assertHasLinkedCycle({path}, andClear: true);
_assertContainsLinkedCycle({testFilePath}, andClear: true);
// We will recreate it with new analysis options.
// But we will reuse the byte store, so can reuse summaries.
disposeAnalysisContextCollection();
// Configure to run a lint.
driver.configure(
analysisOptions: AnalysisOptionsImpl()
..lint = true
..lintRules = [
Registry.ruleRegistry.getRule('prefer_is_not_empty'),
],
writeTestPackageAnalysisOptionsFile(
AnalysisOptionsFileConfig(
lints: ['prefer_is_not_empty'],
),
);
// Check that the lint was run, and reported.
_assertHasLintReported(
(await driver.getErrors(path)).errors,
'prefer_is_not_empty',
);
await resolveTestFile();
_assertHasLintReported(result.errors, 'prefer_is_not_empty');
// Lints don't affect summaries, nothing should be linked.
_assertNoLinkedCycles();
}
void _assertHasLinkedCycle(Set<String> expected, {bool andClear = false}) {
void _assertContainsLinkedCycle(Set<String> expected,
{bool andClear = false}) {
expect(_linkedCycles, contains(unorderedEquals(expected)));
if (andClear) {
_linkedCycles.clear();

View file

@ -9,6 +9,7 @@ import 'package:analyzer/dart/analysis/analysis_context_collection.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/dart/analysis/analysis_context_collection.dart';
import 'package:analyzer/src/dart/analysis/byte_store.dart';
import 'package:analyzer/src/dart/analysis/driver.dart';
import 'package:analyzer/src/dart/analysis/driver_based_analysis_context.dart';
import 'package:analyzer/src/dart/analysis/experiments.dart';
@ -120,6 +121,8 @@ abstract class ContextResolutionTest
with ResourceProviderMixin, ResolutionTest {
static bool _lintRulesAreRegistered = false;
final ByteStore _byteStore = MemoryByteStore();
Map<String, String> _declaredVariables = {};
AnalysisContextCollection _analysisContextCollection;
@ -167,6 +170,12 @@ abstract class ContextResolutionTest
return _analysisContextCollection.contextFor(path);
}
void disposeAnalysisContextCollection() {
if (_analysisContextCollection != null) {
_analysisContextCollection = null;
}
}
/// TODO(scheglov) Replace this with a method that changes a file in
/// [AnalysisContextCollectionImpl].
AnalysisDriver driverFor(String path) {
@ -212,6 +221,7 @@ abstract class ContextResolutionTest
}
_analysisContextCollection = AnalysisContextCollectionImpl(
byteStore: _byteStore,
declaredVariables: _declaredVariables,
enableIndex: true,
includedPaths: collectionIncludedPaths.map(convertPath).toList(),