mirror of
https://github.com/dart-lang/sdk
synced 2024-09-18 21:21:18 +00:00
Remove 'serializeLibrary(LibraryElement)' and its tests.
Switch PrelinkerTest to AST based unlinked summaries. The *_common.dart files in tests might be not actually 'common', and we could pull them into corresponding only subclasses. R=paulberry@google.com BUG= Review URL: https://codereview.chromium.org/2353773002 .
This commit is contained in:
parent
cd05ee0c81
commit
d13a887292
File diff suppressed because it is too large
Load diff
|
@ -4,15 +4,13 @@
|
|||
|
||||
library analyzer.test.src.summary.prelinker_test;
|
||||
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/generated/source_io.dart';
|
||||
import 'package:analyzer/src/generated/utilities_dart.dart';
|
||||
import 'package:analyzer/src/summary/idl.dart';
|
||||
import 'package:analyzer/src/summary/prelink.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
import 'package:unittest/unittest.dart';
|
||||
|
||||
import 'summarize_elements_test.dart';
|
||||
import 'summarize_ast_test.dart';
|
||||
import 'summary_common.dart';
|
||||
|
||||
main() {
|
||||
|
@ -26,10 +24,7 @@ main() {
|
|||
* information, and then recreating it using the prelinker.
|
||||
*/
|
||||
@reflectiveTest
|
||||
class PrelinkerTest extends SummarizeElementsTest {
|
||||
final Map<String, UnlinkedPublicNamespace> uriToPublicNamespace =
|
||||
<String, UnlinkedPublicNamespace>{};
|
||||
|
||||
class PrelinkerTest extends LinkedSummarizeAstTest {
|
||||
@override
|
||||
bool get expectAbsoluteUrisInDependencies => false;
|
||||
|
||||
|
@ -40,60 +35,25 @@ class PrelinkerTest extends SummarizeElementsTest {
|
|||
bool get strongMode => false;
|
||||
|
||||
@override
|
||||
Source addNamedSource(String filePath, String contents) {
|
||||
Source source = super.addNamedSource(filePath, contents);
|
||||
uriToPublicNamespace[absUri(filePath)] =
|
||||
computePublicNamespaceFromText(contents, source);
|
||||
return source;
|
||||
}
|
||||
void serializeLibraryText(String text, {bool allowErrors: false}) {
|
||||
super.serializeLibraryText(text, allowErrors: allowErrors);
|
||||
|
||||
String resolveToAbsoluteUri(LibraryElement library, String relativeUri) {
|
||||
Source resolvedSource =
|
||||
context.sourceFactory.resolveUri(library.source, relativeUri);
|
||||
if (resolvedSource == null) {
|
||||
fail('Failed to resolve relative uri "$relativeUri"');
|
||||
}
|
||||
return resolvedSource.uri.toString();
|
||||
}
|
||||
|
||||
@override
|
||||
void serializeLibraryElement(LibraryElement library) {
|
||||
super.serializeLibraryElement(library);
|
||||
uriToPublicNamespace[library.source.uri.toString()] =
|
||||
unlinkedUnits[0].publicNamespace;
|
||||
Map<String, UnlinkedUnit> uriToUnit = <String, UnlinkedUnit>{};
|
||||
expect(unlinkedUnits.length, unitUris.length);
|
||||
for (int i = 1; i < unlinkedUnits.length; i++) {
|
||||
uriToUnit[unitUris[i]] = unlinkedUnits[i];
|
||||
}
|
||||
UnlinkedUnit getPart(String relativeUri) {
|
||||
String absoluteUri = resolveToAbsoluteUri(library, relativeUri);
|
||||
UnlinkedUnit unit = uriToUnit[absoluteUri];
|
||||
if (unit == null) {
|
||||
fail('Prelinker unexpectedly requested unit for "$relativeUri"'
|
||||
' (resolves to "$absoluteUri").');
|
||||
}
|
||||
return unit;
|
||||
String absoluteUri =
|
||||
resolveRelativeUri(linkerInputs.testDartUri, Uri.parse(relativeUri))
|
||||
.toString();
|
||||
return linkerInputs.getUnit(absoluteUri);
|
||||
}
|
||||
|
||||
UnlinkedPublicNamespace getImport(String relativeUri) {
|
||||
String absoluteUri = resolveToAbsoluteUri(library, relativeUri);
|
||||
UnlinkedPublicNamespace namespace = SerializedMockSdk
|
||||
.instance.uriToUnlinkedUnit[absoluteUri]?.publicNamespace;
|
||||
if (namespace == null) {
|
||||
namespace = uriToPublicNamespace[absoluteUri];
|
||||
}
|
||||
if (namespace == null && !allowMissingFiles) {
|
||||
fail('Prelinker unexpectedly requested namespace for "$relativeUri"'
|
||||
' (resolves to "$absoluteUri").'
|
||||
' Namespaces available: ${uriToPublicNamespace.keys}');
|
||||
}
|
||||
return namespace;
|
||||
return getPart(relativeUri)?.publicNamespace;
|
||||
}
|
||||
|
||||
linked = new LinkedLibrary.fromBuffer(prelink(
|
||||
unlinkedUnits[0], getPart, getImport, context.declaredVariables.get)
|
||||
.toBuffer());
|
||||
linkerInputs.unlinkedDefiningUnit,
|
||||
getPart,
|
||||
getImport,
|
||||
(String declaredVariable) => null).toBuffer());
|
||||
validateLinkedLibrary(linked);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,12 +26,13 @@ import 'package:unittest/unittest.dart';
|
|||
|
||||
import '../context/abstract_context.dart';
|
||||
import '../task/strong/inferred_type_test.dart';
|
||||
import 'resynthesize_test.dart';
|
||||
import 'resynthesize_common.dart';
|
||||
import 'summary_common.dart';
|
||||
|
||||
main() {
|
||||
groupSep = ' | ';
|
||||
defineReflectiveTests(ResynthesizeAstTest);
|
||||
defineReflectiveTests(ResynthesizeAstSpecTest);
|
||||
defineReflectiveTests(ResynthesizeAstStrongTest);
|
||||
defineReflectiveTests(AstInferredTypeTest);
|
||||
}
|
||||
|
||||
|
@ -683,27 +684,65 @@ var v = new C().m(1, b: 'bbb', c: 2.0);
|
|||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ResynthesizeAstTest extends ResynthesizeTest
|
||||
with _AstResynthesizeTestMixin {
|
||||
class ResynthesizeAstSpecTest extends _ResynthesizeAstTest {
|
||||
@override
|
||||
bool get checkPropagatedTypes => false;
|
||||
AnalysisOptionsImpl createOptions() =>
|
||||
super.createOptions()..strongMode = false;
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ResynthesizeAstStrongTest extends _ResynthesizeAstTest {
|
||||
@override
|
||||
AnalysisOptionsImpl createOptions() =>
|
||||
super.createOptions()..strongMode = true;
|
||||
|
||||
@override
|
||||
LibraryElementImpl checkLibrary(String text,
|
||||
{bool allowErrors: false, bool dumpSummaries: false}) {
|
||||
Source source = addTestSource(text);
|
||||
LibraryElementImpl resynthesized = _encodeDecodeLibraryElement(source);
|
||||
LibraryElementImpl original = context.computeLibraryElement(source);
|
||||
checkLibraryElements(original, resynthesized);
|
||||
return resynthesized;
|
||||
@failingTest
|
||||
test_const_invokeConstructor_named_unresolved() {
|
||||
super.test_const_invokeConstructor_named_unresolved();
|
||||
}
|
||||
|
||||
@override
|
||||
DartSdk createDartSdk() => AbstractContextTest.SHARED_MOCK_SDK;
|
||||
@failingTest
|
||||
test_const_invokeConstructor_named_unresolved3() {
|
||||
super.test_const_invokeConstructor_named_unresolved3();
|
||||
}
|
||||
|
||||
@override
|
||||
TestSummaryResynthesizer encodeDecodeLibrarySource(Source source) {
|
||||
return _encodeLibrary(source);
|
||||
@failingTest
|
||||
test_instantiateToBounds_boundRefersToLaterTypeArgument() {
|
||||
// TODO(paulberry): this is failing due to dartbug.com/27072.
|
||||
super.test_instantiateToBounds_boundRefersToLaterTypeArgument();
|
||||
}
|
||||
|
||||
@override
|
||||
@failingTest
|
||||
test_syntheticFunctionType_genericClosure() {
|
||||
super.test_syntheticFunctionType_genericClosure();
|
||||
}
|
||||
|
||||
@override
|
||||
@failingTest
|
||||
test_syntheticFunctionType_inGenericClass() {
|
||||
super.test_syntheticFunctionType_inGenericClass();
|
||||
}
|
||||
|
||||
@override
|
||||
@failingTest
|
||||
test_syntheticFunctionType_noArguments() {
|
||||
super.test_syntheticFunctionType_noArguments();
|
||||
}
|
||||
|
||||
@override
|
||||
@failingTest
|
||||
test_syntheticFunctionType_withArguments() {
|
||||
super.test_syntheticFunctionType_withArguments();
|
||||
}
|
||||
|
||||
@override
|
||||
@failingTest
|
||||
test_unused_type_parameter() {
|
||||
super.test_unused_type_parameter();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -863,3 +902,34 @@ abstract class _AstResynthesizeTestMixinInterface {
|
|||
*/
|
||||
bool get allowMissingFiles;
|
||||
}
|
||||
|
||||
abstract class _ResynthesizeAstTest extends ResynthesizeTest
|
||||
with _AstResynthesizeTestMixin {
|
||||
@override
|
||||
bool get checkPropagatedTypes => false;
|
||||
|
||||
@override
|
||||
LibraryElementImpl checkLibrary(String text,
|
||||
{bool allowErrors: false, bool dumpSummaries: false}) {
|
||||
Source source = addTestSource(text);
|
||||
LibraryElementImpl resynthesized = _encodeDecodeLibraryElement(source);
|
||||
LibraryElementImpl original = context.computeLibraryElement(source);
|
||||
checkLibraryElements(original, resynthesized);
|
||||
return resynthesized;
|
||||
}
|
||||
|
||||
@override
|
||||
void compareLocalElementsOfExecutable(ExecutableElement resynthesized,
|
||||
ExecutableElement original, String desc) {
|
||||
// We don't resynthesize local elements during link.
|
||||
// So, we should not compare them.
|
||||
}
|
||||
|
||||
@override
|
||||
DartSdk createDartSdk() => AbstractContextTest.SHARED_MOCK_SDK;
|
||||
|
||||
@override
|
||||
TestSummaryResynthesizer encodeDecodeLibrarySource(Source source) {
|
||||
return _encodeLibrary(source);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
|
||||
library test.src.serialization.elements_test;
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/constant/value.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
|
@ -24,19 +22,12 @@ import 'package:analyzer/src/generated/source.dart';
|
|||
import 'package:analyzer/src/generated/testing/ast_factory.dart';
|
||||
import 'package:analyzer/src/summary/idl.dart';
|
||||
import 'package:analyzer/src/summary/resynthesize.dart';
|
||||
import 'package:analyzer/src/summary/summarize_elements.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
import 'package:unittest/unittest.dart';
|
||||
|
||||
import '../../generated/test_support.dart';
|
||||
import '../abstract_single_unit.dart';
|
||||
import '../context/abstract_context.dart';
|
||||
import 'summary_common.dart' show canonicalize;
|
||||
|
||||
main() {
|
||||
groupSep = ' | ';
|
||||
defineReflectiveTests(ResynthesizeElementTest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract base class for resynthesizing and comparing elements.
|
||||
|
@ -1135,64 +1126,6 @@ abstract class AbstractResynthesizeTest extends AbstractSingleUnitTest {
|
|||
AnalysisOptionsImpl createOptions() =>
|
||||
new AnalysisOptionsImpl()..enableGenericMethods = true;
|
||||
|
||||
/**
|
||||
* Serialize the given [library] into a summary. Then create a
|
||||
* [TestSummaryResynthesizer] which can deserialize it, along with any
|
||||
* references it makes to `dart:core`.
|
||||
*
|
||||
* Errors will lead to a test failure unless [allowErrors] is `true`.
|
||||
*/
|
||||
TestSummaryResynthesizer encodeLibrary(LibraryElementImpl library,
|
||||
{bool allowErrors: false, bool dumpSummaries: false}) {
|
||||
if (!allowErrors) {
|
||||
assertNoErrors(library.source);
|
||||
}
|
||||
addLibrary('dart:core');
|
||||
addLibrary('dart:async');
|
||||
addLibrary('dart:math');
|
||||
return encodeLibraryElement(library, dumpSummaries: dumpSummaries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the library element [library] into a summary, and then create a
|
||||
* [TestSummaryResynthesizer] which can deserialize it.
|
||||
*
|
||||
* Caller is responsible for checking the library for errors, and adding any
|
||||
* dependent libraries using [addLibrary].
|
||||
*/
|
||||
TestSummaryResynthesizer encodeLibraryElement(LibraryElementImpl library,
|
||||
{bool dumpSummaries: false}) {
|
||||
Map<String, UnlinkedUnit> unlinkedSummaries = <String, UnlinkedUnit>{};
|
||||
LinkedLibrary getLinkedSummaryFor(LibraryElement lib) {
|
||||
LibrarySerializationResult serialized = serializeLibrary(
|
||||
lib, context.typeProvider, context.analysisOptions.strongMode);
|
||||
for (int i = 0; i < serialized.unlinkedUnits.length; i++) {
|
||||
unlinkedSummaries[serialized.unitUris[i]] =
|
||||
new UnlinkedUnit.fromBuffer(serialized.unlinkedUnits[i].toBuffer());
|
||||
}
|
||||
return new LinkedLibrary.fromBuffer(serialized.linked.toBuffer());
|
||||
}
|
||||
|
||||
Map<String, LinkedLibrary> linkedSummaries = <String, LinkedLibrary>{
|
||||
library.source.uri.toString(): getLinkedSummaryFor(library)
|
||||
};
|
||||
for (Source source in otherLibrarySources) {
|
||||
LibraryElement original = context.computeLibraryElement(source);
|
||||
String uri = source.uri.toString();
|
||||
linkedSummaries[uri] = getLinkedSummaryFor(original);
|
||||
}
|
||||
if (dumpSummaries) {
|
||||
unlinkedSummaries.forEach((String path, UnlinkedUnit unit) {
|
||||
print('Unlinked $path: ${JSON.encode(canonicalize(unit))}');
|
||||
});
|
||||
linkedSummaries.forEach((String path, LinkedLibrary lib) {
|
||||
print('Linked $path: ${JSON.encode(canonicalize(lib))}');
|
||||
});
|
||||
}
|
||||
return new TestSummaryResynthesizer(
|
||||
null, context, unlinkedSummaries, linkedSummaries, allowMissingFiles);
|
||||
}
|
||||
|
||||
ElementImpl getActualElement(Element element, String desc) {
|
||||
if (element == null) {
|
||||
return null;
|
||||
|
@ -1343,114 +1276,6 @@ abstract class AbstractResynthesizeTest extends AbstractSingleUnitTest {
|
|||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ResynthesizeElementTest extends ResynthesizeTest {
|
||||
@override
|
||||
LibraryElementImpl checkLibrary(String text,
|
||||
{bool allowErrors: false, bool dumpSummaries: false}) {
|
||||
Source source = addTestSource(text);
|
||||
LibraryElementImpl original = context.computeLibraryElement(source);
|
||||
LibraryElementImpl resynthesized = resynthesizeLibraryElement(
|
||||
encodeLibrary(original,
|
||||
allowErrors: allowErrors, dumpSummaries: dumpSummaries),
|
||||
source.uri.toString(),
|
||||
original);
|
||||
checkLibraryElements(original, resynthesized);
|
||||
return resynthesized;
|
||||
}
|
||||
|
||||
@override
|
||||
SummaryResynthesizer encodeDecodeLibrarySource(Source librarySource) {
|
||||
LibraryElement libraryElement =
|
||||
context.computeLibraryElement(librarySource);
|
||||
return encodeLibrary(libraryElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the given [library] into a summary. Then create a
|
||||
* [TestSummaryResynthesizer] which can deserialize it, along with any
|
||||
* references it makes to `dart:core`.
|
||||
*
|
||||
* Errors will lead to a test failure unless [allowErrors] is `true`.
|
||||
*/
|
||||
TestSummaryResynthesizer encodeLibrary(LibraryElementImpl library,
|
||||
{bool allowErrors: false, bool dumpSummaries: false}) {
|
||||
if (!allowErrors) {
|
||||
assertNoErrors(library.source);
|
||||
}
|
||||
addLibrary('dart:core');
|
||||
addLibrary('dart:async');
|
||||
addLibrary('dart:math');
|
||||
return encodeLibraryElement(library, dumpSummaries: dumpSummaries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the library element [library] into a summary, and then create a
|
||||
* [TestSummaryResynthesizer] which can deserialize it.
|
||||
*
|
||||
* Caller is responsible for checking the library for errors, and adding any
|
||||
* dependent libraries using [addLibrary].
|
||||
*/
|
||||
TestSummaryResynthesizer encodeLibraryElement(LibraryElementImpl library,
|
||||
{bool dumpSummaries: false}) {
|
||||
Map<String, UnlinkedUnit> unlinkedSummaries = <String, UnlinkedUnit>{};
|
||||
LinkedLibrary getLinkedSummaryFor(LibraryElement lib) {
|
||||
LibrarySerializationResult serialized = serializeLibrary(
|
||||
lib, context.typeProvider, context.analysisOptions.strongMode);
|
||||
for (int i = 0; i < serialized.unlinkedUnits.length; i++) {
|
||||
unlinkedSummaries[serialized.unitUris[i]] =
|
||||
new UnlinkedUnit.fromBuffer(serialized.unlinkedUnits[i].toBuffer());
|
||||
}
|
||||
return new LinkedLibrary.fromBuffer(serialized.linked.toBuffer());
|
||||
}
|
||||
|
||||
Map<String, LinkedLibrary> linkedSummaries = <String, LinkedLibrary>{
|
||||
library.source.uri.toString(): getLinkedSummaryFor(library)
|
||||
};
|
||||
for (Source source in otherLibrarySources) {
|
||||
LibraryElement original = context.computeLibraryElement(source);
|
||||
String uri = source.uri.toString();
|
||||
linkedSummaries[uri] = getLinkedSummaryFor(original);
|
||||
}
|
||||
if (dumpSummaries) {
|
||||
unlinkedSummaries.forEach((String path, UnlinkedUnit unit) {
|
||||
print('Unlinked $path: ${JSON.encode(canonicalize(unit))}');
|
||||
});
|
||||
linkedSummaries.forEach((String path, LinkedLibrary lib) {
|
||||
print('Linked $path: ${JSON.encode(canonicalize(lib))}');
|
||||
});
|
||||
}
|
||||
return new TestSummaryResynthesizer(
|
||||
null, context, unlinkedSummaries, linkedSummaries, allowMissingFiles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resynthesize the library element associated with [uri] using
|
||||
* [resynthesizer], and verify that it only had to consult one summary in
|
||||
* order to do so. [original] is consulted merely to verify that no
|
||||
* unnecessary resynthesis work was performed.
|
||||
*/
|
||||
LibraryElementImpl resynthesizeLibraryElement(
|
||||
TestSummaryResynthesizer resynthesizer,
|
||||
String uri,
|
||||
LibraryElement original) {
|
||||
LibraryElementImpl resynthesized = resynthesizer.getLibraryElement(uri);
|
||||
checkMinimalResynthesisWork(resynthesizer, original);
|
||||
return resynthesized;
|
||||
}
|
||||
|
||||
test_core() {
|
||||
addLibrary('dart:async');
|
||||
addLibrary('dart:math');
|
||||
String uri = 'dart:core';
|
||||
LibraryElementImpl original =
|
||||
context.computeLibraryElement(context.sourceFactory.forUri(uri));
|
||||
LibraryElementImpl resynthesized = resynthesizeLibraryElement(
|
||||
encodeLibraryElement(original), uri, original);
|
||||
checkLibraryElements(original, resynthesized);
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
abstract class ResynthesizeTest extends AbstractResynthesizeTest {
|
||||
LibraryElementImpl checkLibrary(String text,
|
|
@ -1,35 +0,0 @@
|
|||
// Copyright (c) 2016, 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.
|
||||
|
||||
library analyzer.test.src.summary.resynthesize_strong_test;
|
||||
|
||||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:analyzer/src/generated/sdk.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
import 'package:unittest/unittest.dart';
|
||||
|
||||
import '../context/abstract_context.dart';
|
||||
import 'resynthesize_test.dart';
|
||||
|
||||
main() {
|
||||
groupSep = ' | ';
|
||||
defineReflectiveTests(ResynthesizeStrongTest);
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ResynthesizeStrongTest extends ResynthesizeElementTest {
|
||||
@override
|
||||
DartSdk createDartSdk() => AbstractContextTest.SHARED_STRONG_MOCK_SDK;
|
||||
|
||||
@override
|
||||
AnalysisOptionsImpl createOptions() =>
|
||||
super.createOptions()..strongMode = true;
|
||||
|
||||
@override
|
||||
@failingTest
|
||||
test_instantiateToBounds_boundRefersToLaterTypeArgument() {
|
||||
// TODO(paulberry): this is failing due to dartbug.com/27072.
|
||||
super.test_instantiateToBounds_boundRefersToLaterTypeArgument();
|
||||
}
|
||||
}
|
|
@ -137,6 +137,8 @@ abstract class LinkedSummarizeAstTest extends SummaryLinkerTest
|
|||
@override
|
||||
List<UnlinkedUnit> unlinkedUnits;
|
||||
|
||||
LinkerInputs linkerInputs;
|
||||
|
||||
@override
|
||||
bool get checkAstDerivedData => true;
|
||||
|
||||
|
@ -152,7 +154,7 @@ abstract class LinkedSummarizeAstTest extends SummaryLinkerTest
|
|||
@override
|
||||
void serializeLibraryText(String text, {bool allowErrors: false}) {
|
||||
Map<String, UnlinkedUnitBuilder> uriToUnit = this._filesToLink.uriToUnit;
|
||||
LinkerInputs linkerInputs = createLinkerInputs(text);
|
||||
linkerInputs = createLinkerInputs(text);
|
||||
linked = link(
|
||||
linkerInputs.linkedLibraries,
|
||||
linkerInputs.getDependency,
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
// Copyright (c) 2016, 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.
|
||||
|
||||
library analyzer.test.src.summary.summarize_elements_strong_test;
|
||||
|
||||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:analyzer/src/generated/sdk.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
import 'package:unittest/unittest.dart';
|
||||
|
||||
import '../context/abstract_context.dart';
|
||||
import 'summarize_elements_test.dart';
|
||||
import 'summary_common.dart';
|
||||
|
||||
main() {
|
||||
groupSep = ' | ';
|
||||
defineReflectiveTests(SummarizeElementsStrongTest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override of [SummaryTest] which creates summaries from the element model
|
||||
* using strong mode.
|
||||
*/
|
||||
@reflectiveTest
|
||||
class SummarizeElementsStrongTest extends SummarizeElementsTest {
|
||||
@override
|
||||
AnalysisOptionsImpl get options => super.options..strongMode = true;
|
||||
|
||||
@override
|
||||
bool get strongMode => true;
|
||||
|
||||
@override
|
||||
DartSdk createDartSdk() => AbstractContextTest.SHARED_STRONG_MOCK_SDK;
|
||||
}
|
|
@ -1,167 +0,0 @@
|
|||
// Copyright (c) 2016, 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.
|
||||
|
||||
library analyzer.test.src.summary.summarize_elements_test;
|
||||
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:analyzer/src/generated/sdk.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/generated/source_io.dart';
|
||||
import 'package:analyzer/src/summary/format.dart';
|
||||
import 'package:analyzer/src/summary/idl.dart';
|
||||
import 'package:analyzer/src/summary/public_namespace_computer.dart'
|
||||
as public_namespace;
|
||||
import 'package:analyzer/src/summary/summarize_elements.dart'
|
||||
as summarize_elements;
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
import 'package:unittest/unittest.dart';
|
||||
|
||||
import '../abstract_single_unit.dart';
|
||||
import '../context/abstract_context.dart';
|
||||
import 'summary_common.dart';
|
||||
|
||||
main() {
|
||||
groupSep = ' | ';
|
||||
defineReflectiveTests(SummarizeElementsTest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override of [SummaryTest] which creates summaries from the element model.
|
||||
*/
|
||||
@reflectiveTest
|
||||
class SummarizeElementsTest extends AbstractSingleUnitTest with SummaryTest {
|
||||
/**
|
||||
* The list of absolute unit URIs corresponding to the compilation units in
|
||||
* [unlinkedUnits].
|
||||
*/
|
||||
List<String> unitUris;
|
||||
|
||||
/**
|
||||
* Map containing all source files in this test, and their corresponding file
|
||||
* contents.
|
||||
*/
|
||||
final Map<Source, String> _fileContents = <Source, String>{};
|
||||
|
||||
@override
|
||||
LinkedLibrary linked;
|
||||
|
||||
@override
|
||||
List<UnlinkedUnit> unlinkedUnits;
|
||||
|
||||
@override
|
||||
bool get checkAstDerivedData => false;
|
||||
|
||||
@override
|
||||
bool get expectAbsoluteUrisInDependencies => true;
|
||||
|
||||
/**
|
||||
* Determine the analysis options that should be used for this test.
|
||||
*/
|
||||
AnalysisOptionsImpl get options =>
|
||||
new AnalysisOptionsImpl()..enableGenericMethods = true;
|
||||
|
||||
@override
|
||||
bool get skipFullyLinkedData => false;
|
||||
|
||||
@override
|
||||
bool get skipNonConstInitializers => true;
|
||||
|
||||
@override
|
||||
bool get strongMode => false;
|
||||
|
||||
@override
|
||||
Source addNamedSource(String filePath, String contents) {
|
||||
Source source = super.addSource(filePath, contents);
|
||||
_fileContents[source] = contents;
|
||||
return source;
|
||||
}
|
||||
|
||||
@override
|
||||
DartSdk createDartSdk() => AbstractContextTest.SHARED_MOCK_SDK;
|
||||
|
||||
/**
|
||||
* Serialize the library containing the given class [element], then
|
||||
* deserialize it and return the summary of the class.
|
||||
*/
|
||||
UnlinkedClass serializeClassElement(ClassElement element) {
|
||||
serializeLibraryElement(element.library);
|
||||
return findClass(element.name, failIfAbsent: true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the given [library] element, then deserialize it and store the
|
||||
* resulting summary in [linked] and [unlinkedUnits].
|
||||
*/
|
||||
void serializeLibraryElement(LibraryElement library) {
|
||||
summarize_elements.LibrarySerializationResult serializedLib =
|
||||
summarize_elements.serializeLibrary(
|
||||
library, context.typeProvider, context.analysisOptions.strongMode);
|
||||
{
|
||||
List<int> buffer = serializedLib.linked.toBuffer();
|
||||
linked = new LinkedLibrary.fromBuffer(buffer);
|
||||
validateLinkedLibrary(linked);
|
||||
}
|
||||
unlinkedUnits = serializedLib.unlinkedUnits.map((UnlinkedUnitBuilder b) {
|
||||
List<int> buffer = b.toBuffer();
|
||||
return new UnlinkedUnit.fromBuffer(buffer);
|
||||
}).toList();
|
||||
unitUris = serializedLib.unitUris;
|
||||
}
|
||||
|
||||
@override
|
||||
void serializeLibraryText(String text, {bool allowErrors: false}) {
|
||||
Source source = addTestSource(text);
|
||||
_fileContents[source] = text;
|
||||
LibraryElement library = context.computeLibraryElement(source);
|
||||
if (!allowErrors) {
|
||||
assertNoErrorsInSource(source);
|
||||
}
|
||||
serializeLibraryElement(library);
|
||||
expect(unlinkedUnits[0].imports.length, linked.importDependencies.length);
|
||||
expect(unlinkedUnits[0].exports.length, linked.exportDependencies.length);
|
||||
expect(linked.units.length, unlinkedUnits.length);
|
||||
for (int i = 0; i < linked.units.length; i++) {
|
||||
expect(unlinkedUnits[i].references.length,
|
||||
lessThanOrEqualTo(linked.units[i].references.length));
|
||||
}
|
||||
verifyPublicNamespace();
|
||||
}
|
||||
|
||||
@override
|
||||
void setUp() {
|
||||
super.setUp();
|
||||
prepareAnalysisContext(options);
|
||||
}
|
||||
|
||||
test_class_no_superclass() {
|
||||
UnlinkedClass cls =
|
||||
serializeClassElement(context.typeProvider.objectType.element);
|
||||
expect(cls.supertype, isNull);
|
||||
expect(cls.hasNoSupertype, isTrue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that [public_namespace.computePublicNamespace] produces data that's
|
||||
* equivalent to that produced by [summarize_elements.serializeLibrary].
|
||||
*/
|
||||
void verifyPublicNamespace() {
|
||||
for (int i = 0; i < unlinkedUnits.length; i++) {
|
||||
Source source = context.sourceFactory.forUri(unitUris[i]);
|
||||
String text = _fileContents[source];
|
||||
if (text == null) {
|
||||
if (!allowMissingFiles) {
|
||||
fail('Could not find file while verifying public namespace: '
|
||||
'${unitUris[i]}');
|
||||
}
|
||||
} else {
|
||||
UnlinkedPublicNamespace namespace =
|
||||
computePublicNamespaceFromText(text, source);
|
||||
expect(canonicalize(namespace),
|
||||
canonicalize(unlinkedUnits[i].publicNamespace),
|
||||
reason: 'publicNamespace(${unitUris[i]})');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,12 +17,8 @@ import 'package_bundle_reader_test.dart' as package_bundle_reader_test;
|
|||
import 'prelinker_test.dart' as prelinker_test;
|
||||
import 'pub_summary_test.dart' as pub_summary_test;
|
||||
import 'resynthesize_ast_test.dart' as resynthesize_ast_test;
|
||||
import 'resynthesize_strong_test.dart' as resynthesize_strong_test;
|
||||
import 'resynthesize_test.dart' as resynthesize_test;
|
||||
import 'summarize_ast_strong_test.dart' as summarize_ast_strong_test;
|
||||
import 'summarize_ast_test.dart' as summarize_ast_test;
|
||||
import 'summarize_elements_strong_test.dart' as summarize_elements_strong_test;
|
||||
import 'summarize_elements_test.dart' as summarize_elements_test;
|
||||
|
||||
/// Utility for manually running all tests.
|
||||
main() {
|
||||
|
@ -38,11 +34,7 @@ main() {
|
|||
prelinker_test.main();
|
||||
pub_summary_test.main();
|
||||
resynthesize_ast_test.main();
|
||||
resynthesize_strong_test.main();
|
||||
resynthesize_test.main();
|
||||
summarize_ast_strong_test.main();
|
||||
summarize_ast_test.main();
|
||||
summarize_elements_strong_test.main();
|
||||
summarize_elements_test.main();
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue