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 dev_compiler.test.dependency_graph_test; | 5 library dev_compiler.test.dependency_graph_test; |
6 | 6 |
7 import 'package:unittest/compact_vm_config.dart'; | 7 import 'package:unittest/compact_vm_config.dart'; |
8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
9 | 9 |
10 import 'package:dev_compiler/src/checker/dart_sdk.dart' | 10 import 'package:dev_compiler/src/checker/dart_sdk.dart' |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 '/a3.dart': 'library a3;', | 48 '/a3.dart': 'library a3;', |
49 '/a4.dart': 'library a4; export "a10.dart";', | 49 '/a4.dart': 'library a4; export "a10.dart";', |
50 '/a5.dart': 'library a5;', | 50 '/a5.dart': 'library a5;', |
51 '/a6.dart': 'part of a2;', | 51 '/a6.dart': 'part of a2;', |
52 '/a7.dart': 'library a7;', | 52 '/a7.dart': 'library a7;', |
53 '/a8.dart': 'library a8; import "a8.dart";', | 53 '/a8.dart': 'library a8; import "a8.dart";', |
54 '/a9.dart': 'library a9; import "a8.dart";', | 54 '/a9.dart': 'library a9; import "a8.dart";', |
55 '/a10.dart': 'library a10;', | 55 '/a10.dart': 'library a10;', |
56 }; | 56 }; |
57 | 57 |
58 nodeOf(String filepath, [bool isPart = false]) => | 58 nodeOf(String filepath) => graph.nodeFromUri(new Uri.file(filepath)); |
59 graph.nodeFromUri(new Uri.file(filepath), isPart); | |
60 | 59 |
61 setUp(() { | 60 setUp(() { |
62 /// We completely reset the TestUriResolver to avoid interference between | 61 /// We completely reset the TestUriResolver to avoid interference between |
63 /// tests (since some tests modify the state of the files). | 62 /// tests (since some tests modify the state of the files). |
64 testUriResolver = new TestUriResolver(testFiles); | 63 testUriResolver = new TestUriResolver(testFiles); |
65 context = new TypeResolver.fromMock(mockSdkSources, options, | 64 context = new TypeResolver.fromMock(mockSdkSources, options, |
66 otherResolvers: [testUriResolver]).context; | 65 otherResolvers: [testUriResolver]).context; |
67 graph = new SourceGraph(context, options); | 66 graph = new SourceGraph(context, options); |
68 }); | 67 }); |
69 | 68 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 'import "a3.dart"; export "a7.dart"; part "a8.dart";'; | 190 'import "a3.dart"; export "a7.dart"; part "a8.dart";'; |
192 node.update(graph); | 191 node.update(graph); |
193 | 192 |
194 expect(node.imports.length, 1); | 193 expect(node.imports.length, 1); |
195 expect(node.exports.length, 1); | 194 expect(node.exports.length, 1); |
196 expect(node.parts.length, 1); | 195 expect(node.parts.length, 1); |
197 expect(node.imports.contains(nodeOf('/a3.dart')), isTrue); | 196 expect(node.imports.contains(nodeOf('/a3.dart')), isTrue); |
198 expect(node.exports.contains(nodeOf('/a7.dart')), isTrue); | 197 expect(node.exports.contains(nodeOf('/a7.dart')), isTrue); |
199 expect(node.parts.contains(nodeOf('/a8.dart')), isTrue); | 198 expect(node.parts.contains(nodeOf('/a8.dart')), isTrue); |
200 }); | 199 }); |
200 | |
201 test('change type', () { | |
Jennifer Messerly
2015/03/05 01:37:01
maybe "change part -> library"
Siggi Cherem (dart-lang)
2015/03/06 18:52:06
Done.
| |
202 var node = nodeOf('/a2.dart'); | |
203 node.update(graph); | |
204 expect(node.imports.length, 2); | |
205 expect(node.exports.length, 1); | |
206 expect(node.parts.length, 1); | |
207 expect(node.imports.contains(nodeOf('/a3.dart')), isTrue); | |
208 expect(node.imports.contains(nodeOf('/a4.dart')), isTrue); | |
209 expect(node.exports.contains(nodeOf('/a5.dart')), isTrue); | |
210 expect(node.parts.contains(nodeOf('/a6.dart')), isTrue); | |
211 | |
212 node.source.contents.modificationTime++; | |
213 node.source.contents.data = ''' | |
214 library a2; | |
215 import 'a3.dart'; | |
216 import 'a4.dart'; | |
217 export 'a5.dart'; | |
218 import 'a6.dart'; // changed from part | |
Jennifer Messerly
2015/03/05 01:37:01
do we have tests for both directions for changes?
Siggi Cherem (dart-lang)
2015/03/06 18:52:06
Added them now.
| |
219 '''; | |
220 var a6 = nodeOf('/a6.dart'); | |
221 a6.source.contents.modificationTime++; | |
222 a6.source.contents.data = ''; | |
223 node.update(graph); | |
224 | |
225 expect(node.imports.length, 3); | |
226 expect(node.exports.length, 1); | |
227 expect(node.parts.length, 0); | |
228 expect(node.imports.contains(nodeOf('/a3.dart')), isTrue); | |
229 expect(node.imports.contains(nodeOf('/a4.dart')), isTrue); | |
230 expect(node.imports.contains(nodeOf('/a6.dart')), isTrue); | |
231 expect(node.exports.contains(nodeOf('/a5.dart')), isTrue); | |
232 }); | |
201 }); | 233 }); |
202 | 234 |
203 group('local changes', () { | 235 group('local changes', () { |
204 group('needs rebuild', () { | 236 group('needs rebuild', () { |
205 test('in HTML', () { | 237 test('in HTML', () { |
206 var node = nodeOf('/index1.html'); | 238 var node = nodeOf('/index1.html'); |
207 node.update(graph); | 239 node.update(graph); |
208 expect(node.needsRebuild, isTrue); | 240 expect(node.needsRebuild, isTrue); |
209 node.needsRebuild = false; | 241 node.needsRebuild = false; |
210 | 242 |
211 node.update(graph); | 243 node.update(graph); |
212 expect(node.needsRebuild, isFalse); | 244 expect(node.needsRebuild, isFalse); |
213 | 245 |
214 // For now, an empty modification is enough to trigger a rebuild | 246 // For now, an empty modification is enough to trigger a rebuild |
215 node.source.contents.modificationTime++; | 247 node.source.contents.modificationTime++; |
216 expect(node.needsRebuild, isFalse); | 248 expect(node.needsRebuild, isFalse); |
217 node.update(graph); | 249 node.update(graph); |
218 expect(node.needsRebuild, isTrue); | 250 expect(node.needsRebuild, isTrue); |
219 }); | 251 }); |
220 | 252 |
221 test('main library in Dart', () { | 253 test('main library in Dart', () { |
222 var node = nodeOf('/a2.dart'); | 254 var node = nodeOf('/a2.dart'); |
223 var partNode = nodeOf('/a6.dart', true); | 255 var partNode = nodeOf('/a6.dart'); |
224 node.update(graph); | 256 node.update(graph); |
225 expect(node.needsRebuild, isTrue); | 257 expect(node.needsRebuild, isTrue); |
226 node.needsRebuild = false; | 258 node.needsRebuild = false; |
227 partNode.needsRebuild = false; | 259 partNode.needsRebuild = false; |
228 | 260 |
229 node.update(graph); | 261 node.update(graph); |
230 expect(node.needsRebuild, isFalse); | 262 expect(node.needsRebuild, isFalse); |
231 | 263 |
232 // For now, an empty modification is enough to trigger a rebuild | 264 // For now, an empty modification is enough to trigger a rebuild |
233 node.source.contents.modificationTime++; | 265 node.source.contents.modificationTime++; |
234 expect(node.needsRebuild, isFalse); | 266 expect(node.needsRebuild, isFalse); |
235 node.update(graph); | 267 node.update(graph); |
236 expect(node.needsRebuild, isTrue); | 268 expect(node.needsRebuild, isTrue); |
237 }); | 269 }); |
238 | 270 |
239 test('part of library in Dart', () { | 271 test('part of library in Dart', () { |
240 var node = nodeOf('/a2.dart'); | 272 var node = nodeOf('/a2.dart'); |
241 var importNode = nodeOf('/a3.dart'); | 273 var importNode = nodeOf('/a3.dart'); |
242 var exportNode = nodeOf('/a5.dart'); | 274 var exportNode = nodeOf('/a5.dart'); |
243 var partNode = nodeOf('/a6.dart', true); | 275 var partNode = nodeOf('/a6.dart'); |
244 node.update(graph); | 276 node.update(graph); |
245 expect(node.needsRebuild, isTrue); | 277 expect(node.needsRebuild, isTrue); |
246 node.needsRebuild = false; | 278 node.needsRebuild = false; |
247 partNode.needsRebuild = false; | 279 partNode.needsRebuild = false; |
248 | 280 |
249 node.update(graph); | 281 node.update(graph); |
250 expect(node.needsRebuild, isFalse); | 282 expect(node.needsRebuild, isFalse); |
251 | 283 |
252 // Modification in imported/exported node makes no difference for local | 284 // Modification in imported/exported node makes no difference for local |
253 // rebuild label (globally that's tested elsewhere) | 285 // rebuild label (globally that's tested elsewhere) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 expect(node.structureChanged, isFalse); | 340 expect(node.structureChanged, isFalse); |
309 node.update(graph); | 341 node.update(graph); |
310 expect(node.structureChanged, isTrue); | 342 expect(node.structureChanged, isTrue); |
311 expect(node.scripts.length, 2); | 343 expect(node.scripts.length, 2); |
312 }); | 344 }); |
313 | 345 |
314 test('no mod in Dart', () { | 346 test('no mod in Dart', () { |
315 var node = nodeOf('/a2.dart'); | 347 var node = nodeOf('/a2.dart'); |
316 var importNode = nodeOf('/a3.dart'); | 348 var importNode = nodeOf('/a3.dart'); |
317 var exportNode = nodeOf('/a5.dart'); | 349 var exportNode = nodeOf('/a5.dart'); |
318 var partNode = nodeOf('/a6.dart', true); | 350 var partNode = nodeOf('/a6.dart'); |
319 node.update(graph); | 351 node.update(graph); |
320 expect(node.structureChanged, isTrue); | 352 expect(node.structureChanged, isTrue); |
321 node.structureChanged = false; | 353 node.structureChanged = false; |
322 | 354 |
323 node.update(graph); | 355 node.update(graph); |
324 expect(node.structureChanged, isFalse); | 356 expect(node.structureChanged, isFalse); |
325 | 357 |
326 // These modifications make no difference at all. | 358 // These modifications make no difference at all. |
327 importNode.source.contents.modificationTime++; | 359 importNode.source.contents.modificationTime++; |
328 exportNode.source.contents.modificationTime++; | 360 exportNode.source.contents.modificationTime++; |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
735 if (seen.contains(n)) { | 767 if (seen.contains(n)) { |
736 sb.write('...\n'); | 768 sb.write('...\n'); |
737 return; | 769 return; |
738 } | 770 } |
739 seen.add(n); | 771 seen.add(n); |
740 sb | 772 sb |
741 ..write(' ') | 773 ..write(' ') |
742 ..write(n.needsRebuild ? '[needs-rebuild] ' : '') | 774 ..write(n.needsRebuild ? '[needs-rebuild] ' : '') |
743 ..write(n.structureChanged ? '[structure-changed] ' : ' ') | 775 ..write(n.structureChanged ? '[structure-changed] ' : ' ') |
744 ..write('\n'); | 776 ..write('\n'); |
745 n.directDeps.forEach((e) => helper(e, indent: indent + 1)); | 777 n.allDeps.forEach((e) => helper(e, indent: indent + 1)); |
746 } | 778 } |
747 helper(node); | 779 helper(node); |
748 return sb.toString(); | 780 return sb.toString(); |
749 } | 781 } |
750 | 782 |
751 bool _same(Set a, Set b) => a.length == b.length && a.containsAll(b); | 783 bool _same(Set a, Set b) => a.length == b.length && a.containsAll(b); |
OLD | NEW |