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 'dart:io' as io; | 7 import 'dart:io' as io; |
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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 String rootPath = tempDir.path; | 227 String rootPath = tempDir.path; |
228 String projectPath = pathContext.join(rootPath, 'project'); | 228 String projectPath = pathContext.join(rootPath, 'project'); |
229 String packageFilePath = pathContext.join(projectPath, '.packages'); | 229 String packageFilePath = pathContext.join(projectPath, '.packages'); |
230 String packageA = pathContext.join(rootPath, 'pkgs', 'a'); | 230 String packageA = pathContext.join(rootPath, 'pkgs', 'a'); |
231 String embedderPath = pathContext.join(packageA, '_embedder.yaml'); | 231 String embedderPath = pathContext.join(packageA, '_embedder.yaml'); |
232 String packageB = pathContext.join(rootPath, 'pkgs', 'b'); | 232 String packageB = pathContext.join(rootPath, 'pkgs', 'b'); |
233 String extensionPath = pathContext.join(packageB, '_sdkext'); | 233 String extensionPath = pathContext.join(packageB, '_sdkext'); |
234 createFile( | 234 createFile( |
235 packageFilePath, | 235 packageFilePath, |
236 ''' | 236 ''' |
237 a:$packageA | 237 a:${pathContext.toUri(packageA)} |
238 b:$packageB | 238 b:${pathContext.toUri(packageB)} |
239 '''); | 239 '''); |
240 String asyncPath = pathContext.join(packageA, 'sdk', 'async.dart'); | 240 String asyncPath = pathContext.join(packageA, 'sdk', 'async.dart'); |
241 String corePath = pathContext.join(packageA, 'sdk', 'core.dart'); | 241 String corePath = pathContext.join(packageA, 'sdk', 'core.dart'); |
242 createFile( | 242 createFile( |
243 embedderPath, | 243 embedderPath, |
244 ''' | 244 ''' |
245 embedded_libs: | 245 embedded_libs: |
246 "dart:async": ${pathContext.relative(asyncPath, from: packageA)} | 246 "dart:async": ${_relativeUri(asyncPath, from: packageA)} |
247 "dart:core": ${pathContext.relative(corePath, from: packageA)} | 247 "dart:core": ${_relativeUri(corePath, from: packageA)} |
248 '''); | 248 '''); |
249 String fooPath = pathContext.join(packageB, 'ext', 'foo.dart'); | 249 String fooPath = pathContext.join(packageB, 'ext', 'foo.dart'); |
250 createFile( | 250 createFile( |
251 extensionPath, | 251 extensionPath, |
252 '''{ | 252 '''{ |
253 "dart:foo": "${pathContext.relative(fooPath, from: packageB)}" | 253 "dart:foo": "${_relativeUri(fooPath, from: packageB)}" |
254 }'''); | 254 }'''); |
255 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 255 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
256 | 256 |
257 SourceFactory factory = builder.createSourceFactory(projectPath, options); | 257 SourceFactory factory = builder.createSourceFactory(projectPath, options); |
258 | 258 |
259 Source asyncSource = factory.forUri('dart:async'); | 259 Source asyncSource = factory.forUri('dart:async'); |
260 expect(asyncSource, isNotNull); | 260 expect(asyncSource, isNotNull); |
261 expect(asyncSource.fullName, asyncPath); | 261 expect(asyncSource.fullName, asyncPath); |
262 | 262 |
263 Source fooSource = factory.forUri('dart:foo'); | 263 Source fooSource = factory.forUri('dart:foo'); |
264 expect(fooSource, isNotNull); | 264 expect(fooSource, isNotNull); |
265 expect(fooSource.fullName, fooPath); | 265 expect(fooSource.fullName, fooPath); |
266 | 266 |
267 Source packageSource = factory.forUri('package:b/b.dart'); | 267 Source packageSource = factory.forUri('package:b/b.dart'); |
268 expect(packageSource, isNotNull); | 268 expect(packageSource, isNotNull); |
269 expect(packageSource.fullName, '$packageB/b.dart'); | 269 expect(packageSource.fullName, pathContext.join(packageB, 'b.dart')); |
270 }); | 270 }); |
271 } | 271 } |
272 | 272 |
273 void test_createSourceFactory_noProvider_packages_embedder_noExtensions() { | 273 void test_createSourceFactory_noProvider_packages_embedder_noExtensions() { |
274 withTempDir((io.Directory tempDir) { | 274 withTempDir((io.Directory tempDir) { |
275 createDefaultSdk(tempDir); | 275 createDefaultSdk(tempDir); |
276 String rootPath = tempDir.path; | 276 String rootPath = tempDir.path; |
277 String projectPath = pathContext.join(rootPath, 'project'); | 277 String projectPath = pathContext.join(rootPath, 'project'); |
278 String packageFilePath = pathContext.join(projectPath, '.packages'); | 278 String packageFilePath = pathContext.join(projectPath, '.packages'); |
279 String packageA = pathContext.join(rootPath, 'pkgs', 'a'); | 279 String packageA = pathContext.join(rootPath, 'pkgs', 'a'); |
280 String embedderPath = pathContext.join(packageA, '_embedder.yaml'); | 280 String embedderPath = pathContext.join(packageA, '_embedder.yaml'); |
281 String packageB = pathContext.join(rootPath, 'pkgs', 'b'); | 281 String packageB = pathContext.join(rootPath, 'pkgs', 'b'); |
282 createFile( | 282 createFile( |
283 packageFilePath, | 283 packageFilePath, |
284 ''' | 284 ''' |
285 a:$packageA | 285 a:${pathContext.toUri(packageA)} |
286 b:$packageB | 286 b:${pathContext.toUri(packageB)} |
287 '''); | 287 '''); |
288 String asyncPath = pathContext.join(packageA, 'sdk', 'async.dart'); | 288 String asyncPath = pathContext.join(packageA, 'sdk', 'async.dart'); |
289 String corePath = pathContext.join(packageA, 'sdk', 'core.dart'); | 289 String corePath = pathContext.join(packageA, 'sdk', 'core.dart'); |
290 createFile( | 290 createFile( |
291 embedderPath, | 291 embedderPath, |
292 ''' | 292 ''' |
293 embedded_libs: | 293 embedded_libs: |
294 "dart:async": ${pathContext.relative(asyncPath, from: packageA)} | 294 "dart:async": ${_relativeUri(asyncPath, from: packageA)} |
295 "dart:core": ${pathContext.relative(corePath, from: packageA)} | 295 "dart:core": ${_relativeUri(corePath, from: packageA)} |
296 '''); | 296 '''); |
297 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 297 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
298 | 298 |
299 SourceFactory factory = builder.createSourceFactory(projectPath, options); | 299 SourceFactory factory = builder.createSourceFactory(projectPath, options); |
300 | 300 |
301 Source dartSource = factory.forUri('dart:async'); | 301 Source dartSource = factory.forUri('dart:async'); |
302 expect(dartSource, isNotNull); | 302 expect(dartSource, isNotNull); |
303 expect(dartSource.fullName, asyncPath); | 303 expect(dartSource.fullName, asyncPath); |
304 | 304 |
305 Source packageSource = factory.forUri('package:b/b.dart'); | 305 Source packageSource = factory.forUri('package:b/b.dart'); |
306 expect(packageSource, isNotNull); | 306 expect(packageSource, isNotNull); |
307 expect(packageSource.fullName, '$packageB/b.dart'); | 307 expect(packageSource.fullName, pathContext.join(packageB, 'b.dart')); |
308 }); | 308 }); |
309 } | 309 } |
310 | 310 |
311 @failingTest | 311 @failingTest |
312 void test_createSourceFactory_noProvider_packages_noEmbedder_extensions() { | 312 void test_createSourceFactory_noProvider_packages_noEmbedder_extensions() { |
313 fail('Incomplete test'); | 313 fail('Incomplete test'); |
314 } | 314 } |
315 | 315 |
316 void test_createSourceFactory_noProvider_packages_noEmbedder_noExtensions() { | 316 void test_createSourceFactory_noProvider_packages_noEmbedder_noExtensions() { |
317 withTempDir((io.Directory tempDir) { | 317 withTempDir((io.Directory tempDir) { |
318 createDefaultSdk(tempDir); | 318 createDefaultSdk(tempDir); |
319 String rootPath = tempDir.path; | 319 String rootPath = tempDir.path; |
320 String projectPath = pathContext.join(rootPath, 'project'); | 320 String projectPath = pathContext.join(rootPath, 'project'); |
321 String packageFilePath = pathContext.join(projectPath, '.packages'); | 321 String packageFilePath = pathContext.join(projectPath, '.packages'); |
| 322 String packageA = pathContext.join(rootPath, 'pkgs', 'a'); |
| 323 String packageB = pathContext.join(rootPath, 'pkgs', 'b'); |
322 createFile( | 324 createFile( |
323 packageFilePath, | 325 packageFilePath, |
324 r''' | 326 ''' |
325 a:file:///pkgs/a | 327 a:${pathContext.toUri(packageA)} |
326 b:file:///pkgs/b | 328 b:${pathContext.toUri(packageB)} |
327 '''); | 329 '''); |
328 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 330 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
329 | 331 |
330 SourceFactory factory = builder.createSourceFactory(projectPath, options); | 332 SourceFactory factory = builder.createSourceFactory(projectPath, options); |
331 | 333 |
332 Source dartSource = factory.forUri('dart:core'); | 334 Source dartSource = factory.forUri('dart:core'); |
333 expect(dartSource, isNotNull); | 335 expect(dartSource, isNotNull); |
334 expect(dartSource.fullName, '$defaultSdkPath/lib/core/core.dart'); | 336 expect(dartSource.fullName, '$defaultSdkPath/lib/core/core.dart'); |
335 | 337 |
336 Source packageSource = factory.forUri('package:a/a.dart'); | 338 Source packageSource = factory.forUri('package:a/a.dart'); |
337 expect(packageSource, isNotNull); | 339 expect(packageSource, isNotNull); |
338 expect(packageSource.fullName, '/pkgs/a/a.dart'); | 340 expect(packageSource.fullName, pathContext.join(packageA, 'a.dart')); |
339 }); | 341 }); |
340 } | 342 } |
341 | 343 |
342 @failingTest | 344 @failingTest |
343 void test_createSourceFactory_provider() { | 345 void test_createSourceFactory_provider() { |
344 fail('Incomplete test'); | 346 fail('Incomplete test'); |
345 } | 347 } |
346 | 348 |
347 /** | 349 /** |
348 * Execute the [test] function with a temporary [directory]. The test function | 350 * Execute the [test] function with a temporary [directory]. The test function |
349 * can perform any disk operations within the directory and the directory (and | 351 * can perform any disk operations within the directory and the directory (and |
350 * its content) will be removed after the function returns. | 352 * its content) will be removed after the function returns. |
351 */ | 353 */ |
352 void withTempDir(test(io.Directory directory)) { | 354 void withTempDir(test(io.Directory directory)) { |
353 io.Directory directory = | 355 io.Directory directory = |
354 io.Directory.systemTemp.createTempSync('analyzer_'); | 356 io.Directory.systemTemp.createTempSync('analyzer_'); |
355 try { | 357 try { |
356 test(directory); | 358 test(directory); |
357 } finally { | 359 } finally { |
358 directory.deleteSync(recursive: true); | 360 directory.deleteSync(recursive: true); |
359 } | 361 } |
360 } | 362 } |
| 363 |
| 364 Uri _relativeUri(String path, {String from}) { |
| 365 String relativePath = pathContext.relative(path, from: from); |
| 366 return pathContext.toUri(relativePath); |
| 367 } |
361 } | 368 } |
362 | 369 |
363 @reflectiveTest | 370 @reflectiveTest |
364 class ContextBuilderTest_WithoutDisk extends EngineTestCase { | 371 class ContextBuilderTest_WithoutDisk extends EngineTestCase { |
365 /** | 372 /** |
366 * The resource provider to be used by tests. | 373 * The resource provider to be used by tests. |
367 */ | 374 */ |
368 MemoryResourceProvider resourceProvider; | 375 MemoryResourceProvider resourceProvider; |
369 | 376 |
370 /** | 377 /** |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 void test_getOptionsFile_inRoot_old() { | 475 void test_getOptionsFile_inRoot_old() { |
469 String path = '/some/directory/path'; | 476 String path = '/some/directory/path'; |
470 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}'; | 477 String filePath = '$path/${AnalysisEngine.ANALYSIS_OPTIONS_FILE}'; |
471 resourceProvider.newFile(filePath, ''); | 478 resourceProvider.newFile(filePath, ''); |
472 | 479 |
473 File result = builder.getOptionsFile(path); | 480 File result = builder.getOptionsFile(path); |
474 expect(result, isNotNull); | 481 expect(result, isNotNull); |
475 expect(result.path, filePath); | 482 expect(result.path, filePath); |
476 } | 483 } |
477 } | 484 } |
OLD | NEW |