Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove tests that attempt to modify files #3309

Merged
merged 2 commits into from May 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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