| 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.source.caching_pub_package_map_provider; | 5 library test.source.caching_pub_package_map_provider; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 import 'dart:io' as io; | 8 import 'dart:io' as io; |
| 9 | 9 |
| 10 import 'package:analysis_server/src/source/caching_pub_package_map_provider.dart
'; | 10 import 'package:analysis_server/src/source/caching_pub_package_map_provider.dart
'; |
| 11 import 'package:analyzer/file_system/file_system.dart'; | 11 import 'package:analyzer/file_system/file_system.dart'; |
| 12 import 'package:analyzer/file_system/memory_file_system.dart'; | 12 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 13 import 'package:analyzer/source/package_map_provider.dart'; | 13 import 'package:analyzer/source/package_map_provider.dart'; |
| 14 import 'package:analyzer/src/generated/engine.dart'; | 14 import 'package:analyzer/src/generated/engine.dart'; |
| 15 import 'package:analyzer/src/generated/sdk_io.dart'; | 15 import 'package:analyzer/src/generated/sdk_io.dart'; |
| 16 import 'package:unittest/unittest.dart'; | 16 import 'package:unittest/unittest.dart'; |
| 17 | 17 |
| 18 main() { | 18 main() { |
| 19 groupSep = ' | '; | 19 groupSep = ' | '; |
| 20 | 20 |
| 21 group('CachingPubPackageMapProvider', () { | 21 group('CachingPubPackageMapProvider', () { |
| 22 MemoryResourceProvider resProvider; | 22 MemoryResourceProvider resProvider; |
| 23 _MockPubListRunner mockRunner; | 23 _MockPubListRunner mockRunner; |
| 24 bool writeFileException; | 24 bool writeFileException; |
| 25 | 25 |
| 26 Map result1 = { | 26 Map result1 = { |
| 27 'packages': { | 27 'packages': {'foo': '/tmp/proj1/packages/foo'}, |
| 28 'foo': '/tmp/proj1/packages/foo' | |
| 29 }, | |
| 30 'input_files': ['/tmp/proj1/pubspec.yaml'] | 28 'input_files': ['/tmp/proj1/pubspec.yaml'] |
| 31 }; | 29 }; |
| 32 | 30 |
| 33 Map result1error = { | 31 Map result1error = {'input_files': ['/tmp/proj1/pubspec.lock']}; |
| 34 'input_files': ['/tmp/proj1/pubspec.lock'] | |
| 35 }; | |
| 36 | 32 |
| 37 Map result2 = { | 33 Map result2 = { |
| 38 'packages': { | 34 'packages': {'bar': '/tmp/proj2/packages/bar'}, |
| 39 'bar': '/tmp/proj2/packages/bar' | |
| 40 }, | |
| 41 'input_files': ['/tmp/proj2/pubspec.yaml'] | 35 'input_files': ['/tmp/proj2/pubspec.yaml'] |
| 42 }; | 36 }; |
| 43 | 37 |
| 44 Folder newProj(Map result) { | 38 Folder newProj(Map result) { |
| 45 Map packages = result['packages']; | 39 Map packages = result['packages']; |
| 46 packages.forEach((String name, String path) { | 40 packages.forEach((String name, String path) { |
| 47 resProvider.newFolder(path); | 41 resProvider.newFolder(path); |
| 48 }); | 42 }); |
| 49 List<String> inputFiles = result['input_files']; | 43 List<String> inputFiles = result['input_files']; |
| 50 for (String path in inputFiles) { | 44 for (String path in inputFiles) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 64 resProvider.modifyFile(cacheFile.path, content); | 58 resProvider.modifyFile(cacheFile.path, content); |
| 65 } | 59 } |
| 66 Resource res = resProvider.getResource(cacheFile.path); | 60 Resource res = resProvider.getResource(cacheFile.path); |
| 67 if (res is File) { | 61 if (res is File) { |
| 68 return res.createSource().modificationStamp; | 62 return res.createSource().modificationStamp; |
| 69 } | 63 } |
| 70 throw 'expected file, but found $res'; | 64 throw 'expected file, but found $res'; |
| 71 } | 65 } |
| 72 | 66 |
| 73 CachingPubPackageMapProvider newPkgProvider() { | 67 CachingPubPackageMapProvider newPkgProvider() { |
| 74 return new CachingPubPackageMapProvider( | 68 return new CachingPubPackageMapProvider(resProvider, |
| 75 resProvider, | 69 DirectoryBasedDartSdk.defaultSdk, mockRunner.runPubList, |
| 76 DirectoryBasedDartSdk.defaultSdk, | |
| 77 mockRunner.runPubList, | |
| 78 mockWriteFile); | 70 mockWriteFile); |
| 79 } | 71 } |
| 80 | 72 |
| 81 setUp(() { | 73 setUp(() { |
| 82 resProvider = new MemoryResourceProvider(); | 74 resProvider = new MemoryResourceProvider(); |
| 83 resProvider.newFolder('/tmp/proj/packages/foo'); | 75 resProvider.newFolder('/tmp/proj/packages/foo'); |
| 84 mockRunner = new _MockPubListRunner(); | 76 mockRunner = new _MockPubListRunner(); |
| 85 writeFileException = false; | 77 writeFileException = false; |
| 86 }); | 78 }); |
| 87 | 79 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 expect(packageList, hasLength(1)); | 289 expect(packageList, hasLength(1)); |
| 298 expect(packageList[0].path, expectedPackages[key]); | 290 expect(packageList[0].path, expectedPackages[key]); |
| 299 } | 291 } |
| 300 List<String> expectedFiles = expected['input_files']; | 292 List<String> expectedFiles = expected['input_files']; |
| 301 expect(info.dependencies, hasLength(expectedFiles.length)); | 293 expect(info.dependencies, hasLength(expectedFiles.length)); |
| 302 for (String path in expectedFiles) { | 294 for (String path in expectedFiles) { |
| 303 expect(info.dependencies, contains(path)); | 295 expect(info.dependencies, contains(path)); |
| 304 } | 296 } |
| 305 } | 297 } |
| 306 | 298 |
| 307 | |
| 308 typedef String MockResultFunction(); | 299 typedef String MockResultFunction(); |
| 309 | 300 |
| 310 /** | 301 /** |
| 311 * Mock for simulating and tracking execution of pub list | 302 * Mock for simulating and tracking execution of pub list |
| 312 */ | 303 */ |
| 313 class _MockPubListRunner { | 304 class _MockPubListRunner { |
| 314 int runCount = 0; | 305 int runCount = 0; |
| 315 List nextResults = []; | 306 List nextResults = []; |
| 316 | 307 |
| 317 void set nextResult(String result) { | 308 void set nextResult(String result) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 provider.newFolder(path); | 385 provider.newFolder(path); |
| 395 } | 386 } |
| 396 int fileCount = _filePaths.length; | 387 int fileCount = _filePaths.length; |
| 397 for (int fileIndex = 0; fileIndex < fileCount; ++fileIndex) { | 388 for (int fileIndex = 0; fileIndex < fileCount; ++fileIndex) { |
| 398 String path = _filePaths[fileIndex]; | 389 String path = _filePaths[fileIndex]; |
| 399 TimestampedData content = _fileContents[fileIndex]; | 390 TimestampedData content = _fileContents[fileIndex]; |
| 400 provider.newFile(path, content.data, content.modificationTime); | 391 provider.newFile(path, content.data, content.modificationTime); |
| 401 } | 392 } |
| 402 } | 393 } |
| 403 } | 394 } |
| OLD | NEW |