| 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 analyzer.test.source.analysis_options_provider_test; | 5 library analyzer.test.source.analysis_options_provider_test; |
| 6 | 6 |
| 7 import 'dart:core'; | 7 import 'dart:core'; |
| 8 | 8 |
| 9 import 'package:analyzer/file_system/file_system.dart'; | 9 import 'package:analyzer/file_system/file_system.dart'; |
| 10 import 'package:analyzer/file_system/memory_file_system.dart'; | 10 import 'package:analyzer/file_system/memory_file_system.dart'; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 void expectMergesTo(String defaults, String overrides, String expected) { | 26 void expectMergesTo(String defaults, String overrides, String expected) { |
| 27 var optionsProvider = new AnalysisOptionsProvider(); | 27 var optionsProvider = new AnalysisOptionsProvider(); |
| 28 var defaultOptions = optionsProvider.getOptionsFromString(defaults); | 28 var defaultOptions = optionsProvider.getOptionsFromString(defaults); |
| 29 var overrideOptions = optionsProvider.getOptionsFromString(overrides); | 29 var overrideOptions = optionsProvider.getOptionsFromString(overrides); |
| 30 var merged = optionsProvider.merge(defaultOptions, overrideOptions); | 30 var merged = optionsProvider.merge(defaultOptions, overrideOptions); |
| 31 expect(merged, optionsProvider.getOptionsFromString(expected)); | 31 expect(merged, optionsProvider.getOptionsFromString(expected)); |
| 32 } | 32 } |
| 33 | 33 |
| 34 group('merging', () { | 34 group('merging', () { |
| 35 test('integration', () { | 35 test('integration', () { |
| 36 expectMergesTo( | 36 expectMergesTo(''' |
| 37 ''' | |
| 38 analyzer: | 37 analyzer: |
| 39 plugins: | 38 plugins: |
| 40 - p1 | 39 - p1 |
| 41 - p2 | 40 - p2 |
| 42 errors: | 41 errors: |
| 43 unused_local_variable : error | 42 unused_local_variable : error |
| 44 linter: | 43 linter: |
| 45 rules: | 44 rules: |
| 46 - camel_case_types | 45 - camel_case_types |
| 47 - one_member_abstracts | 46 - one_member_abstracts |
| 48 ''', | 47 ''', ''' |
| 49 ''' | |
| 50 analyzer: | 48 analyzer: |
| 51 plugins: | 49 plugins: |
| 52 - p3 | 50 - p3 |
| 53 errors: | 51 errors: |
| 54 unused_local_variable : ignore # overrides error | 52 unused_local_variable : ignore # overrides error |
| 55 linter: | 53 linter: |
| 56 rules: | 54 rules: |
| 57 one_member_abstracts: false # promotes and disables | 55 one_member_abstracts: false # promotes and disables |
| 58 always_specify_return_types: true | 56 always_specify_return_types: true |
| 59 ''', | 57 ''', ''' |
| 60 ''' | |
| 61 analyzer: | 58 analyzer: |
| 62 plugins: | 59 plugins: |
| 63 - p1 | 60 - p1 |
| 64 - p2 | 61 - p2 |
| 65 - p3 | 62 - p3 |
| 66 errors: | 63 errors: |
| 67 unused_local_variable : ignore | 64 unused_local_variable : ignore |
| 68 linter: | 65 linter: |
| 69 rules: | 66 rules: |
| 70 camel_case_types: true | 67 camel_case_types: true |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 var rawProvider = new MemoryResourceProvider(); | 121 var rawProvider = new MemoryResourceProvider(); |
| 125 resourceProvider = new TestResourceProvider(rawProvider); | 122 resourceProvider = new TestResourceProvider(rawProvider); |
| 126 pathTranslator = new TestPathTranslator(rawProvider); | 123 pathTranslator = new TestPathTranslator(rawProvider); |
| 127 provider = new AnalysisOptionsProvider(new SourceFactory([ | 124 provider = new AnalysisOptionsProvider(new SourceFactory([ |
| 128 new ResourceUriResolver(rawProvider), | 125 new ResourceUriResolver(rawProvider), |
| 129 ])); | 126 ])); |
| 130 } | 127 } |
| 131 | 128 |
| 132 void test_getOptions_crawlUp_hasInFolder() { | 129 void test_getOptions_crawlUp_hasInFolder() { |
| 133 pathTranslator.newFolder('/foo/bar'); | 130 pathTranslator.newFolder('/foo/bar'); |
| 134 pathTranslator.newFile( | 131 pathTranslator.newFile('/foo/$optionsFileName', r''' |
| 135 '/foo/$optionsFileName', | |
| 136 r''' | |
| 137 analyzer: | 132 analyzer: |
| 138 ignore: | 133 ignore: |
| 139 - foo | 134 - foo |
| 140 '''); | 135 '''); |
| 141 pathTranslator.newFile( | 136 pathTranslator.newFile('/foo/bar/$optionsFileName', r''' |
| 142 '/foo/bar/$optionsFileName', | |
| 143 r''' | |
| 144 analyzer: | 137 analyzer: |
| 145 ignore: | 138 ignore: |
| 146 - bar | 139 - bar |
| 147 '''); | 140 '''); |
| 148 Map<String, YamlNode> options = _getOptions('/foo/bar', crawlUp: true); | 141 Map<String, YamlNode> options = _getOptions('/foo/bar', crawlUp: true); |
| 149 expect(options, hasLength(1)); | 142 expect(options, hasLength(1)); |
| 150 { | 143 { |
| 151 YamlMap analyzer = options['analyzer']; | 144 YamlMap analyzer = options['analyzer']; |
| 152 expect(analyzer, isNotNull); | 145 expect(analyzer, isNotNull); |
| 153 expect(analyzer['ignore'], unorderedEquals(['bar'])); | 146 expect(analyzer['ignore'], unorderedEquals(['bar'])); |
| 154 } | 147 } |
| 155 } | 148 } |
| 156 | 149 |
| 157 void test_getOptions_crawlUp_hasInParent() { | 150 void test_getOptions_crawlUp_hasInParent() { |
| 158 pathTranslator.newFolder('/foo/bar/baz'); | 151 pathTranslator.newFolder('/foo/bar/baz'); |
| 159 pathTranslator.newFile( | 152 pathTranslator.newFile('/foo/$optionsFileName', r''' |
| 160 '/foo/$optionsFileName', | |
| 161 r''' | |
| 162 analyzer: | 153 analyzer: |
| 163 ignore: | 154 ignore: |
| 164 - foo | 155 - foo |
| 165 '''); | 156 '''); |
| 166 pathTranslator.newFile( | 157 pathTranslator.newFile('/foo/bar/$optionsFileName', r''' |
| 167 '/foo/bar/$optionsFileName', | |
| 168 r''' | |
| 169 analyzer: | 158 analyzer: |
| 170 ignore: | 159 ignore: |
| 171 - bar | 160 - bar |
| 172 '''); | 161 '''); |
| 173 Map<String, YamlNode> options = _getOptions('/foo/bar/baz', crawlUp: true); | 162 Map<String, YamlNode> options = _getOptions('/foo/bar/baz', crawlUp: true); |
| 174 expect(options, hasLength(1)); | 163 expect(options, hasLength(1)); |
| 175 { | 164 { |
| 176 YamlMap analyzer = options['analyzer']; | 165 YamlMap analyzer = options['analyzer']; |
| 177 expect(analyzer, isNotNull); | 166 expect(analyzer, isNotNull); |
| 178 expect(analyzer['ignore'], unorderedEquals(['bar'])); | 167 expect(analyzer['ignore'], unorderedEquals(['bar'])); |
| 179 } | 168 } |
| 180 } | 169 } |
| 181 | 170 |
| 182 void test_getOptions_doesNotExist() { | 171 void test_getOptions_doesNotExist() { |
| 183 pathTranslator.newFolder('/notFile'); | 172 pathTranslator.newFolder('/notFile'); |
| 184 Map<String, YamlNode> options = _getOptions('/notFile'); | 173 Map<String, YamlNode> options = _getOptions('/notFile'); |
| 185 expect(options, isEmpty); | 174 expect(options, isEmpty); |
| 186 } | 175 } |
| 187 | 176 |
| 188 void test_getOptions_empty() { | 177 void test_getOptions_empty() { |
| 189 pathTranslator.newFile('/$optionsFileName', r'''#empty'''); | 178 pathTranslator.newFile('/$optionsFileName', r'''#empty'''); |
| 190 Map<String, YamlNode> options = _getOptions('/'); | 179 Map<String, YamlNode> options = _getOptions('/'); |
| 191 expect(options, isNotNull); | 180 expect(options, isNotNull); |
| 192 expect(options, isEmpty); | 181 expect(options, isEmpty); |
| 193 } | 182 } |
| 194 | 183 |
| 195 void test_getOptions_include() { | 184 void test_getOptions_include() { |
| 196 pathTranslator.newFile( | 185 pathTranslator.newFile('/foo.include', r''' |
| 197 '/foo.include', | |
| 198 r''' | |
| 199 analyzer: | 186 analyzer: |
| 200 ignore: | 187 ignore: |
| 201 - ignoreme.dart | 188 - ignoreme.dart |
| 202 - 'sdk_ext/**' | 189 - 'sdk_ext/**' |
| 203 '''); | 190 '''); |
| 204 pathTranslator.newFile( | 191 pathTranslator.newFile('/$optionsFileName', r''' |
| 205 '/$optionsFileName', | |
| 206 r''' | |
| 207 include: foo.include | 192 include: foo.include |
| 208 '''); | 193 '''); |
| 209 Map<String, YamlNode> options = _getOptions('/'); | 194 Map<String, YamlNode> options = _getOptions('/'); |
| 210 expect(options, hasLength(1)); | 195 expect(options, hasLength(1)); |
| 211 { | 196 { |
| 212 YamlMap analyzer = options['analyzer']; | 197 YamlMap analyzer = options['analyzer']; |
| 213 expect(analyzer, hasLength(1)); | 198 expect(analyzer, hasLength(1)); |
| 214 { | 199 { |
| 215 YamlList ignore = analyzer['ignore']; | 200 YamlList ignore = analyzer['ignore']; |
| 216 expect(ignore, hasLength(2)); | 201 expect(ignore, hasLength(2)); |
| 217 expect(ignore[0], 'ignoreme.dart'); | 202 expect(ignore[0], 'ignoreme.dart'); |
| 218 expect(ignore[1], 'sdk_ext/**'); | 203 expect(ignore[1], 'sdk_ext/**'); |
| 219 } | 204 } |
| 220 } | 205 } |
| 221 } | 206 } |
| 222 | 207 |
| 223 void test_getOptions_include_missing() { | 208 void test_getOptions_include_missing() { |
| 224 pathTranslator.newFile( | 209 pathTranslator.newFile('/$optionsFileName', r''' |
| 225 '/$optionsFileName', | |
| 226 r''' | |
| 227 include: /foo.include | 210 include: /foo.include |
| 228 '''); | 211 '''); |
| 229 Map<String, YamlNode> options = _getOptions('/'); | 212 Map<String, YamlNode> options = _getOptions('/'); |
| 230 expect(options, hasLength(0)); | 213 expect(options, hasLength(0)); |
| 231 } | 214 } |
| 232 | 215 |
| 233 void test_getOptions_invalid() { | 216 void test_getOptions_invalid() { |
| 234 pathTranslator.newFile('/$optionsFileName', r''':'''); | 217 pathTranslator.newFile('/$optionsFileName', r''':'''); |
| 235 expect(() { | 218 expect(() { |
| 236 _getOptions('/'); | 219 _getOptions('/'); |
| 237 }, throws); | 220 }, throws); |
| 238 } | 221 } |
| 239 | 222 |
| 240 void test_getOptions_simple() { | 223 void test_getOptions_simple() { |
| 241 pathTranslator.newFile( | 224 pathTranslator.newFile('/$optionsFileName', r''' |
| 242 '/$optionsFileName', | |
| 243 r''' | |
| 244 analyzer: | 225 analyzer: |
| 245 ignore: | 226 ignore: |
| 246 - ignoreme.dart | 227 - ignoreme.dart |
| 247 - 'sdk_ext/**' | 228 - 'sdk_ext/**' |
| 248 '''); | 229 '''); |
| 249 Map<String, YamlNode> options = _getOptions('/'); | 230 Map<String, YamlNode> options = _getOptions('/'); |
| 250 expect(options, hasLength(1)); | 231 expect(options, hasLength(1)); |
| 251 { | 232 { |
| 252 YamlMap analyzer = options['analyzer']; | 233 YamlMap analyzer = options['analyzer']; |
| 253 expect(analyzer, hasLength(1)); | 234 expect(analyzer, hasLength(1)); |
| 254 { | 235 { |
| 255 YamlList ignore = analyzer['ignore']; | 236 YamlList ignore = analyzer['ignore']; |
| 256 expect(ignore, hasLength(2)); | 237 expect(ignore, hasLength(2)); |
| 257 expect(ignore[0], 'ignoreme.dart'); | 238 expect(ignore[0], 'ignoreme.dart'); |
| 258 expect(ignore[1], 'sdk_ext/**'); | 239 expect(ignore[1], 'sdk_ext/**'); |
| 259 } | 240 } |
| 260 } | 241 } |
| 261 } | 242 } |
| 262 | 243 |
| 263 Map<String, YamlNode> _getOptions(String posixPath, {bool crawlUp: false}) { | 244 Map<String, YamlNode> _getOptions(String posixPath, {bool crawlUp: false}) { |
| 264 Resource resource = pathTranslator.getResource(posixPath); | 245 Resource resource = pathTranslator.getResource(posixPath); |
| 265 return provider.getOptions(resource, crawlUp: crawlUp); | 246 return provider.getOptions(resource, crawlUp: crawlUp); |
| 266 } | 247 } |
| 267 } | 248 } |
| OLD | NEW |