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

Side by Side Diff: pkg/analyzer/test/src/task/options_work_manager_test.dart

Issue 1413973003: Analysis Options processing task and manager. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: No partial results fix. Created 5 years, 2 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/task/options_test.dart ('k') | pkg/analyzer/test/src/task/test_all.dart » ('j') | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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.task.html_work_manager_test; 5 library test.src.task.options_work_manager_test;
6 6
7 import 'package:analyzer/src/context/cache.dart'; 7 import 'package:analyzer/src/context/cache.dart';
8 import 'package:analyzer/src/generated/engine.dart' 8 import 'package:analyzer/src/generated/engine.dart'
9 show 9 show
10 AnalysisEngine, 10 AnalysisEngine,
11 AnalysisErrorInfo, 11 AnalysisErrorInfo,
12 AnalysisErrorInfoImpl, 12 AnalysisErrorInfoImpl,
13 CacheState, 13 CacheState,
14 ChangeNoticeImpl, 14 ChangeNoticeImpl,
15 InternalAnalysisContext; 15 InternalAnalysisContext;
16 import 'package:analyzer/src/generated/error.dart' 16 import 'package:analyzer/src/generated/error.dart'
17 show AnalysisError, HtmlErrorCode; 17 show AnalysisError, AnalysisOptionsErrorCode;
18 import 'package:analyzer/src/generated/java_engine.dart' show CaughtException; 18 import 'package:analyzer/src/generated/java_engine.dart';
19 import 'package:analyzer/src/generated/source.dart'; 19 import 'package:analyzer/src/generated/source.dart';
20 import 'package:analyzer/src/task/html.dart'; 20 import 'package:analyzer/src/task/options.dart';
21 import 'package:analyzer/src/task/html_work_manager.dart'; 21 import 'package:analyzer/src/task/options_work_manager.dart';
22 import 'package:analyzer/task/dart.dart'; 22 import 'package:analyzer/task/dart.dart';
23 import 'package:analyzer/task/general.dart'; 23 import 'package:analyzer/task/general.dart';
24 import 'package:analyzer/task/html.dart';
25 import 'package:analyzer/task/model.dart'; 24 import 'package:analyzer/task/model.dart';
26 import 'package:typed_mock/typed_mock.dart'; 25 import 'package:typed_mock/typed_mock.dart';
27 import 'package:unittest/unittest.dart'; 26 import 'package:unittest/unittest.dart';
28 27
29 import '../../generated/test_support.dart'; 28 import '../../generated/test_support.dart';
30 import '../../reflective_tests.dart'; 29 import '../../reflective_tests.dart';
31 import '../../utils.dart'; 30 import '../../utils.dart';
32 31
33 main() { 32 main() {
34 initializeTestEnvironment(); 33 initializeTestEnvironment();
35 runReflectiveTests(HtmlWorkManagerTest); 34 runReflectiveTests(OptionsWorkManagerTest);
36 } 35 }
37 36
38 @reflectiveTest 37 @reflectiveTest
39 class HtmlWorkManagerTest { 38 class OptionsWorkManagerTest {
39 static final optionsFile = AnalysisEngine.ANALYSIS_OPTIONS_FILE;
40 InternalAnalysisContext context = new _InternalAnalysisContextMock(); 40 InternalAnalysisContext context = new _InternalAnalysisContextMock();
41 AnalysisCache cache; 41 AnalysisCache cache;
42 HtmlWorkManager manager; 42
43 OptionsWorkManager manager;
43 44
44 CaughtException caughtException = new CaughtException(null, null); 45 CaughtException caughtException = new CaughtException(null, null);
45 46
46 Source source1 = new TestSource('1.html'); 47 Source source1 = new TestSource('test1/$optionsFile');
47 Source source2 = new TestSource('2.html'); 48 Source source2 = new TestSource('test2/$optionsFile');
48 Source source3 = new TestSource('3.html'); 49 Source source3 = new TestSource('test3/$optionsFile');
49 Source source4 = new TestSource('4.html'); 50 Source source4 = new TestSource('test4/$optionsFile');
50 CacheEntry entry1; 51 CacheEntry entry1;
51 CacheEntry entry2; 52 CacheEntry entry2;
52 CacheEntry entry3; 53 CacheEntry entry3;
53 CacheEntry entry4; 54 CacheEntry entry4;
54 55
55 void expect_sourceQueue(List<Source> sources) { 56 void expect_sourceQueue(List<Source> sources) {
56 expect(manager.sourceQueue, unorderedEquals(sources)); 57 expect(manager.sourceQueue, unorderedEquals(sources));
57 } 58 }
58 59
59 void setUp() { 60 void setUp() {
60 cache = context.analysisCache; 61 cache = context.analysisCache;
61 manager = new HtmlWorkManager(context); 62 manager = new OptionsWorkManager(context);
62 entry1 = context.getCacheEntry(source1); 63 entry1 = context.getCacheEntry(source1);
63 entry2 = context.getCacheEntry(source2); 64 entry2 = context.getCacheEntry(source2);
64 entry3 = context.getCacheEntry(source3); 65 entry3 = context.getCacheEntry(source3);
65 entry4 = context.getCacheEntry(source4); 66 entry4 = context.getCacheEntry(source4);
66 } 67 }
67 68
68 void test_applyChange_add() { 69 void test_applyChange_add() {
69 // add source1 70 // add source1
70 manager.applyChange([source1], [], []); 71 manager.applyChange([source1], [], []);
71 expect_sourceQueue([source1]); 72 expect_sourceQueue([source1]);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 manager.applyChange([], [], [source2]); 106 manager.applyChange([], [], [source2]);
106 expect_sourceQueue([]); 107 expect_sourceQueue([]);
107 // remove source3 108 // remove source3
108 manager.applyChange([], [], [source3]); 109 manager.applyChange([], [], [source3]);
109 expect_sourceQueue([]); 110 expect_sourceQueue([]);
110 } 111 }
111 112
112 void test_applyPriorityTargets() { 113 void test_applyPriorityTargets() {
113 when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(true); 114 when(context.shouldErrorsBeAnalyzed(source2, null)).thenReturn(true);
114 when(context.shouldErrorsBeAnalyzed(source3, null)).thenReturn(true); 115 when(context.shouldErrorsBeAnalyzed(source3, null)).thenReturn(true);
115 manager.priorityResultQueue.add(new TargetedResult(source1, HTML_ERRORS)); 116 manager.priorityResultQueue
116 manager.priorityResultQueue.add(new TargetedResult(source2, HTML_ERRORS)); 117 .add(new TargetedResult(source1, ANALYSIS_OPTIONS_ERRORS));
118 manager.priorityResultQueue
119 .add(new TargetedResult(source2, ANALYSIS_OPTIONS_ERRORS));
117 // -source1 +source3 120 // -source1 +source3
118 manager.applyPriorityTargets([source2, source3]); 121 manager.applyPriorityTargets([source2, source3]);
119 expect( 122 expect(
120 manager.priorityResultQueue, 123 manager.priorityResultQueue,
121 unorderedEquals([ 124 unorderedEquals([
122 new TargetedResult(source2, HTML_ERRORS), 125 new TargetedResult(source2, ANALYSIS_OPTIONS_ERRORS),
123 new TargetedResult(source3, HTML_ERRORS) 126 new TargetedResult(source3, ANALYSIS_OPTIONS_ERRORS)
124 ])); 127 ]));
125 // get next request 128 // get next request
126 TargetedResult request = manager.getNextResult(); 129 TargetedResult request = manager.getNextResult();
127 expect(request.target, source2); 130 expect(request.target, source2);
128 expect(request.result, HTML_ERRORS); 131 expect(request.result, ANALYSIS_OPTIONS_ERRORS);
129 } 132 }
130 133
131 void test_getErrors_fullList() { 134 void test_getErrors() {
132 AnalysisError error1 = 135 AnalysisError error1 = new AnalysisError(
133 new AnalysisError(source1, 1, 0, HtmlErrorCode.PARSE_ERROR, ['']); 136 source1, 1, 0, AnalysisOptionsErrorCode.PARSE_ERROR, ['']);
134 AnalysisError error2 = 137 AnalysisError error2 = new AnalysisError(
135 new AnalysisError(source1, 2, 0, HtmlErrorCode.PARSE_ERROR, ['']); 138 source1, 2, 0, AnalysisOptionsErrorCode.PARSE_ERROR, ['']);
136 entry1.setValue(HTML_DOCUMENT_ERRORS, <AnalysisError>[error1], []); 139 entry1.setValue(
137 140 ANALYSIS_OPTIONS_ERRORS, <AnalysisError>[error1, error2], []);
138 DartScript script = new DartScript(source1, []);
139 entry1.setValue(DART_SCRIPTS, [script], []);
140 CacheEntry scriptEntry = context.getCacheEntry(script);
141 scriptEntry.setValue(DART_ERRORS, [error2], []);
142
143 List<AnalysisError> errors = manager.getErrors(source1);
144 expect(errors, unorderedEquals([error1, error2]));
145 }
146
147 void test_getErrors_partialList() {
148 AnalysisError error1 =
149 new AnalysisError(source1, 1, 0, HtmlErrorCode.PARSE_ERROR, ['']);
150 AnalysisError error2 =
151 new AnalysisError(source1, 2, 0, HtmlErrorCode.PARSE_ERROR, ['']);
152 entry1.setValue(HTML_DOCUMENT_ERRORS, <AnalysisError>[error1, error2], []);
153 141
154 List<AnalysisError> errors = manager.getErrors(source1); 142 List<AnalysisError> errors = manager.getErrors(source1);
155 expect(errors, unorderedEquals([error1, error2])); 143 expect(errors, unorderedEquals([error1, error2]));
156 } 144 }
157 145
158 void test_getNextResult_hasNormal_firstIsError() { 146 void test_getNextResult_hasNormal_firstIsError() {
159 entry1.setErrorState(caughtException, [HTML_ERRORS]); 147 entry1.setErrorState(caughtException, [ANALYSIS_OPTIONS_ERRORS]);
160 manager.sourceQueue.addAll([source1, source2]); 148 manager.sourceQueue.addAll([source1, source2]);
161 TargetedResult request = manager.getNextResult(); 149 TargetedResult request = manager.getNextResult();
162 expect(request.target, source2); 150 expect(request.target, source2);
163 expect(request.result, HTML_ERRORS); 151 expect(request.result, ANALYSIS_OPTIONS_ERRORS);
164 // source1 is out, source2 is waiting 152 // source1 is out, source2 is waiting
165 expect_sourceQueue([source2]); 153 expect_sourceQueue([source2]);
166 } 154 }
167 155
168 void test_getNextResult_hasNormal_firstIsInvalid() { 156 void test_getNextResult_hasNormal_firstIsInvalid() {
169 entry1.setState(HTML_ERRORS, CacheState.INVALID); 157 entry1.setState(ANALYSIS_OPTIONS_ERRORS, CacheState.INVALID);
170 manager.sourceQueue.addAll([source1, source2]); 158 manager.sourceQueue.addAll([source1, source2]);
171 TargetedResult request = manager.getNextResult(); 159 TargetedResult request = manager.getNextResult();
172 expect(request.target, source1); 160 expect(request.target, source1);
173 expect(request.result, HTML_ERRORS); 161 expect(request.result, ANALYSIS_OPTIONS_ERRORS);
174 // no changes until computed 162 // no changes until computed
175 expect_sourceQueue([source1, source2]); 163 expect_sourceQueue([source1, source2]);
176 } 164 }
177 165
178 void test_getNextResult_hasNormal_firstIsValid() { 166 void test_getNextResult_hasNormal_firstIsValid() {
179 entry1.setValue(HTML_ERRORS, [], []); 167 entry1.setValue(ANALYSIS_OPTIONS_ERRORS, [], []);
180 manager.sourceQueue.addAll([source1, source2]); 168 manager.sourceQueue.addAll([source1, source2]);
181 TargetedResult request = manager.getNextResult(); 169 TargetedResult request = manager.getNextResult();
182 expect(request.target, source2); 170 expect(request.target, source2);
183 expect(request.result, HTML_ERRORS); 171 expect(request.result, ANALYSIS_OPTIONS_ERRORS);
184 // source1 is out, source2 is waiting 172 // source1 is out, source2 is waiting
185 expect_sourceQueue([source2]); 173 expect_sourceQueue([source2]);
186 } 174 }
187 175
188 void test_getNextResult_hasNormalAndPriority() { 176 void test_getNextResult_hasNormalAndPriority() {
189 entry1.setState(HTML_ERRORS, CacheState.INVALID); 177 entry1.setState(ANALYSIS_OPTIONS_ERRORS, CacheState.INVALID);
190 manager.sourceQueue.addAll([source1, source2]); 178 manager.sourceQueue.addAll([source1, source2]);
191 manager.addPriorityResult(source3, HTML_ERRORS); 179 manager.addPriorityResult(source3, ANALYSIS_OPTIONS_ERRORS);
192 180
193 TargetedResult request = manager.getNextResult(); 181 TargetedResult request = manager.getNextResult();
194 expect(request.target, source3); 182 expect(request.target, source3);
195 expect(request.result, HTML_ERRORS); 183 expect(request.result, ANALYSIS_OPTIONS_ERRORS);
196 // no changes until computed 184 // no changes until computed
197 expect_sourceQueue([source1, source2]); 185 expect_sourceQueue([source1, source2]);
198 } 186 }
199 187
200 void test_getNextResult_hasPriority() { 188 void test_getNextResult_hasPriority() {
201 manager.addPriorityResult(source1, HTML_ERRORS); 189 manager.addPriorityResult(source1, ANALYSIS_OPTIONS_ERRORS);
202 manager.addPriorityResult(source2, HTML_ERRORS); 190 manager.addPriorityResult(source2, ANALYSIS_OPTIONS_ERRORS);
203 expect( 191 expect(
204 manager.priorityResultQueue, 192 manager.priorityResultQueue,
205 unorderedEquals([ 193 unorderedEquals([
206 new TargetedResult(source1, HTML_ERRORS), 194 new TargetedResult(source1, ANALYSIS_OPTIONS_ERRORS),
207 new TargetedResult(source2, HTML_ERRORS) 195 new TargetedResult(source2, ANALYSIS_OPTIONS_ERRORS)
208 ])); 196 ]));
209 197
210 TargetedResult request = manager.getNextResult(); 198 TargetedResult request = manager.getNextResult();
211 expect(request.target, source1); 199 expect(request.target, source1);
212 expect(request.result, HTML_ERRORS); 200 expect(request.result, ANALYSIS_OPTIONS_ERRORS);
213 // no changes until computed 201 // no changes until computed
214 expect( 202 expect(
215 manager.priorityResultQueue, 203 manager.priorityResultQueue,
216 unorderedEquals([ 204 unorderedEquals([
217 new TargetedResult(source1, HTML_ERRORS), 205 new TargetedResult(source1, ANALYSIS_OPTIONS_ERRORS),
218 new TargetedResult(source2, HTML_ERRORS) 206 new TargetedResult(source2, ANALYSIS_OPTIONS_ERRORS)
219 ])); 207 ]));
220 } 208 }
221 209
222 void test_getNextResult_nothingToDo() { 210 void test_getNextResult_nothingToDo() {
223 TargetedResult request = manager.getNextResult(); 211 TargetedResult request = manager.getNextResult();
224 expect(request, isNull); 212 expect(request, isNull);
225 } 213 }
226 214
227 void test_getNextResultPriority_hasPriority() { 215 void test_getNextResultPriority_hasPriority() {
228 manager.addPriorityResult(source1, SOURCE_KIND); 216 manager.addPriorityResult(source1, SOURCE_KIND);
229 expect(manager.getNextResultPriority(), WorkOrderPriority.PRIORITY); 217 expect(manager.getNextResultPriority(), WorkOrderPriority.PRIORITY);
230 } 218 }
231 219
232 void test_getNextResultPriority_hasSource() { 220 void test_getNextResultPriority_hasSource() {
233 manager.sourceQueue.addAll([source1]); 221 manager.sourceQueue.addAll([source1]);
234 expect(manager.getNextResultPriority(), WorkOrderPriority.NORMAL); 222 expect(manager.getNextResultPriority(), WorkOrderPriority.NORMAL);
235 } 223 }
236 224
237 void test_getNextResultPriority_nothingToDo() { 225 void test_getNextResultPriority_nothingToDo() {
238 expect(manager.getNextResultPriority(), WorkOrderPriority.NONE); 226 expect(manager.getNextResultPriority(), WorkOrderPriority.NONE);
239 } 227 }
240 228
241 void test_onAnalysisOptionsChanged() {
242 when(context.exists(anyObject)).thenReturn(true);
243 // set cache values
244 entry1.setValue(DART_SCRIPTS, [], []);
245 entry1.setValue(HTML_DOCUMENT, null, []);
246 entry1.setValue(HTML_DOCUMENT_ERRORS, [], []);
247 entry1.setValue(HTML_ERRORS, [], []);
248 entry1.setValue(REFERENCED_LIBRARIES, [], []);
249 // notify
250 manager.onAnalysisOptionsChanged();
251 // Only resolution-based values are invalidated.
252 expect(entry1.getState(DART_SCRIPTS), CacheState.VALID);
253 expect(entry1.getState(HTML_DOCUMENT), CacheState.VALID);
254 expect(entry1.getState(HTML_DOCUMENT_ERRORS), CacheState.VALID);
255 expect(entry1.getState(HTML_ERRORS), CacheState.INVALID);
256 expect(entry1.getState(REFERENCED_LIBRARIES), CacheState.VALID);
257 }
258
259 void test_onResultInvalidated_scheduleInvalidatedLibraries() {
260 // set HTML_ERRORS for source1 and source3
261 entry1.setValue(HTML_ERRORS, [], []);
262 entry3.setValue(HTML_ERRORS, [], []);
263 // invalidate HTML_ERRORS for source1, schedule it
264 entry1.setState(HTML_ERRORS, CacheState.INVALID);
265 expect_sourceQueue([source1]);
266 // invalidate HTML_ERRORS for source3, schedule it
267 entry3.setState(HTML_ERRORS, CacheState.INVALID);
268 expect_sourceQueue([source1, source3]);
269 }
270
271 void test_onSourceFactoryChanged() {
272 when(context.exists(anyObject)).thenReturn(true);
273 // set cache values
274 entry1.setValue(DART_SCRIPTS, [], []);
275 entry1.setValue(HTML_DOCUMENT, null, []);
276 entry1.setValue(HTML_DOCUMENT_ERRORS, [], []);
277 entry1.setValue(HTML_ERRORS, [], []);
278 entry1.setValue(REFERENCED_LIBRARIES, [], []);
279 // notify
280 manager.onSourceFactoryChanged();
281 // Only resolution-based values are invalidated.
282 expect(entry1.getState(DART_SCRIPTS), CacheState.VALID);
283 expect(entry1.getState(HTML_DOCUMENT), CacheState.VALID);
284 expect(entry1.getState(HTML_DOCUMENT_ERRORS), CacheState.VALID);
285 expect(entry1.getState(HTML_ERRORS), CacheState.INVALID);
286 expect(entry1.getState(REFERENCED_LIBRARIES), CacheState.INVALID);
287 }
288
289 void test_resultsComputed_errors() { 229 void test_resultsComputed_errors() {
290 AnalysisError error1 = 230 AnalysisError error1 = new AnalysisError(
291 new AnalysisError(source1, 1, 0, HtmlErrorCode.PARSE_ERROR, ['']); 231 source1, 1, 0, AnalysisOptionsErrorCode.PARSE_ERROR, ['']);
292 AnalysisError error2 = 232 AnalysisError error2 = new AnalysisError(
293 new AnalysisError(source1, 2, 0, HtmlErrorCode.PARSE_ERROR, ['']); 233 source1, 2, 0, AnalysisOptionsErrorCode.PARSE_ERROR, ['']);
294 LineInfo lineInfo = new LineInfo([0]); 234 LineInfo lineInfo = new LineInfo([0]);
295 entry1.setValue(LINE_INFO, lineInfo, []); 235 entry1.setValue(LINE_INFO, lineInfo, []);
296 entry1.setValue(HTML_ERRORS, <AnalysisError>[error1, error2], []); 236 entry1.setValue(
237 ANALYSIS_OPTIONS_ERRORS, <AnalysisError>[error1, error2], []);
297 // RESOLVED_UNIT is ready, set errors 238 // RESOLVED_UNIT is ready, set errors
298 manager.resultsComputed(source1, {HTML_ERRORS: null}); 239 manager.resultsComputed(source1, {ANALYSIS_OPTIONS_ERRORS: null});
299 // all of the errors are included 240 // all of the errors are included
300 ChangeNoticeImpl notice = context.getNotice(source1); 241 ChangeNoticeImpl notice = context.getNotice(source1);
301 expect(notice.errors, unorderedEquals([error1, error2])); 242 expect(notice.errors, unorderedEquals([error1, error2]));
302 expect(notice.lineInfo, lineInfo); 243 expect(notice.lineInfo, lineInfo);
303 } 244 }
304 } 245 }
305 246
306 class _InternalAnalysisContextMock extends TypedMock 247 class _InternalAnalysisContextMock extends TypedMock
307 implements InternalAnalysisContext { 248 implements InternalAnalysisContext {
308 @override 249 @override
(...skipping 14 matching lines...) Expand all
323 CacheEntry entry = analysisCache.get(target); 264 CacheEntry entry = analysisCache.get(target);
324 if (entry == null) { 265 if (entry == null) {
325 entry = new CacheEntry(target); 266 entry = new CacheEntry(target);
326 analysisCache.put(entry); 267 analysisCache.put(entry);
327 } 268 }
328 return entry; 269 return entry;
329 } 270 }
330 271
331 @override 272 @override
332 AnalysisErrorInfo getErrors(Source source) { 273 AnalysisErrorInfo getErrors(Source source) {
333 String name = source.shortName;
334 List<AnalysisError> errors = AnalysisError.NO_ERRORS; 274 List<AnalysisError> errors = AnalysisError.NO_ERRORS;
335 if (AnalysisEngine.isDartFileName(name) || source is DartScript) { 275 if (AnalysisEngine.isAnalysisOptionsFileName(source.shortName)) {
336 errors = getCacheEntry(source).getValue(DART_ERRORS); 276 errors = getCacheEntry(source).getValue(ANALYSIS_OPTIONS_ERRORS);
337 } else if (AnalysisEngine.isHtmlFileName(name)) {
338 errors = getCacheEntry(source).getValue(HTML_ERRORS);
339 } 277 }
340 return new AnalysisErrorInfoImpl( 278 return new AnalysisErrorInfoImpl(
341 errors, getCacheEntry(source).getValue(LINE_INFO)); 279 errors, getCacheEntry(source).getValue(LINE_INFO));
342 } 280 }
343 281
344 @override 282 @override
345 ChangeNoticeImpl getNotice(Source source) { 283 ChangeNoticeImpl getNotice(Source source) =>
346 return _pendingNotices.putIfAbsent( 284 _pendingNotices.putIfAbsent(source, () => new ChangeNoticeImpl(source));
347 source, () => new ChangeNoticeImpl(source));
348 }
349 285
350 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 286 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
351 } 287 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/task/options_test.dart ('k') | pkg/analyzer/test/src/task/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698