| 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:analysis_server/src/source/optimizing_pub_package_map_provider.d
art'; | 10 import 'package:analysis_server/src/source/optimizing_pub_package_map_provider.d
art'; |
| 11 import 'package:analysis_server/uri/resolver_provider.dart'; | 11 import 'package:analysis_server/uri/resolver_provider.dart'; |
| 12 import 'package:analyzer/file_system/file_system.dart'; | 12 import 'package:analyzer/file_system/file_system.dart'; |
| 13 import 'package:analyzer/file_system/memory_file_system.dart'; | 13 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 14 import 'package:analyzer/instrumentation/instrumentation.dart'; | 14 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 15 import 'package:analyzer/source/package_map_resolver.dart'; | 15 import 'package:analyzer/source/package_map_resolver.dart'; |
| 16 import 'package:analyzer/source/path_filter.dart'; |
| 16 import 'package:analyzer/src/generated/engine.dart'; | 17 import 'package:analyzer/src/generated/engine.dart'; |
| 17 import 'package:analyzer/src/generated/source.dart'; | 18 import 'package:analyzer/src/generated/source.dart'; |
| 18 import 'package:analyzer/src/generated/source_io.dart'; | 19 import 'package:analyzer/src/generated/source_io.dart'; |
| 19 import 'package:path/path.dart'; | 20 import 'package:path/path.dart'; |
| 20 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 21 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 21 import 'package:unittest/unittest.dart'; | 22 import 'package:unittest/unittest.dart'; |
| 22 | 23 |
| 23 import 'mocks.dart'; | 24 import 'mocks.dart'; |
| 24 | 25 |
| 25 main() { | 26 main() { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 return pumpEventQueue().then((_) { | 164 return pumpEventQueue().then((_) { |
| 164 expect(manager.currentContextPaths.toSet(), | 165 expect(manager.currentContextPaths.toSet(), |
| 165 [subdir1Path, subdir2Path, projPath].toSet()); | 166 [subdir1Path, subdir2Path, projPath].toSet()); |
| 166 expect(manager.currentContextTimestamps[projPath], manager.now); | 167 expect(manager.currentContextTimestamps[projPath], manager.now); |
| 167 expect(manager.currentContextTimestamps[subdir1Path], manager.now); | 168 expect(manager.currentContextTimestamps[subdir1Path], manager.now); |
| 168 expect(manager.currentContextTimestamps[subdir2Path], manager.now); | 169 expect(manager.currentContextTimestamps[subdir2Path], manager.now); |
| 169 }); | 170 }); |
| 170 }); | 171 }); |
| 171 } | 172 } |
| 172 | 173 |
| 174 test_path_filter() async { |
| 175 // Setup context. |
| 176 Folder root = resourceProvider.newFolder(projPath); |
| 177 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 178 expect(manager.currentContextFilePaths[projPath], isEmpty); |
| 179 // Set ignore patterns for context. |
| 180 manager.setIgnorePatternsForContext(root, |
| 181 ['sdk_ext/**', 'lib/ignoreme.dart']); |
| 182 // Start creating files. |
| 183 newFile([projPath, AbstractContextManager.PUBSPEC_NAME]); |
| 184 String libPath = newFolder([projPath, LIB_NAME]); |
| 185 newFile([libPath, 'main.dart']); |
| 186 newFile([libPath, 'ignoreme.dart']); |
| 187 String sdkExtPath = newFolder([projPath, 'sdk_ext']); |
| 188 newFile([sdkExtPath, 'entry.dart']); |
| 189 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']); |
| 190 newFile([sdkExtSrcPath, 'part.dart']); |
| 191 // Pump event loop so new files are discovered and added to context. |
| 192 await pumpEventQueue(); |
| 193 // Verify that ignored files were ignored. |
| 194 Map<String, int> fileTimestamps = manager.currentContextFilePaths[projPath]; |
| 195 expect(fileTimestamps, isNotEmpty); |
| 196 List<String> files = fileTimestamps.keys.toList(); |
| 197 expect(files.length, equals(1)); |
| 198 expect(files[0], equals('/my/proj/lib/main.dart')); |
| 199 } |
| 200 |
| 173 test_refresh_oneContext() { | 201 test_refresh_oneContext() { |
| 174 // create two contexts with pubspec.yaml files | 202 // create two contexts with pubspec.yaml files |
| 175 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); | 203 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); |
| 176 resourceProvider.newFile(pubspecPath, 'pubspec1'); | 204 resourceProvider.newFile(pubspecPath, 'pubspec1'); |
| 177 | 205 |
| 178 String proj2Path = '/my/proj2'; | 206 String proj2Path = '/my/proj2'; |
| 179 resourceProvider.newFolder(proj2Path); | 207 resourceProvider.newFolder(proj2Path); |
| 180 String pubspec2Path = posix.join(proj2Path, 'pubspec.yaml'); | 208 String pubspec2Path = posix.join(proj2Path, 'pubspec.yaml'); |
| 181 resourceProvider.newFile(pubspec2Path, 'pubspec2'); | 209 resourceProvider.newFile(pubspec2Path, 'pubspec2'); |
| 182 | 210 |
| (...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 class TestUriResolver extends UriResolver { | 1142 class TestUriResolver extends UriResolver { |
| 1115 Map<Uri, Source> uriMap; | 1143 Map<Uri, Source> uriMap; |
| 1116 | 1144 |
| 1117 TestUriResolver(this.uriMap); | 1145 TestUriResolver(this.uriMap); |
| 1118 | 1146 |
| 1119 @override | 1147 @override |
| 1120 Source resolveAbsolute(Uri uri) { | 1148 Source resolveAbsolute(Uri uri) { |
| 1121 return uriMap[uri]; | 1149 return uriMap[uri]; |
| 1122 } | 1150 } |
| 1123 } | 1151 } |
| OLD | NEW |