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

Side by Side Diff: pkg/analyzer/test/src/context/context_test.dart

Issue 1350993002: Reset AnalysisDriver on priority sources changes. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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/lib/task/model.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) 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 test.src.context.context_test; 5 library test.src.context.context_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analyzer/file_system/memory_file_system.dart'; 9 import 'package:analyzer/file_system/memory_file_system.dart';
10 import 'package:analyzer/src/cancelable_future.dart'; 10 import 'package:analyzer/src/cancelable_future.dart';
(...skipping 1777 matching lines...) Expand 10 before | Expand all | Expand 10 after
1788 addSource("/test.dart", "library lib; part 'no-such-file.dart';"); 1788 addSource("/test.dart", "library lib; part 'no-such-file.dart';");
1789 _analyzeAll_assertFinished(); 1789 _analyzeAll_assertFinished();
1790 expect(context.getLibraryElement(source), isNotNull, 1790 expect(context.getLibraryElement(source), isNotNull,
1791 reason: "performAnalysisTask failed to compute an element model"); 1791 reason: "performAnalysisTask failed to compute an element model");
1792 } 1792 }
1793 1793
1794 void test_performAnalysisTask_modifiedAfterParse() { 1794 void test_performAnalysisTask_modifiedAfterParse() {
1795 // TODO(scheglov) no threads in Dart 1795 // TODO(scheglov) no threads in Dart
1796 // Source source = _addSource("/test.dart", "library lib;"); 1796 // Source source = _addSource("/test.dart", "library lib;");
1797 // int initialTime = _context.getModificationStamp(source); 1797 // int initialTime = _context.getModificationStamp(source);
1798 // List<Source> sources = new List<Source>(); 1798 // List<Source> sources = <Source>[];
1799 // sources.add(source); 1799 // sources.add(source);
1800 // _context.analysisPriorityOrder = sources; 1800 // _context.analysisPriorityOrder = sources;
1801 // _context.parseCompilationUnit(source); 1801 // _context.parseCompilationUnit(source);
1802 // while (initialTime == JavaSystem.currentTimeMillis()) { 1802 // while (initialTime == JavaSystem.currentTimeMillis()) {
1803 // Thread.sleep(1); 1803 // Thread.sleep(1);
1804 // // Force the modification time to be different. 1804 // // Force the modification time to be different.
1805 // } 1805 // }
1806 // _context.setContents(source, "library test;"); 1806 // _context.setContents(source, "library test;");
1807 // JUnitTestCase.assertTrue(initialTime != _context.getModificationStamp(sour ce)); 1807 // JUnitTestCase.assertTrue(initialTime != _context.getModificationStamp(sour ce));
1808 // _analyzeAll_assertFinished(); 1808 // _analyzeAll_assertFinished();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1903 options.hint = false; 1903 options.hint = false;
1904 context.analysisOptions = options; 1904 context.analysisOptions = options;
1905 AnalysisOptions result = context.analysisOptions; 1905 AnalysisOptions result = context.analysisOptions;
1906 expect(result.cacheSize, options.cacheSize); 1906 expect(result.cacheSize, options.cacheSize);
1907 expect(result.dart2jsHint, options.dart2jsHint); 1907 expect(result.dart2jsHint, options.dart2jsHint);
1908 expect(result.hint, options.hint); 1908 expect(result.hint, options.hint);
1909 } 1909 }
1910 1910
1911 void test_setAnalysisPriorityOrder() { 1911 void test_setAnalysisPriorityOrder() {
1912 int priorityCount = 4; 1912 int priorityCount = 4;
1913 List<Source> sources = new List<Source>(); 1913 List<Source> sources = <Source>[];
1914 for (int index = 0; index < priorityCount; index++) { 1914 for (int index = 0; index < priorityCount; index++) {
1915 sources.add(addSource("/lib.dart$index", "")); 1915 sources.add(addSource("/lib.dart$index", ""));
1916 } 1916 }
1917 context.analysisPriorityOrder = sources; 1917 context.analysisPriorityOrder = sources;
1918 expect(_getPriorityOrder(context).length, priorityCount); 1918 expect(_getPriorityOrder(context).length, priorityCount);
1919 } 1919 }
1920 1920
1921 void test_setAnalysisPriorityOrder_empty() { 1921 void test_setAnalysisPriorityOrder_empty() {
1922 context.analysisPriorityOrder = new List<Source>(); 1922 context.analysisPriorityOrder = <Source>[];
1923 } 1923 }
1924 1924
1925 void test_setAnalysisPriorityOrder_nonEmpty() { 1925 void test_setAnalysisPriorityOrder_nonEmpty() {
1926 List<Source> sources = new List<Source>(); 1926 List<Source> sources = <Source>[];
1927 sources.add(addSource("/lib.dart", "library lib;")); 1927 sources.add(addSource("/lib.dart", "library lib;"));
1928 context.analysisPriorityOrder = sources; 1928 context.analysisPriorityOrder = sources;
1929 } 1929 }
1930 1930
1931 void test_setAnalysisPriorityOrder_resetAnalysisDriver() {
1932 Source source = addSource('/lib.dart', 'library lib;');
1933 // start analysis
1934 context.performAnalysisTask();
1935 expect(context.driver.currentWorkOrder, isNotNull);
1936 // set priority sources, AnalysisDriver is reset
1937 context.analysisPriorityOrder = <Source>[source];
1938 expect(context.driver.currentWorkOrder, isNull);
1939 // analysis continues
1940 context.performAnalysisTask();
1941 expect(context.driver.currentWorkOrder, isNotNull);
1942 }
1943
1931 Future test_setChangedContents_libraryWithPart() { 1944 Future test_setChangedContents_libraryWithPart() {
1932 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 1945 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
1933 options.incremental = true; 1946 options.incremental = true;
1934 context.analysisOptions = options; 1947 context.analysisOptions = options;
1935 SourcesChangedListener listener = new SourcesChangedListener(); 1948 SourcesChangedListener listener = new SourcesChangedListener();
1936 context.onSourcesChanged.listen(listener.onData); 1949 context.onSourcesChanged.listen(listener.onData);
1937 String oldCode = r''' 1950 String oldCode = r'''
1938 library lib; 1951 library lib;
1939 part 'part.dart'; 1952 part 'part.dart';
1940 int a = 0;'''; 1953 int a = 0;''';
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
2060 expect(context.sourcesNeedingProcessing.contains(source), isFalse); 2073 expect(context.sourcesNeedingProcessing.contains(source), isFalse);
2061 } 2074 }
2062 2075
2063 void xtest_performAnalysisTask_stress() { 2076 void xtest_performAnalysisTask_stress() {
2064 int maxCacheSize = 4; 2077 int maxCacheSize = 4;
2065 AnalysisOptionsImpl options = 2078 AnalysisOptionsImpl options =
2066 new AnalysisOptionsImpl.from(context.analysisOptions); 2079 new AnalysisOptionsImpl.from(context.analysisOptions);
2067 options.cacheSize = maxCacheSize; 2080 options.cacheSize = maxCacheSize;
2068 context.analysisOptions = options; 2081 context.analysisOptions = options;
2069 int sourceCount = maxCacheSize + 2; 2082 int sourceCount = maxCacheSize + 2;
2070 List<Source> sources = new List<Source>(); 2083 List<Source> sources = <Source>[];
2071 ChangeSet changeSet = new ChangeSet(); 2084 ChangeSet changeSet = new ChangeSet();
2072 for (int i = 0; i < sourceCount; i++) { 2085 for (int i = 0; i < sourceCount; i++) {
2073 Source source = addSource("/lib$i.dart", "library lib$i;"); 2086 Source source = addSource("/lib$i.dart", "library lib$i;");
2074 sources.add(source); 2087 sources.add(source);
2075 changeSet.addedSource(source); 2088 changeSet.addedSource(source);
2076 } 2089 }
2077 context.applyChanges(changeSet); 2090 context.applyChanges(changeSet);
2078 context.analysisPriorityOrder = sources; 2091 context.analysisPriorityOrder = sources;
2079 for (int i = 0; i < 1000; i++) { 2092 for (int i = 0; i < 1000; i++) {
2080 List<ChangeNotice> notice = context.performAnalysisTask().changeNotices; 2093 List<ChangeNotice> notice = context.performAnalysisTask().changeNotices;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2139 } 2152 }
2140 return null; 2153 return null;
2141 } 2154 }
2142 2155
2143 void _flushAst(Source source) { 2156 void _flushAst(Source source) {
2144 CacheEntry entry = 2157 CacheEntry entry =
2145 context.getCacheEntry(new LibrarySpecificUnit(source, source)); 2158 context.getCacheEntry(new LibrarySpecificUnit(source, source));
2146 entry.setState(RESOLVED_UNIT, CacheState.FLUSHED); 2159 entry.setState(RESOLVED_UNIT, CacheState.FLUSHED);
2147 } 2160 }
2148 2161
2149 List<Source> _getPriorityOrder(AnalysisContextImpl context2) { 2162 List<Source> _getPriorityOrder(AnalysisContextImpl context) {
2150 return context2.test_priorityOrder; 2163 return context.test_priorityOrder;
2151 } 2164 }
2152 2165
2153 void _performPendingAnalysisTasks([int maxTasks = 512]) { 2166 void _performPendingAnalysisTasks([int maxTasks = 512]) {
2154 for (int i = 0; context.performAnalysisTask().hasMoreWork; i++) { 2167 for (int i = 0; context.performAnalysisTask().hasMoreWork; i++) {
2155 if (i > maxTasks) { 2168 if (i > maxTasks) {
2156 fail('Analysis did not terminate.'); 2169 fail('Analysis did not terminate.');
2157 } 2170 }
2158 } 2171 }
2159 } 2172 }
2160 2173
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
2490 } 2503 }
2491 } 2504 }
2492 2505
2493 class _AnalysisContextImplTest_test_applyChanges_removeContainer 2506 class _AnalysisContextImplTest_test_applyChanges_removeContainer
2494 implements SourceContainer { 2507 implements SourceContainer {
2495 Source libB; 2508 Source libB;
2496 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB); 2509 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB);
2497 @override 2510 @override
2498 bool contains(Source source) => source == libB; 2511 bool contains(Source source) => source == libB;
2499 } 2512 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/task/model.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698