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/error.dart'; |
14 import 'package:analyzer/src/generated/source.dart'; | 15 import 'package:analyzer/src/generated/source.dart'; |
15 import 'package:analyzer/src/generated/source_io.dart'; | 16 import 'package:analyzer/src/generated/source_io.dart'; |
16 import 'package:package_config/packages.dart'; | 17 import 'package:package_config/packages.dart'; |
17 import 'package:path/path.dart'; | 18 import 'package:path/path.dart'; |
18 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 19 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
19 import 'package:unittest/unittest.dart'; | 20 import 'package:unittest/unittest.dart'; |
20 | 21 |
21 import 'mocks.dart'; | 22 import 'mocks.dart'; |
22 import 'utils.dart'; | 23 import 'utils.dart'; |
23 | 24 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 expect(subProjContextInfo, isNotNull); | 130 expect(subProjContextInfo, isNotNull); |
130 expect(subProjContextInfo.folder, subProjFolder); | 131 expect(subProjContextInfo.folder, subProjFolder); |
131 expect(projContextInfo.context != subProjContextInfo.context, isTrue); | 132 expect(projContextInfo.context != subProjContextInfo.context, isTrue); |
132 // Check that contextsInAnalysisRoot() works. | 133 // Check that contextsInAnalysisRoot() works. |
133 List<AnalysisContext> contexts = manager.contextsInAnalysisRoot(projFolder); | 134 List<AnalysisContext> contexts = manager.contextsInAnalysisRoot(projFolder); |
134 expect(contexts, hasLength(2)); | 135 expect(contexts, hasLength(2)); |
135 expect(contexts, contains(projContextInfo.context)); | 136 expect(contexts, contains(projContextInfo.context)); |
136 expect(contexts, contains(subProjContextInfo.context)); | 137 expect(contexts, contains(subProjContextInfo.context)); |
137 } | 138 } |
138 | 139 |
| 140 test_error_filter_analysis_option() async { |
| 141 // Create files. |
| 142 newFile( |
| 143 [projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE], |
| 144 r''' |
| 145 analyzer: |
| 146 errors: |
| 147 unused_local_variable: ignore |
| 148 '''); |
| 149 // Setup context. |
| 150 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 151 |
| 152 // Verify filter setup. |
| 153 List<ErrorFilter> filters = |
| 154 callbacks.currentContext.getConfigurationData(CONFIGURED_ERROR_FILTERS); |
| 155 expect(filters, isNotNull); |
| 156 expect(filters, hasLength(1)); |
| 157 expect( |
| 158 filters.first(new AnalysisError( |
| 159 new TestSource(), 0, 1, HintCode.UNUSED_LOCAL_VARIABLE, [ |
| 160 ['x'] |
| 161 ])), |
| 162 isTrue); |
| 163 } |
| 164 |
| 165 test_error_filter_analysis_option_synonyms() async { |
| 166 // Create files. |
| 167 newFile( |
| 168 [projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE], |
| 169 r''' |
| 170 analyzer: |
| 171 errors: |
| 172 unused_local_variable: ignore |
| 173 ambiguous_import: false |
| 174 '''); |
| 175 // Setup context. |
| 176 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 177 |
| 178 // Verify filter setup. |
| 179 List<ErrorFilter> filters = |
| 180 callbacks.currentContext.getConfigurationData(CONFIGURED_ERROR_FILTERS); |
| 181 expect(filters, isNotNull); |
| 182 expect(filters, hasLength(2)); |
| 183 } |
| 184 |
| 185 test_error_filter_analysis_option_unpsecified() async { |
| 186 // Create files. |
| 187 newFile( |
| 188 [projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE], |
| 189 r''' |
| 190 analyzer: |
| 191 # errors: |
| 192 # unused_local_variable: ignore |
| 193 '''); |
| 194 // Setup context. |
| 195 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 196 |
| 197 // Verify filter setup. |
| 198 List<ErrorFilter> filters = |
| 199 callbacks.currentContext.getConfigurationData(CONFIGURED_ERROR_FILTERS); |
| 200 expect(filters, isEmpty); |
| 201 } |
| 202 |
139 test_ignoreFilesInPackagesFolder() { | 203 test_ignoreFilesInPackagesFolder() { |
140 // create a context with a pubspec.yaml file | 204 // create a context with a pubspec.yaml file |
141 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); | 205 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); |
142 resourceProvider.newFile(pubspecPath, 'pubspec'); | 206 resourceProvider.newFile(pubspecPath, 'pubspec'); |
143 // create a file in the "packages" folder | 207 // create a file in the "packages" folder |
144 String filePath1 = posix.join(projPath, 'packages', 'file1.dart'); | 208 String filePath1 = posix.join(projPath, 'packages', 'file1.dart'); |
145 resourceProvider.newFile(filePath1, 'contents'); | 209 resourceProvider.newFile(filePath1, 'contents'); |
146 // "packages" files are ignored initially | 210 // "packages" files are ignored initially |
147 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 211 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
148 expect(callbacks.currentContextFilePaths[projPath], isEmpty); | 212 expect(callbacks.currentContextFilePaths[projPath], isEmpty); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 // Create files. | 290 // Create files. |
227 String libPath = newFolder([projPath, LIB_NAME]); | 291 String libPath = newFolder([projPath, LIB_NAME]); |
228 newFile([libPath, 'main.dart']); | 292 newFile([libPath, 'main.dart']); |
229 newFile([libPath, 'nope.dart']); | 293 newFile([libPath, 'nope.dart']); |
230 String sdkExtPath = newFolder([projPath, 'sdk_ext']); | 294 String sdkExtPath = newFolder([projPath, 'sdk_ext']); |
231 newFile([sdkExtPath, 'entry.dart']); | 295 newFile([sdkExtPath, 'entry.dart']); |
232 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']); | 296 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']); |
233 newFile([sdkExtSrcPath, 'part.dart']); | 297 newFile([sdkExtSrcPath, 'part.dart']); |
234 // Setup analysis options file with ignore list. | 298 // Setup analysis options file with ignore list. |
235 newFile( | 299 newFile( |
236 [projPath, '.analysis_options'], | 300 [projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE], |
237 r''' | 301 r''' |
238 analyzer: | 302 analyzer: |
239 exclude: | 303 exclude: |
240 - lib/nope.dart | 304 - lib/nope.dart |
241 - 'sdk_ext/**' | 305 - 'sdk_ext/**' |
242 '''); | 306 '''); |
243 // Setup context. | 307 // Setup context. |
244 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 308 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
245 // Verify that analysis options was parsed and the ignore patterns applied. | 309 // Verify that analysis options was parsed and the ignore patterns applied. |
246 Map<String, int> fileTimestamps = | 310 Map<String, int> fileTimestamps = |
(...skipping 16 matching lines...) Expand all Loading... |
263 String otherLibPath = newFolder([projPath, 'other_lib']); | 327 String otherLibPath = newFolder([projPath, 'other_lib']); |
264 newFile([otherLibPath, 'entry.dart']); | 328 newFile([otherLibPath, 'entry.dart']); |
265 newFile( | 329 newFile( |
266 [otherLibPath, 'pubspec.yaml'], | 330 [otherLibPath, 'pubspec.yaml'], |
267 r''' | 331 r''' |
268 name: other_lib | 332 name: other_lib |
269 '''); | 333 '''); |
270 // Setup analysis options file with ignore list that ignores the 'other_lib' | 334 // Setup analysis options file with ignore list that ignores the 'other_lib' |
271 // directory by name. | 335 // directory by name. |
272 newFile( | 336 newFile( |
273 [projPath, '.analysis_options'], | 337 [projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE], |
274 r''' | 338 r''' |
275 analyzer: | 339 analyzer: |
276 exclude: | 340 exclude: |
277 - 'other_lib' | 341 - 'other_lib' |
278 '''); | 342 '''); |
279 // Setup context. | 343 // Setup context. |
280 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 344 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
281 // Verify that the context in other_lib wasn't created and that the | 345 // Verify that the context in other_lib wasn't created and that the |
282 // context in lib was created. | 346 // context in lib was created. |
283 var contexts = | 347 var contexts = |
(...skipping 15 matching lines...) Expand all Loading... |
299 String otherLibPath = newFolder([projPath, 'other_lib']); | 363 String otherLibPath = newFolder([projPath, 'other_lib']); |
300 newFile([otherLibPath, 'entry.dart']); | 364 newFile([otherLibPath, 'entry.dart']); |
301 newFile( | 365 newFile( |
302 [otherLibPath, 'pubspec.yaml'], | 366 [otherLibPath, 'pubspec.yaml'], |
303 r''' | 367 r''' |
304 name: other_lib | 368 name: other_lib |
305 '''); | 369 '''); |
306 // Setup analysis options file with ignore list that ignores 'other_lib' | 370 // Setup analysis options file with ignore list that ignores 'other_lib' |
307 // and all descendants. | 371 // and all descendants. |
308 newFile( | 372 newFile( |
309 [projPath, '.analysis_options'], | 373 [projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE], |
310 r''' | 374 r''' |
311 analyzer: | 375 analyzer: |
312 exclude: | 376 exclude: |
313 - 'other_lib/**' | 377 - 'other_lib/**' |
314 '''); | 378 '''); |
315 // Setup context. | 379 // Setup context. |
316 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 380 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
317 // Verify that the context in other_lib wasn't created and that the | 381 // Verify that the context in other_lib wasn't created and that the |
318 // context in lib was created. | 382 // context in lib was created. |
319 var contexts = | 383 var contexts = |
(...skipping 15 matching lines...) Expand all Loading... |
335 String otherLibPath = newFolder([projPath, 'other_lib']); | 399 String otherLibPath = newFolder([projPath, 'other_lib']); |
336 newFile([otherLibPath, 'entry.dart']); | 400 newFile([otherLibPath, 'entry.dart']); |
337 newFile( | 401 newFile( |
338 [otherLibPath, 'pubspec.yaml'], | 402 [otherLibPath, 'pubspec.yaml'], |
339 r''' | 403 r''' |
340 name: other_lib | 404 name: other_lib |
341 '''); | 405 '''); |
342 // Setup analysis options file with ignore list that ignores 'other_lib' | 406 // Setup analysis options file with ignore list that ignores 'other_lib' |
343 // and all immediate children. | 407 // and all immediate children. |
344 newFile( | 408 newFile( |
345 [projPath, '.analysis_options'], | 409 [projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE], |
346 r''' | 410 r''' |
347 analyzer: | 411 analyzer: |
348 exclude: | 412 exclude: |
349 - 'other_lib/*' | 413 - 'other_lib/*' |
350 '''); | 414 '''); |
351 // Setup context. | 415 // Setup context. |
352 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 416 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
353 // Verify that the context in other_lib wasn't created and that the | 417 // Verify that the context in other_lib wasn't created and that the |
354 // context in lib was created. | 418 // context in lib was created. |
355 var contexts = | 419 var contexts = |
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1126 String fileA = '$project/foo.dart'; | 1190 String fileA = '$project/foo.dart'; |
1127 resourceProvider.newFile(fileA, ''); | 1191 resourceProvider.newFile(fileA, ''); |
1128 manager.setRoots(<String>[project], <String>[], <String, String>{}); | 1192 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
1129 callbacks.assertContextPaths([project]); | 1193 callbacks.assertContextPaths([project]); |
1130 callbacks.assertContextFiles(project, [fileA]); | 1194 callbacks.assertContextFiles(project, [fileA]); |
1131 } | 1195 } |
1132 | 1196 |
1133 test_strong_mode_analysis_option() async { | 1197 test_strong_mode_analysis_option() async { |
1134 // Create files. | 1198 // Create files. |
1135 newFile( | 1199 newFile( |
1136 [projPath, '.analysis_options'], | 1200 [projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE], |
1137 r''' | 1201 r''' |
1138 analyzer: | 1202 analyzer: |
1139 strong-mode: true | 1203 strong-mode: true |
1140 '''); | 1204 '''); |
1141 String libPath = newFolder([projPath, LIB_NAME]); | 1205 String libPath = newFolder([projPath, LIB_NAME]); |
1142 newFile([libPath, 'main.dart']); | 1206 newFile([libPath, 'main.dart']); |
1143 // Setup context. | 1207 // Setup context. |
1144 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 1208 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
1145 // Verify that analysis options was parsed and strong-mode set. | 1209 // Verify that analysis options was parsed and strong-mode set. |
1146 Map<String, int> fileTimestamps = | 1210 Map<String, int> fileTimestamps = |
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1842 class TestUriResolver extends UriResolver { | 1906 class TestUriResolver extends UriResolver { |
1843 Map<Uri, Source> uriMap; | 1907 Map<Uri, Source> uriMap; |
1844 | 1908 |
1845 TestUriResolver(this.uriMap); | 1909 TestUriResolver(this.uriMap); |
1846 | 1910 |
1847 @override | 1911 @override |
1848 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 1912 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
1849 return uriMap[uri]; | 1913 return uriMap[uri]; |
1850 } | 1914 } |
1851 } | 1915 } |
OLD | NEW |