OLD | NEW |
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 test.analysis_server.src.single_context_manager; | 5 library test.analysis_server.src.single_context_manager; |
6 | 6 |
7 import 'dart:core' hide Resource; | 7 import 'dart:core' hide Resource; |
8 | 8 |
9 import 'package:analysis_server/src/single_context_manager.dart'; | 9 import 'package:analysis_server/src/single_context_manager.dart'; |
10 import 'package:analyzer/file_system/file_system.dart'; | |
11 import 'package:analyzer/file_system/memory_file_system.dart'; | 10 import 'package:analyzer/file_system/memory_file_system.dart'; |
12 import 'package:analyzer/src/generated/engine.dart'; | 11 import 'package:analyzer/src/generated/engine.dart'; |
13 import 'package:analyzer/src/generated/java_io.dart'; | 12 import 'package:analyzer/src/generated/java_io.dart'; |
14 import 'package:analyzer/src/generated/sdk.dart'; | 13 import 'package:analyzer/src/generated/sdk.dart'; |
15 import 'package:analyzer/src/generated/source.dart'; | 14 import 'package:analyzer/src/generated/source.dart'; |
16 import 'package:analyzer/src/generated/source_io.dart'; | 15 import 'package:analyzer/src/generated/source_io.dart'; |
17 import 'package:analyzer/src/util/glob.dart'; | 16 import 'package:analyzer/src/util/glob.dart'; |
18 import 'package:linter/src/plugin/linter_plugin.dart'; | 17 import 'package:linter/src/plugin/linter_plugin.dart'; |
19 import 'package:path/path.dart'; | 18 import 'package:path/path.dart'; |
20 import 'package:plugin/manager.dart'; | 19 import 'package:plugin/manager.dart'; |
(...skipping 12 matching lines...) Expand all Loading... |
33 } | 32 } |
34 | 33 |
35 @reflectiveTest | 34 @reflectiveTest |
36 class SingleContextManagerTest { | 35 class SingleContextManagerTest { |
37 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); | 36 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); |
38 | 37 |
39 TestUriResolver packageResolver; | 38 TestUriResolver packageResolver; |
40 TestContextManagerCallbacks callbacks; | 39 TestContextManagerCallbacks callbacks; |
41 SingleContextManager manager; | 40 SingleContextManager manager; |
42 | 41 |
43 /** | |
44 * TODO(scheglov) rename after copying tests! | |
45 */ | |
46 String projPath = '/my/project'; | |
47 Folder rootFolder; | |
48 | |
49 List<Glob> get analysisFilesGlobs { | 42 List<Glob> get analysisFilesGlobs { |
50 List<String> patterns = <String>[ | 43 List<String> patterns = <String>[ |
51 '**/*.${AnalysisEngine.SUFFIX_DART}', | 44 '**/*.${AnalysisEngine.SUFFIX_DART}', |
52 '**/*.${AnalysisEngine.SUFFIX_HTML}', | 45 '**/*.${AnalysisEngine.SUFFIX_HTML}', |
53 ]; | 46 ]; |
54 return patterns | 47 return patterns |
55 .map((pattern) => new Glob(JavaFile.pathContext.separator, pattern)) | 48 .map((pattern) => new Glob(JavaFile.pathContext.separator, pattern)) |
56 .toList(); | 49 .toList(); |
57 } | 50 } |
58 | 51 |
59 String newFile(List<String> pathComponents, [String content = '']) { | 52 String newFile(List<String> pathComponents, [String content = '']) { |
60 String filePath = posix.joinAll(pathComponents); | 53 String filePath = posix.joinAll(pathComponents); |
61 resourceProvider.newFile(filePath, content); | 54 resourceProvider.newFile(filePath, content); |
62 return filePath; | 55 return filePath; |
63 } | 56 } |
64 | 57 |
65 String newFolder(List<String> pathComponents) { | 58 String newFolder(List<String> pathComponents) { |
66 String folderPath = posix.joinAll(pathComponents); | 59 String folderPath = posix.joinAll(pathComponents); |
67 resourceProvider.newFolder(folderPath); | 60 resourceProvider.newFolder(folderPath); |
68 return folderPath; | 61 return folderPath; |
69 } | 62 } |
70 | 63 |
71 void setUp() { | 64 void setUp() { |
72 rootFolder = resourceProvider.newFolder(projPath); | 65 packageResolver = new TestUriResolver(); |
73 packageResolver = new TestUriResolver(resourceProvider, rootFolder); | |
74 | 66 |
75 _processRequiredPlugins(); | 67 _processRequiredPlugins(); |
76 DartSdkManager sdkManager = new DartSdkManager((_) { | 68 DartSdkManager sdkManager = new DartSdkManager((_) { |
77 return new MockSdk(); | 69 return new MockSdk(); |
78 }); | 70 }); |
79 manager = new SingleContextManager(resourceProvider, sdkManager, | 71 manager = new SingleContextManager(resourceProvider, sdkManager, |
80 () => packageResolver, analysisFilesGlobs); | 72 () => packageResolver, analysisFilesGlobs); |
81 callbacks = new TestContextManagerCallbacks(resourceProvider); | 73 callbacks = new TestContextManagerCallbacks(resourceProvider); |
82 manager.callbacks = callbacks; | 74 manager.callbacks = callbacks; |
83 resourceProvider.newFolder(projPath); | |
84 } | 75 } |
85 | 76 |
86 void test_isIgnored_false() { | 77 void test_isIgnored_false() { |
87 String project = '/project'; | 78 String project = '/project'; |
88 manager.setRoots(<String>[project], <String>[], <String, String>{}); | 79 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
89 expect(manager.isIgnored('$project/file.dart'), isFalse); | 80 expect(manager.isIgnored('$project/file.dart'), isFalse); |
90 } | 81 } |
91 | 82 |
92 void test_isIgnored_true_inDotFolder() { | 83 void test_isIgnored_true_inDotFolder() { |
93 String project = '/project'; | 84 String project = '/project'; |
(...skipping 30 matching lines...) Expand all Loading... |
124 manager.setRoots(<String>[root1, root2], <String>[], <String, String>{}); | 115 manager.setRoots(<String>[root1, root2], <String>[], <String, String>{}); |
125 expect(manager.isInAnalysisRoot('$context/root3/file.dart'), isFalse); | 116 expect(manager.isInAnalysisRoot('$context/root3/file.dart'), isFalse); |
126 } | 117 } |
127 | 118 |
128 void test_isInAnalysisRoot_true() { | 119 void test_isInAnalysisRoot_true() { |
129 String project = '/project'; | 120 String project = '/project'; |
130 manager.setRoots(<String>[project], <String>[], <String, String>{}); | 121 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
131 expect(manager.isInAnalysisRoot('$project/file.dart'), isTrue); | 122 expect(manager.isInAnalysisRoot('$project/file.dart'), isTrue); |
132 } | 123 } |
133 | 124 |
| 125 void test_refresh() { |
| 126 String project = '/project'; |
| 127 String file1 = '$project/file1.dart'; |
| 128 String file2 = '$project/file2.dart'; |
| 129 // create files |
| 130 resourceProvider.newFile(file1, ''); |
| 131 resourceProvider.newFile(file2, ''); |
| 132 // set roots |
| 133 manager.setRoots(<String>[project], <String>[file2], <String, String>{}); |
| 134 callbacks.assertContextPaths([project]); |
| 135 callbacks.assertContextFiles(project, [file1]); |
| 136 // refresh |
| 137 manager.refresh([]); |
| 138 callbacks.assertContextPaths([project]); |
| 139 callbacks.assertContextFiles(project, [file1]); |
| 140 } |
| 141 |
134 void test_setRoots_addFolderWithDartFile() { | 142 void test_setRoots_addFolderWithDartFile() { |
135 String filePath = posix.join(projPath, 'lib', 'foo.dart'); | 143 String project = '/project'; |
136 resourceProvider.newFile(filePath, 'contents'); | 144 String file = '$project/lib/foo.dart'; |
137 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 145 resourceProvider.newFile(file, ''); |
| 146 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
138 // verify | 147 // verify |
139 callbacks.assertContextFiles(projPath, [filePath]); | 148 callbacks.assertContextPaths([project]); |
140 // There is an analysis context. | 149 callbacks.assertContextFiles(project, [file]); |
141 List<AnalysisContext> contextsInAnalysisRoot = | |
142 manager.contextsInAnalysisRoot(rootFolder); | |
143 expect(contextsInAnalysisRoot, hasLength(1)); | |
144 AnalysisContext context = contextsInAnalysisRoot[0]; | |
145 expect(context, isNotNull); | |
146 // Files in lib/ have package: URIs. | |
147 Source result = context.sourceFactory.forUri('package:foo/foo.dart'); | |
148 expect(result, isNotNull); | |
149 expect(result.exists(), isTrue); | |
150 } | 150 } |
151 | 151 |
152 void test_setRoots_addFolderWithDartFileInSubfolder() { | 152 void test_setRoots_addFolderWithDartFileInSubfolder() { |
153 String filePath = posix.join(projPath, 'foo', 'bar.dart'); | 153 String project = '/project'; |
154 resourceProvider.newFile(filePath, 'contents'); | 154 String file = '$project/foo/bar.dart'; |
155 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 155 resourceProvider.newFile(file, ''); |
| 156 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
156 // verify | 157 // verify |
157 callbacks.assertContextFiles(projPath, [filePath]); | 158 callbacks.assertContextFiles(project, [file]); |
158 } | 159 } |
159 | 160 |
160 void test_setRoots_addFolderWithDummyLink() { | 161 void test_setRoots_addFolderWithDummyLink() { |
161 String filePath = posix.join(projPath, 'foo.dart'); | 162 String project = '/project'; |
162 resourceProvider.newDummyLink(filePath); | 163 String file = '$project/foo.dart'; |
163 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 164 resourceProvider.newDummyLink(file); |
| 165 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
164 // verify | 166 // verify |
165 callbacks.assertContextFiles(projPath, []); | 167 callbacks.assertContextFiles(project, []); |
166 } | 168 } |
167 | 169 |
168 void test_setRoots_exclude_newRoot_withExcludedFile() { | 170 void test_setRoots_exclude_newRoot_withExcludedFile() { |
169 String project = '/project'; | 171 String project = '/project'; |
170 String file1 = '$project/file1.dart'; | 172 String file1 = '$project/file1.dart'; |
171 String file2 = '$project/file2.dart'; | 173 String file2 = '$project/file2.dart'; |
172 // create files | 174 // create files |
173 resourceProvider.newFile(file1, '// 1'); | 175 resourceProvider.newFile(file1, ''); |
174 resourceProvider.newFile(file2, '// 2'); | 176 resourceProvider.newFile(file2, ''); |
175 // set roots | 177 // set roots |
176 manager.setRoots(<String>[project], <String>[file1], <String, String>{}); | 178 manager.setRoots(<String>[project], <String>[file1], <String, String>{}); |
177 callbacks.assertContextPaths([project]); | 179 callbacks.assertContextPaths([project]); |
178 callbacks.assertContextFiles(project, [file2]); | 180 callbacks.assertContextFiles(project, [file2]); |
179 } | 181 } |
180 | 182 |
181 void test_setRoots_exclude_newRoot_withExcludedFolder() { | 183 void test_setRoots_exclude_newRoot_withExcludedFolder() { |
182 String project = '/project'; | 184 String project = '/project'; |
183 String folderA = '$project/aaa'; | 185 String folderA = '$project/aaa'; |
184 String folderB = '$project/bbb'; | 186 String folderB = '$project/bbb'; |
185 String fileA = '$folderA/a.dart'; | 187 String fileA = '$folderA/a.dart'; |
186 String fileB = '$folderB/b.dart'; | 188 String fileB = '$folderB/b.dart'; |
187 // create files | 189 // create files |
188 resourceProvider.newFile(fileA, 'library a;'); | 190 resourceProvider.newFile(fileA, ''); |
189 resourceProvider.newFile(fileB, 'library b;'); | 191 resourceProvider.newFile(fileB, ''); |
190 // set roots | 192 // set roots |
191 manager.setRoots(<String>[project], <String>[folderB], <String, String>{}); | 193 manager.setRoots(<String>[project], <String>[folderB], <String, String>{}); |
192 callbacks.assertContextPaths([project]); | 194 callbacks.assertContextPaths([project]); |
193 callbacks.assertContextFiles(project, [fileA]); | 195 callbacks.assertContextFiles(project, [fileA]); |
194 } | 196 } |
195 | 197 |
196 void test_setRoots_exclude_sameRoot_addExcludedFile() { | 198 void test_setRoots_exclude_sameRoot_addExcludedFile() { |
197 String project = '/project'; | 199 String project = '/project'; |
198 String file1 = '$project/file1.dart'; | 200 String file1 = '$project/file1.dart'; |
199 String file2 = '$project/file2.dart'; | 201 String file2 = '$project/file2.dart'; |
200 // create files | 202 // create files |
201 resourceProvider.newFile(file1, '// 1'); | 203 resourceProvider.newFile(file1, ''); |
202 resourceProvider.newFile(file2, '// 2'); | 204 resourceProvider.newFile(file2, ''); |
203 // set roots | 205 // set roots |
204 manager.setRoots(<String>[project], <String>[], <String, String>{}); | 206 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
205 callbacks.assertContextPaths([project]); | 207 callbacks.assertContextPaths([project]); |
206 callbacks.assertContextFiles(project, [file1, file2]); | 208 callbacks.assertContextFiles(project, [file1, file2]); |
207 // exclude "2" | 209 // exclude "2" |
208 manager.setRoots(<String>[project], <String>[file2], <String, String>{}); | 210 manager.setRoots(<String>[project], <String>[file2], <String, String>{}); |
209 callbacks.assertContextPaths([project]); | 211 callbacks.assertContextPaths([project]); |
210 callbacks.assertContextFiles(project, [file1]); | 212 callbacks.assertContextFiles(project, [file1]); |
211 } | 213 } |
212 | 214 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 manager.setRoots(<String>[project], <String>[folderB], <String, String>{}); | 278 manager.setRoots(<String>[project], <String>[folderB], <String, String>{}); |
277 callbacks.assertContextPaths([project]); | 279 callbacks.assertContextPaths([project]); |
278 callbacks.assertContextFiles(project, [fileA]); | 280 callbacks.assertContextFiles(project, [fileA]); |
279 // stop excluding "bbb/" | 281 // stop excluding "bbb/" |
280 manager.setRoots(<String>[project], <String>[], <String, String>{}); | 282 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
281 callbacks.assertContextPaths([project]); | 283 callbacks.assertContextPaths([project]); |
282 callbacks.assertContextFiles(project, [fileA, fileB]); | 284 callbacks.assertContextFiles(project, [fileA, fileB]); |
283 } | 285 } |
284 | 286 |
285 void test_setRoots_ignoreGlobs() { | 287 void test_setRoots_ignoreGlobs() { |
286 String file1 = '$projPath/file.dart'; | 288 String project = '/project'; |
287 String file2 = '$projPath/file.foo'; | 289 String file1 = '$project/file.dart'; |
| 290 String file2 = '$project/file.foo'; |
288 // create files | 291 // create files |
289 resourceProvider.newFile(file1, ''); | 292 resourceProvider.newFile(file1, ''); |
290 resourceProvider.newFile(file2, ''); | 293 resourceProvider.newFile(file2, ''); |
291 // set roots | 294 // set roots |
292 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 295 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
293 callbacks.assertContextPaths([projPath]); | 296 callbacks.assertContextPaths([project]); |
294 callbacks.assertContextFiles(projPath, [file1]); | 297 callbacks.assertContextFiles(project, [file1]); |
295 } | 298 } |
296 | 299 |
297 void test_setRoots_newContextFolder_coverNewRoot() { | 300 void test_setRoots_newContextFolder_coverNewRoot() { |
298 String contextPath = '/context'; | 301 String contextPath = '/context'; |
299 String root1 = '$contextPath/root1'; | 302 String root1 = '$contextPath/root1'; |
300 String file1 = '$root1/file1.dart'; | 303 String file1 = '$root1/file1.dart'; |
301 String root2 = '$contextPath/root2'; | 304 String root2 = '$contextPath/root2'; |
302 String file2 = '$root2/file1.dart'; | 305 String file2 = '$root2/file1.dart'; |
303 // create files | 306 // create files |
304 resourceProvider.newFile(file1, ''); | 307 resourceProvider.newFile(file1, ''); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 // context to be ignored. | 365 // context to be ignored. |
363 String project = '/.pub/project'; | 366 String project = '/.pub/project'; |
364 String fileA = '$project/foo.dart'; | 367 String fileA = '$project/foo.dart'; |
365 resourceProvider.newFile(fileA, ''); | 368 resourceProvider.newFile(fileA, ''); |
366 manager.setRoots(<String>[project], <String>[], <String, String>{}); | 369 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
367 callbacks.assertContextPaths([project]); | 370 callbacks.assertContextPaths([project]); |
368 callbacks.assertContextFiles(project, [fileA]); | 371 callbacks.assertContextFiles(project, [fileA]); |
369 } | 372 } |
370 | 373 |
371 test_watch_addFile() async { | 374 test_watch_addFile() async { |
372 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 375 String project = '/project'; |
| 376 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
373 // empty folder initially | 377 // empty folder initially |
374 callbacks.assertContextFiles(projPath, []); | 378 callbacks.assertContextFiles(project, []); |
375 // add file | 379 // add file |
376 String filePath = posix.join(projPath, 'foo.dart'); | 380 String file = '$project/foo.dart'; |
377 resourceProvider.newFile(filePath, 'contents'); | 381 resourceProvider.newFile(file, 'contents'); |
378 // the file was added | 382 // the file was added |
379 await pumpEventQueue(); | 383 await pumpEventQueue(); |
380 callbacks.assertContextFiles(projPath, [filePath]); | 384 callbacks.assertContextFiles(project, [file]); |
381 } | 385 } |
382 | 386 |
383 test_watch_addFile_excluded() async { | 387 test_watch_addFile_excluded() async { |
384 String folderA = '$projPath/aaa'; | 388 String project = '/project'; |
385 String folderB = '$projPath/bbb'; | 389 String folderA = '$project/aaa'; |
| 390 String folderB = '$project/bbb'; |
386 String fileA = '$folderA/a.dart'; | 391 String fileA = '$folderA/a.dart'; |
387 String fileB = '$folderB/b.dart'; | 392 String fileB = '$folderB/b.dart'; |
388 // create files | 393 // create files |
389 resourceProvider.newFile(fileA, 'library a;'); | 394 resourceProvider.newFile(fileA, 'library a;'); |
390 // set roots | 395 // set roots |
391 manager.setRoots(<String>[projPath], <String>[folderB], <String, String>{}); | 396 manager.setRoots(<String>[project], <String>[folderB], <String, String>{}); |
392 callbacks.assertContextPaths([projPath]); | 397 callbacks.assertContextPaths([project]); |
393 callbacks.assertContextFiles(projPath, [fileA]); | 398 callbacks.assertContextFiles(project, [fileA]); |
394 // add a file, ignored as excluded | 399 // add a file, ignored as excluded |
395 resourceProvider.newFile(fileB, 'library b;'); | 400 resourceProvider.newFile(fileB, 'library b;'); |
396 await pumpEventQueue(); | 401 await pumpEventQueue(); |
397 callbacks.assertContextPaths([projPath]); | 402 callbacks.assertContextPaths([project]); |
398 callbacks.assertContextFiles(projPath, [fileA]); | 403 callbacks.assertContextFiles(project, [fileA]); |
399 } | 404 } |
400 | 405 |
401 test_watch_addFile_notInRoot() async { | 406 test_watch_addFile_notInRoot() async { |
402 String contextPath = '/roots'; | 407 String contextPath = '/roots'; |
403 String root1 = '$contextPath/root1'; | 408 String root1 = '$contextPath/root1'; |
404 String root2 = '$contextPath/root2'; | 409 String root2 = '$contextPath/root2'; |
405 String root3 = '$contextPath/root3'; | 410 String root3 = '$contextPath/root3'; |
406 String file1 = '$root1/file1.dart'; | 411 String file1 = '$root1/file1.dart'; |
407 String file2 = '$root2/file2.dart'; | 412 String file2 = '$root2/file2.dart'; |
408 String file3 = '$root3/file3.dart'; | 413 String file3 = '$root3/file3.dart'; |
(...skipping 21 matching lines...) Expand all Loading... |
430 manager.setRoots(<String>[project], <String>[], <String, String>{}); | 435 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
431 callbacks.assertContextPaths([project]); | 436 callbacks.assertContextPaths([project]); |
432 callbacks.assertContextFiles(project, [fileA]); | 437 callbacks.assertContextFiles(project, [fileA]); |
433 resourceProvider.newFile(fileB, ''); | 438 resourceProvider.newFile(fileB, ''); |
434 await pumpEventQueue(); | 439 await pumpEventQueue(); |
435 callbacks.assertContextPaths([project]); | 440 callbacks.assertContextPaths([project]); |
436 callbacks.assertContextFiles(project, [fileA]); | 441 callbacks.assertContextFiles(project, [fileA]); |
437 } | 442 } |
438 | 443 |
439 test_watch_addFileInSubfolder() async { | 444 test_watch_addFileInSubfolder() async { |
440 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 445 String project = '/project'; |
| 446 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
441 // empty folder initially | 447 // empty folder initially |
442 callbacks.assertContextFiles(projPath, []); | 448 callbacks.assertContextFiles(project, []); |
443 // add file in subfolder | 449 // add file in subfolder |
444 String filePath = posix.join(projPath, 'foo', 'bar.dart'); | 450 String file = '$project/foo/bar.dart'; |
445 resourceProvider.newFile(filePath, 'contents'); | 451 resourceProvider.newFile(file, 'contents'); |
446 // the file was added | 452 // the file was added |
447 await pumpEventQueue(); | 453 await pumpEventQueue(); |
448 callbacks.assertContextFiles(projPath, [filePath]); | 454 callbacks.assertContextFiles(project, [file]); |
449 } | 455 } |
450 | 456 |
451 test_watch_deleteFile() async { | 457 test_watch_deleteFile() async { |
452 String filePath = posix.join(projPath, 'foo.dart'); | 458 String project = '/project'; |
| 459 String file = '$project/foo.dart'; |
453 // add root with a file | 460 // add root with a file |
454 resourceProvider.newFile(filePath, 'contents'); | 461 resourceProvider.newFile(file, 'contents'); |
455 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 462 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
456 // the file was added | 463 // the file was added |
457 callbacks.assertContextFiles(projPath, [filePath]); | 464 callbacks.assertContextFiles(project, [file]); |
458 // delete the file | 465 // delete the file |
459 resourceProvider.deleteFile(filePath); | 466 resourceProvider.deleteFile(file); |
460 await pumpEventQueue(); | 467 await pumpEventQueue(); |
461 callbacks.assertContextFiles(projPath, []); | 468 callbacks.assertContextFiles(project, []); |
462 } | 469 } |
463 | 470 |
464 test_watch_deleteFolder() async { | 471 test_watch_deleteFolder() async { |
465 String filePath = posix.join(projPath, 'foo.dart'); | 472 String project = '/project'; |
| 473 String file = '$project/foo.dart'; |
466 // add root with a file | 474 // add root with a file |
467 resourceProvider.newFile(filePath, 'contents'); | 475 resourceProvider.newFile(file, 'contents'); |
468 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 476 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
469 // the file was added | 477 // the file was added |
470 callbacks.assertContextFiles(projPath, [filePath]); | 478 callbacks.assertContextFiles(project, [file]); |
471 // delete the folder | 479 // delete the folder |
472 resourceProvider.deleteFolder(projPath); | 480 resourceProvider.deleteFolder(project); |
473 await pumpEventQueue(); | 481 await pumpEventQueue(); |
474 callbacks.assertContextFiles(projPath, []); | 482 callbacks.assertContextFiles(project, []); |
475 } | 483 } |
476 | 484 |
477 test_watch_modifyFile() async { | 485 test_watch_modifyFile() async { |
478 String filePath = posix.join(projPath, 'foo.dart'); | 486 String project = '/project'; |
| 487 String file = '$project/foo.dart'; |
479 // add root with a file | 488 // add root with a file |
480 resourceProvider.newFile(filePath, 'contents'); | 489 resourceProvider.newFile(file, 'contents'); |
481 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 490 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
482 // the file was added | 491 // the file was added |
483 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; | 492 Map<String, int> filePaths = callbacks.currentContextFilePaths[project]; |
484 expect(filePaths, hasLength(1)); | 493 expect(filePaths, hasLength(1)); |
485 expect(filePaths, contains(filePath)); | 494 expect(filePaths, contains(file)); |
486 expect(filePaths[filePath], equals(callbacks.now)); | 495 expect(filePaths[file], equals(callbacks.now)); |
487 // update the file | 496 // update the file |
488 callbacks.now++; | 497 callbacks.now++; |
489 resourceProvider.modifyFile(filePath, 'new contents'); | 498 resourceProvider.modifyFile(file, 'new contents'); |
490 await pumpEventQueue(); | 499 await pumpEventQueue(); |
491 return expect(filePaths[filePath], equals(callbacks.now)); | 500 return expect(filePaths[file], equals(callbacks.now)); |
492 } | 501 } |
493 | 502 |
494 void _processRequiredPlugins() { | 503 void _processRequiredPlugins() { |
495 List<Plugin> plugins = <Plugin>[]; | 504 List<Plugin> plugins = <Plugin>[]; |
496 plugins.addAll(AnalysisEngine.instance.requiredPlugins); | 505 plugins.addAll(AnalysisEngine.instance.requiredPlugins); |
497 plugins.add(AnalysisEngine.instance.commandLinePlugin); | 506 plugins.add(AnalysisEngine.instance.commandLinePlugin); |
498 plugins.add(AnalysisEngine.instance.optionsPlugin); | 507 plugins.add(AnalysisEngine.instance.optionsPlugin); |
499 plugins.add(linterPlugin); | 508 plugins.add(linterPlugin); |
500 ExtensionManager manager = new ExtensionManager(); | 509 ExtensionManager manager = new ExtensionManager(); |
501 manager.processPlugins(plugins); | 510 manager.processPlugins(plugins); |
502 } | 511 } |
503 } | 512 } |
504 | 513 |
505 class TestUriResolver extends UriResolver { | 514 class TestUriResolver extends UriResolver { |
506 final ResourceProvider resourceProvider; | |
507 final Folder rootFolder; | |
508 | |
509 TestUriResolver(this.resourceProvider, this.rootFolder); | |
510 | |
511 @override | 515 @override |
512 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 516 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
513 if (uri.scheme == 'package') { | |
514 List<String> segments = uri.pathSegments; | |
515 if (segments.length >= 2) { | |
516 List<String> relSegments = <String>['lib']..addAll(segments.skip(1)); | |
517 String relPath = resourceProvider.pathContext.joinAll(relSegments); | |
518 Resource file = rootFolder.getChild(relPath); | |
519 if (file is File && file.exists) { | |
520 return file.createSource(uri); | |
521 } | |
522 } | |
523 } | |
524 return null; | 517 return null; |
525 } | 518 } |
526 } | 519 } |
OLD | NEW |