| 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; | 5 library test.analysis.notification.analysis_options; |
| 6 | 6 |
| 7 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 7 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 8 import 'package:analysis_server/src/constants.dart'; | 8 import 'package:analysis_server/src/constants.dart'; |
| 9 import 'package:analysis_server/src/domain_analysis.dart'; | 9 import 'package:analysis_server/src/domain_analysis.dart'; |
| 10 import 'package:analyzer/src/generated/engine.dart'; | 10 import 'package:analyzer/src/generated/engine.dart'; |
| 11 import 'package:analyzer/src/services/lint.dart'; |
| 11 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 12 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 12 import 'package:unittest/unittest.dart'; | 13 import 'package:unittest/unittest.dart'; |
| 13 | 14 |
| 14 import '../analysis_abstract.dart'; | 15 import '../analysis_abstract.dart'; |
| 15 import '../mocks.dart'; | 16 import '../mocks.dart'; |
| 16 import '../utils.dart'; | 17 import '../utils.dart'; |
| 17 | 18 |
| 18 main() { | 19 main() { |
| 19 initializeTestEnvironment(); | 20 initializeTestEnvironment(); |
| 20 defineReflectiveTests(AnalysisOptionsFileNotificationTest); | 21 defineReflectiveTests(AnalysisOptionsFileNotificationTest); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 wasTaskModelEnabled = AnalysisEngine.instance.useTaskModel; | 79 wasTaskModelEnabled = AnalysisEngine.instance.useTaskModel; |
| 79 AnalysisEngine.instance.useTaskModel = true; | 80 AnalysisEngine.instance.useTaskModel = true; |
| 80 } | 81 } |
| 81 | 82 |
| 82 @override | 83 @override |
| 83 void tearDown() { | 84 void tearDown() { |
| 84 AnalysisEngine.instance.useTaskModel = wasTaskModelEnabled; | 85 AnalysisEngine.instance.useTaskModel = wasTaskModelEnabled; |
| 85 super.tearDown(); | 86 super.tearDown(); |
| 86 } | 87 } |
| 87 | 88 |
| 89 test_lint_options_changes() async { |
| 90 addOptionsFile(''' |
| 91 linter: |
| 92 rules: |
| 93 - camel_case_types |
| 94 - constant_identifier_names |
| 95 '''); |
| 96 |
| 97 addTestFile(testSource); |
| 98 setAnalysisRoot(); |
| 99 |
| 100 await waitForTasksFinished(); |
| 101 |
| 102 verifyLintsEnabled(['camel_case_types', 'constant_identifier_names']); |
| 103 |
| 104 addOptionsFile(''' |
| 105 linter: |
| 106 rules: |
| 107 - camel_case_types |
| 108 '''); |
| 109 |
| 110 await pumpEventQueue(); |
| 111 await waitForTasksFinished(); |
| 112 |
| 113 verifyLintsEnabled(['camel_case_types']); |
| 114 } |
| 115 |
| 88 test_options_file_added() async { | 116 test_options_file_added() async { |
| 89 addTestFile(testSource); | 117 addTestFile(testSource); |
| 90 setAnalysisRoot(); | 118 setAnalysisRoot(); |
| 91 | 119 |
| 92 await waitForTasksFinished(); | 120 await waitForTasksFinished(); |
| 93 | 121 |
| 94 // Verify strong-mode disabled. | 122 // Verify strong-mode disabled. |
| 95 verifyStrongMode(enabled: false); | 123 verifyStrongMode(enabled: false); |
| 96 | 124 |
| 97 // Clear errors. | 125 // Clear errors. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 filesErrors[testFile] = []; | 182 filesErrors[testFile] = []; |
| 155 | 183 |
| 156 setStrongMode(false); | 184 setStrongMode(false); |
| 157 | 185 |
| 158 await pumpEventQueue(); | 186 await pumpEventQueue(); |
| 159 await waitForTasksFinished(); | 187 await waitForTasksFinished(); |
| 160 | 188 |
| 161 verifyStrongMode(enabled: false); | 189 verifyStrongMode(enabled: false); |
| 162 } | 190 } |
| 163 | 191 |
| 192 void verifyLintsEnabled(List<String> lints) { |
| 193 expect(testContext.analysisOptions.lint, true); |
| 194 var rules = getLints(testContext).map((rule) => rule.name); |
| 195 expect(rules, unorderedEquals(lints)); |
| 196 } |
| 197 |
| 164 verifyStrongMode({bool enabled}) { | 198 verifyStrongMode({bool enabled}) { |
| 165 // Verify strong-mode enabled. | 199 // Verify strong-mode enabled. |
| 166 expect(testContext.analysisOptions.strongMode, enabled); | 200 expect(testContext.analysisOptions.strongMode, enabled); |
| 167 | 201 |
| 168 if (enabled) { | 202 if (enabled) { |
| 169 // Should produce a warning and an error. | 203 // Should produce a warning and an error. |
| 170 expect( | 204 expect( |
| 171 errors.map((error) => error.type), | 205 errors.map((error) => error.type), |
| 172 unorderedEquals([ | 206 unorderedEquals([ |
| 173 AnalysisErrorType.STATIC_TYPE_WARNING, | 207 AnalysisErrorType.STATIC_TYPE_WARNING, |
| 174 AnalysisErrorType.COMPILE_TIME_ERROR | 208 AnalysisErrorType.COMPILE_TIME_ERROR |
| 175 ])); | 209 ])); |
| 176 } else { | 210 } else { |
| 177 // Should only produce a hint. | 211 // Should only produce a hint. |
| 178 expect(errors.map((error) => error.type), | 212 expect(errors.map((error) => error.type), |
| 179 unorderedEquals([AnalysisErrorType.HINT])); | 213 unorderedEquals([AnalysisErrorType.HINT])); |
| 180 } | 214 } |
| 181 } | 215 } |
| 182 } | 216 } |
| OLD | NEW |