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:analyzer/file_system/file_system.dart'; | 7 import 'package:analyzer/file_system/file_system.dart'; |
8 import 'package:analyzer/file_system/memory_file_system.dart'; | 8 import 'package:analyzer/file_system/memory_file_system.dart'; |
9 import 'package:analyzer/src/generated/source.dart'; | 9 import 'package:analyzer/src/generated/source.dart'; |
10 import 'package:test/test.dart'; | 10 import 'package:test/test.dart'; |
11 | 11 |
12 import 'package:dev_compiler/src/analysis_context.dart'; | 12 import 'package:dev_compiler/src/analysis_context.dart'; |
13 import 'package:dev_compiler/src/options.dart'; | 13 import 'package:dev_compiler/src/options.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:dev_compiler/src/testing.dart'; | 16 import 'package:dev_compiler/src/testing.dart'; |
17 import 'package:path/path.dart' as path; | 17 import 'package:path/path.dart' as path; |
18 | 18 |
19 void main() { | 19 void main() { |
20 var options = new CompilerOptions( | 20 var options = new CompilerOptions( |
21 runtimeDir: '/dev_compiler_runtime/', useMockSdk: true); | 21 runtimeDir: '/dev_compiler_runtime/', |
| 22 sourceOptions: new SourceResolverOptions(useMockSdk: true)); |
22 MemoryResourceProvider testResourceProvider; | 23 MemoryResourceProvider testResourceProvider; |
23 ResourceUriResolver testUriResolver; | 24 ResourceUriResolver testUriResolver; |
24 var context; | 25 var context; |
25 var graph; | 26 var graph; |
26 | 27 |
27 /// Initial values for test files | 28 /// Initial values for test files |
28 var testFiles = { | 29 var testFiles = { |
29 '/index1.html': ''' | 30 '/index1.html': ''' |
30 <script src="foo.js"></script> | 31 <script src="foo.js"></script> |
31 ''', | 32 ''', |
(...skipping 23 matching lines...) Expand all Loading... |
55 '/a10.dart': 'library a10;', | 56 '/a10.dart': 'library a10;', |
56 }; | 57 }; |
57 | 58 |
58 nodeOf(String filepath) => graph.nodeFromUri(new Uri.file(filepath)); | 59 nodeOf(String filepath) => graph.nodeFromUri(new Uri.file(filepath)); |
59 | 60 |
60 setUp(() { | 61 setUp(() { |
61 /// We completely reset the TestUriResolver to avoid interference between | 62 /// We completely reset the TestUriResolver to avoid interference between |
62 /// tests (since some tests modify the state of the files). | 63 /// tests (since some tests modify the state of the files). |
63 testResourceProvider = createTestResourceProvider(testFiles); | 64 testResourceProvider = createTestResourceProvider(testFiles); |
64 testUriResolver = new ResourceUriResolver(testResourceProvider); | 65 testUriResolver = new ResourceUriResolver(testResourceProvider); |
65 context = createAnalysisContext(options, fileResolvers: [testUriResolver]); | 66 context = createAnalysisContextWithSources( |
| 67 options.strongOptions, options.sourceOptions, |
| 68 fileResolvers: [testUriResolver]); |
66 graph = new SourceGraph(context, new LogReporter(context), options); | 69 graph = new SourceGraph(context, new LogReporter(context), options); |
67 }); | 70 }); |
68 | 71 |
69 updateFile(Source source, [String newContents]) { | 72 updateFile(Source source, [String newContents]) { |
70 var path = testResourceProvider.pathContext.fromUri(source.uri); | 73 var path = testResourceProvider.pathContext.fromUri(source.uri); |
71 if (newContents == null) newContents = source.contents.data; | 74 if (newContents == null) newContents = source.contents.data; |
72 testResourceProvider.updateFile(path, newContents); | 75 testResourceProvider.updateFile(path, newContents); |
73 } | 76 } |
74 | 77 |
75 group('HTML deps', () { | 78 group('HTML deps', () { |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 | | |-- a8.dart [needs-rebuild] [structure-changed] | 635 | | |-- a8.dart [needs-rebuild] [structure-changed] |
633 | | | |-- a8.dart... | 636 | | | |-- a8.dart... |
634 | |-- a6.dart (part) | 637 | |-- a6.dart (part) |
635 $_RUNTIME_GRAPH | 638 $_RUNTIME_GRAPH |
636 '''); | 639 '''); |
637 }); | 640 }); |
638 }); | 641 }); |
639 | 642 |
640 group('server-mode', () { | 643 group('server-mode', () { |
641 setUp(() { | 644 setUp(() { |
642 var options2 = new CompilerOptions( | 645 var opts = new CompilerOptions( |
643 runtimeDir: '/dev_compiler_runtime/', | 646 runtimeDir: '/dev_compiler_runtime/', |
644 useMockSdk: true, | 647 sourceOptions: new SourceResolverOptions(useMockSdk: true), |
645 serverMode: true); | 648 serverMode: true); |
646 context = | 649 context = createAnalysisContextWithSources( |
647 createAnalysisContext(options2, fileResolvers: [testUriResolver]); | 650 opts.strongOptions, opts.sourceOptions, |
648 graph = new SourceGraph(context, new LogReporter(context), options2); | 651 fileResolvers: [testUriResolver]); |
| 652 graph = new SourceGraph(context, new LogReporter(context), opts); |
649 }); | 653 }); |
650 | 654 |
651 test('messages widget is automatically included', () { | 655 test('messages widget is automatically included', () { |
652 var node = nodeOf('/index3.html'); | 656 var node = nodeOf('/index3.html'); |
653 expectGraph(node, ''' | 657 expectGraph(node, ''' |
654 index3.html | 658 index3.html |
655 $_RUNTIME_GRAPH | 659 $_RUNTIME_GRAPH |
656 |-- messages_widget.js | 660 |-- messages_widget.js |
657 |-- messages.css | 661 |-- messages.css |
658 '''); | 662 '''); |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 var source = nodeOf('/bar.dart').source; | 1083 var source = nodeOf('/bar.dart').source; |
1080 updateFile(source, "hi"); | 1084 updateFile(source, "hi"); |
1081 results = []; | 1085 results = []; |
1082 rebuild(node, buildWithTransitiveChange); | 1086 rebuild(node, buildWithTransitiveChange); |
1083 expect(results, ['bar.dart', 'foo.dart']); | 1087 expect(results, ['bar.dart', 'foo.dart']); |
1084 }); | 1088 }); |
1085 }); | 1089 }); |
1086 | 1090 |
1087 group('null for non-existing files', () { | 1091 group('null for non-existing files', () { |
1088 setUp(() { | 1092 setUp(() { |
1089 context = | 1093 context = createAnalysisContextWithSources( |
1090 createAnalysisContext(options, fileResolvers: [testUriResolver]); | 1094 options.strongOptions, options.sourceOptions, |
| 1095 fileResolvers: [testUriResolver]); |
1091 graph = new SourceGraph(context, new LogReporter(context), options); | 1096 graph = new SourceGraph(context, new LogReporter(context), options); |
1092 }); | 1097 }); |
1093 | 1098 |
1094 test('recognize locally change between existing and not-existing', () { | 1099 test('recognize locally change between existing and not-existing', () { |
1095 var n = nodeOf('/foo.dart'); | 1100 var n = nodeOf('/foo.dart'); |
1096 expect(n.source.exists(), isFalse); | 1101 expect(n.source.exists(), isFalse); |
1097 var source = | 1102 var source = |
1098 testResourceProvider.newFile('/foo.dart', 'hi').createSource(); | 1103 testResourceProvider.newFile('/foo.dart', 'hi').createSource(); |
1099 expect( | 1104 expect( |
1100 testUriResolver.resolveAbsolute(new Uri.file('/foo.dart')), source); | 1105 testUriResolver.resolveAbsolute(new Uri.file('/foo.dart')), source); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1163 helper(node); | 1168 helper(node); |
1164 return sb.toString(); | 1169 return sb.toString(); |
1165 } | 1170 } |
1166 | 1171 |
1167 final runtimeFilesWithoutPath = defaultRuntimeFiles | 1172 final runtimeFilesWithoutPath = defaultRuntimeFiles |
1168 .map((f) => f.replaceAll('dart/', '')) | 1173 .map((f) => f.replaceAll('dart/', '')) |
1169 .toList(growable: false); | 1174 .toList(growable: false); |
1170 final _RUNTIME_GRAPH = runtimeFilesWithoutPath.map((s) => '|-- $s').join('\n'); | 1175 final _RUNTIME_GRAPH = runtimeFilesWithoutPath.map((s) => '|-- $s').join('\n'); |
1171 final _RUNTIME_GRAPH_REBUILD = | 1176 final _RUNTIME_GRAPH_REBUILD = |
1172 runtimeFilesWithoutPath.map((s) => '|-- $s [needs-rebuild]').join('\n'); | 1177 runtimeFilesWithoutPath.map((s) => '|-- $s [needs-rebuild]').join('\n'); |
OLD | NEW |