| 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/source/embedder.dart'; | 13 import 'package:analyzer/source/embedder.dart'; |
| 14 import 'package:analyzer/source/error_processor.dart'; |
| 14 import 'package:analyzer/src/generated/engine.dart'; | 15 import 'package:analyzer/src/generated/engine.dart'; |
| 15 import 'package:analyzer/src/generated/error.dart'; | 16 import 'package:analyzer/src/generated/error.dart'; |
| 16 import 'package:analyzer/src/generated/source.dart'; | 17 import 'package:analyzer/src/generated/source.dart'; |
| 17 import 'package:analyzer/src/generated/source_io.dart'; | 18 import 'package:analyzer/src/generated/source_io.dart'; |
| 18 import 'package:analyzer/src/services/lint.dart'; | 19 import 'package:analyzer/src/services/lint.dart'; |
| 19 import 'package:linter/src/plugin/linter_plugin.dart'; | 20 import 'package:linter/src/plugin/linter_plugin.dart'; |
| 20 import 'package:linter/src/rules/avoid_as.dart'; | 21 import 'package:linter/src/rules/avoid_as.dart'; |
| 21 import 'package:package_config/packages.dart'; | 22 import 'package:package_config/packages.dart'; |
| 22 import 'package:path/path.dart'; | 23 import 'package:path/path.dart'; |
| 23 import 'package:plugin/manager.dart'; | 24 import 'package:plugin/manager.dart'; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 new AnalysisError(new TestSource(), 0, 1, HintCode.INVALID_ASSIGNMENT, [ | 82 new AnalysisError(new TestSource(), 0, 1, HintCode.INVALID_ASSIGNMENT, [ |
| 82 ['x'], | 83 ['x'], |
| 83 ['y'] | 84 ['y'] |
| 84 ]); | 85 ]); |
| 85 | 86 |
| 86 AnalysisError unused_local_variable = new AnalysisError( | 87 AnalysisError unused_local_variable = new AnalysisError( |
| 87 new TestSource(), 0, 1, HintCode.UNUSED_LOCAL_VARIABLE, [ | 88 new TestSource(), 0, 1, HintCode.UNUSED_LOCAL_VARIABLE, [ |
| 88 ['x'] | 89 ['x'] |
| 89 ]); | 90 ]); |
| 90 | 91 |
| 91 List<ErrorFilter> get errorFilters => | 92 List<ErrorProcessor> get errorProcessors => callbacks.currentContext |
| 92 callbacks.currentContext.getConfigurationData(CONFIGURED_ERROR_FILTERS); | 93 .getConfigurationData(CONFIGURED_ERROR_PROCESSORS); |
| 93 | 94 |
| 94 List<Linter> get lints => getLints(callbacks.currentContext); | 95 List<Linter> get lints => getLints(callbacks.currentContext); |
| 95 | 96 |
| 96 AnalysisOptions get options => callbacks.currentContext.analysisOptions; | 97 AnalysisOptions get options => callbacks.currentContext.analysisOptions; |
| 97 | 98 |
| 98 void deleteFile(List<String> pathComponents) { | 99 void deleteFile(List<String> pathComponents) { |
| 99 String filePath = posix.joinAll(pathComponents); | 100 String filePath = posix.joinAll(pathComponents); |
| 100 resourceProvider.deleteFile(filePath); | 101 resourceProvider.deleteFile(filePath); |
| 101 } | 102 } |
| 102 | 103 |
| 104 ErrorProcessor getProcessor(AnalysisError error) => |
| 105 ErrorProcessor.getProcessor(callbacks.currentContext, error); |
| 106 |
| 103 String newFile(List<String> pathComponents, [String content = '']) { | 107 String newFile(List<String> pathComponents, [String content = '']) { |
| 104 String filePath = posix.joinAll(pathComponents); | 108 String filePath = posix.joinAll(pathComponents); |
| 105 resourceProvider.newFile(filePath, content); | 109 resourceProvider.newFile(filePath, content); |
| 106 return filePath; | 110 return filePath; |
| 107 } | 111 } |
| 108 | 112 |
| 109 String newFolder(List<String> pathComponents) { | 113 String newFolder(List<String> pathComponents) { |
| 110 String folderPath = posix.joinAll(pathComponents); | 114 String folderPath = posix.joinAll(pathComponents); |
| 111 resourceProvider.newFolder(folderPath); | 115 resourceProvider.newFolder(folderPath); |
| 112 return folderPath; | 116 return folderPath; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 linter: | 156 linter: |
| 153 rules: | 157 rules: |
| 154 - camel_case_types | 158 - camel_case_types |
| 155 '''); | 159 '''); |
| 156 | 160 |
| 157 // Setup context. | 161 // Setup context. |
| 158 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 162 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 159 await pumpEventQueue(); | 163 await pumpEventQueue(); |
| 160 | 164 |
| 161 // Verify options were set. | 165 // Verify options were set. |
| 162 expect(errorFilters, hasLength(1)); | 166 expect(errorProcessors, hasLength(1)); |
| 163 expect(lints, hasLength(1)); | 167 expect(lints, hasLength(1)); |
| 164 expect(options.enableGenericMethods, isTrue); | 168 expect(options.enableGenericMethods, isTrue); |
| 165 | 169 |
| 166 // Remove options. | 170 // Remove options. |
| 167 deleteFile([projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE]); | 171 deleteFile([projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE]); |
| 168 await pumpEventQueue(); | 172 await pumpEventQueue(); |
| 169 | 173 |
| 170 // Verify defaults restored. | 174 // Verify defaults restored. |
| 171 expect(errorFilters, isEmpty); | 175 expect(errorProcessors, isEmpty); |
| 172 expect(lints, isEmpty); | 176 expect(lints, isEmpty); |
| 173 expect(options.enableGenericMethods, isFalse); | 177 expect(options.enableGenericMethods, isFalse); |
| 174 } | 178 } |
| 175 | 179 |
| 176 test_analysis_options_file_delete_with_embedder() async { | 180 test_analysis_options_file_delete_with_embedder() async { |
| 177 // Setup _embedder.yaml. | 181 // Setup _embedder.yaml. |
| 178 String libPath = newFolder([projPath, LIB_NAME]); | 182 String libPath = newFolder([projPath, LIB_NAME]); |
| 179 newFile( | 183 newFile( |
| 180 [libPath, '_embedder.yaml'], | 184 [libPath, '_embedder.yaml'], |
| 181 r''' | 185 r''' |
| (...skipping 26 matching lines...) Expand all Loading... |
| 208 - camel_case_types | 212 - camel_case_types |
| 209 '''); | 213 '''); |
| 210 | 214 |
| 211 // Setup context. | 215 // Setup context. |
| 212 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 216 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 213 await pumpEventQueue(); | 217 await pumpEventQueue(); |
| 214 | 218 |
| 215 // Verify options were set. | 219 // Verify options were set. |
| 216 expect(options.enableGenericMethods, isTrue); | 220 expect(options.enableGenericMethods, isTrue); |
| 217 expect(options.strongMode, isTrue); | 221 expect(options.strongMode, isTrue); |
| 218 expect(errorFilters, hasLength(2)); | 222 expect(errorProcessors, hasLength(2)); |
| 219 expect(lints, hasLength(2)); | 223 expect(lints, hasLength(2)); |
| 220 | 224 |
| 221 // Remove options. | 225 // Remove options. |
| 222 deleteFile([projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE]); | 226 deleteFile([projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE]); |
| 223 await pumpEventQueue(); | 227 await pumpEventQueue(); |
| 224 | 228 |
| 225 // Verify defaults restored. | 229 // Verify defaults restored. |
| 226 expect(options.enableGenericMethods, isFalse); | 230 expect(options.enableGenericMethods, isFalse); |
| 227 expect(lints, hasLength(1)); | 231 expect(lints, hasLength(1)); |
| 228 expect(lints.first, new isInstanceOf<AvoidAs>()); | 232 expect(lints.first, new isInstanceOf<AvoidAs>()); |
| 229 expect(errorFilters, hasLength(1)); | 233 expect(errorProcessors, hasLength(1)); |
| 230 expect(errorFilters.first(missing_return), isTrue); | 234 expect(getProcessor(missing_return).severity, isNull); |
| 231 } | 235 } |
| 232 | 236 |
| 233 test_analysis_options_parse_failure() async { | 237 test_analysis_options_parse_failure() async { |
| 234 // Create files. | 238 // Create files. |
| 235 String libPath = newFolder([projPath, LIB_NAME]); | 239 String libPath = newFolder([projPath, LIB_NAME]); |
| 236 newFile([libPath, 'main.dart']); | 240 newFile([libPath, 'main.dart']); |
| 237 String sdkExtPath = newFolder([projPath, 'sdk_ext']); | 241 String sdkExtPath = newFolder([projPath, 'sdk_ext']); |
| 238 newFile([sdkExtPath, 'entry.dart']); | 242 newFile([sdkExtPath, 'entry.dart']); |
| 239 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']); | 243 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']); |
| 240 newFile([sdkExtSrcPath, 'part.dart']); | 244 newFile([sdkExtSrcPath, 'part.dart']); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 // * from `_embedder.yaml`: | 338 // * from `_embedder.yaml`: |
| 335 expect(context.analysisOptions.strongMode, isTrue); | 339 expect(context.analysisOptions.strongMode, isTrue); |
| 336 expect(context.analysisOptions.enableSuperMixins, isTrue); | 340 expect(context.analysisOptions.enableSuperMixins, isTrue); |
| 337 // * from `.analysis_options`: | 341 // * from `.analysis_options`: |
| 338 expect(context.analysisOptions.enableGenericMethods, isTrue); | 342 expect(context.analysisOptions.enableGenericMethods, isTrue); |
| 339 // * verify tests are excluded | 343 // * verify tests are excluded |
| 340 expect(callbacks.currentContextFilePaths[projPath].keys, | 344 expect(callbacks.currentContextFilePaths[projPath].keys, |
| 341 ['/my/proj/sdk_ext/entry.dart']); | 345 ['/my/proj/sdk_ext/entry.dart']); |
| 342 | 346 |
| 343 // Verify filter setup. | 347 // Verify filter setup. |
| 344 expect(errorFilters, hasLength(2)); | 348 expect(errorProcessors, hasLength(2)); |
| 345 | 349 |
| 346 // * (embedder.) | 350 // * (embedder.) |
| 347 expect(errorFilters.any((f) => f(missing_return)), isTrue); | 351 expect(getProcessor(missing_return).severity, isNull); |
| 348 | 352 |
| 349 // * (options.) | 353 // * (options.) |
| 350 expect(errorFilters.any((f) => f(unused_local_variable)), isTrue); | 354 expect(getProcessor(unused_local_variable).severity, isNull); |
| 351 | 355 |
| 352 // Verify lints. | 356 // Verify lints. |
| 353 var lintNames = lints.map((lint) => lint.name); | 357 var lintNames = lints.map((lint) => lint.name); |
| 354 | 358 |
| 355 expect( | 359 expect( |
| 356 lintNames, | 360 lintNames, |
| 357 unorderedEquals( | 361 unorderedEquals( |
| 358 ['avoid_as' /* embedder */, 'camel_case_types' /* options */])); | 362 ['avoid_as' /* embedder */, 'camel_case_types' /* options */])); |
| 359 | 363 |
| 360 // Sanity check embedder libs. | 364 // Sanity check embedder libs. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 [projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE], | 416 [projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE], |
| 413 r''' | 417 r''' |
| 414 analyzer: | 418 analyzer: |
| 415 errors: | 419 errors: |
| 416 unused_local_variable: ignore | 420 unused_local_variable: ignore |
| 417 '''); | 421 '''); |
| 418 // Setup context. | 422 // Setup context. |
| 419 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 423 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 420 | 424 |
| 421 // Verify filter setup. | 425 // Verify filter setup. |
| 422 expect(errorFilters, isNotNull); | 426 expect(errorProcessors, hasLength(1)); |
| 423 expect(errorFilters, hasLength(1)); | 427 expect(getProcessor(unused_local_variable).severity, isNull); |
| 424 expect(errorFilters.first(unused_local_variable), isTrue); | |
| 425 } | 428 } |
| 426 | 429 |
| 427 test_error_filter_analysis_option_multiple_filters() async { | 430 test_error_filter_analysis_option_multiple_filters() async { |
| 428 // Create files. | 431 // Create files. |
| 429 newFile( | 432 newFile( |
| 430 [projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE], | 433 [projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE], |
| 431 r''' | 434 r''' |
| 432 analyzer: | 435 analyzer: |
| 433 errors: | 436 errors: |
| 434 invalid_assignment: ignore | 437 invalid_assignment: ignore |
| 435 unused_local_variable: ignore | 438 unused_local_variable: error |
| 436 '''); | 439 '''); |
| 437 // Setup context. | 440 // Setup context. |
| 438 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 441 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 439 | 442 |
| 440 // Verify filter setup. | 443 // Verify filter setup. |
| 441 expect(errorFilters, isNotNull); | 444 expect(errorProcessors, hasLength(2)); |
| 442 expect(errorFilters, hasLength(2)); | |
| 443 | 445 |
| 444 expect(errorFilters.any((filter) => filter(unused_local_variable)), isTrue); | 446 expect(getProcessor(invalid_assignment_error).severity, isNull); |
| 445 expect( | 447 expect(getProcessor(unused_local_variable).severity, ErrorSeverity.ERROR); |
| 446 errorFilters.any((filter) => filter(invalid_assignment_error)), isTrue); | |
| 447 } | 448 } |
| 448 | 449 |
| 449 test_error_filter_analysis_option_synonyms() async { | 450 test_error_filter_analysis_option_synonyms() async { |
| 450 // Create files. | 451 // Create files. |
| 451 newFile( | 452 newFile( |
| 452 [projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE], | 453 [projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE], |
| 453 r''' | 454 r''' |
| 454 analyzer: | 455 analyzer: |
| 455 errors: | 456 errors: |
| 456 unused_local_variable: ignore | 457 unused_local_variable: ignore |
| 457 ambiguous_import: false | 458 ambiguous_import: false |
| 458 '''); | 459 '''); |
| 459 // Setup context. | 460 // Setup context. |
| 460 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 461 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 461 | 462 |
| 462 // Verify filter setup. | 463 // Verify filter setup. |
| 463 expect(errorFilters, isNotNull); | 464 expect(errorProcessors, isNotNull); |
| 464 expect(errorFilters, hasLength(2)); | 465 expect(errorProcessors, hasLength(2)); |
| 465 } | 466 } |
| 466 | 467 |
| 467 test_error_filter_analysis_option_unpsecified() async { | 468 test_error_filter_analysis_option_unpsecified() async { |
| 468 // Create files. | 469 // Create files. |
| 469 newFile( | 470 newFile( |
| 470 [projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE], | 471 [projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE], |
| 471 r''' | 472 r''' |
| 472 analyzer: | 473 analyzer: |
| 473 # errors: | 474 # errors: |
| 474 # unused_local_variable: ignore | 475 # unused_local_variable: ignore |
| 475 '''); | 476 '''); |
| 476 // Setup context. | 477 // Setup context. |
| 477 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 478 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 478 | 479 |
| 479 // Verify filter setup. | 480 // Verify filter setup. |
| 480 expect(errorFilters, isEmpty); | 481 expect(errorProcessors, isEmpty); |
| 481 } | 482 } |
| 482 | 483 |
| 483 test_ignoreFilesInPackagesFolder() { | 484 test_ignoreFilesInPackagesFolder() { |
| 484 // create a context with a pubspec.yaml file | 485 // create a context with a pubspec.yaml file |
| 485 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); | 486 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); |
| 486 resourceProvider.newFile(pubspecPath, 'pubspec'); | 487 resourceProvider.newFile(pubspecPath, 'pubspec'); |
| 487 // create a file in the "packages" folder | 488 // create a file in the "packages" folder |
| 488 String filePath1 = posix.join(projPath, 'packages', 'file1.dart'); | 489 String filePath1 = posix.join(projPath, 'packages', 'file1.dart'); |
| 489 resourceProvider.newFile(filePath1, 'contents'); | 490 resourceProvider.newFile(filePath1, 'contents'); |
| 490 // "packages" files are ignored initially | 491 // "packages" files are ignored initially |
| (...skipping 1924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2415 class TestUriResolver extends UriResolver { | 2416 class TestUriResolver extends UriResolver { |
| 2416 Map<Uri, Source> uriMap; | 2417 Map<Uri, Source> uriMap; |
| 2417 | 2418 |
| 2418 TestUriResolver(this.uriMap); | 2419 TestUriResolver(this.uriMap); |
| 2419 | 2420 |
| 2420 @override | 2421 @override |
| 2421 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 2422 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
| 2422 return uriMap[uri]; | 2423 return uriMap[uri]; |
| 2423 } | 2424 } |
| 2424 } | 2425 } |
| OLD | NEW |