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

Side by Side Diff: pkg/analysis_server/test/single_context_manager_test.dart

Issue 2945313002: Remove the unused class SingleContextManager (Closed)
Patch Set: Created 3 years, 6 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:core';
6
7 import 'package:analysis_server/src/single_context_manager.dart';
8 import 'package:analysis_server/src/utilities/null_string_sink.dart';
9 import 'package:analyzer/file_system/memory_file_system.dart';
10 import 'package:analyzer/src/dart/analysis/driver.dart';
11 import 'package:analyzer/src/generated/engine.dart';
12 import 'package:analyzer/src/generated/sdk.dart';
13 import 'package:analyzer/src/generated/source.dart';
14 import 'package:analyzer/src/generated/source_io.dart';
15 import 'package:analyzer/src/util/glob.dart';
16 import 'package:front_end/src/base/performace_logger.dart';
17 import 'package:path/path.dart' as path;
18 import 'package:plugin/manager.dart';
19 import 'package:plugin/plugin.dart';
20 import 'package:test/test.dart';
21 import 'package:test_reflective_loader/test_reflective_loader.dart';
22
23 import 'context_manager_test.dart' show TestContextManagerCallbacks;
24 import 'mocks.dart';
25
26 main() {
27 defineReflectiveSuite(() {
28 defineReflectiveTests(SingleContextManagerTest);
29 });
30 }
31
32 @reflectiveTest
33 class SingleContextManagerTest {
34 MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
35
36 TestUriResolver packageResolver;
37 TestContextManagerCallbacks callbacks;
38 SingleContextManager manager;
39
40 List<Glob> get analysisFilesGlobs {
41 List<String> patterns = <String>[
42 '**/*.${AnalysisEngine.SUFFIX_DART}',
43 '**/*.${AnalysisEngine.SUFFIX_HTML}',
44 ];
45 return patterns
46 .map((pattern) => new Glob(path.posix.separator, pattern))
47 .toList();
48 }
49
50 String newFile(List<String> pathComponents, [String content = '']) {
51 String filePath = path.posix.joinAll(pathComponents);
52 resourceProvider.newFile(filePath, content);
53 return filePath;
54 }
55
56 String newFolder(List<String> pathComponents) {
57 String folderPath = path.posix.joinAll(pathComponents);
58 resourceProvider.newFolder(folderPath);
59 return folderPath;
60 }
61
62 void setUp() {
63 packageResolver = new TestUriResolver();
64
65 _processRequiredPlugins();
66 DartSdkManager sdkManager = new DartSdkManager('/', false);
67 manager = new SingleContextManager(resourceProvider, sdkManager,
68 (_) => packageResolver, analysisFilesGlobs, new AnalysisOptionsImpl());
69 PerformanceLog logger = new PerformanceLog(new NullStringSink());
70 AnalysisDriverScheduler scheduler = new AnalysisDriverScheduler(logger);
71 callbacks = new TestContextManagerCallbacks(
72 resourceProvider, sdkManager, logger, scheduler);
73 manager.callbacks = callbacks;
74 }
75
76 void test_isIgnored_false() {
77 String project = '/project';
78 resourceProvider.newFolder(project);
79 manager.setRoots(<String>[project], <String>[], <String, String>{});
80 expect(manager.isIgnored('$project/file.dart'), isFalse);
81 }
82
83 void test_isIgnored_true_inDotFolder() {
84 String project = '/project';
85 resourceProvider.newFolder(project);
86 manager.setRoots(<String>[project], <String>[], <String, String>{});
87 expect(manager.isIgnored('$project/foo/.bar/file.dart'), isTrue);
88 }
89
90 void test_isIgnored_true_inExcludedPath() {
91 String project = '/project';
92 String excludedPath = '/project/excluded';
93 resourceProvider.newFolder(project);
94 manager.setRoots(
95 <String>[project], <String>[excludedPath], <String, String>{});
96 expect(manager.isIgnored('$excludedPath/file.dart'), isTrue);
97 }
98
99 void test_isIgnored_true_notInRoot() {
100 String root1 = '/context/root1';
101 String root2 = '/context/root2';
102 resourceProvider.newFolder(root1);
103 resourceProvider.newFolder(root2);
104 manager.setRoots(<String>[root1, root2], <String>[], <String, String>{});
105 expect(manager.isIgnored('/context/root3/file.dart'), isTrue);
106 }
107
108 void test_isInAnalysisRoot_false_inExcludedPath() {
109 String project = '/project';
110 String excludedPath = '/project/excluded';
111 resourceProvider.newFolder(project);
112 manager.setRoots(
113 <String>[project], <String>[excludedPath], <String, String>{});
114 expect(manager.isInAnalysisRoot('$excludedPath/file.dart'), isFalse);
115 }
116
117 void test_isInAnalysisRoot_false_notInRoot() {
118 String root1 = '/context/root1';
119 String root2 = '/context/root2';
120 resourceProvider.newFolder(root1);
121 resourceProvider.newFolder(root2);
122 manager.setRoots(<String>[root1, root2], <String>[], <String, String>{});
123 expect(manager.isInAnalysisRoot('/context/root3/file.dart'), isFalse);
124 }
125
126 void test_isInAnalysisRoot_true() {
127 String project = '/project';
128 resourceProvider.newFolder(project);
129 manager.setRoots(<String>[project], <String>[], <String, String>{});
130 expect(manager.isInAnalysisRoot('$project/file.dart'), isTrue);
131 }
132
133 void test_refresh() {
134 String project = '/project';
135 String file1 = '$project/file1.dart';
136 String file2 = '$project/file2.dart';
137 // create files
138 resourceProvider.newFile(file1, '');
139 resourceProvider.newFile(file2, '');
140 // set roots
141 manager.setRoots(<String>[project], <String>[file2], <String, String>{});
142 callbacks.assertContextPaths([project]);
143 callbacks.assertContextFiles(project, [file1]);
144 // refresh
145 manager.refresh([]);
146 callbacks.assertContextPaths([project]);
147 callbacks.assertContextFiles(project, [file1]);
148 }
149
150 void test_setRoots_addFolderWithDartFile() {
151 String project = '/project';
152 String file = '$project/lib/foo.dart';
153 resourceProvider.newFile(file, '');
154 manager.setRoots(<String>[project], <String>[], <String, String>{});
155 // verify
156 callbacks.assertContextPaths([project]);
157 callbacks.assertContextFiles(project, [file]);
158 }
159
160 void test_setRoots_addFolderWithDartFileInSubfolder() {
161 String project = '/project';
162 String file = '$project/foo/bar.dart';
163 resourceProvider.newFile(file, '');
164 manager.setRoots(<String>[project], <String>[], <String, String>{});
165 // verify
166 callbacks.assertContextFiles(project, [file]);
167 }
168
169 void test_setRoots_addFolderWithDummyLink() {
170 String project = '/project';
171 String file = '$project/foo.dart';
172 resourceProvider.newDummyLink(file);
173 manager.setRoots(<String>[project], <String>[], <String, String>{});
174 // verify
175 callbacks.assertContextFiles(project, []);
176 }
177
178 void test_setRoots_exclude_newRoot_withExcludedFile() {
179 String project = '/project';
180 String file1 = '$project/file1.dart';
181 String file2 = '$project/file2.dart';
182 // create files
183 resourceProvider.newFile(file1, '');
184 resourceProvider.newFile(file2, '');
185 // set roots
186 manager.setRoots(<String>[project], <String>[file1], <String, String>{});
187 callbacks.assertContextPaths([project]);
188 callbacks.assertContextFiles(project, [file2]);
189 }
190
191 void test_setRoots_exclude_newRoot_withExcludedFolder() {
192 String project = '/project';
193 String folderA = '$project/aaa';
194 String folderB = '$project/bbb';
195 String fileA = '$folderA/a.dart';
196 String fileB = '$folderB/b.dart';
197 // create files
198 resourceProvider.newFile(fileA, '');
199 resourceProvider.newFile(fileB, '');
200 // set roots
201 manager.setRoots(<String>[project], <String>[folderB], <String, String>{});
202 callbacks.assertContextPaths([project]);
203 callbacks.assertContextFiles(project, [fileA]);
204 }
205
206 void test_setRoots_exclude_sameRoot_addExcludedFile() {
207 String project = '/project';
208 String file1 = '$project/file1.dart';
209 String file2 = '$project/file2.dart';
210 // create files
211 resourceProvider.newFile(file1, '');
212 resourceProvider.newFile(file2, '');
213 // set roots
214 manager.setRoots(<String>[project], <String>[], <String, String>{});
215 callbacks.assertContextPaths([project]);
216 callbacks.assertContextFiles(project, [file1, file2]);
217 // exclude "2"
218 manager.setRoots(<String>[project], <String>[file2], <String, String>{});
219 callbacks.assertContextPaths([project]);
220 callbacks.assertContextFiles(project, [file1]);
221 }
222
223 void test_setRoots_exclude_sameRoot_addExcludedFolder() {
224 String project = '/project';
225 String folderA = '$project/aaa';
226 String folderB = '$project/bbb';
227 String fileA = '$folderA/a.dart';
228 String fileB = '$folderB/b.dart';
229 // create files
230 resourceProvider.newFile(fileA, 'library a;');
231 resourceProvider.newFile(fileB, 'library b;');
232 // initially both "aaa/a" and "bbb/b" are included
233 manager.setRoots(<String>[project], <String>[], <String, String>{});
234 callbacks.assertContextPaths([project]);
235 callbacks.assertContextFiles(project, [fileA, fileB]);
236 // exclude "bbb/"
237 manager.setRoots(<String>[project], <String>[folderB], <String, String>{});
238 callbacks.assertContextPaths([project]);
239 callbacks.assertContextFiles(project, [fileA]);
240 }
241
242 void test_setRoots_exclude_sameRoot_removeExcludedFile() {
243 String project = '/project';
244 String file1 = '$project/file1.dart';
245 String file2 = '$project/file2.dart';
246 // create files
247 resourceProvider.newFile(file1, '// 1');
248 resourceProvider.newFile(file2, '// 2');
249 // set roots
250 manager.setRoots(<String>[project], <String>[file2], <String, String>{});
251 callbacks.assertContextPaths([project]);
252 callbacks.assertContextFiles(project, [file1]);
253 // stop excluding "2"
254 manager.setRoots(<String>[project], <String>[], <String, String>{});
255 callbacks.assertContextPaths([project]);
256 callbacks.assertContextFiles(project, [file1, file2]);
257 }
258
259 void test_setRoots_exclude_sameRoot_removeExcludedFile_inFolder() {
260 String project = '/project';
261 String file1 = '$project/bin/file1.dart';
262 String file2 = '$project/bin/file2.dart';
263 // create files
264 resourceProvider.newFile(file1, '// 1');
265 resourceProvider.newFile(file2, '// 2');
266 // set roots
267 manager.setRoots(<String>[project], <String>[file2], <String, String>{});
268 callbacks.assertContextPaths([project]);
269 callbacks.assertContextFiles(project, [file1]);
270 // stop excluding "2"
271 manager.setRoots(<String>[project], <String>[], <String, String>{});
272 callbacks.assertContextPaths([project]);
273 callbacks.assertContextFiles(project, [file1, file2]);
274 }
275
276 void test_setRoots_exclude_sameRoot_removeExcludedFolder() {
277 String project = '/project';
278 String folderA = '$project/aaa';
279 String folderB = '$project/bbb';
280 String fileA = '$folderA/a.dart';
281 String fileB = '$folderB/b.dart';
282 // create files
283 resourceProvider.newFile(fileA, 'library a;');
284 resourceProvider.newFile(fileB, 'library b;');
285 // exclude "bbb/"
286 manager.setRoots(<String>[project], <String>[folderB], <String, String>{});
287 callbacks.assertContextPaths([project]);
288 callbacks.assertContextFiles(project, [fileA]);
289 // stop excluding "bbb/"
290 manager.setRoots(<String>[project], <String>[], <String, String>{});
291 callbacks.assertContextPaths([project]);
292 callbacks.assertContextFiles(project, [fileA, fileB]);
293 }
294
295 void test_setRoots_ignoreGlobs() {
296 String project = '/project';
297 String file1 = '$project/file.dart';
298 String file2 = '$project/file.foo';
299 // create files
300 resourceProvider.newFile(file1, '');
301 resourceProvider.newFile(file2, '');
302 // set roots
303 manager.setRoots(<String>[project], <String>[], <String, String>{});
304 callbacks.assertContextPaths([project]);
305 callbacks.assertContextFiles(project, [file1]);
306 }
307
308 void test_setRoots_newContextFolder_coverNewRoot() {
309 String contextPath = '/context';
310 String root1 = '$contextPath/root1';
311 String file1 = '$root1/file1.dart';
312 String root2 = '$contextPath/root2';
313 String file2 = '$root2/file1.dart';
314 // create files
315 resourceProvider.newFile(file1, '');
316 resourceProvider.newFile(file2, '');
317 // cover single root '/context/root1'
318 manager.setRoots(<String>[root1], <String>[], <String, String>{});
319 callbacks.assertContextPaths([root1]);
320 callbacks.assertContextFiles(root1, [file1]);
321 // cover two roots
322 manager.setRoots(<String>[root1, root2], <String>[], <String, String>{});
323 callbacks.assertContextPaths([contextPath]);
324 callbacks.assertContextFiles(contextPath, [file1, file2]);
325 // cover single root '/context/root2'
326 manager.setRoots(<String>[root2], <String>[], <String, String>{});
327 callbacks.assertContextPaths([root2]);
328 callbacks.assertContextFiles(root2, [file2]);
329 }
330
331 void test_setRoots_newContextFolder_replace() {
332 String contextPath1 = '/context1';
333 String root11 = '$contextPath1/root1';
334 String root12 = '$contextPath1/root2';
335 String file11 = '$root11/file1.dart';
336 String file12 = '$root12/file2.dart';
337 String contextPath2 = '/context2';
338 String root21 = '$contextPath2/root1';
339 String root22 = '$contextPath2/root2';
340 String file21 = '$root21/file1.dart';
341 String file22 = '$root22/file2.dart';
342 // create files
343 resourceProvider.newFile(file11, '');
344 resourceProvider.newFile(file12, '');
345 resourceProvider.newFile(file21, '');
346 resourceProvider.newFile(file22, '');
347 // set roots in '/context1'
348 manager.setRoots(<String>[root11, root12], <String>[], <String, String>{});
349 callbacks.assertContextPaths([contextPath1]);
350 callbacks.assertContextFiles(contextPath1, [file11, file12]);
351 // set roots in '/context2'
352 manager.setRoots(<String>[root21, root22], <String>[], <String, String>{});
353 callbacks.assertContextPaths([contextPath2]);
354 callbacks.assertContextFiles(contextPath2, [file21, file22]);
355 }
356
357 void test_setRoots_pathContainsDotFile() {
358 // If the path to a file (relative to the context root) contains a folder
359 // whose name begins with '.', then the file is ignored.
360 String project = '/project';
361 String fileA = '$project/foo.dart';
362 String fileB = '$project/.pub/bar.dart';
363 resourceProvider.newFile(fileA, '');
364 resourceProvider.newFile(fileB, '');
365 manager.setRoots(<String>[project], <String>[], <String, String>{});
366 callbacks.assertContextPaths([project]);
367 callbacks.assertContextFiles(project, [fileA]);
368 }
369
370 void test_setRoots_rootPathContainsDotFile() {
371 // If the path to the context root itself contains a folder whose name
372 // begins with '.', then that is not sufficient to cause any files in the
373 // context to be ignored.
374 String project = '/.pub/project';
375 String fileA = '$project/foo.dart';
376 resourceProvider.newFile(fileA, '');
377 manager.setRoots(<String>[project], <String>[], <String, String>{});
378 callbacks.assertContextPaths([project]);
379 callbacks.assertContextFiles(project, [fileA]);
380 }
381
382 test_watch_addFile() async {
383 String project = '/project';
384 resourceProvider.newFolder(project);
385 manager.setRoots(<String>[project], <String>[], <String, String>{});
386 // empty folder initially
387 callbacks.assertContextFiles(project, []);
388 // add file
389 String file = '$project/foo.dart';
390 resourceProvider.newFile(file, 'contents');
391 // the file was added
392 await pumpEventQueue();
393 callbacks.assertContextFiles(project, [file]);
394 }
395
396 test_watch_addFile_afterChangingRoots() async {
397 String contextPath = '/context';
398 String root1 = '$contextPath/root1';
399 String root2 = '$contextPath/root2';
400 String file1 = '$root1/file1.dart';
401 String file2 = '$root2/file2.dart';
402 resourceProvider.newFolder(root1);
403 resourceProvider.newFolder(root2);
404 manager.setRoots(<String>[root1], <String>[], <String, String>{});
405 manager.setRoots(<String>[root2], <String>[], <String, String>{});
406 manager.setRoots(<String>[root1, root2], <String>[], <String, String>{});
407 manager.setRoots(<String>[root2], <String>[], <String, String>{});
408 // empty folder initially
409 callbacks.assertContextFiles(root2, []);
410 // add files
411 resourceProvider.newFile(file1, '');
412 resourceProvider.newFile(file2, '');
413 // the file was added
414 await pumpEventQueue();
415 callbacks.assertContextFiles(root2, [file2]);
416 }
417
418 test_watch_addFile_excluded() async {
419 String project = '/project';
420 String folderA = '$project/aaa';
421 String folderB = '$project/bbb';
422 String fileA = '$folderA/a.dart';
423 String fileB = '$folderB/b.dart';
424 // create files
425 resourceProvider.newFile(fileA, 'library a;');
426 // set roots
427 manager.setRoots(<String>[project], <String>[folderB], <String, String>{});
428 callbacks.assertContextPaths([project]);
429 callbacks.assertContextFiles(project, [fileA]);
430 // add a file, ignored as excluded
431 resourceProvider.newFile(fileB, 'library b;');
432 await pumpEventQueue();
433 callbacks.assertContextPaths([project]);
434 callbacks.assertContextFiles(project, [fileA]);
435 }
436
437 test_watch_addFile_notInRoot() async {
438 String contextPath = '/roots';
439 String root1 = '$contextPath/root1';
440 String root2 = '$contextPath/root2';
441 String root3 = '$contextPath/root3';
442 String file1 = '$root1/file1.dart';
443 String file2 = '$root2/file2.dart';
444 String file3 = '$root3/file3.dart';
445 // create files
446 resourceProvider.newFile(file1, '');
447 resourceProvider.newFile(file2, '');
448 // set roots
449 manager.setRoots(<String>[root1, root2], <String>[], <String, String>{});
450 callbacks.assertContextPaths([contextPath]);
451 callbacks.assertContextFiles(contextPath, [file1, file2]);
452 // add a file, not in a root - ignored
453 resourceProvider.newFile(file3, '');
454 await pumpEventQueue();
455 callbacks.assertContextPaths([contextPath]);
456 callbacks.assertContextFiles(contextPath, [file1, file2]);
457 }
458
459 test_watch_addFile_pathContainsDotFile() async {
460 // If a file is added and the absolute path to it contains a folder whose
461 // name begins with '.', then the file is ignored.
462 String project = '/project';
463 String fileA = '$project/foo.dart';
464 String fileB = '$project/.pub/bar.dart';
465 resourceProvider.newFile(fileA, '');
466 manager.setRoots(<String>[project], <String>[], <String, String>{});
467 callbacks.assertContextPaths([project]);
468 callbacks.assertContextFiles(project, [fileA]);
469 resourceProvider.newFile(fileB, '');
470 await pumpEventQueue();
471 callbacks.assertContextPaths([project]);
472 callbacks.assertContextFiles(project, [fileA]);
473 }
474
475 test_watch_addFileInSubFolder() async {
476 String project = '/project';
477 resourceProvider.newFolder(project);
478 manager.setRoots(<String>[project], <String>[], <String, String>{});
479 // empty folder initially
480 callbacks.assertContextFiles(project, []);
481 // add file in subfolder
482 String file = '$project/foo/bar.dart';
483 resourceProvider.newFile(file, 'contents');
484 // the file was added
485 await pumpEventQueue();
486 callbacks.assertContextFiles(project, [file]);
487 }
488
489 test_watch_deleteFile() async {
490 String project = '/project';
491 String file = '$project/foo.dart';
492 // add root with a file
493 resourceProvider.newFile(file, 'contents');
494 manager.setRoots(<String>[project], <String>[], <String, String>{});
495 // the file was added
496 callbacks.assertContextFiles(project, [file]);
497 // delete the file
498 resourceProvider.deleteFile(file);
499 await pumpEventQueue();
500 callbacks.assertContextFiles(project, []);
501 }
502
503 test_watch_deleteFolder() async {
504 String project = '/project';
505 String file = '$project/foo.dart';
506 // add root with a file
507 resourceProvider.newFile(file, 'contents');
508 manager.setRoots(<String>[project], <String>[], <String, String>{});
509 // the file was added
510 callbacks.assertContextFiles(project, [file]);
511 // delete the folder
512 resourceProvider.deleteFolder(project);
513 await pumpEventQueue();
514 callbacks.assertContextFiles(project, []);
515 }
516
517 test_watch_modifyFile() async {
518 String project = '/project';
519 String file = '$project/foo.dart';
520 // add root with a file
521 resourceProvider.newFile(file, 'contents');
522 manager.setRoots(<String>[project], <String>[], <String, String>{});
523 // the file was added
524 Map<String, int> filePaths = callbacks.currentContextFilePaths[project];
525 expect(filePaths, hasLength(1));
526 expect(filePaths, contains(file));
527 expect(filePaths[file], equals(callbacks.now));
528 // update the file
529 callbacks.now++;
530 resourceProvider.modifyFile(file, 'new contents');
531 await pumpEventQueue();
532 return expect(filePaths[file], equals(callbacks.now));
533 }
534
535 void _processRequiredPlugins() {
536 List<Plugin> plugins = <Plugin>[];
537 plugins.addAll(AnalysisEngine.instance.requiredPlugins);
538 ExtensionManager manager = new ExtensionManager();
539 manager.processPlugins(plugins);
540 }
541 }
542
543 class TestUriResolver extends UriResolver {
544 @override
545 Source resolveAbsolute(Uri uri, [Uri actualUri]) {
546 return null;
547 }
548 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/socket_server.dart ('k') | pkg/analysis_server/test/socket_server_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698