Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.src.context.context_builder_test; | 5 library analyzer.test.src.context.context_builder_test; |
| 6 | 6 |
| 7 import 'package:analyzer/file_system/file_system.dart'; | 7 import 'package:analyzer/file_system/file_system.dart'; |
| 8 import 'package:analyzer/file_system/memory_file_system.dart'; | 8 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 9 import 'package:analyzer/plugin/options.dart'; | 9 import 'package:analyzer/plugin/options.dart'; |
| 10 import 'package:analyzer/source/package_map_resolver.dart'; | 10 import 'package:analyzer/source/package_map_resolver.dart'; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 * The context builder to be used in the test. | 58 * The context builder to be used in the test. |
| 59 */ | 59 */ |
| 60 ContextBuilder builder; | 60 ContextBuilder builder; |
| 61 | 61 |
| 62 /** | 62 /** |
| 63 * The path to the default SDK, or `null` if the test has not explicitly | 63 * The path to the default SDK, or `null` if the test has not explicitly |
| 64 * invoked [createDefaultSdk]. | 64 * invoked [createDefaultSdk]. |
| 65 */ | 65 */ |
| 66 String defaultSdkPath = null; | 66 String defaultSdkPath = null; |
| 67 | 67 |
| 68 Uri convertedUri(String directoryPath) { | |
|
scheglov
2016/10/06 16:55:38
The method name does not say anything about direct
Brian Wilkerson
2016/10/06 17:14:55
renamed
| |
| 69 // return pathContext.toUri(resourceProvider.convertPath(directoryPath)); | |
|
scheglov
2016/10/06 16:55:38
Remove this line?
Brian Wilkerson
2016/10/06 17:14:55
Done
| |
| 70 return new Uri.directory(resourceProvider.convertPath(directoryPath), | |
| 71 windows: pathContext.style == path.windows.style); | |
| 72 } | |
| 73 | |
| 68 void createDefaultSdk(Folder sdkDir) { | 74 void createDefaultSdk(Folder sdkDir) { |
| 69 defaultSdkPath = pathContext.join(sdkDir.path, 'default', 'sdk'); | 75 defaultSdkPath = pathContext.join(sdkDir.path, 'default', 'sdk'); |
| 70 String librariesFilePath = pathContext.join(defaultSdkPath, 'lib', | 76 String librariesFilePath = pathContext.join(defaultSdkPath, 'lib', |
| 71 '_internal', 'sdk_library_metadata', 'lib', 'libraries.dart'); | 77 '_internal', 'sdk_library_metadata', 'lib', 'libraries.dart'); |
| 72 resourceProvider.newFile( | 78 resourceProvider.newFile( |
| 73 librariesFilePath, | 79 librariesFilePath, |
| 74 r''' | 80 r''' |
| 75 const Map<String, LibraryInfo> libraries = const { | 81 const Map<String, LibraryInfo> libraries = const { |
| 76 "async": const LibraryInfo("async/async.dart"), | 82 "async": const LibraryInfo("async/async.dart"), |
| 77 "core": const LibraryInfo("core/core.dart"), | 83 "core": const LibraryInfo("core/core.dart"), |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 106 void test_convertPackagesToMap_noPackages() { | 112 void test_convertPackagesToMap_noPackages() { |
| 107 expect(builder.convertPackagesToMap(Packages.noPackages), isEmpty); | 113 expect(builder.convertPackagesToMap(Packages.noPackages), isEmpty); |
| 108 } | 114 } |
| 109 | 115 |
| 110 void test_convertPackagesToMap_null() { | 116 void test_convertPackagesToMap_null() { |
| 111 expect(builder.convertPackagesToMap(null), isEmpty); | 117 expect(builder.convertPackagesToMap(null), isEmpty); |
| 112 } | 118 } |
| 113 | 119 |
| 114 void test_convertPackagesToMap_packages() { | 120 void test_convertPackagesToMap_packages() { |
| 115 String fooName = 'foo'; | 121 String fooName = 'foo'; |
| 116 String fooPath = '/pkg/foo'; | 122 String fooPath = resourceProvider.convertPath('/pkg/foo'); |
| 117 Uri fooUri = new Uri.directory(fooPath); | 123 Uri fooUri = pathContext.toUri(fooPath); |
| 118 String barName = 'bar'; | 124 String barName = 'bar'; |
| 119 String barPath = '/pkg/bar'; | 125 String barPath = resourceProvider.convertPath('/pkg/bar'); |
| 120 Uri barUri = new Uri.directory(barPath); | 126 Uri barUri = pathContext.toUri(barPath); |
| 121 | 127 |
| 122 MapPackages packages = new MapPackages({fooName: fooUri, barName: barUri}); | 128 MapPackages packages = new MapPackages({fooName: fooUri, barName: barUri}); |
| 123 Map<String, List<Folder>> result = builder.convertPackagesToMap(packages); | 129 Map<String, List<Folder>> result = builder.convertPackagesToMap(packages); |
| 124 expect(result, isNotNull); | 130 expect(result, isNotNull); |
| 125 expect(result, hasLength(2)); | 131 expect(result, hasLength(2)); |
| 126 expect(result[fooName], hasLength(1)); | 132 expect(result[fooName], hasLength(1)); |
| 127 expect(result[fooName][0].path, fooPath); | 133 expect(result[fooName][0].path, fooPath); |
| 128 expect(result[barName], hasLength(1)); | 134 expect(result[barName], hasLength(1)); |
| 129 expect(result[barName][0].path, barPath); | 135 expect(result[barName][0].path, barPath); |
| 130 } | 136 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 144 _expectEqualOptions(options, defaultOptions); | 150 _expectEqualOptions(options, defaultOptions); |
| 145 } | 151 } |
| 146 | 152 |
| 147 void test_createDefaultOptions_noDefault() { | 153 void test_createDefaultOptions_noDefault() { |
| 148 AnalysisOptions options = builder.createDefaultOptions(); | 154 AnalysisOptions options = builder.createDefaultOptions(); |
| 149 _expectEqualOptions(options, new AnalysisOptionsImpl()); | 155 _expectEqualOptions(options, new AnalysisOptionsImpl()); |
| 150 } | 156 } |
| 151 | 157 |
| 152 void test_createPackageMap_fromPackageDirectory_explicit() { | 158 void test_createPackageMap_fromPackageDirectory_explicit() { |
| 153 // Use a package directory that is outside the project directory. | 159 // Use a package directory that is outside the project directory. |
| 154 String rootPath = '/root'; | 160 String rootPath = resourceProvider.convertPath('/root'); |
| 155 String projectPath = pathContext.join(rootPath, 'project'); | 161 String projectPath = pathContext.join(rootPath, 'project'); |
| 156 String packageDirPath = pathContext.join(rootPath, 'packages'); | 162 String packageDirPath = pathContext.join(rootPath, 'packages'); |
| 157 String fooName = 'foo'; | 163 String fooName = 'foo'; |
| 158 String fooPath = pathContext.join(packageDirPath, fooName); | 164 String fooPath = pathContext.join(packageDirPath, fooName); |
| 159 String barName = 'bar'; | 165 String barName = 'bar'; |
| 160 String barPath = pathContext.join(packageDirPath, barName); | 166 String barPath = pathContext.join(packageDirPath, barName); |
| 161 resourceProvider.newFolder(projectPath); | 167 resourceProvider.newFolder(projectPath); |
| 162 resourceProvider.newFolder(fooPath); | 168 resourceProvider.newFolder(fooPath); |
| 163 resourceProvider.newFolder(barPath); | 169 resourceProvider.newFolder(barPath); |
| 164 | 170 |
| 165 builder.defaultPackagesDirectoryPath = packageDirPath; | 171 builder.defaultPackagesDirectoryPath = packageDirPath; |
| 166 | 172 |
| 167 Packages packages = builder.createPackageMap(projectPath); | 173 Packages packages = builder.createPackageMap(projectPath); |
| 168 expect(packages, isNotNull); | 174 expect(packages, isNotNull); |
| 169 Map<String, Uri> map = packages.asMap(); | 175 Map<String, Uri> map = packages.asMap(); |
| 170 expect(map, hasLength(2)); | 176 expect(map, hasLength(2)); |
| 171 expect(map[fooName], new Uri.directory(fooPath)); | 177 expect(map[fooName], convertedUri(fooPath)); |
| 172 expect(map[barName], new Uri.directory(barPath)); | 178 expect(map[barName], convertedUri(barPath)); |
| 173 } | 179 } |
| 174 | 180 |
| 175 void test_createPackageMap_fromPackageDirectory_inRoot() { | 181 void test_createPackageMap_fromPackageDirectory_inRoot() { |
| 176 // Use a package directory that is inside the project directory. | 182 // Use a package directory that is inside the project directory. |
| 177 String projectPath = '/root/project'; | 183 String projectPath = resourceProvider.convertPath('/root/project'); |
| 178 String packageDirPath = pathContext.join(projectPath, 'packages'); | 184 String packageDirPath = pathContext.join(projectPath, 'packages'); |
| 179 String fooName = 'foo'; | 185 String fooName = 'foo'; |
| 180 String fooPath = pathContext.join(packageDirPath, fooName); | 186 String fooPath = pathContext.join(packageDirPath, fooName); |
| 181 String barName = 'bar'; | 187 String barName = 'bar'; |
| 182 String barPath = pathContext.join(packageDirPath, barName); | 188 String barPath = pathContext.join(packageDirPath, barName); |
| 183 resourceProvider.newFolder(fooPath); | 189 resourceProvider.newFolder(fooPath); |
| 184 resourceProvider.newFolder(barPath); | 190 resourceProvider.newFolder(barPath); |
| 185 | 191 |
| 186 Packages packages = builder.createPackageMap(projectPath); | 192 Packages packages = builder.createPackageMap(projectPath); |
| 187 expect(packages, isNotNull); | 193 expect(packages, isNotNull); |
| 188 Map<String, Uri> map = packages.asMap(); | 194 Map<String, Uri> map = packages.asMap(); |
| 189 expect(map, hasLength(2)); | 195 expect(map, hasLength(2)); |
| 190 expect(map[fooName], new Uri.directory(fooPath)); | 196 expect(map[fooName], convertedUri(fooPath)); |
| 191 expect(map[barName], new Uri.directory(barPath)); | 197 expect(map[barName], convertedUri(barPath)); |
| 192 } | 198 } |
| 193 | 199 |
| 194 void test_createPackageMap_fromPackageFile_explicit() { | 200 void test_createPackageMap_fromPackageFile_explicit() { |
| 195 // Use a package file that is outside the project directory's hierarchy. | 201 // Use a package file that is outside the project directory's hierarchy. |
| 196 String rootPath = '/root'; | 202 String rootPath = resourceProvider.convertPath('/root'); |
| 197 String projectPath = pathContext.join(rootPath, 'project'); | 203 String projectPath = pathContext.join(rootPath, 'project'); |
| 198 String packageFilePath = pathContext.join(rootPath, 'child', '.packages'); | 204 String packageFilePath = pathContext.join(rootPath, 'child', '.packages'); |
| 199 resourceProvider.newFolder(projectPath); | 205 resourceProvider.newFolder(projectPath); |
| 206 Uri fooUri = convertedUri('/pkg/foo'); | |
| 207 Uri barUri = convertedUri('/pkg/bar'); | |
| 200 createFile( | 208 createFile( |
| 201 packageFilePath, | 209 packageFilePath, |
| 202 r''' | 210 ''' |
| 203 foo:/pkg/foo | 211 foo:$fooUri |
| 204 bar:/pkg/bar | 212 bar:$barUri |
| 205 '''); | 213 '''); |
| 206 | 214 |
| 207 builder.defaultPackageFilePath = packageFilePath; | 215 builder.defaultPackageFilePath = packageFilePath; |
| 208 Packages packages = builder.createPackageMap(projectPath); | 216 Packages packages = builder.createPackageMap(projectPath); |
| 209 expect(packages, isNotNull); | 217 expect(packages, isNotNull); |
| 210 Map<String, Uri> map = packages.asMap(); | 218 Map<String, Uri> map = packages.asMap(); |
| 211 expect(map, hasLength(2)); | 219 expect(map, hasLength(2)); |
| 212 expect(map['foo'], new Uri.directory('/pkg/foo')); | 220 expect(map['foo'], fooUri); |
| 213 expect(map['bar'], new Uri.directory('/pkg/bar')); | 221 expect(map['bar'], barUri); |
| 214 } | 222 } |
| 215 | 223 |
| 216 void test_createPackageMap_fromPackageFile_inParentOfRoot() { | 224 void test_createPackageMap_fromPackageFile_inParentOfRoot() { |
| 217 // Use a package file that is inside the parent of the project directory. | 225 // Use a package file that is inside the parent of the project directory. |
| 218 String rootPath = '/root'; | 226 String rootPath = resourceProvider.convertPath('/root'); |
| 219 String projectPath = pathContext.join(rootPath, 'project'); | 227 String projectPath = pathContext.join(rootPath, 'project'); |
| 220 String packageFilePath = pathContext.join(rootPath, '.packages'); | 228 String packageFilePath = pathContext.join(rootPath, '.packages'); |
| 221 resourceProvider.newFolder(projectPath); | 229 resourceProvider.newFolder(projectPath); |
| 230 Uri fooUri = convertedUri('/pkg/foo'); | |
| 231 Uri barUri = convertedUri('/pkg/bar'); | |
| 222 createFile( | 232 createFile( |
| 223 packageFilePath, | 233 packageFilePath, |
| 224 r''' | 234 ''' |
| 225 foo:/pkg/foo | 235 foo:$fooUri |
| 226 bar:/pkg/bar | 236 bar:$barUri |
| 227 '''); | 237 '''); |
| 228 | 238 |
| 229 Packages packages = builder.createPackageMap(projectPath); | 239 Packages packages = builder.createPackageMap(projectPath); |
| 230 expect(packages, isNotNull); | 240 expect(packages, isNotNull); |
| 231 Map<String, Uri> map = packages.asMap(); | 241 Map<String, Uri> map = packages.asMap(); |
| 232 expect(map, hasLength(2)); | 242 expect(map, hasLength(2)); |
| 233 expect(map['foo'], new Uri.directory('/pkg/foo')); | 243 expect(map['foo'], fooUri); |
| 234 expect(map['bar'], new Uri.directory('/pkg/bar')); | 244 expect(map['bar'], barUri); |
| 235 } | 245 } |
| 236 | 246 |
| 237 void test_createPackageMap_fromPackageFile_inRoot() { | 247 void test_createPackageMap_fromPackageFile_inRoot() { |
| 238 // Use a package file that is inside the project directory. | 248 // Use a package file that is inside the project directory. |
| 239 String rootPath = '/root'; | 249 String rootPath = resourceProvider.convertPath('/root'); |
| 240 String projectPath = pathContext.join(rootPath, 'project'); | 250 String projectPath = pathContext.join(rootPath, 'project'); |
| 241 String packageFilePath = pathContext.join(projectPath, '.packages'); | 251 String packageFilePath = pathContext.join(projectPath, '.packages'); |
| 242 resourceProvider.newFolder(projectPath); | 252 resourceProvider.newFolder(projectPath); |
| 253 Uri fooUri = convertedUri('/pkg/foo'); | |
| 254 Uri barUri = convertedUri('/pkg/bar'); | |
| 243 createFile( | 255 createFile( |
| 244 packageFilePath, | 256 packageFilePath, |
| 245 r''' | 257 ''' |
| 246 foo:/pkg/foo | 258 foo:$fooUri |
| 247 bar:/pkg/bar | 259 bar:$barUri |
| 248 '''); | 260 '''); |
| 249 | 261 |
| 250 Packages packages = builder.createPackageMap(projectPath); | 262 Packages packages = builder.createPackageMap(projectPath); |
| 251 expect(packages, isNotNull); | 263 expect(packages, isNotNull); |
| 252 Map<String, Uri> map = packages.asMap(); | 264 Map<String, Uri> map = packages.asMap(); |
| 253 expect(map, hasLength(2)); | 265 expect(map, hasLength(2)); |
| 254 expect(map['foo'], new Uri.directory('/pkg/foo')); | 266 expect(map['foo'], fooUri); |
| 255 expect(map['bar'], new Uri.directory('/pkg/bar')); | 267 expect(map['bar'], barUri); |
| 256 } | 268 } |
| 257 | 269 |
| 258 void test_createPackageMap_none() { | 270 void test_createPackageMap_none() { |
| 259 String rootPath = '/root'; | 271 String rootPath = resourceProvider.convertPath('/root'); |
| 260 Packages packages = builder.createPackageMap(rootPath); | 272 Packages packages = builder.createPackageMap(rootPath); |
| 261 expect(packages, same(Packages.noPackages)); | 273 expect(packages, same(Packages.noPackages)); |
| 262 } | 274 } |
| 263 | 275 |
| 264 void test_createSourceFactory_fileProvider() { | 276 void test_createSourceFactory_fileProvider() { |
| 265 String rootPath = '/root'; | 277 String rootPath = resourceProvider.convertPath('/root'); |
| 266 Folder rootFolder = resourceProvider.getFolder(rootPath); | 278 Folder rootFolder = resourceProvider.getFolder(rootPath); |
| 267 createDefaultSdk(rootFolder); | 279 createDefaultSdk(rootFolder); |
| 268 String projectPath = pathContext.join(rootPath, 'project'); | 280 String projectPath = pathContext.join(rootPath, 'project'); |
| 269 String packageFilePath = pathContext.join(projectPath, '.packages'); | 281 String packageFilePath = pathContext.join(projectPath, '.packages'); |
| 270 String packageA = pathContext.join(rootPath, 'pkgs', 'a'); | 282 String packageA = pathContext.join(rootPath, 'pkgs', 'a'); |
| 271 String packageB = pathContext.join(rootPath, 'pkgs', 'b'); | 283 String packageB = pathContext.join(rootPath, 'pkgs', 'b'); |
| 272 createFile( | 284 createFile( |
| 273 packageFilePath, | 285 packageFilePath, |
| 274 ''' | 286 ''' |
| 275 a:${pathContext.toUri(packageA)} | 287 a:${pathContext.toUri(packageA)} |
| 276 b:${pathContext.toUri(packageB)} | 288 b:${pathContext.toUri(packageB)} |
| 277 '''); | 289 '''); |
| 278 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 290 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 279 UriResolver resolver = new ResourceUriResolver(resourceProvider); | 291 UriResolver resolver = new ResourceUriResolver(resourceProvider); |
| 280 builder.fileResolverProvider = (folder) => resolver; | 292 builder.fileResolverProvider = (folder) => resolver; |
| 281 SourceFactoryImpl factory = | 293 SourceFactoryImpl factory = |
| 282 builder.createSourceFactory(projectPath, options); | 294 builder.createSourceFactory(projectPath, options); |
| 283 expect(factory.resolvers, contains(same(resolver))); | 295 expect(factory.resolvers, contains(same(resolver))); |
| 284 } | 296 } |
| 285 | 297 |
| 286 void test_createSourceFactory_noProvider_packages_embedder_extensions() { | 298 void test_createSourceFactory_noProvider_packages_embedder_extensions() { |
| 287 String rootPath = '/root'; | 299 String rootPath = resourceProvider.convertPath('/root'); |
| 288 Folder rootFolder = resourceProvider.getFolder(rootPath); | 300 Folder rootFolder = resourceProvider.getFolder(rootPath); |
| 289 createDefaultSdk(rootFolder); | 301 createDefaultSdk(rootFolder); |
| 290 String projectPath = pathContext.join(rootPath, 'project'); | 302 String projectPath = pathContext.join(rootPath, 'project'); |
| 291 String packageFilePath = pathContext.join(projectPath, '.packages'); | 303 String packageFilePath = pathContext.join(projectPath, '.packages'); |
| 292 String packageA = pathContext.join(rootPath, 'pkgs', 'a'); | 304 String packageA = pathContext.join(rootPath, 'pkgs', 'a'); |
| 293 String embedderPath = pathContext.join(packageA, '_embedder.yaml'); | 305 String embedderPath = pathContext.join(packageA, '_embedder.yaml'); |
| 294 String packageB = pathContext.join(rootPath, 'pkgs', 'b'); | 306 String packageB = pathContext.join(rootPath, 'pkgs', 'b'); |
| 295 String extensionPath = pathContext.join(packageB, '_sdkext'); | 307 String extensionPath = pathContext.join(packageB, '_sdkext'); |
| 296 createFile( | 308 createFile( |
| 297 packageFilePath, | 309 packageFilePath, |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 325 Source fooSource = factory.forUri('dart:foo'); | 337 Source fooSource = factory.forUri('dart:foo'); |
| 326 expect(fooSource, isNotNull); | 338 expect(fooSource, isNotNull); |
| 327 expect(fooSource.fullName, fooPath); | 339 expect(fooSource.fullName, fooPath); |
| 328 | 340 |
| 329 Source packageSource = factory.forUri('package:b/b.dart'); | 341 Source packageSource = factory.forUri('package:b/b.dart'); |
| 330 expect(packageSource, isNotNull); | 342 expect(packageSource, isNotNull); |
| 331 expect(packageSource.fullName, pathContext.join(packageB, 'b.dart')); | 343 expect(packageSource.fullName, pathContext.join(packageB, 'b.dart')); |
| 332 } | 344 } |
| 333 | 345 |
| 334 void test_createSourceFactory_noProvider_packages_embedder_noExtensions() { | 346 void test_createSourceFactory_noProvider_packages_embedder_noExtensions() { |
| 335 String rootPath = '/root'; | 347 String rootPath = resourceProvider.convertPath('/root'); |
| 336 Folder rootFolder = resourceProvider.getFolder(rootPath); | 348 Folder rootFolder = resourceProvider.getFolder(rootPath); |
| 337 createDefaultSdk(rootFolder); | 349 createDefaultSdk(rootFolder); |
| 338 String projectPath = pathContext.join(rootPath, 'project'); | 350 String projectPath = pathContext.join(rootPath, 'project'); |
| 339 String packageFilePath = pathContext.join(projectPath, '.packages'); | 351 String packageFilePath = pathContext.join(projectPath, '.packages'); |
| 340 String packageA = pathContext.join(rootPath, 'pkgs', 'a'); | 352 String packageA = pathContext.join(rootPath, 'pkgs', 'a'); |
| 341 String embedderPath = pathContext.join(packageA, '_embedder.yaml'); | 353 String embedderPath = pathContext.join(packageA, '_embedder.yaml'); |
| 342 String packageB = pathContext.join(rootPath, 'pkgs', 'b'); | 354 String packageB = pathContext.join(rootPath, 'pkgs', 'b'); |
| 343 createFile( | 355 createFile( |
| 344 packageFilePath, | 356 packageFilePath, |
| 345 ''' | 357 ''' |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 367 expect(packageSource, isNotNull); | 379 expect(packageSource, isNotNull); |
| 368 expect(packageSource.fullName, pathContext.join(packageB, 'b.dart')); | 380 expect(packageSource.fullName, pathContext.join(packageB, 'b.dart')); |
| 369 } | 381 } |
| 370 | 382 |
| 371 @failingTest | 383 @failingTest |
| 372 void test_createSourceFactory_noProvider_packages_noEmbedder_extensions() { | 384 void test_createSourceFactory_noProvider_packages_noEmbedder_extensions() { |
| 373 fail('Incomplete test'); | 385 fail('Incomplete test'); |
| 374 } | 386 } |
| 375 | 387 |
| 376 void test_createSourceFactory_noProvider_packages_noEmbedder_noExtensions() { | 388 void test_createSourceFactory_noProvider_packages_noEmbedder_noExtensions() { |
| 377 String rootPath = '/root'; | 389 String rootPath = resourceProvider.convertPath('/root'); |
| 378 Folder rootFolder = resourceProvider.getFolder(rootPath); | 390 Folder rootFolder = resourceProvider.getFolder(rootPath); |
| 379 createDefaultSdk(rootFolder); | 391 createDefaultSdk(rootFolder); |
| 380 String projectPath = pathContext.join(rootPath, 'project'); | 392 String projectPath = pathContext.join(rootPath, 'project'); |
| 381 String packageFilePath = pathContext.join(projectPath, '.packages'); | 393 String packageFilePath = pathContext.join(projectPath, '.packages'); |
| 382 String packageA = pathContext.join(rootPath, 'pkgs', 'a'); | 394 String packageA = pathContext.join(rootPath, 'pkgs', 'a'); |
| 383 String packageB = pathContext.join(rootPath, 'pkgs', 'b'); | 395 String packageB = pathContext.join(rootPath, 'pkgs', 'b'); |
| 384 createFile( | 396 createFile( |
| 385 packageFilePath, | 397 packageFilePath, |
| 386 ''' | 398 ''' |
| 387 a:${pathContext.toUri(packageA)} | 399 a:${pathContext.toUri(packageA)} |
| 388 b:${pathContext.toUri(packageB)} | 400 b:${pathContext.toUri(packageB)} |
| 389 '''); | 401 '''); |
| 390 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 402 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 391 | 403 |
| 392 SourceFactory factory = builder.createSourceFactory(projectPath, options); | 404 SourceFactory factory = builder.createSourceFactory(projectPath, options); |
| 393 | 405 |
| 394 Source dartSource = factory.forUri('dart:core'); | 406 Source dartSource = factory.forUri('dart:core'); |
| 395 expect(dartSource, isNotNull); | 407 expect(dartSource, isNotNull); |
| 396 expect(dartSource.fullName, '$defaultSdkPath/lib/core/core.dart'); | 408 expect(dartSource.fullName, |
| 409 pathContext.join(defaultSdkPath, 'lib', 'core', 'core.dart')); | |
| 397 | 410 |
| 398 Source packageSource = factory.forUri('package:a/a.dart'); | 411 Source packageSource = factory.forUri('package:a/a.dart'); |
| 399 expect(packageSource, isNotNull); | 412 expect(packageSource, isNotNull); |
| 400 expect(packageSource.fullName, pathContext.join(packageA, 'a.dart')); | 413 expect(packageSource.fullName, pathContext.join(packageA, 'a.dart')); |
| 401 } | 414 } |
| 402 | 415 |
| 403 void test_createSourceFactory_packageProvider() { | 416 void test_createSourceFactory_packageProvider() { |
| 404 String rootPath = '/root'; | 417 String rootPath = resourceProvider.convertPath('/root'); |
| 405 Folder rootFolder = resourceProvider.getFolder(rootPath); | 418 Folder rootFolder = resourceProvider.getFolder(rootPath); |
| 406 createDefaultSdk(rootFolder); | 419 createDefaultSdk(rootFolder); |
| 407 String projectPath = pathContext.join(rootPath, 'project'); | 420 String projectPath = pathContext.join(rootPath, 'project'); |
| 408 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 421 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 409 UriResolver resolver = new PackageMapUriResolver(resourceProvider, {}); | 422 UriResolver resolver = new PackageMapUriResolver(resourceProvider, {}); |
| 410 builder.packageResolverProvider = (folder) => resolver; | 423 builder.packageResolverProvider = (folder) => resolver; |
| 411 SourceFactoryImpl factory = | 424 SourceFactoryImpl factory = |
| 412 builder.createSourceFactory(projectPath, options); | 425 builder.createSourceFactory(projectPath, options); |
| 413 expect(factory.resolvers, contains(same(resolver))); | 426 expect(factory.resolvers, contains(same(resolver))); |
| 414 } | 427 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 470 DartSdk sdk = builder.findSdk(null, new AnalysisOptionsImpl()); | 483 DartSdk sdk = builder.findSdk(null, new AnalysisOptionsImpl()); |
| 471 expect(sdk, isNotNull); | 484 expect(sdk, isNotNull); |
| 472 } | 485 } |
| 473 | 486 |
| 474 void test_getAnalysisOptions_default_noOverrides() { | 487 void test_getAnalysisOptions_default_noOverrides() { |
| 475 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); | 488 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); |
| 476 defaultOptions.enableGenericMethods = true; | 489 defaultOptions.enableGenericMethods = true; |
| 477 builder.defaultOptions = defaultOptions; | 490 builder.defaultOptions = defaultOptions; |
| 478 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); | 491 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); |
| 479 expected.enableGenericMethods = true; | 492 expected.enableGenericMethods = true; |
| 480 String path = '/some/directory/path'; | 493 String path = resourceProvider.convertPath('/some/directory/path'); |
| 481 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}'; | 494 String filePath = |
| 495 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); | |
| 482 resourceProvider.newFile( | 496 resourceProvider.newFile( |
| 483 filePath, | 497 filePath, |
| 484 ''' | 498 ''' |
| 485 linter: | 499 linter: |
| 486 rules: | 500 rules: |
| 487 - empty_constructor_bodies | 501 - empty_constructor_bodies |
| 488 '''); | 502 '''); |
| 489 | 503 |
| 490 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); | 504 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); |
| 491 AnalysisOptions options = builder.getAnalysisOptions(context, path); | 505 AnalysisOptions options = builder.getAnalysisOptions(context, path); |
| 492 _expectEqualOptions(options, expected); | 506 _expectEqualOptions(options, expected); |
| 493 } | 507 } |
| 494 | 508 |
| 495 void test_getAnalysisOptions_default_overrides() { | 509 void test_getAnalysisOptions_default_overrides() { |
| 496 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); | 510 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); |
| 497 defaultOptions.enableGenericMethods = true; | 511 defaultOptions.enableGenericMethods = true; |
| 498 builder.defaultOptions = defaultOptions; | 512 builder.defaultOptions = defaultOptions; |
| 499 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); | 513 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); |
| 500 expected.enableSuperMixins = true; | 514 expected.enableSuperMixins = true; |
| 501 expected.enableGenericMethods = true; | 515 expected.enableGenericMethods = true; |
| 502 String path = '/some/directory/path'; | 516 String path = resourceProvider.convertPath('/some/directory/path'); |
| 503 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}'; | 517 String filePath = |
| 518 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); | |
| 504 resourceProvider.newFile( | 519 resourceProvider.newFile( |
| 505 filePath, | 520 filePath, |
| 506 ''' | 521 ''' |
| 507 analyzer: | 522 analyzer: |
| 508 language: | 523 language: |
| 509 enableSuperMixins : true | 524 enableSuperMixins : true |
| 510 '''); | 525 '''); |
| 511 | 526 |
| 512 AnalysisEngine engine = AnalysisEngine.instance; | 527 AnalysisEngine engine = AnalysisEngine.instance; |
| 513 OptionsPlugin plugin = engine.optionsPlugin; | 528 OptionsPlugin plugin = engine.optionsPlugin; |
| 514 plugin.registerExtensionPoints((_) {}); | 529 plugin.registerExtensionPoints((_) {}); |
| 515 try { | 530 try { |
| 516 _TestOptionsProcessor processor = new _TestOptionsProcessor(); | 531 _TestOptionsProcessor processor = new _TestOptionsProcessor(); |
| 517 processor.expectedOptions = <String, Object>{ | 532 processor.expectedOptions = <String, Object>{ |
| 518 'analyzer': { | 533 'analyzer': { |
| 519 'language': {'enableSuperMixins': true} | 534 'language': {'enableSuperMixins': true} |
| 520 } | 535 } |
| 521 }; | 536 }; |
| 522 (plugin.optionsProcessorExtensionPoint as ExtensionPointImpl) | 537 (plugin.optionsProcessorExtensionPoint as ExtensionPointImpl) |
| 523 .add(processor); | 538 .add(processor); |
| 524 AnalysisContext context = engine.createAnalysisContext(); | 539 AnalysisContext context = engine.createAnalysisContext(); |
| 525 AnalysisOptions options = builder.getAnalysisOptions(context, path); | 540 AnalysisOptions options = builder.getAnalysisOptions(context, path); |
| 526 _expectEqualOptions(options, expected); | 541 _expectEqualOptions(options, expected); |
| 527 } finally { | 542 } finally { |
| 528 plugin.registerExtensionPoints((_) {}); | 543 plugin.registerExtensionPoints((_) {}); |
| 529 } | 544 } |
| 530 } | 545 } |
| 531 | 546 |
| 532 void test_getAnalysisOptions_invalid() { | 547 void test_getAnalysisOptions_invalid() { |
| 533 String path = '/some/directory/path'; | 548 String path = resourceProvider.convertPath('/some/directory/path'); |
| 534 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}'; | 549 String filePath = |
| 550 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); | |
| 535 resourceProvider.newFile(filePath, ';'); | 551 resourceProvider.newFile(filePath, ';'); |
| 536 | 552 |
| 537 AnalysisEngine engine = AnalysisEngine.instance; | 553 AnalysisEngine engine = AnalysisEngine.instance; |
| 538 OptionsPlugin plugin = engine.optionsPlugin; | 554 OptionsPlugin plugin = engine.optionsPlugin; |
| 539 plugin.registerExtensionPoints((_) {}); | 555 plugin.registerExtensionPoints((_) {}); |
| 540 try { | 556 try { |
| 541 _TestOptionsProcessor processor = new _TestOptionsProcessor(); | 557 _TestOptionsProcessor processor = new _TestOptionsProcessor(); |
| 542 (plugin.optionsProcessorExtensionPoint as ExtensionPointImpl) | 558 (plugin.optionsProcessorExtensionPoint as ExtensionPointImpl) |
| 543 .add(processor); | 559 .add(processor); |
| 544 AnalysisContext context = engine.createAnalysisContext(); | 560 AnalysisContext context = engine.createAnalysisContext(); |
| 545 AnalysisOptions options = builder.getAnalysisOptions(context, path); | 561 AnalysisOptions options = builder.getAnalysisOptions(context, path); |
| 546 expect(options, isNotNull); | 562 expect(options, isNotNull); |
| 547 expect(processor.errorCount, 1); | 563 expect(processor.errorCount, 1); |
| 548 } finally { | 564 } finally { |
| 549 plugin.registerExtensionPoints((_) {}); | 565 plugin.registerExtensionPoints((_) {}); |
| 550 } | 566 } |
| 551 } | 567 } |
| 552 | 568 |
| 553 void test_getAnalysisOptions_noDefault_noOverrides() { | 569 void test_getAnalysisOptions_noDefault_noOverrides() { |
| 554 String path = '/some/directory/path'; | 570 String path = resourceProvider.convertPath('/some/directory/path'); |
| 555 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}'; | 571 String filePath = |
| 572 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); | |
| 556 resourceProvider.newFile( | 573 resourceProvider.newFile( |
| 557 filePath, | 574 filePath, |
| 558 ''' | 575 ''' |
| 559 linter: | 576 linter: |
| 560 rules: | 577 rules: |
| 561 - empty_constructor_bodies | 578 - empty_constructor_bodies |
| 562 '''); | 579 '''); |
| 563 | 580 |
| 564 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); | 581 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); |
| 565 AnalysisOptions options = builder.getAnalysisOptions(context, path); | 582 AnalysisOptions options = builder.getAnalysisOptions(context, path); |
| 566 _expectEqualOptions(options, new AnalysisOptionsImpl()); | 583 _expectEqualOptions(options, new AnalysisOptionsImpl()); |
| 567 } | 584 } |
| 568 | 585 |
| 569 void test_getAnalysisOptions_noDefault_overrides() { | 586 void test_getAnalysisOptions_noDefault_overrides() { |
| 570 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); | 587 AnalysisOptionsImpl expected = new AnalysisOptionsImpl(); |
| 571 expected.enableSuperMixins = true; | 588 expected.enableSuperMixins = true; |
| 572 String path = '/some/directory/path'; | 589 String path = resourceProvider.convertPath('/some/directory/path'); |
| 573 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}'; | 590 String filePath = |
| 591 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); | |
| 574 resourceProvider.newFile( | 592 resourceProvider.newFile( |
| 575 filePath, | 593 filePath, |
| 576 ''' | 594 ''' |
| 577 analyzer: | 595 analyzer: |
| 578 language: | 596 language: |
| 579 enableSuperMixins : true | 597 enableSuperMixins : true |
| 580 '''); | 598 '''); |
| 581 | 599 |
| 582 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); | 600 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); |
| 583 AnalysisOptions options = builder.getAnalysisOptions(context, path); | 601 AnalysisOptions options = builder.getAnalysisOptions(context, path); |
| 584 _expectEqualOptions(options, expected); | 602 _expectEqualOptions(options, expected); |
| 585 } | 603 } |
| 586 | 604 |
| 587 void test_getOptionsFile_explicit() { | 605 void test_getOptionsFile_explicit() { |
| 588 String path = '/some/directory/path'; | 606 String path = resourceProvider.convertPath('/some/directory/path'); |
| 589 String filePath = '/options/analysis.yaml'; | 607 String filePath = resourceProvider.convertPath('/options/analysis.yaml'); |
| 590 resourceProvider.newFile(filePath, ''); | 608 resourceProvider.newFile(filePath, ''); |
| 591 | 609 |
| 592 builder.defaultAnalysisOptionsFilePath = filePath; | 610 builder.defaultAnalysisOptionsFilePath = filePath; |
| 593 File result = builder.getOptionsFile(path); | 611 File result = builder.getOptionsFile(path); |
| 594 expect(result, isNotNull); | 612 expect(result, isNotNull); |
| 595 expect(result.path, filePath); | 613 expect(result.path, filePath); |
| 596 } | 614 } |
| 597 | 615 |
| 598 void test_getOptionsFile_inParentOfRoot_new() { | 616 void test_getOptionsFile_inParentOfRoot_new() { |
| 599 String parentPath = '/some/directory'; | 617 String parentPath = resourceProvider.convertPath('/some/directory'); |
| 600 String path = '$parentPath/path'; | 618 String path = pathContext.join(parentPath, 'path'); |
| 601 String filePath = | 619 String filePath = |
| 602 '$parentPath/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}'; | 620 pathContext.join(parentPath, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); |
| 603 resourceProvider.newFile(filePath, ''); | 621 resourceProvider.newFile(filePath, ''); |
| 604 | 622 |
| 605 File result = builder.getOptionsFile(path); | 623 File result = builder.getOptionsFile(path); |
| 606 expect(result, isNotNull); | 624 expect(result, isNotNull); |
| 607 expect(result.path, filePath); | 625 expect(result.path, filePath); |
| 608 } | 626 } |
| 609 | 627 |
| 610 void test_getOptionsFile_inParentOfRoot_old() { | 628 void test_getOptionsFile_inParentOfRoot_old() { |
| 611 String parentPath = '/some/directory'; | 629 String parentPath = resourceProvider.convertPath('/some/directory'); |
| 612 String path = '$parentPath/path'; | 630 String path = pathContext.join(parentPath, 'path'); |
| 613 String filePath = '$parentPath/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}'; | 631 String filePath = |
| 632 pathContext.join(parentPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE); | |
| 614 resourceProvider.newFile(filePath, ''); | 633 resourceProvider.newFile(filePath, ''); |
| 615 | 634 |
| 616 File result = builder.getOptionsFile(path); | 635 File result = builder.getOptionsFile(path); |
| 617 expect(result, isNotNull); | 636 expect(result, isNotNull); |
| 618 expect(result.path, filePath); | 637 expect(result.path, filePath); |
| 619 } | 638 } |
| 620 | 639 |
| 621 void test_getOptionsFile_inRoot_new() { | 640 void test_getOptionsFile_inRoot_new() { |
| 622 String path = '/some/directory/path'; | 641 String path = resourceProvider.convertPath('/some/directory/path'); |
| 623 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE}'; | 642 String filePath = |
| 643 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE); | |
| 624 resourceProvider.newFile(filePath, ''); | 644 resourceProvider.newFile(filePath, ''); |
| 625 | 645 |
| 626 File result = builder.getOptionsFile(path); | 646 File result = builder.getOptionsFile(path); |
| 627 expect(result, isNotNull); | 647 expect(result, isNotNull); |
| 628 expect(result.path, filePath); | 648 expect(result.path, filePath); |
| 629 } | 649 } |
| 630 | 650 |
| 631 void test_getOptionsFile_inRoot_old() { | 651 void test_getOptionsFile_inRoot_old() { |
| 632 String path = '/some/directory/path'; | 652 String path = resourceProvider.convertPath('/some/directory/path'); |
| 633 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}'; | 653 String filePath = |
| 654 pathContext.join(path, AnalysisEngine.ANALYSIS_OPTIONS_FILE); | |
| 634 resourceProvider.newFile(filePath, ''); | 655 resourceProvider.newFile(filePath, ''); |
| 635 | 656 |
| 636 File result = builder.getOptionsFile(path); | 657 File result = builder.getOptionsFile(path); |
| 637 expect(result, isNotNull); | 658 expect(result, isNotNull); |
| 638 expect(result.path, filePath); | 659 expect(result.path, filePath); |
| 639 } | 660 } |
| 640 | 661 |
| 641 void _expectEqualOptions( | 662 void _expectEqualOptions( |
| 642 AnalysisOptionsImpl actual, AnalysisOptionsImpl expected) { | 663 AnalysisOptionsImpl actual, AnalysisOptionsImpl expected) { |
| 643 // TODO(brianwilkerson) Consider moving this to AnalysisOptionsImpl.==. | 664 // TODO(brianwilkerson) Consider moving this to AnalysisOptionsImpl.==. |
| 644 expect(actual.analyzeFunctionBodiesPredicate, | 665 expect(actual.analyzeFunctionBodiesPredicate, |
| 645 same(expected.analyzeFunctionBodiesPredicate)); | 666 same(expected.analyzeFunctionBodiesPredicate)); |
| 646 expect(actual.cacheSize, expected.cacheSize); | |
| 647 expect(actual.dart2jsHint, expected.dart2jsHint); | 667 expect(actual.dart2jsHint, expected.dart2jsHint); |
| 648 expect(actual.enableAssertMessage, expected.enableAssertMessage); | 668 expect(actual.enableAssertMessage, expected.enableAssertMessage); |
| 649 expect(actual.enableStrictCallChecks, expected.enableStrictCallChecks); | 669 expect(actual.enableStrictCallChecks, expected.enableStrictCallChecks); |
| 650 expect(actual.enableGenericMethods, expected.enableGenericMethods); | 670 expect(actual.enableGenericMethods, expected.enableGenericMethods); |
| 651 expect(actual.enableSuperMixins, expected.enableSuperMixins); | 671 expect(actual.enableSuperMixins, expected.enableSuperMixins); |
| 652 expect(actual.enableTiming, expected.enableTiming); | 672 expect(actual.enableTiming, expected.enableTiming); |
| 653 expect(actual.generateImplicitErrors, expected.generateImplicitErrors); | 673 expect(actual.generateImplicitErrors, expected.generateImplicitErrors); |
| 654 expect(actual.generateSdkErrors, expected.generateSdkErrors); | 674 expect(actual.generateSdkErrors, expected.generateSdkErrors); |
| 655 expect(actual.hint, expected.hint); | 675 expect(actual.hint, expected.hint); |
| 656 expect(actual.incremental, expected.incremental); | 676 expect(actual.incremental, expected.incremental); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 712 fail('Unexpected invocation of optionsProcessed'); | 732 fail('Unexpected invocation of optionsProcessed'); |
| 713 } | 733 } |
| 714 expect(options, hasLength(expectedOptions.length)); | 734 expect(options, hasLength(expectedOptions.length)); |
| 715 for (String key in expectedOptions.keys) { | 735 for (String key in expectedOptions.keys) { |
| 716 expect(options.containsKey(key), isTrue, reason: 'missing key $key'); | 736 expect(options.containsKey(key), isTrue, reason: 'missing key $key'); |
| 717 expect(options[key], expectedOptions[key], | 737 expect(options[key], expectedOptions[key], |
| 718 reason: 'values for key $key do not match'); | 738 reason: 'values for key $key do not match'); |
| 719 } | 739 } |
| 720 } | 740 } |
| 721 } | 741 } |
| OLD | NEW |