Chromium Code Reviews| Index: pkg/analyzer/test/src/summary/resynthesize_test.dart |
| diff --git a/pkg/analyzer/test/src/summary/resynthesize_test.dart b/pkg/analyzer/test/src/summary/resynthesize_test.dart |
| index 4dde487e52828c15fbf753c41284807eeaacc598..fc558926f7c3a475baefc6472c5b6b01f5bf1579 100644 |
| --- a/pkg/analyzer/test/src/summary/resynthesize_test.dart |
| +++ b/pkg/analyzer/test/src/summary/resynthesize_test.dart |
| @@ -51,7 +51,8 @@ class ResynthTest extends ResolverTestCase { |
| LibraryElementImpl original = resolve2(source); |
| LibraryElementImpl resynthesized = resynthesizeLibraryElement( |
| encodeLibrary(original, allowErrors: allowErrors), |
| - source.uri.toString()); |
| + source.uri.toString(), |
| + original); |
| checkLibraryElements(original, resynthesized); |
| } |
| @@ -101,6 +102,31 @@ class ResynthTest extends ResolverTestCase { |
| // TODO(paulberry): test metadata. |
| } |
| + /** |
| + * Verify that the [resynthesizer] didn't do any unnecessary work when |
| + * resynthesizing [library]. |
| + */ |
| + void checkMinimalResynthesisWork( |
| + _TestSummaryResynthesizer resynthesizer, LibraryElement library) { |
| + // Check that no other summaries needed to be resynthesized to resynthesize |
| + // the library element. |
| + expect(resynthesizer.resynthesisCount, 1); |
| + // Check that the only linked summary consulted was that for [uri]. |
| + expect(resynthesizer.linkedSummariesRequested, hasLength(1)); |
| + expect(resynthesizer.linkedSummariesRequested.first, |
| + library.source.uri.toString()); |
| + // Check that the only unlinked summaries consulted were those for the |
| + // library in question. |
| + Set<String> expectedCompilationUnitUris = |
| + <String>[library.source.uri.toString()].toSet(); |
| + for (CompilationUnitElement partUnit in library.parts) { |
|
scheglov
2016/02/01 21:45:22
You could use "library.units" and avoid the specia
Paul Berry
2016/02/01 22:32:32
Done.
|
| + expectedCompilationUnitUris.add(partUnit.source.uri.toString()); |
| + } |
| + for (String requestedUri in resynthesizer.unlinkedSummariesRequested) { |
| + expect(expectedCompilationUnitUris, contains(requestedUri)); |
| + } |
| + } |
| + |
| void compareClassElements( |
| ClassElementImpl resynthesized, ClassElementImpl original, String desc) { |
| compareElements(resynthesized, original, desc); |
| @@ -690,14 +716,15 @@ class ResynthTest extends ResolverTestCase { |
| /** |
| * Resynthesize the library element associated with [uri] using |
| * [resynthesizer], and verify that it only had to consult one summary in |
| - * order to do so. |
| + * order to do so. [original] is consulted merely to verify that no |
| + * unnecessary resynthesis work was performed. |
| */ |
| LibraryElementImpl resynthesizeLibraryElement( |
| - _TestSummaryResynthesizer resynthesizer, String uri) { |
| + _TestSummaryResynthesizer resynthesizer, |
| + String uri, |
| + LibraryElement original) { |
| LibraryElementImpl resynthesized = resynthesizer.getLibraryElement(uri); |
| - // Check that no other summaries needed to be resynthesized to resynthesize |
| - // the library element. |
| - expect(resynthesizer.resynthesisCount, 1); |
| + checkMinimalResynthesisWork(resynthesizer, original); |
| return resynthesized; |
| } |
| @@ -1316,8 +1343,8 @@ class C { |
| String uri = 'dart:core'; |
| LibraryElementImpl original = |
| resolve2(analysisContext2.sourceFactory.forUri(uri)); |
| - LibraryElementImpl resynthesized = |
| - resynthesizeLibraryElement(encodeLibraryElement(original), uri); |
| + LibraryElementImpl resynthesized = resynthesizeLibraryElement( |
| + encodeLibraryElement(original), uri, original); |
| checkLibraryElements(original, resynthesized); |
| } |
| @@ -2218,6 +2245,7 @@ var x;'''); |
| _TestSummaryResynthesizer resynthesizer = encodeLibrary(original.library); |
| ElementLocationImpl location = original.location; |
| Element result = resynthesizer.getElement(location); |
| + checkMinimalResynthesisWork(resynthesizer, original.library); |
| // Check that no other summaries needed to be resynthesized to resynthesize |
| // the library element. |
| expect(resynthesizer.resynthesisCount, 1); |
| @@ -2230,6 +2258,18 @@ class _TestSummaryResynthesizer extends SummaryResynthesizer { |
| final Map<String, UnlinkedUnit> unlinkedSummaries; |
| final Map<String, LinkedLibrary> linkedSummaries; |
| + /** |
| + * The set of uris for which unlinked summaries have been requested using |
| + * [getUnlinkedSummary]. |
| + */ |
| + final Set<String> unlinkedSummariesRequested = new Set<String>(); |
| + |
| + /** |
| + * The set of uris for which linked summaries have been requested using |
| + * [getLinkedSummary]. |
| + */ |
| + final Set<String> linkedSummariesRequested = new Set<String>(); |
| + |
| _TestSummaryResynthesizer( |
| SummaryResynthesizer parent, |
| AnalysisContext context, |
| @@ -2242,6 +2282,7 @@ class _TestSummaryResynthesizer extends SummaryResynthesizer { |
| @override |
| LinkedLibrary getLinkedSummary(String uri) { |
| + linkedSummariesRequested.add(uri); |
| LinkedLibrary serializedLibrary = linkedSummaries[uri]; |
| if (serializedLibrary == null) { |
| fail('Unexpectedly tried to get linked summary for $uri'); |
| @@ -2251,6 +2292,7 @@ class _TestSummaryResynthesizer extends SummaryResynthesizer { |
| @override |
| UnlinkedUnit getUnlinkedSummary(String uri) { |
| + unlinkedSummariesRequested.add(uri); |
| UnlinkedUnit serializedUnit = unlinkedSummaries[uri]; |
| if (serializedUnit == null) { |
| fail('Unexpectedly tried to get unlinked summary for $uri'); |