Skip to content

Commit

Permalink
Remove tests that attempt to modify files (#3309)
Browse files Browse the repository at this point in the history
Closes #3202

Calling `MemoryResourceProvider.modifyFile` is not sufficient for the
analyzer to respond to the changes, `AnalysisDriver.changeFile` is the
important call, but we don't have access to that member from the tests.
The real world behavior that would lead to this scenario requires more
complex interactions we can do with `resolveSources`.

Remove these tests entirely since they are not testing what they purport
and are not useful as they stand.
  • Loading branch information
natebosch committed May 25, 2022
1 parent 995fc94 commit 7067c3b
Showing 1 changed file with 0 additions and 78 deletions.
78 changes: 0 additions & 78 deletions build_resolvers/test/resolver_test.dart
Expand Up @@ -7,10 +7,8 @@ import 'dart:io' show Platform;
import 'dart:isolate';

import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/analysis/session.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/file_system/memory_file_system.dart';
import 'package:build/build.dart';
import 'package:build/experiments.dart';
import 'package:build_resolvers/src/analysis_driver.dart';
Expand Down Expand Up @@ -768,82 +766,6 @@ int? get x => 1;
);
}, resolvers: AnalyzerResolvers());
});

test(
'can get an unresolved AstNode for an old Element after resolving '
'additional assets', () async {
var resolvers = AnalyzerResolvers();
await resolveSources({
'a|web/main.dart': 'int x;',
}, (resolver) async {
var lib = await resolver.libraryFor(entryPoint);
var x = lib.topLevelElements.firstWhere((x) => !x.isSynthetic);
expect(x.name, 'x');
(x.library!.session.resourceProvider as MemoryResourceProvider)
.modifyFile('/a/web/main.dart', 'int x = 1;');

// Validate that direct session usage would throw
expect(() => lib.session.getParsedLibraryByElement(x.library!),
throwsA(isA<InconsistentAnalysisException>()),
skip: 'https://github.com/dart-lang/build/issues/3202');

var astNode = await resolver.astNodeFor(x);
expect(astNode, isA<VariableDeclaration>());
expect((astNode as VariableDeclaration).name.name, 'x');
expect(astNode.declaredElement, isNull);
}, resolvers: resolvers);
});

test(
'can get a resolved AstNode for an old Element after resolving '
'additional assets', () async {
var resolvers = AnalyzerResolvers();
await resolveSources({
'a|web/main.dart': 'int x;',
}, (resolver) async {
var lib = await resolver.libraryFor(entryPoint);
var x = lib.topLevelElements.firstWhere((x) => !x.isSynthetic);
expect(x.name, 'x');
(x.library!.session.resourceProvider as MemoryResourceProvider)
.modifyFile('/a/web/main.dart', 'int x = 1;');

// Validate that direct session usage would throw
expect(() => lib.session.getParsedLibraryByElement(x.library!),
throwsA(isA<InconsistentAnalysisException>()),
skip: 'https://github.com/dart-lang/build/issues/3202');

var astNode = await resolver.astNodeFor(x, resolve: true);
expect(astNode, isA<VariableDeclaration>());
expect((astNode as VariableDeclaration).name.name, 'x');
expect(astNode.declaredElement, isNotNull);
}, resolvers: resolvers);
});

test('library results can be used even if the session is invalidated',
() async {
var resolvers = AnalyzerResolvers();
await resolveSources({
'a|web/main.dart': 'int x;',
}, (resolver) async {
var lib = await resolver.libraryFor(entryPoint);
var x = lib.topLevelElements.firstWhere((x) => !x.isSynthetic);
expect(x.name, 'x');
var originalResult = await lib.session
.getResolvedLibrary(lib.source.fullName) as ResolvedLibraryResult;
(x.library!.session.resourceProvider as MemoryResourceProvider)
.modifyFile('/a/web/main.dart', 'int x = 1;');

// Validate that direct session usage would throw
expect(() => lib.session.getResolvedLibrary(lib.source.fullName),
throwsA(isA<InconsistentAnalysisException>()),
skip: 'https://github.com/dart-lang/build/issues/3202');

var astNode = originalResult.getElementDeclaration(x)!.node;
expect(astNode, isA<VariableDeclaration>());
expect((astNode as VariableDeclaration).name.name, 'x');
expect(astNode.declaredElement, isNotNull);
}, resolvers: resolvers);
});
});
}

Expand Down

0 comments on commit 7067c3b

Please sign in to comment.