Chromium Code Reviews| 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'; |
| 11 import 'package:analyzer/source/analysis_options_provider.dart'; | 11 import 'package:analyzer/source/analysis_options_provider.dart'; |
| 12 import 'package:analyzer/src/generated/engine.dart'; | 12 import 'package:analyzer/src/generated/engine.dart'; |
| 13 import 'package:analyzer/src/generated/source.dart'; | |
| 13 import 'package:test/test.dart'; | 14 import 'package:test/test.dart'; |
| 14 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 15 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 15 import 'package:yaml/yaml.dart'; | 16 import 'package:yaml/yaml.dart'; |
| 16 | 17 |
| 17 import '../resource_utils.dart'; | 18 import '../resource_utils.dart'; |
| 18 | 19 |
| 19 main() { | 20 main() { |
| 20 defineReflectiveSuite(() { | 21 defineReflectiveSuite(() { |
| 21 defineReflectiveTests(AnalysisOptionsProviderOldTest); | 22 defineReflectiveTests(AnalysisOptionsProviderOldTest); |
| 22 defineReflectiveTests(AnalysisOptionsProviderNewTest); | 23 defineReflectiveTests(AnalysisOptionsProviderNewTest); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 | 109 |
| 109 @reflectiveTest | 110 @reflectiveTest |
| 110 class AnalysisOptionsProviderOldTest extends AnalysisOptionsProviderTest { | 111 class AnalysisOptionsProviderOldTest extends AnalysisOptionsProviderTest { |
| 111 String get optionsFileName => AnalysisEngine.ANALYSIS_OPTIONS_FILE; | 112 String get optionsFileName => AnalysisEngine.ANALYSIS_OPTIONS_FILE; |
| 112 } | 113 } |
| 113 | 114 |
| 114 abstract class AnalysisOptionsProviderTest { | 115 abstract class AnalysisOptionsProviderTest { |
| 115 TestPathTranslator pathTranslator; | 116 TestPathTranslator pathTranslator; |
| 116 ResourceProvider resourceProvider; | 117 ResourceProvider resourceProvider; |
| 117 | 118 |
| 118 AnalysisOptionsProvider provider = new AnalysisOptionsProvider(); | 119 AnalysisOptionsProvider provider; |
| 119 | 120 |
| 120 String get optionsFileName; | 121 String get optionsFileName; |
| 121 | 122 |
| 122 void setUp() { | 123 void setUp() { |
| 123 var rawProvider = new MemoryResourceProvider(); | 124 var rawProvider = new MemoryResourceProvider(); |
| 124 resourceProvider = new TestResourceProvider(rawProvider); | 125 resourceProvider = new TestResourceProvider(rawProvider); |
| 125 pathTranslator = new TestPathTranslator(rawProvider); | 126 pathTranslator = new TestPathTranslator(rawProvider); |
| 127 provider = new AnalysisOptionsProvider(new SourceFactory([ | |
| 128 new ResourceUriResolver(rawProvider), | |
| 129 ])); | |
| 126 } | 130 } |
| 127 | 131 |
| 128 void test_getOptions_crawlUp_hasInFolder() { | 132 void test_getOptions_crawlUp_hasInFolder() { |
| 129 pathTranslator.newFolder('/foo/bar'); | 133 pathTranslator.newFolder('/foo/bar'); |
| 130 pathTranslator.newFile( | 134 pathTranslator.newFile( |
| 131 '/foo/$optionsFileName', | 135 '/foo/$optionsFileName', |
| 132 r''' | 136 r''' |
| 133 analyzer: | 137 analyzer: |
| 134 ignore: | 138 ignore: |
| 135 - foo | 139 - foo |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 expect(options, isEmpty); | 185 expect(options, isEmpty); |
| 182 } | 186 } |
| 183 | 187 |
| 184 void test_getOptions_empty() { | 188 void test_getOptions_empty() { |
| 185 pathTranslator.newFile('/$optionsFileName', r'''#empty'''); | 189 pathTranslator.newFile('/$optionsFileName', r'''#empty'''); |
| 186 Map<String, YamlNode> options = _getOptions('/'); | 190 Map<String, YamlNode> options = _getOptions('/'); |
| 187 expect(options, isNotNull); | 191 expect(options, isNotNull); |
| 188 expect(options, isEmpty); | 192 expect(options, isEmpty); |
| 189 } | 193 } |
| 190 | 194 |
| 195 void test_getOptions_include() { | |
|
Brian Wilkerson
2016/11/11 19:37:47
Should we have a test for package: URIs, or is it
| |
| 196 pathTranslator.newFile( | |
| 197 '/foo.include', | |
| 198 r''' | |
| 199 analyzer: | |
| 200 ignore: | |
| 201 - ignoreme.dart | |
| 202 - 'sdk_ext/**' | |
| 203 '''); | |
| 204 pathTranslator.newFile( | |
| 205 '/$optionsFileName', | |
| 206 r''' | |
| 207 include: /foo.include | |
| 208 '''); | |
| 209 Map<String, YamlNode> options = _getOptions('/'); | |
| 210 expect(options, hasLength(1)); | |
| 211 { | |
| 212 YamlMap analyzer = options['analyzer']; | |
| 213 expect(analyzer, hasLength(1)); | |
| 214 { | |
| 215 YamlList ignore = analyzer['ignore']; | |
| 216 expect(ignore, hasLength(2)); | |
| 217 expect(ignore[0], 'ignoreme.dart'); | |
| 218 expect(ignore[1], 'sdk_ext/**'); | |
| 219 } | |
| 220 } | |
| 221 } | |
| 222 | |
| 223 void test_getOptions_include_missing() { | |
| 224 pathTranslator.newFile( | |
| 225 '/$optionsFileName', | |
| 226 r''' | |
| 227 include: /foo.include | |
| 228 '''); | |
| 229 Map<String, YamlNode> options = _getOptions('/'); | |
| 230 expect(options, hasLength(0)); | |
| 231 } | |
| 232 | |
| 191 void test_getOptions_invalid() { | 233 void test_getOptions_invalid() { |
| 192 pathTranslator.newFile('/$optionsFileName', r''':'''); | 234 pathTranslator.newFile('/$optionsFileName', r''':'''); |
| 193 expect(() { | 235 expect(() { |
| 194 _getOptions('/'); | 236 _getOptions('/'); |
| 195 }, throws); | 237 }, throws); |
| 196 } | 238 } |
| 197 | 239 |
| 198 void test_getOptions_simple() { | 240 void test_getOptions_simple() { |
| 199 pathTranslator.newFile( | 241 pathTranslator.newFile( |
| 200 '/$optionsFileName', | 242 '/$optionsFileName', |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 216 expect(ignore[1], 'sdk_ext/**'); | 258 expect(ignore[1], 'sdk_ext/**'); |
| 217 } | 259 } |
| 218 } | 260 } |
| 219 } | 261 } |
| 220 | 262 |
| 221 Map<String, YamlNode> _getOptions(String posixPath, {bool crawlUp: false}) { | 263 Map<String, YamlNode> _getOptions(String posixPath, {bool crawlUp: false}) { |
| 222 Resource resource = pathTranslator.getResource(posixPath); | 264 Resource resource = pathTranslator.getResource(posixPath); |
| 223 return provider.getOptions(resource, crawlUp: crawlUp); | 265 return provider.getOptions(resource, crawlUp: crawlUp); |
| 224 } | 266 } |
| 225 } | 267 } |
| OLD | NEW |