| 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 'package:analysis_server/src/context_manager.dart'; | 7 import 'package:analysis_server/src/context_manager.dart'; |
| 8 import 'package:analysis_server/src/package_map_provider.dart'; | 8 import 'package:analysis_server/src/package_map_provider.dart'; |
| 9 import 'package:analysis_testing/reflective_tests.dart'; | 9 import 'package:analysis_testing/reflective_tests.dart'; |
| 10 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 manager.setRoots(<String>[projPath], <String>[]); | 49 manager.setRoots(<String>[projPath], <String>[]); |
| 50 expect(manager.currentContextFilePaths[projPath], isEmpty); | 50 expect(manager.currentContextFilePaths[projPath], isEmpty); |
| 51 // "packages" files are ignored during watch | 51 // "packages" files are ignored during watch |
| 52 String filePath2 = posix.join(projPath, 'packages', 'file2.dart'); | 52 String filePath2 = posix.join(projPath, 'packages', 'file2.dart'); |
| 53 resourceProvider.newFile(filePath2, 'contents'); | 53 resourceProvider.newFile(filePath2, 'contents'); |
| 54 return pumpEventQueue().then((_) { | 54 return pumpEventQueue().then((_) { |
| 55 expect(manager.currentContextFilePaths[projPath], isEmpty); | 55 expect(manager.currentContextFilePaths[projPath], isEmpty); |
| 56 }); | 56 }); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void test_isInAnalysisRoot_excluded() { |
| 60 // prepare paths |
| 61 String project = '/project'; |
| 62 String excludedFolder = '$project/excluded'; |
| 63 // set roots |
| 64 resourceProvider.newFolder(project); |
| 65 resourceProvider.newFolder(excludedFolder); |
| 66 manager.setRoots(<String>[project], <String>[excludedFolder]); |
| 67 // verify |
| 68 expect(manager.isInAnalysisRoot('$excludedFolder/test.dart'), isFalse); |
| 69 } |
| 70 |
| 59 void test_isInAnalysisRoot_inRoot() { | 71 void test_isInAnalysisRoot_inRoot() { |
| 60 manager.setRoots(<String>[projPath], <String>[]); | 72 manager.setRoots(<String>[projPath], <String>[]); |
| 61 expect(manager.isInAnalysisRoot('$projPath/test.dart'), isTrue); | 73 expect(manager.isInAnalysisRoot('$projPath/test.dart'), isTrue); |
| 62 } | 74 } |
| 63 | 75 |
| 64 void test_isInAnalysisRoot_notInRoot() { | 76 void test_isInAnalysisRoot_notInRoot() { |
| 65 manager.setRoots(<String>[projPath], <String>[]); | 77 manager.setRoots(<String>[projPath], <String>[]); |
| 66 expect(manager.isInAnalysisRoot('/test.dart'), isFalse); | 78 expect(manager.isInAnalysisRoot('/test.dart'), isFalse); |
| 67 } | 79 } |
| 68 | 80 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 161 |
| 150 void test_setRoots_addFolderWithoutPubspec() { | 162 void test_setRoots_addFolderWithoutPubspec() { |
| 151 packageMapProvider.packageMap = null; | 163 packageMapProvider.packageMap = null; |
| 152 manager.setRoots(<String>[projPath], <String>[]); | 164 manager.setRoots(<String>[projPath], <String>[]); |
| 153 // verify | 165 // verify |
| 154 expect(manager.currentContextPaths, hasLength(1)); | 166 expect(manager.currentContextPaths, hasLength(1)); |
| 155 expect(manager.currentContextPaths, contains(projPath)); | 167 expect(manager.currentContextPaths, contains(projPath)); |
| 156 expect(manager.currentContextFilePaths[projPath], hasLength(0)); | 168 expect(manager.currentContextFilePaths[projPath], hasLength(0)); |
| 157 } | 169 } |
| 158 | 170 |
| 171 void test_setRoots_exclude_newRoot_withExcludedFile() { |
| 172 // prepare paths |
| 173 String project = '/project'; |
| 174 String file1 = '$project/file1.dart'; |
| 175 String file2 = '$project/file2.dart'; |
| 176 // create files |
| 177 resourceProvider.newFile(file1, '// 1'); |
| 178 resourceProvider.newFile(file2, '// 2'); |
| 179 // set roots |
| 180 manager.setRoots(<String>[project], <String>[file1]); |
| 181 manager.assertContextPaths([project]); |
| 182 manager.assertContextFiles(project, [file2]); |
| 183 } |
| 184 |
| 185 void test_setRoots_exclude_newRoot_withExcludedFolder() { |
| 186 // prepare paths |
| 187 String project = '/project'; |
| 188 String folderA = '$project/aaa'; |
| 189 String folderB = '$project/bbb'; |
| 190 String fileA = '$folderA/a.dart'; |
| 191 String fileB = '$folderB/b.dart'; |
| 192 // create files |
| 193 resourceProvider.newFile(fileA, 'library a;'); |
| 194 resourceProvider.newFile(fileB, 'library b;'); |
| 195 // set roots |
| 196 manager.setRoots(<String>[project], <String>[folderB]); |
| 197 manager.assertContextPaths([project]); |
| 198 manager.assertContextFiles(project, [fileA]); |
| 199 } |
| 200 |
| 201 void test_setRoots_exclude_sameRoot_addExcludedFile() { |
| 202 // prepare paths |
| 203 String project = '/project'; |
| 204 String file1 = '$project/file1.dart'; |
| 205 String file2 = '$project/file2.dart'; |
| 206 // create files |
| 207 resourceProvider.newFile(file1, '// 1'); |
| 208 resourceProvider.newFile(file2, '// 2'); |
| 209 // set roots |
| 210 manager.setRoots(<String>[project], <String>[]); |
| 211 manager.assertContextPaths([project]); |
| 212 manager.assertContextFiles(project, [file1, file2]); |
| 213 // exclude "2" |
| 214 manager.setRoots(<String>[project], <String>[file2]); |
| 215 manager.assertContextPaths([project]); |
| 216 manager.assertContextFiles(project, [file1]); |
| 217 } |
| 218 |
| 219 void test_setRoots_exclude_sameRoot_addExcludedFolder() { |
| 220 // prepare paths |
| 221 String project = '/project'; |
| 222 String folderA = '$project/aaa'; |
| 223 String folderB = '$project/bbb'; |
| 224 String fileA = '$folderA/a.dart'; |
| 225 String fileB = '$folderB/b.dart'; |
| 226 // create files |
| 227 resourceProvider.newFile(fileA, 'library a;'); |
| 228 resourceProvider.newFile(fileB, 'library b;'); |
| 229 // initially both "aaa/a" and "bbb/b" are included |
| 230 manager.setRoots(<String>[project], <String>[]); |
| 231 manager.assertContextPaths([project]); |
| 232 manager.assertContextFiles(project, [fileA, fileB]); |
| 233 // exclude "bbb/" |
| 234 manager.setRoots(<String>[project], <String>[folderB]); |
| 235 manager.assertContextPaths([project]); |
| 236 manager.assertContextFiles(project, [fileA]); |
| 237 } |
| 238 |
| 239 void test_setRoots_exclude_sameRoot_removeExcludedFile() { |
| 240 // prepare paths |
| 241 String project = '/project'; |
| 242 String file1 = '$project/file1.dart'; |
| 243 String file2 = '$project/file2.dart'; |
| 244 // create files |
| 245 resourceProvider.newFile(file1, '// 1'); |
| 246 resourceProvider.newFile(file2, '// 2'); |
| 247 // set roots |
| 248 manager.setRoots(<String>[project], <String>[file2]); |
| 249 manager.assertContextPaths([project]); |
| 250 manager.assertContextFiles(project, [file1]); |
| 251 // stop excluding "2" |
| 252 manager.setRoots(<String>[project], <String>[]); |
| 253 manager.assertContextPaths([project]); |
| 254 manager.assertContextFiles(project, [file1, file2]); |
| 255 } |
| 256 |
| 257 void test_setRoots_exclude_sameRoot_removeExcludedFolder() { |
| 258 // prepare paths |
| 259 String project = '/project'; |
| 260 String folderA = '$project/aaa'; |
| 261 String folderB = '$project/bbb'; |
| 262 String fileA = '$folderA/a.dart'; |
| 263 String fileB = '$folderB/b.dart'; |
| 264 // create files |
| 265 resourceProvider.newFile(fileA, 'library a;'); |
| 266 resourceProvider.newFile(fileB, 'library b;'); |
| 267 // exclude "bbb/" |
| 268 manager.setRoots(<String>[project], <String>[folderB]); |
| 269 manager.assertContextPaths([project]); |
| 270 manager.assertContextFiles(project, [fileA]); |
| 271 // stop excluding "bbb/" |
| 272 manager.setRoots(<String>[project], <String>[]); |
| 273 manager.assertContextPaths([project]); |
| 274 manager.assertContextFiles(project, [fileA, fileB]); |
| 275 } |
| 276 |
| 159 void test_setRoots_ignoreSubContext_ofSubContext() { | 277 void test_setRoots_ignoreSubContext_ofSubContext() { |
| 160 // prepare paths | 278 // prepare paths |
| 161 String root = '/root'; | 279 String root = '/root'; |
| 162 String rootFile = '$root/root.dart'; | 280 String rootFile = '$root/root.dart'; |
| 163 String subProject = '$root/sub'; | 281 String subProject = '$root/sub'; |
| 164 String subPubspec = '$subProject/pubspec.yaml'; | 282 String subPubspec = '$subProject/pubspec.yaml'; |
| 165 String subFile = '$subProject/bin/sub.dart'; | 283 String subFile = '$subProject/bin/sub.dart'; |
| 166 String subSubPubspec = '$subProject/subsub/pubspec.yaml'; | 284 String subSubPubspec = '$subProject/subsub/pubspec.yaml'; |
| 167 // create files | 285 // create files |
| 168 resourceProvider.newFile(rootFile, 'library root;'); | 286 resourceProvider.newFile(rootFile, 'library root;'); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 // add file in subfolder | 400 // add file in subfolder |
| 283 String filePath = posix.join(projPath, 'foo', 'bar.dart'); | 401 String filePath = posix.join(projPath, 'foo', 'bar.dart'); |
| 284 resourceProvider.newFile(filePath, 'contents'); | 402 resourceProvider.newFile(filePath, 'contents'); |
| 285 // the file was added | 403 // the file was added |
| 286 return pumpEventQueue().then((_) { | 404 return pumpEventQueue().then((_) { |
| 287 expect(filePaths, hasLength(1)); | 405 expect(filePaths, hasLength(1)); |
| 288 expect(filePaths, contains(filePath)); | 406 expect(filePaths, contains(filePath)); |
| 289 }); | 407 }); |
| 290 } | 408 } |
| 291 | 409 |
| 410 test_watch_addFile_excluded() { |
| 411 // prepare paths |
| 412 String project = '/project'; |
| 413 String folderA = '$project/aaa'; |
| 414 String folderB = '$project/bbb'; |
| 415 String fileA = '$folderA/a.dart'; |
| 416 String fileB = '$folderB/b.dart'; |
| 417 // create files |
| 418 resourceProvider.newFile(fileA, 'library a;'); |
| 419 // set roots |
| 420 manager.setRoots(<String>[project], <String>[folderB]); |
| 421 manager.assertContextPaths([project]); |
| 422 manager.assertContextFiles(project, [fileA]); |
| 423 // add a file, ignored as excluded |
| 424 resourceProvider.newFile(fileB, 'library b;'); |
| 425 return pumpEventQueue().then((_) { |
| 426 manager.assertContextPaths([project]); |
| 427 manager.assertContextFiles(project, [fileA]); |
| 428 }); |
| 429 } |
| 430 |
| 292 test_watch_addPubspec_toRoot() { | 431 test_watch_addPubspec_toRoot() { |
| 293 // prepare paths | 432 // prepare paths |
| 294 String root = '/root'; | 433 String root = '/root'; |
| 295 String rootFile = '$root/root.dart'; | 434 String rootFile = '$root/root.dart'; |
| 296 String rootPubspec = '$root/pubspec.yaml'; | 435 String rootPubspec = '$root/pubspec.yaml'; |
| 297 // create files | 436 // create files |
| 298 resourceProvider.newFile(rootFile, 'library root;'); | 437 resourceProvider.newFile(rootFile, 'library root;'); |
| 299 // set roots | 438 // set roots |
| 300 manager.setRoots(<String>[root], <String>[]); | 439 manager.setRoots(<String>[root], <String>[]); |
| 301 manager.assertContextPaths([root]); | 440 manager.assertContextPaths([root]); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 currentContextFilePaths.remove(path); | 697 currentContextFilePaths.remove(path); |
| 559 currentContextPackageMaps.remove(path); | 698 currentContextPackageMaps.remove(path); |
| 560 } | 699 } |
| 561 | 700 |
| 562 @override | 701 @override |
| 563 void updateContextPackageMap(Folder contextFolder, Map<String, | 702 void updateContextPackageMap(Folder contextFolder, Map<String, |
| 564 List<Folder>> packageMap) { | 703 List<Folder>> packageMap) { |
| 565 currentContextPackageMaps[contextFolder.path] = packageMap; | 704 currentContextPackageMaps[contextFolder.path] = packageMap; |
| 566 } | 705 } |
| 567 } | 706 } |
| OLD | NEW |