| 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:core' hide Resource; | 8 import 'dart:core' hide Resource; |
| 9 import 'dart:io' as io; | 9 import 'dart:io' as io; |
| 10 | 10 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 Map result2 = { | 38 Map result2 = { |
| 39 'packages': {'bar': '/tmp/proj2/packages/bar'}, | 39 'packages': {'bar': '/tmp/proj2/packages/bar'}, |
| 40 'input_files': ['/tmp/proj2/pubspec.yaml'] | 40 'input_files': ['/tmp/proj2/pubspec.yaml'] |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 Folder newProj(Map result) { | 43 Folder newProj(Map result) { |
| 44 Map packages = result['packages']; | 44 Map packages = result['packages']; |
| 45 packages.forEach((String name, String path) { | 45 packages.forEach((String name, String path) { |
| 46 resProvider.newFolder(path); | 46 resProvider.newFolder(path); |
| 47 }); | 47 }); |
| 48 List<String> inputFiles = result['input_files']; | 48 List<String> inputFiles = result['input_files'] as List<String>; |
| 49 for (String path in inputFiles) { | 49 for (String path in inputFiles) { |
| 50 resProvider.newFile(path, ''); | 50 resProvider.newFile(path, ''); |
| 51 } | 51 } |
| 52 Folder projectFolder = resProvider.getResource(inputFiles[0]).parent; | 52 Folder projectFolder = resProvider.getResource(inputFiles[0]).parent; |
| 53 resProvider.newFile(projectFolder.path + '/pubspec.lock', ''); | 53 resProvider.newFile(projectFolder.path + '/pubspec.lock', ''); |
| 54 return projectFolder; | 54 return projectFolder; |
| 55 } | 55 } |
| 56 | 56 |
| 57 int mockWriteFile(File cacheFile, String content) { | 57 int mockWriteFile(File cacheFile, String content) { |
| 58 if (writeFileException) { | 58 if (writeFileException) { |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 PackageMapInfo info = pkgProvider.computePackageMap(folder1); | 275 PackageMapInfo info = pkgProvider.computePackageMap(folder1); |
| 276 expect(mockRunner.runCount, 2); | 276 expect(mockRunner.runCount, 2); |
| 277 _assertInfo(info, result1); | 277 _assertInfo(info, result1); |
| 278 }); | 278 }); |
| 279 }); | 279 }); |
| 280 }); | 280 }); |
| 281 } | 281 } |
| 282 | 282 |
| 283 _assertError(PackageMapInfo info, Map expected) { | 283 _assertError(PackageMapInfo info, Map expected) { |
| 284 expect(info.packageMap, isNull); | 284 expect(info.packageMap, isNull); |
| 285 List<String> expectedFiles = expected['input_files']; | 285 List<String> expectedFiles = expected['input_files'] as List<String>; |
| 286 expect(info.dependencies, hasLength(expectedFiles.length)); | 286 expect(info.dependencies, hasLength(expectedFiles.length)); |
| 287 for (String path in expectedFiles) { | 287 for (String path in expectedFiles) { |
| 288 expect(info.dependencies, contains(path)); | 288 expect(info.dependencies, contains(path)); |
| 289 } | 289 } |
| 290 } | 290 } |
| 291 | 291 |
| 292 _assertInfo(PackageMapInfo info, Map expected) { | 292 _assertInfo(PackageMapInfo info, Map expected) { |
| 293 Map<String, String> expectedPackages = expected['packages']; | 293 Map<String, String> expectedPackages = |
| 294 expected['packages'] as Map<String, String>; |
| 294 expect(info.packageMap, hasLength(expectedPackages.length)); | 295 expect(info.packageMap, hasLength(expectedPackages.length)); |
| 295 for (String key in expectedPackages.keys) { | 296 for (String key in expectedPackages.keys) { |
| 296 List<Folder> packageList = info.packageMap[key]; | 297 List<Folder> packageList = info.packageMap[key]; |
| 297 expect(packageList, hasLength(1)); | 298 expect(packageList, hasLength(1)); |
| 298 expect(packageList[0].path, expectedPackages[key]); | 299 expect(packageList[0].path, expectedPackages[key]); |
| 299 } | 300 } |
| 300 List<String> expectedFiles = expected['input_files']; | 301 List<String> expectedFiles = expected['input_files'] as List<String>; |
| 301 expect(info.dependencies, hasLength(expectedFiles.length)); | 302 expect(info.dependencies, hasLength(expectedFiles.length)); |
| 302 for (String path in expectedFiles) { | 303 for (String path in expectedFiles) { |
| 303 expect(info.dependencies, contains(path)); | 304 expect(info.dependencies, contains(path)); |
| 304 } | 305 } |
| 305 } | 306 } |
| 306 | 307 |
| 307 typedef String MockResultFunction(); | 308 typedef String MockResultFunction(); |
| 308 | 309 |
| 309 /** | 310 /** |
| 310 * Mock for simulating and tracking execution of pub list | 311 * Mock for simulating and tracking execution of pub list |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 provider.newFolder(path); | 394 provider.newFolder(path); |
| 394 } | 395 } |
| 395 int fileCount = _filePaths.length; | 396 int fileCount = _filePaths.length; |
| 396 for (int fileIndex = 0; fileIndex < fileCount; ++fileIndex) { | 397 for (int fileIndex = 0; fileIndex < fileCount; ++fileIndex) { |
| 397 String path = _filePaths[fileIndex]; | 398 String path = _filePaths[fileIndex]; |
| 398 TimestampedData content = _fileContents[fileIndex]; | 399 TimestampedData content = _fileContents[fileIndex]; |
| 399 provider.newFile(path, content.data, content.modificationTime); | 400 provider.newFile(path, content.data, content.modificationTime); |
| 400 } | 401 } |
| 401 } | 402 } |
| 402 } | 403 } |
| OLD | NEW |