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

Side by Side Diff: test/dependency_graph_test.dart

Issue 1143683002: cleanup: simplify creation of AnalysisContext (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 7 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
« lib/src/options.dart ('K') | « lib/src/testing.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
11 11
12 import 'package:dev_compiler/src/checker/dart_sdk.dart' 12 import 'package:dev_compiler/src/analysis_context.dart';
13 show mockSdkSources, dartSdkDirectory;
14 import 'package:dev_compiler/src/options.dart'; 13 import 'package:dev_compiler/src/options.dart';
15 import 'package:dev_compiler/src/checker/resolver.dart';
16 import 'package:dev_compiler/src/dependency_graph.dart'; 14 import 'package:dev_compiler/src/dependency_graph.dart';
17 import 'package:dev_compiler/src/report.dart'; 15 import 'package:dev_compiler/src/report.dart';
18 import 'package:dev_compiler/src/testing.dart'; 16 import 'package:dev_compiler/src/testing.dart';
19 import 'package:path/path.dart' as path; 17 import 'package:path/path.dart' as path;
20 18
21 import 'test_util.dart'; 19 import 'test_util.dart';
22 20
23 void main() { 21 void main() {
24 configureTest(); 22 configureTest();
25 23
26 var options = new CompilerOptions(runtimeDir: '/dev_compiler_runtime/'); 24 var options = new CompilerOptions(
25 runtimeDir: '/dev_compiler_runtime/', useMockSdk: true);
27 MemoryResourceProvider testResourceProvider; 26 MemoryResourceProvider testResourceProvider;
28 ResourceUriResolver testUriResolver; 27 ResourceUriResolver testUriResolver;
29 var context; 28 var context;
30 var graph; 29 var graph;
31 30
32 /// Initial values for test files 31 /// Initial values for test files
33 var testFiles = { 32 var testFiles = {
34 '/index1.html': ''' 33 '/index1.html': '''
35 <script src="foo.js"></script> 34 <script src="foo.js"></script>
36 ''', 35 ''',
(...skipping 23 matching lines...) Expand all
60 '/a10.dart': 'library a10;', 59 '/a10.dart': 'library a10;',
61 }; 60 };
62 61
63 nodeOf(String filepath) => graph.nodeFromUri(new Uri.file(filepath)); 62 nodeOf(String filepath) => graph.nodeFromUri(new Uri.file(filepath));
64 63
65 setUp(() { 64 setUp(() {
66 /// We completely reset the TestUriResolver to avoid interference between 65 /// We completely reset the TestUriResolver to avoid interference between
67 /// tests (since some tests modify the state of the files). 66 /// tests (since some tests modify the state of the files).
68 testResourceProvider = createTestResourceProvider(testFiles); 67 testResourceProvider = createTestResourceProvider(testFiles);
69 testUriResolver = new ResourceUriResolver(testResourceProvider); 68 testUriResolver = new ResourceUriResolver(testResourceProvider);
70 context = new TypeResolver.fromMock(mockSdkSources, options, 69 context = createAnalysisContext(options, fileResolvers: [testUriResolver]);
71 otherResolvers: [testUriResolver]).context;
72 graph = new SourceGraph(context, new LogReporter(context), options); 70 graph = new SourceGraph(context, new LogReporter(context), options);
73 }); 71 });
74 72
75 updateFile(Source source, [String newContents]) { 73 updateFile(Source source, [String newContents]) {
76 var path = testResourceProvider.pathContext.fromUri(source.uri); 74 var path = testResourceProvider.pathContext.fromUri(source.uri);
77 if (newContents == null) newContents = source.contents.data; 75 if (newContents == null) newContents = source.contents.data;
78 testResourceProvider.updateFile(path, newContents); 76 testResourceProvider.updateFile(path, newContents);
79 } 77 }
80 78
81 group('HTML deps', () { 79 group('HTML deps', () {
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 | | | |-- a8.dart... 637 | | | |-- a8.dart...
640 | |-- a6.dart (part) 638 | |-- a6.dart (part)
641 $_RUNTIME_GRAPH 639 $_RUNTIME_GRAPH
642 '''); 640 ''');
643 }); 641 });
644 }); 642 });
645 643
646 group('server-mode', () { 644 group('server-mode', () {
647 setUp(() { 645 setUp(() {
648 var options2 = new CompilerOptions( 646 var options2 = new CompilerOptions(
649 runtimeDir: '/dev_compiler_runtime/', serverMode: true); 647 runtimeDir: '/dev_compiler_runtime/',
650 context = new TypeResolver.fromMock(mockSdkSources, options2, 648 useMockSdk: true,
651 otherResolvers: [testUriResolver]).context; 649 serverMode: true);
650 context =
651 createAnalysisContext(options2, fileResolvers: [testUriResolver]);
652 graph = new SourceGraph(context, new LogReporter(context), options2); 652 graph = new SourceGraph(context, new LogReporter(context), options2);
653 }); 653 });
654 654
655 test('messages widget is automatically included', () { 655 test('messages widget is automatically included', () {
656 var node = nodeOf('/index3.html'); 656 var node = nodeOf('/index3.html');
657 expectGraph(node, ''' 657 expectGraph(node, '''
658 index3.html 658 index3.html
659 $_RUNTIME_GRAPH 659 $_RUNTIME_GRAPH
660 |-- messages_widget.js 660 |-- messages_widget.js
661 |-- messages.css 661 |-- messages.css
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 var source = nodeOf('/bar.dart').source; 1083 var source = nodeOf('/bar.dart').source;
1084 updateFile(source, "hi"); 1084 updateFile(source, "hi");
1085 results = []; 1085 results = [];
1086 rebuild(node, buildWithTransitiveChange); 1086 rebuild(node, buildWithTransitiveChange);
1087 expect(results, ['bar.dart', 'foo.dart']); 1087 expect(results, ['bar.dart', 'foo.dart']);
1088 }); 1088 });
1089 }); 1089 });
1090 1090
1091 group('null for non-existing files', () { 1091 group('null for non-existing files', () {
1092 setUp(() { 1092 setUp(() {
1093 context = new TypeResolver.fromMock(mockSdkSources, options, 1093 context =
1094 otherResolvers: [testUriResolver]).context; 1094 createAnalysisContext(options, fileResolvers: [testUriResolver]);
1095 graph = new SourceGraph(context, new LogReporter(context), options); 1095 graph = new SourceGraph(context, new LogReporter(context), options);
1096 }); 1096 });
1097 1097
1098 test('recognize locally change between existing and not-existing', () { 1098 test('recognize locally change between existing and not-existing', () {
1099 var n = nodeOf('/foo.dart'); 1099 var n = nodeOf('/foo.dart');
1100 expect(n.source.exists(), isFalse); 1100 expect(n.source.exists(), isFalse);
1101 var source = 1101 var source =
1102 testResourceProvider.newFile('/foo.dart', 'hi').createSource(); 1102 testResourceProvider.newFile('/foo.dart', 'hi').createSource();
1103 expect( 1103 expect(
1104 testUriResolver.resolveAbsolute(new Uri.file('/foo.dart')), source); 1104 testUriResolver.resolveAbsolute(new Uri.file('/foo.dart')), source);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 helper(node); 1169 helper(node);
1170 return sb.toString(); 1170 return sb.toString();
1171 } 1171 }
1172 1172
1173 final runtimeFilesWithoutPath = defaultRuntimeFiles 1173 final runtimeFilesWithoutPath = defaultRuntimeFiles
1174 .map((f) => f.replaceAll('dart/', '')) 1174 .map((f) => f.replaceAll('dart/', ''))
1175 .toList(growable: false); 1175 .toList(growable: false);
1176 final _RUNTIME_GRAPH = runtimeFilesWithoutPath.map((s) => '|-- $s').join('\n'); 1176 final _RUNTIME_GRAPH = runtimeFilesWithoutPath.map((s) => '|-- $s').join('\n');
1177 final _RUNTIME_GRAPH_REBUILD = 1177 final _RUNTIME_GRAPH_REBUILD =
1178 runtimeFilesWithoutPath.map((s) => '|-- $s [needs-rebuild]').join('\n'); 1178 runtimeFilesWithoutPath.map((s) => '|-- $s [needs-rebuild]').join('\n');
OLDNEW
« lib/src/options.dart ('K') | « lib/src/testing.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698