Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: pkg/analysis_server/test/context_directory_manager_test.dart

Issue 332383006: Trigger re-analysis when a file changes on disk. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.context.directory.manager; 5 library test.context.directory.manager;
6 6
7 import 'mocks.dart'; 7 import 'mocks.dart';
8 import 'package:analysis_server/src/context_directory_manager.dart'; 8 import 'package:analysis_server/src/context_directory_manager.dart';
9 import 'package:analysis_server/src/resource.dart'; 9 import 'package:analysis_server/src/resource.dart';
10 import 'package:path/path.dart'; 10 import 'package:path/path.dart';
11 import 'package:unittest/unittest.dart'; 11 import 'package:unittest/unittest.dart';
12 import 'package:analyzer/src/generated/engine.dart'; 12 import 'package:analyzer/src/generated/engine.dart';
13 import 'package:analyzer/src/generated/source.dart'; 13 import 'package:analyzer/src/generated/source.dart';
14 14
15 class TestContextDirectoryManager extends ContextDirectoryManager { 15 class TestContextDirectoryManager extends ContextDirectoryManager {
16 TestContextDirectoryManager(MemoryResourceProvider provider) : super(provider) ; 16 TestContextDirectoryManager(MemoryResourceProvider provider) : super(provider) ;
17 17
18 /**
19 * Source of timestamps stored in [currentContextFilePaths]
Brian Wilkerson 2014/06/17 17:55:02 Missing period?
Paul Berry 2014/06/17 18:07:50 Done.
20 */
21 int now = 0;
22
18 final Set<String> currentContextPaths = new Set<String>(); 23 final Set<String> currentContextPaths = new Set<String>();
19 final Map<String, String> currentContextPubspecPaths = <String, String>{}; 24 final Map<String, String> currentContextPubspecPaths = <String, String>{};
20 final Map<String, Set<String>> currentContextFilePaths = <String, Set<String>> {}; 25
26 /**
27 * Map from context to (map from file path to timestamp of last event)
28 */
29 final Map<String, Map<String, int>> currentContextFilePaths = <String, Map<Str ing, int>>{};
21 30
22 @override 31 @override
23 void addContext(Folder folder, File pubspecFile) { 32 void addContext(Folder folder, File pubspecFile) {
24 String path = folder.path; 33 String path = folder.path;
25 currentContextPaths.add(path); 34 currentContextPaths.add(path);
26 currentContextPubspecPaths[path] = pubspecFile != null ? pubspecFile.path : null; 35 currentContextPubspecPaths[path] = pubspecFile != null ? pubspecFile.path : null;
27 currentContextFilePaths[path] = new Set<String>(); 36 currentContextFilePaths[path] = <String, int>{};
28 } 37 }
29 38
30 @override 39 @override
31 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { 40 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) {
32 Set<String> filePaths = currentContextFilePaths[contextFolder.path]; 41 Map<String, int> filePaths = currentContextFilePaths[contextFolder.path];
33 for (Source source in changeSet.addedSources) { 42 for (Source source in changeSet.addedSources) {
34 expect(filePaths, isNot(contains(source.fullName))); 43 expect(filePaths, isNot(contains(source.fullName)));
35 filePaths.add(source.fullName); 44 filePaths[source.fullName] = now;
36 } 45 }
37 for (Source source in changeSet.removedSources) { 46 for (Source source in changeSet.removedSources) {
38 expect(filePaths, contains(source.fullName)); 47 expect(filePaths, contains(source.fullName));
39 filePaths.remove(source.fullName); 48 filePaths.remove(source.fullName);
40 } 49 }
41 // TODO(paulberry): handle source.changedSources. 50 for (Source source in changeSet.changedSources) {
51 expect(filePaths, contains(source.fullName));
52 filePaths[source.fullName] = now;
53 }
42 } 54 }
43 55
44 @override 56 @override
45 void removeContext(Folder folder) { 57 void removeContext(Folder folder) {
46 String path = folder.path; 58 String path = folder.path;
47 currentContextPaths.remove(path); 59 currentContextPaths.remove(path);
48 currentContextPubspecPaths.remove(path); 60 currentContextPubspecPaths.remove(path);
49 currentContextFilePaths.remove(path); 61 currentContextFilePaths.remove(path);
50 } 62 }
51 } 63 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 }); 141 });
130 142
131 test('ignore files in packages dir', () { 143 test('ignore files in packages dir', () {
132 String projPath = '/my/proj'; 144 String projPath = '/my/proj';
133 provider.newFolder(projPath); 145 provider.newFolder(projPath);
134 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); 146 String pubspecPath = posix.join(projPath, 'pubspec.yaml');
135 provider.newFile(pubspecPath, 'pubspec'); 147 provider.newFile(pubspecPath, 'pubspec');
136 String filePath1 = posix.join(projPath, 'packages', 'file1.dart'); 148 String filePath1 = posix.join(projPath, 'packages', 'file1.dart');
137 provider.newFile(filePath1, 'contents'); 149 provider.newFile(filePath1, 'contents');
138 manager.setRoots(<String>[projPath], <String>[]); 150 manager.setRoots(<String>[projPath], <String>[]);
139 Set<String> filePaths = manager.currentContextFilePaths[projPath]; 151 Map<String, int> filePaths = manager.currentContextFilePaths[projPath];
140 expect(filePaths, hasLength(0)); 152 expect(filePaths, hasLength(0));
141 String filePath2 = posix.join(projPath, 'packages', 'file2.dart'); 153 String filePath2 = posix.join(projPath, 'packages', 'file2.dart');
142 provider.newFile(filePath2, 'contents'); 154 provider.newFile(filePath2, 'contents');
143 return pumpEventQueue().then((_) { 155 return pumpEventQueue().then((_) {
144 expect(filePaths, hasLength(0)); 156 expect(filePaths, hasLength(0));
145 }); 157 });
146 }); 158 });
147 159
148 group('detect context modifications', () { 160 group('detect context modifications', () {
149 String projPath; 161 String projPath;
150 162
151 setUp(() { 163 setUp(() {
152 projPath = '/my/proj'; 164 projPath = '/my/proj';
153 provider.newFolder(projPath); 165 provider.newFolder(projPath);
154 }); 166 });
155 167
156 test('Add file', () { 168 test('Add file', () {
157 manager.setRoots(<String>[projPath], <String>[]); 169 manager.setRoots(<String>[projPath], <String>[]);
158 Set<String> filePaths = manager.currentContextFilePaths[projPath]; 170 Map<String, int> filePaths = manager.currentContextFilePaths[projPath];
159 expect(filePaths, hasLength(0)); 171 expect(filePaths, hasLength(0));
160 String filePath = posix.join(projPath, 'foo.dart'); 172 String filePath = posix.join(projPath, 'foo.dart');
161 provider.newFile(filePath, 'contents'); 173 provider.newFile(filePath, 'contents');
162 return pumpEventQueue().then((_) { 174 return pumpEventQueue().then((_) {
163 expect(filePaths, hasLength(1)); 175 expect(filePaths, hasLength(1));
164 expect(filePaths, contains(filePath)); 176 expect(filePaths, contains(filePath));
165 }); 177 });
166 }); 178 });
167 179
168 test('Add file in subdirectory', () { 180 test('Add file in subdirectory', () {
169 manager.setRoots(<String>[projPath], <String>[]); 181 manager.setRoots(<String>[projPath], <String>[]);
170 Set<String> filePaths = manager.currentContextFilePaths[projPath]; 182 Map<String, int> filePaths = manager.currentContextFilePaths[projPath];
171 expect(filePaths, hasLength(0)); 183 expect(filePaths, hasLength(0));
172 String filePath = posix.join(projPath, 'foo', 'bar.dart'); 184 String filePath = posix.join(projPath, 'foo', 'bar.dart');
173 provider.newFile(filePath, 'contents'); 185 provider.newFile(filePath, 'contents');
174 return pumpEventQueue().then((_) { 186 return pumpEventQueue().then((_) {
175 expect(filePaths, hasLength(1)); 187 expect(filePaths, hasLength(1));
176 expect(filePaths, contains(filePath)); 188 expect(filePaths, contains(filePath));
177 }); 189 });
178 }); 190 });
179 191
180 test('Delete file', () { 192 test('Delete file', () {
181 String filePath = posix.join(projPath, 'foo.dart'); 193 String filePath = posix.join(projPath, 'foo.dart');
182 provider.newFile(filePath, 'contents'); 194 provider.newFile(filePath, 'contents');
183 manager.setRoots(<String>[projPath], <String>[]); 195 manager.setRoots(<String>[projPath], <String>[]);
184 Set<String> filePaths = manager.currentContextFilePaths[projPath]; 196 Map<String, int> filePaths = manager.currentContextFilePaths[projPath];
185 expect(filePaths, hasLength(1)); 197 expect(filePaths, hasLength(1));
186 expect(filePaths, contains(filePath)); 198 expect(filePaths, contains(filePath));
187 provider.deleteFile(filePath); 199 provider.deleteFile(filePath);
188 return pumpEventQueue().then((_) => expect(filePaths, hasLength(0))); 200 return pumpEventQueue().then((_) => expect(filePaths, hasLength(0)));
189 }); 201 });
202
203 test('Modify file', () {
204 String filePath = posix.join(projPath, 'foo.dart');
205 provider.newFile(filePath, 'contents');
206 manager.setRoots(<String>[projPath], <String>[]);
207 Map<String, int> filePaths = manager.currentContextFilePaths[projPath];
208 expect(filePaths, hasLength(1));
209 expect(filePaths, contains(filePath));
210 expect(filePaths[filePath], equals(manager.now));
211 manager.now++;
212 provider.modifyFile(filePath, 'new contents');
213 return pumpEventQueue().then((_) => expect(filePaths[filePath], equals(
214 manager.now)));
215 });
190 }); 216 });
191 }); 217 });
192 } 218 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/context_directory_manager.dart ('k') | pkg/analysis_server/test/domain_analysis_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698