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

Side by Side Diff: pkg/analyzer/test/src/dart/analysis/driver_test.dart

Issue 2818623003: Add a flag for caching all analysis results in the driver. (Closed)
Patch Set: Created 3 years, 8 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/dart/analysis/base.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.driver; 5 library analyzer.test.driver;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 21 matching lines...) Expand all
32 import 'package:test/test.dart'; 32 import 'package:test/test.dart';
33 import 'package:test_reflective_loader/test_reflective_loader.dart'; 33 import 'package:test_reflective_loader/test_reflective_loader.dart';
34 import 'package:typed_mock/typed_mock.dart'; 34 import 'package:typed_mock/typed_mock.dart';
35 35
36 import '../../../utils.dart'; 36 import '../../../utils.dart';
37 import '../../context/mock_sdk.dart'; 37 import '../../context/mock_sdk.dart';
38 import 'base.dart'; 38 import 'base.dart';
39 39
40 main() { 40 main() {
41 defineReflectiveSuite(() { 41 defineReflectiveSuite(() {
42 defineReflectiveTests(AnalysisDriverSchedulerTest);
42 defineReflectiveTests(AnalysisDriverTest); 43 defineReflectiveTests(AnalysisDriverTest);
43 defineReflectiveTests(AnalysisDriverSchedulerTest); 44 defineReflectiveTests(CacheAllAnalysisDriverTest);
44 }); 45 });
45 } 46 }
46 47
47 /** 48 /**
48 * Returns a [Future] that completes after pumping the event queue [times] 49 * Returns a [Future] that completes after pumping the event queue [times]
49 * times. By default, this should pump the event queue enough times to allow 50 * times. By default, this should pump the event queue enough times to allow
50 * any code to run, as long as it's not waiting on some external event. 51 * any code to run, as long as it's not waiting on some external event.
51 */ 52 */
52 Future pumpEventQueue([int times = 5000]) { 53 Future pumpEventQueue([int times = 5000]) {
53 if (times == 0) return new Future.value(); 54 if (times == 0) return new Future.value();
(...skipping 2542 matching lines...) Expand 10 before | Expand all | Expand 10 after
2596 /** 2597 /**
2597 * Return the [provider] specific path for the given Posix [path]. 2598 * Return the [provider] specific path for the given Posix [path].
2598 */ 2599 */
2599 String _p(String path) => provider.convertPath(path); 2600 String _p(String path) => provider.convertPath(path);
2600 2601
2601 static String _md5(String content) { 2602 static String _md5(String content) {
2602 return hex.encode(md5.convert(UTF8.encode(content)).bytes); 2603 return hex.encode(md5.convert(UTF8.encode(content)).bytes);
2603 } 2604 }
2604 } 2605 }
2605 2606
2607 @reflectiveTest
2608 class CacheAllAnalysisDriverTest extends BaseAnalysisDriverTest {
2609 bool get disableChangesAndCacheAllResults => true;
2610
2611 test_addFile() async {
2612 var a = _p('/test/lib/a.dart');
2613 var b = _p('/test/lib/b.dart');
2614 driver.addFile(a);
2615 driver.addFile(b);
2616 }
2617
2618 test_changeFile() async {
2619 var path = _p('/test.dart');
2620 expect(() {
2621 driver.changeFile(path);
2622 }, throwsStateError);
2623 }
2624
2625 test_getResult_libraryUnits() async {
2626 var lib = _p('/lib.dart');
2627 var part1 = _p('/part1.dart');
2628 var part2 = _p('/part2.dart');
2629
2630 provider.newFile(
2631 lib,
2632 r'''
2633 library test;
2634 part 'part1.dart';
2635 part 'part2.dart';
2636 ''');
2637 provider.newFile(part1, 'part of test; class A {}');
2638 provider.newFile(part2, 'part of test; class B {}');
2639
2640 driver.addFile(lib);
2641 driver.addFile(part1);
2642 driver.addFile(part2);
2643
2644 // No analyzed libraries initially.
2645 expect(driver.test.numOfAnalyzedLibraries, 0);
2646
2647 AnalysisResult libResult = await driver.getResult(lib);
2648 AnalysisResult partResult1 = await driver.getResult(part1);
2649 AnalysisResult partResult2 = await driver.getResult(part2);
2650
2651 // Just one library was analyzed, results for parts are cached.
2652 expect(driver.test.numOfAnalyzedLibraries, 1);
2653
2654 expect(libResult.path, lib);
2655 expect(partResult1.path, part1);
2656 expect(partResult2.path, part2);
2657
2658 expect(libResult.unit, isNotNull);
2659 expect(partResult1.unit, isNotNull);
2660 expect(partResult2.unit, isNotNull);
2661
2662 // The parts uses the same resynthesized library element.
2663 var libLibrary = libResult.unit.element.library;
2664 var partLibrary1 = partResult1.unit.element.library;
2665 var partLibrary2 = partResult2.unit.element.library;
2666 expect(partLibrary1, same(libLibrary));
2667 expect(partLibrary2, same(libLibrary));
2668 }
2669
2670 test_getResult_singleFile() async {
2671 var path = _p('/test.dart');
2672 provider.newFile(path, 'main() {}');
2673 driver.addFile(path);
2674
2675 AnalysisResult result1 = await driver.getResult(path);
2676 expect(driver.test.numOfAnalyzedLibraries, 1);
2677 var unit1 = result1.unit;
2678 var unitElement1 = unit1.element;
2679 expect(result1.path, path);
2680 expect(unit1, isNotNull);
2681 expect(unitElement1, isNotNull);
2682
2683 AnalysisResult result2 = await driver.getResult(path);
2684 expect(driver.test.numOfAnalyzedLibraries, 1);
2685 expect(result2.path, path);
2686 expect(result2.unit, same(unit1));
2687 expect(result2.unit.element, same(unitElement1));
2688 }
2689
2690 test_removeFile() async {
2691 var path = _p('/test.dart');
2692 expect(() {
2693 driver.removeFile(path);
2694 }, throwsStateError);
2695 }
2696
2697 String _p(String path) => provider.convertPath(path);
2698 }
2699
2606 class _SourceMock extends TypedMock implements Source {} 2700 class _SourceMock extends TypedMock implements Source {}
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/dart/analysis/base.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698