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 |
11 import 'package:analysis_server/src/source/caching_pub_package_map_provider.dart
'; | 11 import 'package:analysis_server/src/source/caching_pub_package_map_provider.dart
'; |
12 import 'package:analyzer/file_system/file_system.dart'; | 12 import 'package:analyzer/file_system/file_system.dart'; |
13 import 'package:analyzer/file_system/memory_file_system.dart'; | 13 import 'package:analyzer/file_system/memory_file_system.dart'; |
14 import 'package:analyzer/source/package_map_provider.dart'; | 14 import 'package:analyzer/source/package_map_provider.dart'; |
15 import 'package:analyzer/src/generated/engine.dart'; | 15 import 'package:analyzer/src/generated/engine.dart'; |
16 import 'package:analyzer/src/generated/sdk_io.dart'; | 16 import 'package:analyzer/src/generated/sdk_io.dart'; |
17 import 'package:unittest/unittest.dart'; | 17 import 'package:unittest/unittest.dart'; |
18 | 18 |
| 19 import '../utils.dart'; |
| 20 |
19 main() { | 21 main() { |
20 groupSep = ' | '; | 22 initializeTestEnvironment(); |
21 | 23 |
22 group('CachingPubPackageMapProvider', () { | 24 group('CachingPubPackageMapProvider', () { |
23 MemoryResourceProvider resProvider; | 25 MemoryResourceProvider resProvider; |
24 _MockPubListRunner mockRunner; | 26 _MockPubListRunner mockRunner; |
25 bool writeFileException; | 27 bool writeFileException; |
26 | 28 |
27 Map result1 = { | 29 Map result1 = { |
28 'packages': {'foo': '/tmp/proj1/packages/foo'}, | 30 'packages': {'foo': '/tmp/proj1/packages/foo'}, |
29 'input_files': ['/tmp/proj1/pubspec.yaml'] | 31 'input_files': ['/tmp/proj1/pubspec.yaml'] |
30 }; | 32 }; |
31 | 33 |
32 Map result1error = {'input_files': ['/tmp/proj1/pubspec.lock']}; | 34 Map result1error = { |
| 35 'input_files': ['/tmp/proj1/pubspec.lock'] |
| 36 }; |
33 | 37 |
34 Map result2 = { | 38 Map result2 = { |
35 'packages': {'bar': '/tmp/proj2/packages/bar'}, | 39 'packages': {'bar': '/tmp/proj2/packages/bar'}, |
36 'input_files': ['/tmp/proj2/pubspec.yaml'] | 40 'input_files': ['/tmp/proj2/pubspec.yaml'] |
37 }; | 41 }; |
38 | 42 |
39 Folder newProj(Map result) { | 43 Folder newProj(Map result) { |
40 Map packages = result['packages']; | 44 Map packages = result['packages']; |
41 packages.forEach((String name, String path) { | 45 packages.forEach((String name, String path) { |
42 resProvider.newFolder(path); | 46 resProvider.newFolder(path); |
(...skipping 16 matching lines...) Expand all Loading... |
59 resProvider.modifyFile(cacheFile.path, content); | 63 resProvider.modifyFile(cacheFile.path, content); |
60 } | 64 } |
61 Resource res = resProvider.getResource(cacheFile.path); | 65 Resource res = resProvider.getResource(cacheFile.path); |
62 if (res is File) { | 66 if (res is File) { |
63 return res.createSource().modificationStamp; | 67 return res.createSource().modificationStamp; |
64 } | 68 } |
65 throw 'expected file, but found $res'; | 69 throw 'expected file, but found $res'; |
66 } | 70 } |
67 | 71 |
68 CachingPubPackageMapProvider newPkgProvider() { | 72 CachingPubPackageMapProvider newPkgProvider() { |
69 return new CachingPubPackageMapProvider(resProvider, | 73 return new CachingPubPackageMapProvider( |
70 DirectoryBasedDartSdk.defaultSdk, mockRunner.runPubList, | 74 resProvider, |
| 75 DirectoryBasedDartSdk.defaultSdk, |
| 76 mockRunner.runPubList, |
71 mockWriteFile); | 77 mockWriteFile); |
72 } | 78 } |
73 | 79 |
74 setUp(() { | 80 setUp(() { |
75 resProvider = new MemoryResourceProvider(); | 81 resProvider = new MemoryResourceProvider(); |
76 resProvider.newFolder('/tmp/proj/packages/foo'); | 82 resProvider.newFolder('/tmp/proj/packages/foo'); |
77 mockRunner = new _MockPubListRunner(); | 83 mockRunner = new _MockPubListRunner(); |
78 writeFileException = false; | 84 writeFileException = false; |
79 }); | 85 }); |
80 | 86 |
81 group('computePackageMap', () { | 87 group('computePackageMap', () { |
82 | |
83 // Assert pub list called once and results are cached in memory | 88 // Assert pub list called once and results are cached in memory |
84 test('cache memory', () { | 89 test('cache memory', () { |
85 expect(mockRunner.runCount, 0); | 90 expect(mockRunner.runCount, 0); |
86 | 91 |
87 Folder folder1 = newProj(result1); | 92 Folder folder1 = newProj(result1); |
88 CachingPubPackageMapProvider pkgProvider = newPkgProvider(); | 93 CachingPubPackageMapProvider pkgProvider = newPkgProvider(); |
89 mockRunner.nextResult = JSON.encode(result1); | 94 mockRunner.nextResult = JSON.encode(result1); |
90 PackageMapInfo info = pkgProvider.computePackageMap(folder1); | 95 PackageMapInfo info = pkgProvider.computePackageMap(folder1); |
91 expect(mockRunner.runCount, 1); | 96 expect(mockRunner.runCount, 1); |
92 _assertInfo(info, result1); | 97 _assertInfo(info, result1); |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 provider.newFolder(path); | 391 provider.newFolder(path); |
387 } | 392 } |
388 int fileCount = _filePaths.length; | 393 int fileCount = _filePaths.length; |
389 for (int fileIndex = 0; fileIndex < fileCount; ++fileIndex) { | 394 for (int fileIndex = 0; fileIndex < fileCount; ++fileIndex) { |
390 String path = _filePaths[fileIndex]; | 395 String path = _filePaths[fileIndex]; |
391 TimestampedData content = _fileContents[fileIndex]; | 396 TimestampedData content = _fileContents[fileIndex]; |
392 provider.newFile(path, content.data, content.modificationTime); | 397 provider.newFile(path, content.data, content.modificationTime); |
393 } | 398 } |
394 } | 399 } |
395 } | 400 } |
OLD | NEW |