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/context/context_test.dart

Issue 2132073003: Validate cache consistency asynchronously. Compute modification times of physical files in a separa… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 5 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.context.context_test; 5 library analyzer.test.src.context.context_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 source, 394 source,
395 r''' 395 r'''
396 main() { 396 main() {
397 print(12); 397 print(12);
398 } 398 }
399 '''); 399 ''');
400 _analyzeAll_assertFinished(); 400 _analyzeAll_assertFinished();
401 expect(context.getResolvedCompilationUnit2(source, source), unit); 401 expect(context.getResolvedCompilationUnit2(source, source), unit);
402 // remove overlay 402 // remove overlay
403 context.setContents(source, null); 403 context.setContents(source, null);
404 context.validateCacheConsistency();
405 _analyzeAll_assertFinished(); 404 _analyzeAll_assertFinished();
406 expect(context.getResolvedCompilationUnit2(source, source), unit); 405 expect(context.getResolvedCompilationUnit2(source, source), unit);
407 } 406 }
408 407
409 Future test_applyChanges_removeContainer() { 408 Future test_applyChanges_removeContainer() {
410 SourcesChangedListener listener = new SourcesChangedListener(); 409 SourcesChangedListener listener = new SourcesChangedListener();
411 context.onSourcesChanged.listen(listener.onData); 410 context.onSourcesChanged.listen(listener.onData);
412 String libAContents = r''' 411 String libAContents = r'''
413 library libA; 412 library libA;
414 import 'libB.dart';'''; 413 import 'libB.dart';''';
(...skipping 12 matching lines...) Expand all
427 expect(sources, hasLength(1)); 426 expect(sources, hasLength(1));
428 expect(sources[0], same(libA)); 427 expect(sources[0], same(libA));
429 return pumpEventQueue().then((_) { 428 return pumpEventQueue().then((_) {
430 listener.assertEvent(wereSourcesAdded: true); 429 listener.assertEvent(wereSourcesAdded: true);
431 listener.assertEvent(wereSourcesAdded: true); 430 listener.assertEvent(wereSourcesAdded: true);
432 listener.assertEvent(wereSourcesRemovedOrDeleted: true); 431 listener.assertEvent(wereSourcesRemovedOrDeleted: true);
433 listener.assertNoMoreEvents(); 432 listener.assertNoMoreEvents();
434 }); 433 });
435 } 434 }
436 435
436 void test_cacheConsistencyValidator_computed() {
437 CacheConsistencyValidator validator = context.cacheConsistencyValidator;
438 // Add sources.
439 MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
440 String path1 = '/test1.dart';
441 String path2 = '/test2.dart';
442 Source source1 = resourceProvider.newFile(path1, '// 1-1').createSource();
443 Source source2 = resourceProvider.newFile(path2, '// 2-1').createSource();
444 context.applyChanges(
445 new ChangeSet()..addedSource(source1)..addedSource(source2));
446 // Same modification times.
447 expect(
448 validator.sourceModificationTimesComputed([source1, source2],
449 [source1.modificationStamp, source2.modificationStamp]),
450 isFalse);
451 // Different modification times.
452 expect(
453 validator.sourceModificationTimesComputed([source1, source2],
454 [source1.modificationStamp + 1, source2.modificationStamp]),
455 isTrue);
456 }
457
458 void test_cacheConsistencyValidator_getSources() {
459 CacheConsistencyValidator validator = context.cacheConsistencyValidator;
460 // Add sources.
461 MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
462 String path1 = '/test1.dart';
463 String path2 = '/test2.dart';
464 Source source1 = resourceProvider.newFile(path1, '// 1-1').createSource();
465 Source source2 = resourceProvider.newFile(path2, '// 2-1').createSource();
466 context.applyChanges(
467 new ChangeSet()..addedSource(source1)..addedSource(source2));
468 // No overlays.
469 expect(validator.getSourcesToComputeModificationTimes(),
470 unorderedEquals([source1, source2]));
471 // Add an overlay.
472 context.setContents(source1, '// 1-2');
473 expect(validator.getSourcesToComputeModificationTimes(),
474 unorderedEquals([source2]));
475 // Remove an overlay.
476 context.setContents(source1, null);
477 expect(validator.getSourcesToComputeModificationTimes(),
478 unorderedEquals([source1, source2]));
479 }
480
437 void test_computeDocumentationComment_class_block() { 481 void test_computeDocumentationComment_class_block() {
438 String comment = "/** Comment */"; 482 String comment = "/** Comment */";
439 Source source = addSource( 483 Source source = addSource(
440 "/test.dart", 484 "/test.dart",
441 """ 485 """
442 $comment 486 $comment
443 class A {}"""); 487 class A {}""");
444 LibraryElement libraryElement = context.computeLibraryElement(source); 488 LibraryElement libraryElement = context.computeLibraryElement(source);
445 expect(libraryElement, isNotNull); 489 expect(libraryElement, isNotNull);
446 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; 490 ClassElement classElement = libraryElement.definingCompilationUnit.types[0];
(...skipping 3374 matching lines...) Expand 10 before | Expand all | Expand 10 after
3821 * Initialize the visitor. 3865 * Initialize the visitor.
3822 */ 3866 */
3823 _ElementGatherer(); 3867 _ElementGatherer();
3824 3868
3825 @override 3869 @override
3826 void visitElement(Element element) { 3870 void visitElement(Element element) {
3827 elements[element] = element; 3871 elements[element] = element;
3828 super.visitElement(element); 3872 super.visitElement(element);
3829 } 3873 }
3830 } 3874 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698