| 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/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
| 8 | 8 |
| 9 import 'package:dev_compiler/src/checker/dart_sdk.dart' | 9 import 'package:dev_compiler/src/checker/dart_sdk.dart' |
| 10 show mockSdkSources, dartSdkDirectory; | 10 show mockSdkSources, dartSdkDirectory; |
| 11 import 'package:dev_compiler/src/testing.dart'; | 11 import 'package:dev_compiler/src/in_memory.dart'; |
| 12 import 'package:dev_compiler/src/options.dart'; | 12 import 'package:dev_compiler/src/options.dart'; |
| 13 import 'package:dev_compiler/src/checker/resolver.dart'; | 13 import 'package:dev_compiler/src/checker/resolver.dart'; |
| 14 import 'package:dev_compiler/src/dependency_graph.dart'; | 14 import 'package:dev_compiler/src/dependency_graph.dart'; |
| 15 import 'package:dev_compiler/src/report.dart'; | 15 import 'package:dev_compiler/src/report.dart'; |
| 16 import 'package:path/path.dart' as path; | 16 import 'package:path/path.dart' as path; |
| 17 | 17 |
| 18 import 'test_util.dart'; | 18 import 'test_util.dart'; |
| 19 | 19 |
| 20 void main() { | 20 void main() { |
| 21 configureTest(); | 21 configureTest(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 '/a8.dart': 'library a8; import "a8.dart";', | 54 '/a8.dart': 'library a8; import "a8.dart";', |
| 55 '/a9.dart': 'library a9; import "a8.dart";', | 55 '/a9.dart': 'library a9; import "a8.dart";', |
| 56 '/a10.dart': 'library a10;', | 56 '/a10.dart': 'library a10;', |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 nodeOf(String filepath) => graph.nodeFromUri(new Uri.file(filepath)); | 59 nodeOf(String filepath) => graph.nodeFromUri(new Uri.file(filepath)); |
| 60 | 60 |
| 61 setUp(() { | 61 setUp(() { |
| 62 /// We completely reset the TestUriResolver to avoid interference between | 62 /// We completely reset the TestUriResolver to avoid interference between |
| 63 /// tests (since some tests modify the state of the files). | 63 /// tests (since some tests modify the state of the files). |
| 64 testUriResolver = new TestUriResolver(testFiles); | 64 testUriResolver = new InMemoryUriResolver(testFiles); |
| 65 context = new TypeResolver.fromMock(mockSdkSources, options, | 65 context = new TypeResolver.fromMock(mockSdkSources, options, |
| 66 otherResolvers: [testUriResolver]).context; | 66 otherResolvers: [testUriResolver]).context; |
| 67 graph = new SourceGraph(context, new LogReporter(), options); | 67 graph = new SourceGraph(context, new LogReporter(), options); |
| 68 }); | 68 }); |
| 69 | 69 |
| 70 group('HTML deps', () { | 70 group('HTML deps', () { |
| 71 test('initial deps', () { | 71 test('initial deps', () { |
| 72 var i1 = nodeOf('/index1.html'); | 72 var i1 = nodeOf('/index1.html'); |
| 73 var i2 = nodeOf('/index2.html'); | 73 var i2 = nodeOf('/index2.html'); |
| 74 expect(i1.scripts.length, 0); | 74 expect(i1.scripts.length, 0); |
| (...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1102 source.contents.data = "hi"; | 1102 source.contents.data = "hi"; |
| 1103 source.contents.modificationTime++; | 1103 source.contents.modificationTime++; |
| 1104 results = []; | 1104 results = []; |
| 1105 rebuild(node, graph, buildWithTransitiveChange); | 1105 rebuild(node, graph, buildWithTransitiveChange); |
| 1106 expect(results, ['bar.dart', 'foo.dart']); | 1106 expect(results, ['bar.dart', 'foo.dart']); |
| 1107 }); | 1107 }); |
| 1108 }); | 1108 }); |
| 1109 | 1109 |
| 1110 group('null for non-existing files', () { | 1110 group('null for non-existing files', () { |
| 1111 setUp(() { | 1111 setUp(() { |
| 1112 testUriResolver = | 1112 testUriResolver = new InMemoryUriResolver(testFiles, |
| 1113 new TestUriResolver(testFiles, representNonExistingFiles: false); | 1113 representNonExistingFiles: false); |
| 1114 context = new TypeResolver.fromMock(mockSdkSources, options, | 1114 context = new TypeResolver.fromMock(mockSdkSources, options, |
| 1115 otherResolvers: [testUriResolver]).context; | 1115 otherResolvers: [testUriResolver]).context; |
| 1116 graph = new SourceGraph(context, new LogReporter(), options); | 1116 graph = new SourceGraph(context, new LogReporter(), options); |
| 1117 }); | 1117 }); |
| 1118 | 1118 |
| 1119 test('recognize locally change between existing and not-existing', () { | 1119 test('recognize locally change between existing and not-existing', () { |
| 1120 var n = nodeOf('/foo.dart'); | 1120 var n = nodeOf('/foo.dart'); |
| 1121 expect(n.source, isNull); | 1121 expect(n.source, isNull); |
| 1122 var source = new TestSource(new Uri.file('/foo.dart'), "hi"); | 1122 var source = new InMemorySource(new Uri.file('/foo.dart'), "hi"); |
| 1123 testUriResolver.files[source.uri] = source; | 1123 testUriResolver.files[source.uri] = source; |
| 1124 expect(n.source, isNull); | 1124 expect(n.source, isNull); |
| 1125 n.update(graph); | 1125 n.update(graph); |
| 1126 expect(n.source, source); | 1126 expect(n.source, source); |
| 1127 expect(n.source.exists(), isTrue); | 1127 expect(n.source.exists(), isTrue); |
| 1128 expect(n.needsRebuild, isTrue); | 1128 expect(n.needsRebuild, isTrue); |
| 1129 }); | 1129 }); |
| 1130 | 1130 |
| 1131 test('non-existing files are tracked in dependencies', () { | 1131 test('non-existing files are tracked in dependencies', () { |
| 1132 var s1 = | 1132 var s1 = |
| 1133 new TestSource(new Uri.file('/foo.dart'), "import 'bar.dart';"); | 1133 new InMemorySource(new Uri.file('/foo.dart'), "import 'bar.dart';"); |
| 1134 testUriResolver.files[s1.uri] = s1; | 1134 testUriResolver.files[s1.uri] = s1; |
| 1135 var node = nodeOf('/foo.dart'); | 1135 var node = nodeOf('/foo.dart'); |
| 1136 rebuild(node, graph, buildNoTransitiveChange); | 1136 rebuild(node, graph, buildNoTransitiveChange); |
| 1137 expect(node.allDeps.length, 1); | 1137 expect(node.allDeps.length, 1); |
| 1138 expect(node.allDeps.contains(nodeOf('/bar.dart')), isTrue); | 1138 expect(node.allDeps.contains(nodeOf('/bar.dart')), isTrue); |
| 1139 expect(nodeOf('/bar.dart').source, isNull); | 1139 expect(nodeOf('/bar.dart').source, isNull); |
| 1140 | 1140 |
| 1141 var s2 = new TestSource(new Uri.file('/bar.dart'), "hi"); | 1141 var s2 = new InMemorySource(new Uri.file('/bar.dart'), "hi"); |
| 1142 testUriResolver.files[s2.uri] = s2; | 1142 testUriResolver.files[s2.uri] = s2; |
| 1143 results = []; | 1143 results = []; |
| 1144 rebuild(node, graph, buildWithTransitiveChange); | 1144 rebuild(node, graph, buildWithTransitiveChange); |
| 1145 expect(results, ['bar.dart', 'foo.dart']); | 1145 expect(results, ['bar.dart', 'foo.dart']); |
| 1146 }); | 1146 }); |
| 1147 }); | 1147 }); |
| 1148 }); | 1148 }); |
| 1149 } | 1149 } |
| 1150 | 1150 |
| 1151 expectGraph(SourceNode node, String expectation) { | 1151 expectGraph(SourceNode node, String expectation) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 } | 1192 } |
| 1193 | 1193 |
| 1194 final runtimeFilesWithoutPath = defaultRuntimeFiles | 1194 final runtimeFilesWithoutPath = defaultRuntimeFiles |
| 1195 .map((f) => f.replaceAll('dart/', '')) | 1195 .map((f) => f.replaceAll('dart/', '')) |
| 1196 .toList(growable: false); | 1196 .toList(growable: false); |
| 1197 final _RUNTIME_GRAPH = runtimeFilesWithoutPath.map((s) => '|-- $s').join('\n'); | 1197 final _RUNTIME_GRAPH = runtimeFilesWithoutPath.map((s) => '|-- $s').join('\n'); |
| 1198 final _RUNTIME_GRAPH_REBUILD = | 1198 final _RUNTIME_GRAPH_REBUILD = |
| 1199 runtimeFilesWithoutPath.map((s) => '|-- $s [needs-rebuild]').join('\n'); | 1199 runtimeFilesWithoutPath.map((s) => '|-- $s [needs-rebuild]').join('\n'); |
| 1200 | 1200 |
| 1201 bool _same(Set a, Set b) => a.length == b.length && a.containsAll(b); | 1201 bool _same(Set a, Set b) => a.length == b.length && a.containsAll(b); |
| OLD | NEW |