OLD | NEW |
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.context.directory.manager; | 5 library test.context.directory.manager; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analysis_server/src/context_manager.dart'; | 9 import 'package:analysis_server/src/context_manager.dart'; |
10 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
11 import 'package:analyzer/file_system/memory_file_system.dart'; | 11 import 'package:analyzer/file_system/memory_file_system.dart'; |
12 import 'package:analyzer/instrumentation/instrumentation.dart'; | 12 import 'package:analyzer/instrumentation/instrumentation.dart'; |
13 import 'package:analyzer/src/generated/engine.dart'; | 13 import 'package:analyzer/src/generated/engine.dart'; |
14 import 'package:analyzer/src/generated/source.dart'; | 14 import 'package:analyzer/src/generated/source.dart'; |
15 import 'package:analyzer/src/generated/source_io.dart'; | 15 import 'package:analyzer/src/generated/source_io.dart'; |
16 import 'package:package_config/packages.dart'; | 16 import 'package:package_config/packages.dart'; |
17 import 'package:path/path.dart'; | 17 import 'package:path/path.dart'; |
18 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 18 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
19 import 'package:unittest/unittest.dart'; | 19 import 'package:unittest/unittest.dart'; |
20 | 20 |
21 import 'mocks.dart'; | 21 import 'mocks.dart'; |
| 22 import 'utils.dart'; |
22 | 23 |
23 main() { | 24 main() { |
24 groupSep = ' | '; | 25 initializeTestEnvironment(); |
25 defineReflectiveTests(AbstractContextManagerTest); | 26 defineReflectiveTests(AbstractContextManagerTest); |
26 } | 27 } |
27 | 28 |
28 @reflectiveTest | 29 @reflectiveTest |
29 class AbstractContextManagerTest { | 30 class AbstractContextManagerTest { |
30 /** | 31 /** |
31 * The name of the 'bin' directory. | 32 * The name of the 'bin' directory. |
32 */ | 33 */ |
33 static const String BIN_NAME = 'bin'; | 34 static const String BIN_NAME = 'bin'; |
34 | 35 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 manager.callbacks = callbacks; | 90 manager.callbacks = callbacks; |
90 resourceProvider.newFolder(projPath); | 91 resourceProvider.newFolder(projPath); |
91 ContextManagerImpl.ENABLE_PACKAGESPEC_SUPPORT = true; | 92 ContextManagerImpl.ENABLE_PACKAGESPEC_SUPPORT = true; |
92 } | 93 } |
93 | 94 |
94 void tearDown() { | 95 void tearDown() { |
95 ContextManagerImpl.ENABLE_PACKAGESPEC_SUPPORT = false; | 96 ContextManagerImpl.ENABLE_PACKAGESPEC_SUPPORT = false; |
96 } | 97 } |
97 | 98 |
98 void test_contextsInAnalysisRoot_nestedContext() { | 99 void test_contextsInAnalysisRoot_nestedContext() { |
99 String subProjPath = join(projPath, 'subproj'); | 100 String subProjPath = posix.join(projPath, 'subproj'); |
100 Folder subProjFolder = resourceProvider.newFolder(subProjPath); | 101 Folder subProjFolder = resourceProvider.newFolder(subProjPath); |
101 resourceProvider.newFile(join(subProjPath, 'pubspec.yaml'), 'contents'); | 102 resourceProvider.newFile( |
102 String subProjFilePath = join(subProjPath, 'file.dart'); | 103 posix.join(subProjPath, 'pubspec.yaml'), 'contents'); |
| 104 String subProjFilePath = posix.join(subProjPath, 'file.dart'); |
103 resourceProvider.newFile(subProjFilePath, 'contents'); | 105 resourceProvider.newFile(subProjFilePath, 'contents'); |
104 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 106 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
105 // Make sure that there really are contexts for both the main project and | 107 // Make sure that there really are contexts for both the main project and |
106 // the subproject. | 108 // the subproject. |
107 Folder projFolder = resourceProvider.getFolder(projPath); | 109 Folder projFolder = resourceProvider.getFolder(projPath); |
108 ContextInfo projContextInfo = manager.getContextInfoFor(projFolder); | 110 ContextInfo projContextInfo = manager.getContextInfoFor(projFolder); |
109 expect(projContextInfo, isNotNull); | 111 expect(projContextInfo, isNotNull); |
110 expect(projContextInfo.folder, projFolder); | 112 expect(projContextInfo.folder, projFolder); |
111 ContextInfo subProjContextInfo = manager.getContextInfoFor(subProjFolder); | 113 ContextInfo subProjContextInfo = manager.getContextInfoFor(subProjFolder); |
112 expect(subProjContextInfo, isNotNull); | 114 expect(subProjContextInfo, isNotNull); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 // set roots | 146 // set roots |
145 resourceProvider.newFolder(project); | 147 resourceProvider.newFolder(project); |
146 resourceProvider.newFolder(excludedFolder); | 148 resourceProvider.newFolder(excludedFolder); |
147 manager.setRoots( | 149 manager.setRoots( |
148 <String>[project], <String>[excludedFolder], <String, String>{}); | 150 <String>[project], <String>[excludedFolder], <String, String>{}); |
149 // verify | 151 // verify |
150 expect(manager.isInAnalysisRoot('$excludedFolder/test.dart'), isFalse); | 152 expect(manager.isInAnalysisRoot('$excludedFolder/test.dart'), isFalse); |
151 } | 153 } |
152 | 154 |
153 void test_isInAnalysisRoot_inNestedContext() { | 155 void test_isInAnalysisRoot_inNestedContext() { |
154 String subProjPath = join(projPath, 'subproj'); | 156 String subProjPath = posix.join(projPath, 'subproj'); |
155 Folder subProjFolder = resourceProvider.newFolder(subProjPath); | 157 Folder subProjFolder = resourceProvider.newFolder(subProjPath); |
156 resourceProvider.newFile(join(subProjPath, 'pubspec.yaml'), 'contents'); | 158 resourceProvider.newFile( |
157 String subProjFilePath = join(subProjPath, 'file.dart'); | 159 posix.join(subProjPath, 'pubspec.yaml'), 'contents'); |
| 160 String subProjFilePath = posix.join(subProjPath, 'file.dart'); |
158 resourceProvider.newFile(subProjFilePath, 'contents'); | 161 resourceProvider.newFile(subProjFilePath, 'contents'); |
159 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 162 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
160 // Make sure that there really is a context for the subproject. | 163 // Make sure that there really is a context for the subproject. |
161 ContextInfo subProjContextInfo = manager.getContextInfoFor(subProjFolder); | 164 ContextInfo subProjContextInfo = manager.getContextInfoFor(subProjFolder); |
162 expect(subProjContextInfo, isNotNull); | 165 expect(subProjContextInfo, isNotNull); |
163 expect(subProjContextInfo.folder, subProjFolder); | 166 expect(subProjContextInfo.folder, subProjFolder); |
164 // Check that isInAnalysisRoot() works. | 167 // Check that isInAnalysisRoot() works. |
165 expect(manager.isInAnalysisRoot(subProjFilePath), isTrue); | 168 expect(manager.isInAnalysisRoot(subProjFilePath), isTrue); |
166 } | 169 } |
167 | 170 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 test_path_filter_analysis_option() async { | 210 test_path_filter_analysis_option() async { |
208 // Create files. | 211 // Create files. |
209 String libPath = newFolder([projPath, LIB_NAME]); | 212 String libPath = newFolder([projPath, LIB_NAME]); |
210 newFile([libPath, 'main.dart']); | 213 newFile([libPath, 'main.dart']); |
211 newFile([libPath, 'nope.dart']); | 214 newFile([libPath, 'nope.dart']); |
212 String sdkExtPath = newFolder([projPath, 'sdk_ext']); | 215 String sdkExtPath = newFolder([projPath, 'sdk_ext']); |
213 newFile([sdkExtPath, 'entry.dart']); | 216 newFile([sdkExtPath, 'entry.dart']); |
214 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']); | 217 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']); |
215 newFile([sdkExtSrcPath, 'part.dart']); | 218 newFile([sdkExtSrcPath, 'part.dart']); |
216 // Setup analysis options file with ignore list. | 219 // Setup analysis options file with ignore list. |
217 newFile([projPath, '.analysis_options'], r''' | 220 newFile( |
| 221 [projPath, '.analysis_options'], |
| 222 r''' |
218 analyzer: | 223 analyzer: |
219 exclude: | 224 exclude: |
220 - lib/nope.dart | 225 - lib/nope.dart |
221 - 'sdk_ext/**' | 226 - 'sdk_ext/**' |
222 '''); | 227 '''); |
223 // Setup context. | 228 // Setup context. |
224 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 229 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
225 // Verify that analysis options was parsed and the ignore patterns applied. | 230 // Verify that analysis options was parsed and the ignore patterns applied. |
226 Map<String, int> fileTimestamps = | 231 Map<String, int> fileTimestamps = |
227 callbacks.currentContextFilePaths[projPath]; | 232 callbacks.currentContextFilePaths[projPath]; |
228 expect(fileTimestamps, isNotEmpty); | 233 expect(fileTimestamps, isNotEmpty); |
229 List<String> files = fileTimestamps.keys.toList(); | 234 List<String> files = fileTimestamps.keys.toList(); |
230 expect(files.length, equals(1)); | 235 expect(files.length, equals(1)); |
231 expect(files[0], equals('/my/proj/lib/main.dart')); | 236 expect(files[0], equals('/my/proj/lib/main.dart')); |
232 } | 237 } |
233 | 238 |
234 test_path_filter_child_contexts_option() async { | 239 test_path_filter_child_contexts_option() async { |
235 // Create files. | 240 // Create files. |
236 String libPath = newFolder([projPath, LIB_NAME]); | 241 String libPath = newFolder([projPath, LIB_NAME]); |
237 newFile([libPath, 'main.dart']); | 242 newFile([libPath, 'main.dart']); |
238 newFile([libPath, 'pubspec.yaml'], r''' | 243 newFile( |
| 244 [libPath, 'pubspec.yaml'], |
| 245 r''' |
239 name: foobar | 246 name: foobar |
240 '''); | 247 '''); |
241 String otherLibPath = newFolder([projPath, 'other_lib']); | 248 String otherLibPath = newFolder([projPath, 'other_lib']); |
242 newFile([otherLibPath, 'entry.dart']); | 249 newFile([otherLibPath, 'entry.dart']); |
243 newFile([otherLibPath, 'pubspec.yaml'], r''' | 250 newFile( |
| 251 [otherLibPath, 'pubspec.yaml'], |
| 252 r''' |
244 name: other_lib | 253 name: other_lib |
245 '''); | 254 '''); |
246 // Setup analysis options file with ignore list that ignores the 'other_lib' | 255 // Setup analysis options file with ignore list that ignores the 'other_lib' |
247 // directory by name. | 256 // directory by name. |
248 newFile([projPath, '.analysis_options'], r''' | 257 newFile( |
| 258 [projPath, '.analysis_options'], |
| 259 r''' |
249 analyzer: | 260 analyzer: |
250 exclude: | 261 exclude: |
251 - 'other_lib' | 262 - 'other_lib' |
252 '''); | 263 '''); |
253 // Setup context. | 264 // Setup context. |
254 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 265 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
255 // Verify that the context in other_lib wasn't created and that the | 266 // Verify that the context in other_lib wasn't created and that the |
256 // context in lib was created. | 267 // context in lib was created. |
257 var contexts = manager.contextsInAnalysisRoot( | 268 var contexts = |
258 resourceProvider.newFolder(projPath)); | 269 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); |
| 270 expect(contexts.length, 2); |
| 271 expect(contexts[0].name, equals('/my/proj')); |
| 272 expect(contexts[1].name, equals('/my/proj/lib')); |
| 273 } |
| 274 |
| 275 test_path_filter_recursive_wildcard_child_contexts_option() async { |
| 276 // Create files. |
| 277 String libPath = newFolder([projPath, LIB_NAME]); |
| 278 newFile([libPath, 'main.dart']); |
| 279 newFile( |
| 280 [libPath, 'pubspec.yaml'], |
| 281 r''' |
| 282 name: foobar |
| 283 '''); |
| 284 String otherLibPath = newFolder([projPath, 'other_lib']); |
| 285 newFile([otherLibPath, 'entry.dart']); |
| 286 newFile( |
| 287 [otherLibPath, 'pubspec.yaml'], |
| 288 r''' |
| 289 name: other_lib |
| 290 '''); |
| 291 // Setup analysis options file with ignore list that ignores 'other_lib' |
| 292 // and all descendants. |
| 293 newFile( |
| 294 [projPath, '.analysis_options'], |
| 295 r''' |
| 296 analyzer: |
| 297 exclude: |
| 298 - 'other_lib/**' |
| 299 '''); |
| 300 // Setup context. |
| 301 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 302 // Verify that the context in other_lib wasn't created and that the |
| 303 // context in lib was created. |
| 304 var contexts = |
| 305 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); |
259 expect(contexts.length, 2); | 306 expect(contexts.length, 2); |
260 expect(contexts[0].name, equals('/my/proj')); | 307 expect(contexts[0].name, equals('/my/proj')); |
261 expect(contexts[1].name, equals('/my/proj/lib')); | 308 expect(contexts[1].name, equals('/my/proj/lib')); |
262 } | 309 } |
263 | 310 |
264 test_path_filter_wildcard_child_contexts_option() async { | 311 test_path_filter_wildcard_child_contexts_option() async { |
265 // Create files. | 312 // Create files. |
266 String libPath = newFolder([projPath, LIB_NAME]); | 313 String libPath = newFolder([projPath, LIB_NAME]); |
267 newFile([libPath, 'main.dart']); | 314 newFile([libPath, 'main.dart']); |
268 newFile([libPath, 'pubspec.yaml'], r''' | 315 newFile( |
| 316 [libPath, 'pubspec.yaml'], |
| 317 r''' |
269 name: foobar | 318 name: foobar |
270 '''); | 319 '''); |
271 String otherLibPath = newFolder([projPath, 'other_lib']); | 320 String otherLibPath = newFolder([projPath, 'other_lib']); |
272 newFile([otherLibPath, 'entry.dart']); | 321 newFile([otherLibPath, 'entry.dart']); |
273 newFile([otherLibPath, 'pubspec.yaml'], r''' | 322 newFile( |
| 323 [otherLibPath, 'pubspec.yaml'], |
| 324 r''' |
274 name: other_lib | 325 name: other_lib |
275 '''); | 326 '''); |
276 // Setup analysis options file with ignore list that ignores 'other_lib' | 327 // Setup analysis options file with ignore list that ignores 'other_lib' |
277 // and all immediate children. | 328 // and all immediate children. |
278 newFile([projPath, '.analysis_options'], r''' | 329 newFile( |
| 330 [projPath, '.analysis_options'], |
| 331 r''' |
279 analyzer: | 332 analyzer: |
280 exclude: | 333 exclude: |
281 - 'other_lib/*' | 334 - 'other_lib/*' |
282 '''); | 335 '''); |
283 // Setup context. | 336 // Setup context. |
284 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 337 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
285 // Verify that the context in other_lib wasn't created and that the | 338 // Verify that the context in other_lib wasn't created and that the |
286 // context in lib was created. | 339 // context in lib was created. |
287 var contexts = manager.contextsInAnalysisRoot( | 340 var contexts = |
288 resourceProvider.newFolder(projPath)); | 341 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); |
289 expect(contexts.length, 2); | 342 expect(contexts.length, 2); |
290 expect(contexts[0].name, equals('/my/proj')); | 343 expect(contexts[0].name, equals('/my/proj')); |
291 expect(contexts[1].name, equals('/my/proj/lib')); | 344 expect(contexts[1].name, equals('/my/proj/lib')); |
292 } | |
293 | |
294 test_path_filter_recursive_wildcard_child_contexts_option() async { | |
295 // Create files. | |
296 String libPath = newFolder([projPath, LIB_NAME]); | |
297 newFile([libPath, 'main.dart']); | |
298 newFile([libPath, 'pubspec.yaml'], r''' | |
299 name: foobar | |
300 '''); | |
301 String otherLibPath = newFolder([projPath, 'other_lib']); | |
302 newFile([otherLibPath, 'entry.dart']); | |
303 newFile([otherLibPath, 'pubspec.yaml'], r''' | |
304 name: other_lib | |
305 '''); | |
306 // Setup analysis options file with ignore list that ignores 'other_lib' | |
307 // and all descendants. | |
308 newFile([projPath, '.analysis_options'], r''' | |
309 analyzer: | |
310 exclude: | |
311 - 'other_lib/**' | |
312 '''); | |
313 // Setup context. | |
314 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | |
315 // Verify that the context in other_lib wasn't created and that the | |
316 // context in lib was created. | |
317 var contexts = manager.contextsInAnalysisRoot( | |
318 resourceProvider.newFolder(projPath)); | |
319 expect(contexts.length, 2); | |
320 expect(contexts[0].name, equals('/my/proj')); | |
321 expect(contexts[1].name, equals('/my/proj/lib')); | |
322 } | 345 } |
323 | 346 |
324 test_refresh_folder_with_packagespec() { | 347 test_refresh_folder_with_packagespec() { |
325 // create a context with a .packages file | 348 // create a context with a .packages file |
326 String packagespecFile = posix.join(projPath, '.packages'); | 349 String packagespecFile = posix.join(projPath, '.packages'); |
327 resourceProvider.newFile(packagespecFile, ''); | 350 resourceProvider.newFile(packagespecFile, ''); |
328 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 351 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
329 return pumpEventQueue().then((_) { | 352 return pumpEventQueue().then((_) { |
330 expect(callbacks.currentContextPaths.toList(), [projPath]); | 353 expect(callbacks.currentContextPaths.toList(), [projPath]); |
331 callbacks.now++; | 354 callbacks.now++; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 | 490 |
468 void test_setRoots_addFolderWithNestedPackageSpec() { | 491 void test_setRoots_addFolderWithNestedPackageSpec() { |
469 String examplePath = newFolder([projPath, EXAMPLE_NAME]); | 492 String examplePath = newFolder([projPath, EXAMPLE_NAME]); |
470 String libPath = newFolder([projPath, LIB_NAME]); | 493 String libPath = newFolder([projPath, LIB_NAME]); |
471 | 494 |
472 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME]); | 495 newFile([projPath, ContextManagerImpl.PACKAGE_SPEC_NAME]); |
473 newFile([libPath, 'main.dart']); | 496 newFile([libPath, 'main.dart']); |
474 newFile([examplePath, ContextManagerImpl.PACKAGE_SPEC_NAME]); | 497 newFile([examplePath, ContextManagerImpl.PACKAGE_SPEC_NAME]); |
475 newFile([examplePath, 'example.dart']); | 498 newFile([examplePath, 'example.dart']); |
476 | 499 |
477 packageMapProvider.packageMap['proj'] = | 500 packageMapProvider.packageMap['proj'] = [ |
478 [resourceProvider.getResource(libPath)]; | 501 resourceProvider.getResource(libPath) |
| 502 ]; |
479 | 503 |
480 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 504 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
481 | 505 |
482 expect(callbacks.currentContextPaths, hasLength(2)); | 506 expect(callbacks.currentContextPaths, hasLength(2)); |
483 | 507 |
484 expect(callbacks.currentContextPaths, contains(projPath)); | 508 expect(callbacks.currentContextPaths, contains(projPath)); |
485 Set<Source> projSources = callbacks.currentContextSources[projPath]; | 509 Set<Source> projSources = callbacks.currentContextSources[projPath]; |
486 expect(projSources, hasLength(1)); | 510 expect(projSources, hasLength(1)); |
487 expect(projSources.first.uri.toString(), 'file:///my/proj/lib/main.dart'); | 511 expect(projSources.first.uri.toString(), 'file:///my/proj/lib/main.dart'); |
488 | 512 |
489 expect(callbacks.currentContextPaths, contains(examplePath)); | 513 expect(callbacks.currentContextPaths, contains(examplePath)); |
490 Set<Source> exampleSources = callbacks.currentContextSources[examplePath]; | 514 Set<Source> exampleSources = callbacks.currentContextSources[examplePath]; |
491 expect(exampleSources, hasLength(1)); | 515 expect(exampleSources, hasLength(1)); |
492 expect(exampleSources.first.uri.toString(), | 516 expect(exampleSources.first.uri.toString(), |
493 'file:///my/proj/example/example.dart'); | 517 'file:///my/proj/example/example.dart'); |
494 } | 518 } |
495 | 519 |
496 void test_setRoots_addFolderWithNestedPubspec() { | 520 void test_setRoots_addFolderWithNestedPubspec() { |
497 String examplePath = newFolder([projPath, EXAMPLE_NAME]); | 521 String examplePath = newFolder([projPath, EXAMPLE_NAME]); |
498 String libPath = newFolder([projPath, LIB_NAME]); | 522 String libPath = newFolder([projPath, LIB_NAME]); |
499 | 523 |
500 newFile([projPath, ContextManagerImpl.PUBSPEC_NAME]); | 524 newFile([projPath, ContextManagerImpl.PUBSPEC_NAME]); |
501 newFile([libPath, 'main.dart']); | 525 newFile([libPath, 'main.dart']); |
502 newFile([examplePath, ContextManagerImpl.PUBSPEC_NAME]); | 526 newFile([examplePath, ContextManagerImpl.PUBSPEC_NAME]); |
503 newFile([examplePath, 'example.dart']); | 527 newFile([examplePath, 'example.dart']); |
504 | 528 |
505 packageMapProvider.packageMap['proj'] = | 529 packageMapProvider.packageMap['proj'] = [ |
506 [resourceProvider.getResource(libPath)]; | 530 resourceProvider.getResource(libPath) |
| 531 ]; |
507 | 532 |
508 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 533 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
509 | 534 |
510 expect(callbacks.currentContextPaths, hasLength(2)); | 535 expect(callbacks.currentContextPaths, hasLength(2)); |
511 | 536 |
512 expect(callbacks.currentContextPaths, contains(projPath)); | 537 expect(callbacks.currentContextPaths, contains(projPath)); |
513 Set<Source> projSources = callbacks.currentContextSources[projPath]; | 538 Set<Source> projSources = callbacks.currentContextSources[projPath]; |
514 expect(projSources, hasLength(1)); | 539 expect(projSources, hasLength(1)); |
515 expect(projSources.first.uri.toString(), 'package:proj/main.dart'); | 540 expect(projSources.first.uri.toString(), 'package:proj/main.dart'); |
516 | 541 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 String libPath = newFolder([projPath, LIB_NAME]); | 605 String libPath = newFolder([projPath, LIB_NAME]); |
581 String srcPath = newFolder([libPath, SRC_NAME]); | 606 String srcPath = newFolder([libPath, SRC_NAME]); |
582 String testPath = newFolder([projPath, TEST_NAME]); | 607 String testPath = newFolder([projPath, TEST_NAME]); |
583 | 608 |
584 newFile([projPath, ContextManagerImpl.PUBSPEC_NAME]); | 609 newFile([projPath, ContextManagerImpl.PUBSPEC_NAME]); |
585 String appPath = newFile([binPath, 'app.dart']); | 610 String appPath = newFile([binPath, 'app.dart']); |
586 newFile([libPath, 'main.dart']); | 611 newFile([libPath, 'main.dart']); |
587 newFile([srcPath, 'internal.dart']); | 612 newFile([srcPath, 'internal.dart']); |
588 String testFilePath = newFile([testPath, 'main_test.dart']); | 613 String testFilePath = newFile([testPath, 'main_test.dart']); |
589 | 614 |
590 packageMapProvider.packageMap['proj'] = | 615 packageMapProvider.packageMap['proj'] = [ |
591 [resourceProvider.getResource(libPath)]; | 616 resourceProvider.getResource(libPath) |
| 617 ]; |
592 | 618 |
593 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 619 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
594 Set<Source> sources = callbacks.currentContextSources[projPath]; | 620 Set<Source> sources = callbacks.currentContextSources[projPath]; |
595 | 621 |
596 expect(callbacks.currentContextPaths, hasLength(1)); | 622 expect(callbacks.currentContextPaths, hasLength(1)); |
597 expect(callbacks.currentContextPaths, contains(projPath)); | 623 expect(callbacks.currentContextPaths, contains(projPath)); |
598 expect(sources, hasLength(4)); | 624 expect(sources, hasLength(4)); |
599 List<String> uris = | 625 List<String> uris = |
600 sources.map((Source source) => source.uri.toString()).toList(); | 626 sources.map((Source source) => source.uri.toString()).toList(); |
601 expect(uris, contains('file://$appPath')); | 627 expect(uris, contains('file://$appPath')); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 String subProjectA_file = '$subProjectA/bin/a.dart'; | 666 String subProjectA_file = '$subProjectA/bin/a.dart'; |
641 String subProjectB_file = '$subProjectB/bin/b.dart'; | 667 String subProjectB_file = '$subProjectB/bin/b.dart'; |
642 // create files | 668 // create files |
643 resourceProvider.newFile('$subProjectA/pubspec.yaml', 'pubspec'); | 669 resourceProvider.newFile('$subProjectA/pubspec.yaml', 'pubspec'); |
644 resourceProvider.newFile('$subProjectB/pubspec.yaml', 'pubspec'); | 670 resourceProvider.newFile('$subProjectB/pubspec.yaml', 'pubspec'); |
645 resourceProvider.newFile(rootFile, 'library root;'); | 671 resourceProvider.newFile(rootFile, 'library root;'); |
646 resourceProvider.newFile(subProjectA_file, 'library a;'); | 672 resourceProvider.newFile(subProjectA_file, 'library a;'); |
647 resourceProvider.newFile(subProjectB_file, 'library b;'); | 673 resourceProvider.newFile(subProjectB_file, 'library b;'); |
648 // configure package maps | 674 // configure package maps |
649 packageMapProvider.packageMaps = { | 675 packageMapProvider.packageMaps = { |
650 subProjectA: {'foo': [resourceProvider.newFolder('/package/foo')]}, | 676 subProjectA: { |
651 subProjectB: {'bar': [resourceProvider.newFolder('/package/bar')]}, | 677 'foo': [resourceProvider.newFolder('/package/foo')] |
| 678 }, |
| 679 subProjectB: { |
| 680 'bar': [resourceProvider.newFolder('/package/bar')] |
| 681 }, |
652 }; | 682 }; |
653 // set roots | 683 // set roots |
654 manager.setRoots(<String>[root], <String>[], <String, String>{}); | 684 manager.setRoots(<String>[root], <String>[], <String, String>{}); |
655 callbacks.assertContextPaths([root, subProjectA, subProjectB]); | 685 callbacks.assertContextPaths([root, subProjectA, subProjectB]); |
656 // verify files | 686 // verify files |
657 callbacks.assertContextFiles(root, [rootFile]); | 687 callbacks.assertContextFiles(root, [rootFile]); |
658 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); | 688 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); |
659 callbacks.assertContextFiles(subProjectB, [subProjectB_file]); | 689 callbacks.assertContextFiles(subProjectB, [subProjectB_file]); |
660 // verify package maps | 690 // verify package maps |
661 _checkPackageMap(root, isNull); | 691 _checkPackageMap(root, isNull); |
662 _checkPackageMap( | 692 _checkPackageMap( |
663 subProjectA, equals(packageMapProvider.packageMaps[subProjectA])); | 693 subProjectA, equals(packageMapProvider.packageMaps[subProjectA])); |
664 _checkPackageMap( | 694 _checkPackageMap( |
665 subProjectB, equals(packageMapProvider.packageMaps[subProjectB])); | 695 subProjectB, equals(packageMapProvider.packageMaps[subProjectB])); |
666 } | 696 } |
667 | 697 |
668 void test_setRoots_addPackageRoot() { | 698 void test_setRoots_addPackageRoot() { |
669 String packagePathFoo = '/package1/foo'; | 699 String packagePathFoo = '/package1/foo'; |
670 String packageRootPath = '/package2/foo'; | 700 String packageRootPath = '/package2/foo'; |
671 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); | 701 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); |
672 packageMapProvider.packageMap = {'foo': [packageFolder]}; | 702 packageMapProvider.packageMap = { |
| 703 'foo': [packageFolder] |
| 704 }; |
673 List<String> includedPaths = <String>[projPath]; | 705 List<String> includedPaths = <String>[projPath]; |
674 List<String> excludedPaths = <String>[]; | 706 List<String> excludedPaths = <String>[]; |
675 manager.setRoots(includedPaths, excludedPaths, <String, String>{}); | 707 manager.setRoots(includedPaths, excludedPaths, <String, String>{}); |
676 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); | 708 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); |
677 manager.setRoots(includedPaths, excludedPaths, <String, String>{ | 709 manager.setRoots(includedPaths, excludedPaths, |
678 projPath: packageRootPath | 710 <String, String>{projPath: packageRootPath}); |
679 }); | |
680 _checkPackageRoot(projPath, equals(packageRootPath)); | 711 _checkPackageRoot(projPath, equals(packageRootPath)); |
681 } | 712 } |
682 | 713 |
683 void test_setRoots_changePackageRoot() { | 714 void test_setRoots_changePackageRoot() { |
684 String packageRootPath1 = '/package1'; | 715 String packageRootPath1 = '/package1'; |
685 String packageRootPath2 = '/package2'; | 716 String packageRootPath2 = '/package2'; |
686 List<String> includedPaths = <String>[projPath]; | 717 List<String> includedPaths = <String>[projPath]; |
687 List<String> excludedPaths = <String>[]; | 718 List<String> excludedPaths = <String>[]; |
688 manager.setRoots(includedPaths, excludedPaths, <String, String>{ | 719 manager.setRoots(includedPaths, excludedPaths, |
689 projPath: packageRootPath1 | 720 <String, String>{projPath: packageRootPath1}); |
690 }); | |
691 _checkPackageRoot(projPath, equals(packageRootPath1)); | 721 _checkPackageRoot(projPath, equals(packageRootPath1)); |
692 manager.setRoots(includedPaths, excludedPaths, <String, String>{ | 722 manager.setRoots(includedPaths, excludedPaths, |
693 projPath: packageRootPath2 | 723 <String, String>{projPath: packageRootPath2}); |
694 }); | |
695 _checkPackageRoot(projPath, equals(packageRootPath2)); | 724 _checkPackageRoot(projPath, equals(packageRootPath2)); |
696 } | 725 } |
697 | 726 |
698 void test_setRoots_exclude_newRoot_withExcludedFile() { | 727 void test_setRoots_exclude_newRoot_withExcludedFile() { |
699 // prepare paths | 728 // prepare paths |
700 String project = '/project'; | 729 String project = '/project'; |
701 String file1 = '$project/file1.dart'; | 730 String file1 = '$project/file1.dart'; |
702 String file2 = '$project/file2.dart'; | 731 String file2 = '$project/file2.dart'; |
703 // create files | 732 // create files |
704 resourceProvider.newFile(file1, '// 1'); | 733 resourceProvider.newFile(file1, '// 1'); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 callbacks.assertContextPaths([project]); | 843 callbacks.assertContextPaths([project]); |
815 callbacks.assertContextFiles(project, [fileA]); | 844 callbacks.assertContextFiles(project, [fileA]); |
816 // stop excluding "bbb/" | 845 // stop excluding "bbb/" |
817 manager.setRoots(<String>[project], <String>[], <String, String>{}); | 846 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
818 callbacks.assertContextPaths([project]); | 847 callbacks.assertContextPaths([project]); |
819 callbacks.assertContextFiles(project, [fileA, fileB]); | 848 callbacks.assertContextFiles(project, [fileA, fileB]); |
820 } | 849 } |
821 | 850 |
822 void test_setRoots_newFolderWithPackageRoot() { | 851 void test_setRoots_newFolderWithPackageRoot() { |
823 String packageRootPath = '/package'; | 852 String packageRootPath = '/package'; |
824 manager.setRoots(<String>[projPath], <String>[], <String, String>{ | 853 manager.setRoots(<String>[projPath], <String>[], |
825 projPath: packageRootPath | 854 <String, String>{projPath: packageRootPath}); |
826 }); | |
827 _checkPackageRoot(projPath, equals(packageRootPath)); | 855 _checkPackageRoot(projPath, equals(packageRootPath)); |
828 } | 856 } |
829 | 857 |
830 void test_setRoots_newlyAddedFoldersGetProperPackageMap() { | 858 void test_setRoots_newlyAddedFoldersGetProperPackageMap() { |
831 String packagePath = '/package/foo'; | 859 String packagePath = '/package/foo'; |
832 Folder packageFolder = resourceProvider.newFolder(packagePath); | 860 Folder packageFolder = resourceProvider.newFolder(packagePath); |
833 packageMapProvider.packageMap = {'foo': [packageFolder]}; | 861 packageMapProvider.packageMap = { |
| 862 'foo': [packageFolder] |
| 863 }; |
834 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 864 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
835 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); | 865 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); |
836 } | 866 } |
837 | 867 |
838 void test_setRoots_packageResolver() { | 868 void test_setRoots_packageResolver() { |
839 Uri uri = Uri.parse('package:foo/foo.dart'); | 869 Uri uri = Uri.parse('package:foo/foo.dart'); |
840 Source source = new TestSource(); | 870 Source source = new TestSource(); |
841 packageResolver = new TestUriResolver({uri: source}); | 871 packageResolver = new TestUriResolver({uri: source}); |
842 String filePath = posix.join(projPath, 'foo.dart'); | 872 String filePath = posix.join(projPath, 'foo.dart'); |
843 resourceProvider.newFile(filePath, 'contents'); | 873 resourceProvider.newFile(filePath, 'contents'); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 manager.setRoots(<String>[projectA], <String>[], <String, String>{}); | 986 manager.setRoots(<String>[projectA], <String>[], <String, String>{}); |
957 callbacks.assertContextPaths([projectA, subProjectA]); | 987 callbacks.assertContextPaths([projectA, subProjectA]); |
958 callbacks.assertContextFiles(projectA, [projectA_file]); | 988 callbacks.assertContextFiles(projectA, [projectA_file]); |
959 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); | 989 callbacks.assertContextFiles(subProjectA, [subProjectA_file]); |
960 } | 990 } |
961 | 991 |
962 void test_setRoots_removePackageRoot() { | 992 void test_setRoots_removePackageRoot() { |
963 String packagePathFoo = '/package1/foo'; | 993 String packagePathFoo = '/package1/foo'; |
964 String packageRootPath = '/package2/foo'; | 994 String packageRootPath = '/package2/foo'; |
965 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); | 995 Folder packageFolder = resourceProvider.newFolder(packagePathFoo); |
966 packageMapProvider.packageMap = {'foo': [packageFolder]}; | 996 packageMapProvider.packageMap = { |
| 997 'foo': [packageFolder] |
| 998 }; |
967 List<String> includedPaths = <String>[projPath]; | 999 List<String> includedPaths = <String>[projPath]; |
968 List<String> excludedPaths = <String>[]; | 1000 List<String> excludedPaths = <String>[]; |
969 manager.setRoots(includedPaths, excludedPaths, <String, String>{ | 1001 manager.setRoots(includedPaths, excludedPaths, |
970 projPath: packageRootPath | 1002 <String, String>{projPath: packageRootPath}); |
971 }); | |
972 _checkPackageRoot(projPath, equals(packageRootPath)); | 1003 _checkPackageRoot(projPath, equals(packageRootPath)); |
973 manager.setRoots(includedPaths, excludedPaths, <String, String>{}); | 1004 manager.setRoots(includedPaths, excludedPaths, <String, String>{}); |
974 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); | 1005 _checkPackageMap(projPath, equals(packageMapProvider.packageMap)); |
975 } | 1006 } |
976 | 1007 |
977 test_watch_addDummyLink() { | 1008 test_watch_addDummyLink() { |
978 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 1009 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
979 // empty folder initially | 1010 // empty folder initially |
980 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; | 1011 Map<String, int> filePaths = callbacks.currentContextFilePaths[projPath]; |
981 expect(filePaths, isEmpty); | 1012 expect(filePaths, isEmpty); |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1504 /** | 1535 /** |
1505 * Map from context to (map from file path to timestamp of last event). | 1536 * Map from context to (map from file path to timestamp of last event). |
1506 */ | 1537 */ |
1507 final Map<String, Map<String, int>> currentContextFilePaths = | 1538 final Map<String, Map<String, int>> currentContextFilePaths = |
1508 <String, Map<String, int>>{}; | 1539 <String, Map<String, int>>{}; |
1509 | 1540 |
1510 /** | 1541 /** |
1511 * A map from the paths of contexts to a set of the sources that should be | 1542 * A map from the paths of contexts to a set of the sources that should be |
1512 * explicitly analyzed in those contexts. | 1543 * explicitly analyzed in those contexts. |
1513 */ | 1544 */ |
1514 final Map<String, Set<Source>> currentContextSources = <String, Set<Source>>{ | 1545 final Map<String, Set<Source>> currentContextSources = |
1515 }; | 1546 <String, Set<Source>>{}; |
1516 | 1547 |
1517 /** | 1548 /** |
1518 * Map from context to folder disposition. | 1549 * Map from context to folder disposition. |
1519 */ | 1550 */ |
1520 final Map<String, FolderDisposition> currentContextDispositions = | 1551 final Map<String, FolderDisposition> currentContextDispositions = |
1521 <String, FolderDisposition>{}; | 1552 <String, FolderDisposition>{}; |
1522 | 1553 |
1523 /** | 1554 /** |
1524 * Resource provider used for this test. | 1555 * Resource provider used for this test. |
1525 */ | 1556 */ |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1624 class TestUriResolver extends UriResolver { | 1655 class TestUriResolver extends UriResolver { |
1625 Map<Uri, Source> uriMap; | 1656 Map<Uri, Source> uriMap; |
1626 | 1657 |
1627 TestUriResolver(this.uriMap); | 1658 TestUriResolver(this.uriMap); |
1628 | 1659 |
1629 @override | 1660 @override |
1630 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 1661 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
1631 return uriMap[uri]; | 1662 return uriMap[uri]; |
1632 } | 1663 } |
1633 } | 1664 } |
OLD | NEW |