| 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.optimizing_pub_package_map_provider; | 5 library test.source.optimizing_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/optimizing_pub_package_map_provider.d
art'; | 10 import 'package:analysis_server/src/source/optimizing_pub_package_map_provider.d
art'; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 90 } |
| 91 | 91 |
| 92 @reflectiveTest | 92 @reflectiveTest |
| 93 class OptimizingPubPackageMapProviderTest { | 93 class OptimizingPubPackageMapProviderTest { |
| 94 MemoryResourceProvider resourceProvider; | 94 MemoryResourceProvider resourceProvider; |
| 95 OptimizingPubPackageMapProvider provider; | 95 OptimizingPubPackageMapProvider provider; |
| 96 Folder projectFolder; | 96 Folder projectFolder; |
| 97 io.ProcessResult pubListResult; | 97 io.ProcessResult pubListResult; |
| 98 | 98 |
| 99 void setPubListError() { | 99 void setPubListError() { |
| 100 pubListResult = new io.ProcessResult(0, 1, '', 'ERROR'); | 100 pubListResult = new _MockProcessResult(0, 1, '', 'ERROR'); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void setPubListResult({Map<String, String> packages: const {}, | 103 void setPubListResult({Map<String, String> packages: const {}, |
| 104 List<String> input_files: const []}) { | 104 List<String> input_files: const []}) { |
| 105 pubListResult = new io.ProcessResult(0, 0, | 105 pubListResult = new _MockProcessResult(0, 0, |
| 106 JSON.encode({'packages': packages, 'input_files': input_files}), ''); | 106 JSON.encode({'packages': packages, 'input_files': input_files}), ''); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void setUp() { | 109 void setUp() { |
| 110 resourceProvider = new MemoryResourceProvider(); | 110 resourceProvider = new MemoryResourceProvider(); |
| 111 provider = new OptimizingPubPackageMapProvider( | 111 provider = new OptimizingPubPackageMapProvider( |
| 112 resourceProvider, null, _runPubList); | 112 resourceProvider, null, _runPubList); |
| 113 projectFolder = resourceProvider.newFolder('/my/proj'); | 113 projectFolder = resourceProvider.newFolder('/my/proj'); |
| 114 } | 114 } |
| 115 | 115 |
| 116 test_computePackageMap_noPreviousInfo() { | 116 test_computePackageMap_noPreviousInfo() { |
| 117 String dep = posix.join(projectFolder.path, 'dep'); | 117 String dep = posix.join(projectFolder.path, 'dep'); |
| 118 String pkgName = 'foo'; | 118 String pkgName = 'foo'; |
| 119 String pkgPath = '/pkg/foo'; | 119 String pkgPath = '/pkg/foo'; |
| 120 setPubListResult(packages: {pkgName: pkgPath}, input_files: [dep]); | 120 setPubListResult(packages: {pkgName: pkgPath}, input_files: [dep]); |
| 121 OptimizingPubPackageMapInfo info = | 121 OptimizingPubPackageMapInfo info = |
| 122 provider.computePackageMap(projectFolder); | 122 provider.computePackageMap(projectFolder); |
| 123 expect(info.dependencies, hasLength(1)); | 123 expect(info.dependencies, hasLength(1)); |
| 124 expect(info.dependencies, contains(dep)); | 124 expect(info.dependencies, contains(dep)); |
| 125 expect(info.packageMap, hasLength(1)); | 125 expect(info.packageMap, hasLength(1)); |
| 126 expect(info.packageMap, contains(pkgName)); | 126 expect(info.packageMap, contains(pkgName)); |
| 127 expect(info.packageMap[pkgName], hasLength(1)); | 127 expect(info.packageMap[pkgName], hasLength(1)); |
| 128 expect(info.packageMap[pkgName][0].path, pkgPath); | 128 expect(info.packageMap[pkgName][0].path, pkgPath); |
| 129 expect(info.modificationTimes, isEmpty); | 129 expect(info.modificationTimes, isEmpty); |
| 130 } | 130 } |
| 131 | 131 |
| 132 test_computePackageMap_noPreviousInfo_pubListError() { | 132 test_computePackageMap_noPreviousInfo_pubListError() { |
| 133 String pubspecLock = posix.join(projectFolder.path, 'pubspec.lock'); | 133 String pubspecLock = posix.join(projectFolder.path, 'pubspec.lock'); |
| 134 String pkgName = 'foo'; | |
| 135 String pkgPath = '/pkg/foo'; | |
| 136 setPubListError(); | 134 setPubListError(); |
| 137 OptimizingPubPackageMapInfo info = | 135 OptimizingPubPackageMapInfo info = |
| 138 provider.computePackageMap(projectFolder); | 136 provider.computePackageMap(projectFolder); |
| 139 expect(info.dependencies, hasLength(1)); | 137 expect(info.dependencies, hasLength(1)); |
| 140 expect(info.dependencies, contains(pubspecLock)); | 138 expect(info.dependencies, contains(pubspecLock)); |
| 141 expect(info.packageMap, isNull); | 139 expect(info.packageMap, isNull); |
| 142 expect(info.modificationTimes, isEmpty); | 140 expect(info.modificationTimes, isEmpty); |
| 143 } | 141 } |
| 144 | 142 |
| 145 test_computePackageMap_withPreviousInfo() { | 143 test_computePackageMap_withPreviousInfo() { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 expect(info2.modificationTimes, hasLength(1)); | 220 expect(info2.modificationTimes, hasLength(1)); |
| 223 expect(info2.modificationTimes, contains(dep)); | 221 expect(info2.modificationTimes, contains(dep)); |
| 224 expect(info2.modificationTimes[dep], timestamp); | 222 expect(info2.modificationTimes[dep], timestamp); |
| 225 } | 223 } |
| 226 | 224 |
| 227 io.ProcessResult _runPubList(Folder folder) { | 225 io.ProcessResult _runPubList(Folder folder) { |
| 228 expect(folder, projectFolder); | 226 expect(folder, projectFolder); |
| 229 return pubListResult; | 227 return pubListResult; |
| 230 } | 228 } |
| 231 } | 229 } |
| 230 |
| 231 class _MockProcessResult implements io.ProcessResult { |
| 232 @override |
| 233 final int pid; |
| 234 |
| 235 @override |
| 236 final int exitCode; |
| 237 |
| 238 @override |
| 239 final stdout; |
| 240 |
| 241 @override |
| 242 final stderr; |
| 243 |
| 244 _MockProcessResult(this.pid, this.exitCode, this.stdout, this.stderr); |
| 245 } |
| OLD | NEW |