Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: pkg/analyzer/test/src/summary/summarize_ast_test.dart

Issue 2225163002: Rework linker tests to use SummaryDataStore. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/test/src/summary/linker_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.test.src.summary.summarize_ast_test; 5 library analyzer.test.src.summary.summarize_ast_test;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 import 'package:analyzer/dart/ast/ast.dart'; 8 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/dart/ast/token.dart'; 9 import 'package:analyzer/dart/ast/token.dart';
10 import 'package:analyzer/src/dart/scanner/reader.dart'; 10 import 'package:analyzer/src/dart/scanner/reader.dart';
11 import 'package:analyzer/src/dart/scanner/scanner.dart'; 11 import 'package:analyzer/src/dart/scanner/scanner.dart';
12 import 'package:analyzer/src/generated/error.dart'; 12 import 'package:analyzer/src/generated/error.dart';
13 import 'package:analyzer/src/generated/java_engine.dart'; 13 import 'package:analyzer/src/generated/java_engine.dart';
14 import 'package:analyzer/src/generated/parser.dart'; 14 import 'package:analyzer/src/generated/parser.dart';
15 import 'package:analyzer/src/generated/source.dart'; 15 import 'package:analyzer/src/generated/source.dart';
16 import 'package:analyzer/src/summary/format.dart'; 16 import 'package:analyzer/src/summary/format.dart';
17 import 'package:analyzer/src/summary/idl.dart'; 17 import 'package:analyzer/src/summary/idl.dart';
18 import 'package:analyzer/src/summary/link.dart'; 18 import 'package:analyzer/src/summary/link.dart';
19 import 'package:analyzer/src/summary/package_bundle_reader.dart';
19 import 'package:analyzer/src/summary/summarize_ast.dart'; 20 import 'package:analyzer/src/summary/summarize_ast.dart';
20 import 'package:analyzer/src/summary/summarize_elements.dart'; 21 import 'package:analyzer/src/summary/summarize_elements.dart';
21 import 'package:unittest/unittest.dart'; 22 import 'package:unittest/unittest.dart';
22 23
23 import '../../reflective_tests.dart'; 24 import '../../reflective_tests.dart';
24 import 'summary_common.dart'; 25 import 'summary_common.dart';
25 26
26 main() { 27 main() {
27 groupSep = ' | '; 28 groupSep = ' | ';
28 runReflectiveTests(LinkedSummarizeAstSpecTest); 29 runReflectiveTests(LinkedSummarizeAstSpecTest);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 bool get expectAbsoluteUrisInDependencies => false; 199 bool get expectAbsoluteUrisInDependencies => false;
199 200
200 @override 201 @override
201 bool get skipFullyLinkedData => false; 202 bool get skipFullyLinkedData => false;
202 203
203 @override 204 @override
204 bool get skipNonConstInitializers => false; 205 bool get skipNonConstInitializers => false;
205 206
206 @override 207 @override
207 void serializeLibraryText(String text, {bool allowErrors: false}) { 208 void serializeLibraryText(String text, {bool allowErrors: false}) {
208 Map<String, UnlinkedUnitBuilder> uriToUnit = this.uriToUnit; 209 Map<String, UnlinkedUnitBuilder> uriToUnit = this._filesToLink.uriToUnit;
209 LinkerInputs linkerInputs = createLinkerInputs(text); 210 LinkerInputs linkerInputs = createLinkerInputs(text);
210 linked = link(linkerInputs.linkedLibraries, linkerInputs.getDependency, 211 linked = link(linkerInputs.linkedLibraries, linkerInputs.getDependency,
211 linkerInputs.getUnit, strongMode)[linkerInputs.testDartUri.toString()]; 212 linkerInputs.getUnit, strongMode)[linkerInputs.testDartUri.toString()];
212 expect(linked, isNotNull); 213 expect(linked, isNotNull);
213 validateLinkedLibrary(linked); 214 validateLinkedLibrary(linked);
214 unlinkedUnits = <UnlinkedUnit>[linkerInputs.unlinkedDefiningUnit]; 215 unlinkedUnits = <UnlinkedUnit>[linkerInputs.unlinkedDefiningUnit];
215 for (String relativeUri 216 for (String relativeUri
216 in linkerInputs.unlinkedDefiningUnit.publicNamespace.parts) { 217 in linkerInputs.unlinkedDefiningUnit.publicNamespace.parts) {
217 UnlinkedUnit unit = uriToUnit[ 218 UnlinkedUnit unit = uriToUnit[
218 resolveRelativeUri(linkerInputs.testDartUri, Uri.parse(relativeUri)) 219 resolveRelativeUri(linkerInputs.testDartUri, Uri.parse(relativeUri))
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 return unit; 282 return unit;
282 } 283 }
283 } 284 }
284 285
285 /** 286 /**
286 * Base class providing the ability to run the summary linker using summaries 287 * Base class providing the ability to run the summary linker using summaries
287 * build from ASTs. 288 * build from ASTs.
288 */ 289 */
289 abstract class SummaryLinkerTest { 290 abstract class SummaryLinkerTest {
290 /** 291 /**
291 * Map from absolute URI to the [UnlinkedUnit] for each compilation unit 292 * Information about the files to be linked.
292 * passed to [addNamedSource].
293 */ 293 */
294 Map<String, UnlinkedUnitBuilder> uriToUnit = <String, UnlinkedUnitBuilder>{}; 294 _FilesToLink _filesToLink = new _FilesToLink();
295
296 /**
297 * Map from absolute URI to the [LinkedLibrary] for each compilation unit in a
298 * package bundle passed to [addBundle].
299 */
300 Map<String, LinkedLibrary> _dependentLinkedLibraries =
301 <String, LinkedLibrary>{};
302
303 /**
304 * Map from absolute URI to the [UnlinkedUnit] for each compilation unit in a
305 * package bundle passed to [addBundle].
306 */
307 Map<String, UnlinkedUnit> _dependentUnlinkedUnits = <String, UnlinkedUnit>{};
308 295
309 /** 296 /**
310 * A test will set this to `true` if it contains `import`, `export`, or 297 * A test will set this to `true` if it contains `import`, `export`, or
311 * `part` declarations that deliberately refer to non-existent files. 298 * `part` declarations that deliberately refer to non-existent files.
312 */ 299 */
313 bool get allowMissingFiles; 300 bool get allowMissingFiles;
314 301
315 /** 302 /**
316 * Add the given package bundle as a dependency so that it may be referenced 303 * Add the given package bundle as a dependency so that it may be referenced
317 * by the files under test. 304 * by the files under test.
318 */ 305 */
319 void addBundle(PackageBundle bundle) { 306 void addBundle(String path, PackageBundle bundle) {
320 for (int i = 0; i < bundle.linkedLibraryUris.length; i++) { 307 _filesToLink.summaryDataStore.addBundle(path, bundle);
321 _dependentLinkedLibraries[bundle.linkedLibraryUris[i]] =
322 bundle.linkedLibraries[i];
323 }
324 for (int i = 0; i < bundle.unlinkedUnitUris.length; i++) {
325 _dependentUnlinkedUnits[bundle.unlinkedUnitUris[i]] =
326 bundle.unlinkedUnits[i];
327 }
328 } 308 }
329 309
330 /** 310 /**
331 * Add the given source file so that it may be referenced by the file under 311 * Add the given source file so that it may be referenced by the file under
332 * test. 312 * test.
333 */ 313 */
334 Source addNamedSource(String filePath, String contents) { 314 Source addNamedSource(String filePath, String contents) {
335 CompilationUnit unit = _parseText(contents); 315 CompilationUnit unit = _parseText(contents);
336 List<int> lineStarts = StringUtilities.computeLineStarts(contents); 316 List<int> lineStarts = StringUtilities.computeLineStarts(contents);
337 UnlinkedUnitBuilder unlinkedUnit = serializeAstUnlinked(unit, lineStarts); 317 UnlinkedUnitBuilder unlinkedUnit = serializeAstUnlinked(unit, lineStarts);
338 uriToUnit[absUri(filePath)] = unlinkedUnit; 318 _filesToLink.uriToUnit[absUri(filePath)] = unlinkedUnit;
339 // Tests using SummaryLinkerTest don't actually need the returned 319 // Tests using SummaryLinkerTest don't actually need the returned
340 // Source, so we can safely return `null`. 320 // Source, so we can safely return `null`.
341 return null; 321 return null;
342 } 322 }
343 323
344 LinkerInputs createLinkerInputs(String text, {String path: '/test.dart'}) { 324 LinkerInputs createLinkerInputs(String text, {String path: '/test.dart'}) {
345 Uri testDartUri = Uri.parse(absUri(path)); 325 Uri testDartUri = Uri.parse(absUri(path));
346 CompilationUnit unit = _parseText(text); 326 CompilationUnit unit = _parseText(text);
347 List<int> lineStarts = StringUtilities.computeLineStarts(text); 327 List<int> lineStarts = StringUtilities.computeLineStarts(text);
348 UnlinkedUnitBuilder unlinkedDefiningUnit = 328 UnlinkedUnitBuilder unlinkedDefiningUnit =
349 serializeAstUnlinked(unit, lineStarts); 329 serializeAstUnlinked(unit, lineStarts);
350 uriToUnit[testDartUri.toString()] = unlinkedDefiningUnit; 330 _filesToLink.uriToUnit[testDartUri.toString()] = unlinkedDefiningUnit;
351 LinkerInputs linkerInputs = new LinkerInputs( 331 LinkerInputs linkerInputs = new LinkerInputs(
352 allowMissingFiles, 332 allowMissingFiles,
353 uriToUnit, 333 _filesToLink.uriToUnit,
354 testDartUri, 334 testDartUri,
355 unlinkedDefiningUnit, 335 unlinkedDefiningUnit,
356 _dependentLinkedLibraries, 336 _filesToLink.summaryDataStore.linkedMap,
357 _dependentUnlinkedUnits); 337 _filesToLink.summaryDataStore.unlinkedMap);
358 // Reset uriToUnit, _dependentLinkedLibraries, and _dependentUnlinkedUnits 338 // Reset _filesToLink in case the test needs to start a new package bundle.
359 // in case the test needs to start a new package bundle. 339 _filesToLink = new _FilesToLink();
360 uriToUnit = <String, UnlinkedUnitBuilder>{};
361 _dependentLinkedLibraries = <String, LinkedLibrary>{};
362 _dependentUnlinkedUnits = <String, UnlinkedUnit>{};
363 return linkerInputs; 340 return linkerInputs;
364 } 341 }
365 342
366 /** 343 /**
367 * Link together the given file, along with any other files passed to 344 * Link together the given file, along with any other files passed to
368 * [addNamedSource], to form a package bundle. Reset the state of the buffers 345 * [addNamedSource], to form a package bundle. Reset the state of the buffers
369 * accumulated by [addNamedSource] and [addBundle] so that further bundles 346 * accumulated by [addNamedSource] and [addBundle] so that further bundles
370 * can be created. 347 * can be created.
371 */ 348 */
372 PackageBundleBuilder createPackageBundle(String text, 349 PackageBundleBuilder createPackageBundle(String text,
(...skipping 17 matching lines...) Expand all
390 CompilationUnit _parseText(String text) { 367 CompilationUnit _parseText(String text) {
391 CharSequenceReader reader = new CharSequenceReader(text); 368 CharSequenceReader reader = new CharSequenceReader(text);
392 Scanner scanner = 369 Scanner scanner =
393 new Scanner(null, reader, AnalysisErrorListener.NULL_LISTENER); 370 new Scanner(null, reader, AnalysisErrorListener.NULL_LISTENER);
394 Token token = scanner.tokenize(); 371 Token token = scanner.tokenize();
395 Parser parser = new Parser(null, AnalysisErrorListener.NULL_LISTENER); 372 Parser parser = new Parser(null, AnalysisErrorListener.NULL_LISTENER);
396 parser.parseGenericMethods = true; 373 parser.parseGenericMethods = true;
397 return parser.parseCompilationUnit(token); 374 return parser.parseCompilationUnit(token);
398 } 375 }
399 } 376 }
377
378 /**
379 * [_FilesToLink] stores information about a set of files to be linked together.
380 * This information is grouped into a class to allow it to be reset easily when
381 * [SummaryLinkerTest.createLinkerInputs] is called.
382 */
383 class _FilesToLink {
384 /**
385 * Map from absolute URI to the [UnlinkedUnit] for each compilation unit
386 * passed to [addNamedSource].
387 */
388 Map<String, UnlinkedUnitBuilder> uriToUnit = <String, UnlinkedUnitBuilder>{};
389
390 /**
391 * Information about summaries to be included in the link process.
392 */
393 SummaryDataStore summaryDataStore = new SummaryDataStore([]);
394 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/summary/linker_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698