| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.analysis.notification_analysis_options_test; | 5 library test.analysis.notification_analysis_options_test; |
| 6 | 6 |
| 7 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 7 import 'package:analysis_server/plugin/protocol/protocol.dart' |
| 8 hide AnalysisOptions; |
| 8 import 'package:analysis_server/src/constants.dart'; | 9 import 'package:analysis_server/src/constants.dart'; |
| 9 import 'package:analysis_server/src/domain_analysis.dart'; | 10 import 'package:analysis_server/src/domain_analysis.dart'; |
| 10 import 'package:analyzer/src/generated/engine.dart'; | 11 import 'package:analyzer/src/generated/engine.dart'; |
| 11 import 'package:analyzer/src/services/lint.dart'; | |
| 12 import 'package:linter/src/rules.dart'; | 12 import 'package:linter/src/rules.dart'; |
| 13 import 'package:test/test.dart'; | 13 import 'package:test/test.dart'; |
| 14 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 14 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 15 | 15 |
| 16 import '../analysis_abstract.dart'; | 16 import '../analysis_abstract.dart'; |
| 17 import '../mocks.dart'; | 17 import '../mocks.dart'; |
| 18 | 18 |
| 19 main() { | 19 main() { |
| 20 defineReflectiveSuite(() { | 20 defineReflectiveSuite(() { |
| 21 defineReflectiveTests(NewAnalysisOptionsFileNotificationTest); | 21 defineReflectiveTests(NewAnalysisOptionsFileNotificationTest); |
| 22 defineReflectiveTests(OldAnalysisOptionsFileNotificationTest); | 22 defineReflectiveTests(OldAnalysisOptionsFileNotificationTest); |
| 23 // These tests all fail, presumably because we are not updating the analysis |
| 24 // options when the file changes and because we are not analyzing the |
| 25 // analysis options file. |
| 26 // defineReflectiveTests(NewAnalysisOptionsFileNotificationTest_Driver); |
| 27 // defineReflectiveTests(OldAnalysisOptionsFileNotificationTest_Driver); |
| 23 }); | 28 }); |
| 24 } | 29 } |
| 25 | 30 |
| 26 abstract class AnalysisOptionsFileNotificationTest | 31 abstract class AnalysisOptionsFileNotificationTest |
| 27 extends AbstractAnalysisTest { | 32 extends AbstractAnalysisTest { |
| 28 Map<String, List<AnalysisError>> filesErrors = {}; | 33 Map<String, List<AnalysisError>> filesErrors = {}; |
| 29 | 34 |
| 30 final testSource = ''' | 35 final testSource = ''' |
| 31 main() { | 36 main() { |
| 32 var x = ''; | 37 var x = ''; |
| 33 int y = x; // Not assignable in strong-mode | 38 int y = x; // Not assignable in strong-mode |
| 34 print(y); | 39 print(y); |
| 35 }'''; | 40 }'''; |
| 36 | 41 |
| 37 List<AnalysisError> get errors => filesErrors[testFile]; | 42 List<AnalysisError> get errors => filesErrors[testFile]; |
| 38 | 43 |
| 39 List<AnalysisError> get optionsFileErrors => filesErrors[optionsFilePath]; | 44 List<AnalysisError> get optionsFileErrors => filesErrors[optionsFilePath]; |
| 40 | 45 |
| 41 String get optionsFilePath; | 46 String get optionsFilePath; |
| 42 | 47 |
| 43 AnalysisContext get testContext => server.getContainingContext(testFile); | |
| 44 | |
| 45 List<AnalysisError> get testFileErrors => filesErrors[testFile]; | 48 List<AnalysisError> get testFileErrors => filesErrors[testFile]; |
| 46 | 49 |
| 47 void addOptionsFile(String contents) { | 50 void addOptionsFile(String contents) { |
| 48 addFile(optionsFilePath, contents); | 51 addFile(optionsFilePath, contents); |
| 49 } | 52 } |
| 50 | 53 |
| 51 void deleteFile(String filePath) { | 54 void deleteFile(String filePath) { |
| 52 resourceProvider.deleteFile(filePath); | 55 resourceProvider.deleteFile(filePath); |
| 53 } | 56 } |
| 54 | 57 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 main() { | 101 main() { |
| 99 String unused = ""; | 102 String unused = ""; |
| 100 } | 103 } |
| 101 '''); | 104 '''); |
| 102 | 105 |
| 103 setAnalysisRoot(); | 106 setAnalysisRoot(); |
| 104 | 107 |
| 105 await waitForTasksFinished(); | 108 await waitForTasksFinished(); |
| 106 | 109 |
| 107 // Verify options file. | 110 // Verify options file. |
| 111 expect(optionsFileErrors, isNotNull); |
| 108 expect(optionsFileErrors, isEmpty); | 112 expect(optionsFileErrors, isEmpty); |
| 109 | 113 |
| 110 // Verify test file. | 114 // Verify test file. |
| 115 expect(testFileErrors, isNotNull); |
| 111 expect(testFileErrors, isEmpty); | 116 expect(testFileErrors, isEmpty); |
| 112 } | 117 } |
| 113 | 118 |
| 114 test_error_filter_removed() async { | 119 test_error_filter_removed() async { |
| 115 addOptionsFile(''' | 120 addOptionsFile(''' |
| 116 analyzer: | 121 analyzer: |
| 117 errors: | 122 errors: |
| 118 unused_local_variable: ignore | 123 unused_local_variable: ignore |
| 119 '''); | 124 '''); |
| 120 | 125 |
| 121 addTestFile(''' | 126 addTestFile(''' |
| 122 main() { | 127 main() { |
| 123 String unused = ""; | 128 String unused = ""; |
| 124 } | 129 } |
| 125 '''); | 130 '''); |
| 126 | 131 |
| 127 setAnalysisRoot(); | 132 setAnalysisRoot(); |
| 128 | 133 |
| 129 await waitForTasksFinished(); | 134 await waitForTasksFinished(); |
| 130 | 135 |
| 131 // Verify options file. | 136 // Verify options file. |
| 137 expect(optionsFileErrors, isNotNull); |
| 132 expect(optionsFileErrors, isEmpty); | 138 expect(optionsFileErrors, isEmpty); |
| 133 | 139 |
| 134 // Verify test file. | 140 // Verify test file. |
| 141 expect(testFileErrors, isNotNull); |
| 135 expect(testFileErrors, isEmpty); | 142 expect(testFileErrors, isEmpty); |
| 136 | 143 |
| 137 addOptionsFile(''' | 144 addOptionsFile(''' |
| 138 analyzer: | 145 analyzer: |
| 139 errors: | 146 errors: |
| 140 # unused_local_variable: ignore | 147 # unused_local_variable: ignore |
| 141 '''); | 148 '''); |
| 142 | 149 |
| 143 await pumpEventQueue(); | 150 await pumpEventQueue(); |
| 144 await waitForTasksFinished(); | 151 await waitForTasksFinished(); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 | 289 |
| 283 setStrongMode(true); | 290 setStrongMode(true); |
| 284 | 291 |
| 285 await pumpEventQueue(); | 292 await pumpEventQueue(); |
| 286 await waitForTasksFinished(); | 293 await waitForTasksFinished(); |
| 287 | 294 |
| 288 verifyStrongMode(enabled: true); | 295 verifyStrongMode(enabled: true); |
| 289 } | 296 } |
| 290 | 297 |
| 291 void verifyLintsEnabled(List<String> lints) { | 298 void verifyLintsEnabled(List<String> lints) { |
| 292 expect(testContext.analysisOptions.lint, true); | 299 AnalysisOptions options = analysisOptions; |
| 293 var rules = getLints(testContext).map((rule) => rule.name); | 300 expect(options.lint, true); |
| 301 var rules = options.lintRules.map((rule) => rule.name); |
| 294 expect(rules, unorderedEquals(lints)); | 302 expect(rules, unorderedEquals(lints)); |
| 295 } | 303 } |
| 296 | 304 |
| 297 verifyStrongMode({bool enabled}) { | 305 verifyStrongMode({bool enabled}) { |
| 298 // Verify strong-mode enabled. | 306 // Verify strong-mode enabled. |
| 299 expect(testContext.analysisOptions.strongMode, enabled); | 307 expect(analysisOptions.strongMode, enabled); |
| 300 | 308 |
| 301 if (enabled) { | 309 if (enabled) { |
| 302 // Should produce a type warning. | 310 // Should produce a type warning. |
| 303 expect(errors.map((error) => error.type), | 311 expect(errors.map((error) => error.type), |
| 304 unorderedEquals([AnalysisErrorType.STATIC_TYPE_WARNING])); | 312 unorderedEquals([AnalysisErrorType.STATIC_TYPE_WARNING])); |
| 305 } else { | 313 } else { |
| 306 // Should only produce a hint. | 314 // Should only produce a hint. |
| 307 expect(errors.map((error) => error.type), | 315 expect(errors.map((error) => error.type), |
| 308 unorderedEquals([AnalysisErrorType.HINT])); | 316 unorderedEquals([AnalysisErrorType.HINT])); |
| 309 } | 317 } |
| 310 } | 318 } |
| 311 } | 319 } |
| 312 | 320 |
| 313 @reflectiveTest | 321 @reflectiveTest |
| 314 class NewAnalysisOptionsFileNotificationTest | 322 class NewAnalysisOptionsFileNotificationTest |
| 315 extends AnalysisOptionsFileNotificationTest { | 323 extends AnalysisOptionsFileNotificationTest { |
| 324 @override |
| 316 String get optionsFilePath => '$projectPath/analysis_options.yaml'; | 325 String get optionsFilePath => '$projectPath/analysis_options.yaml'; |
| 317 } | 326 } |
| 318 | 327 |
| 319 @reflectiveTest | 328 @reflectiveTest |
| 329 class NewAnalysisOptionsFileNotificationTest_Driver |
| 330 extends NewAnalysisOptionsFileNotificationTest { |
| 331 @override |
| 332 void setUp() { |
| 333 enableNewAnalysisDriver = true; |
| 334 generateSummaryFiles = true; |
| 335 super.setUp(); |
| 336 } |
| 337 } |
| 338 |
| 339 @reflectiveTest |
| 320 class OldAnalysisOptionsFileNotificationTest | 340 class OldAnalysisOptionsFileNotificationTest |
| 321 extends AnalysisOptionsFileNotificationTest { | 341 extends AnalysisOptionsFileNotificationTest { |
| 342 @override |
| 322 String get optionsFilePath => '$projectPath/.analysis_options'; | 343 String get optionsFilePath => '$projectPath/.analysis_options'; |
| 323 } | 344 } |
| 345 |
| 346 @reflectiveTest |
| 347 class OldAnalysisOptionsFileNotificationTest_Driver |
| 348 extends OldAnalysisOptionsFileNotificationTest { |
| 349 @override |
| 350 void setUp() { |
| 351 enableNewAnalysisDriver = true; |
| 352 generateSummaryFiles = true; |
| 353 super.setUp(); |
| 354 } |
| 355 } |
| OLD | NEW |