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

Side by Side Diff: pkg/analyzer/test/src/context/abstract_context.dart

Issue 1838453002: Use shared MockSdk instances in resynthesize tests. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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
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 analyzer.test.src.context.abstract_context; 5 library analyzer.test.src.context.abstract_context;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/dart/element/visitor.dart'; 9 import 'package:analyzer/dart/element/visitor.dart';
10 import 'package:analyzer/file_system/file_system.dart'; 10 import 'package:analyzer/file_system/file_system.dart';
(...skipping 27 matching lines...) Expand all
38 })); 38 }));
39 return result; 39 return result;
40 } 40 }
41 41
42 /** 42 /**
43 * A function to be called for every [Element]. 43 * A function to be called for every [Element].
44 */ 44 */
45 typedef void _ElementVisitorFunction(Element element); 45 typedef void _ElementVisitorFunction(Element element);
46 46
47 class AbstractContextTest { 47 class AbstractContextTest {
48 static final MockSdk SHARED_MOCK_SDK = new MockSdk();
49 static final MockSdk SHARED_STRONG_MOCK_SDK = new MockSdk();
50
48 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); 51 MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
49 52
50 DartSdk sdk = new MockSdk(); 53 DartSdk sdk;
51 SourceFactory sourceFactory; 54 SourceFactory sourceFactory;
52 AnalysisContextImpl context; 55 AnalysisContextImpl context;
53 AnalysisCache analysisCache; 56 AnalysisCache analysisCache;
54 AnalysisDriver analysisDriver; 57 AnalysisDriver analysisDriver;
55 58
56 UriResolver sdkResolver; 59 UriResolver sdkResolver;
57 UriResolver resourceResolver; 60 UriResolver resourceResolver;
58 61
59 AnalysisTask task; 62 AnalysisTask task;
60 Map<ResultDescriptor<dynamic>, dynamic> oldOutputs; 63 Map<ResultDescriptor<dynamic>, dynamic> oldOutputs;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 outputs = task.outputs; 116 outputs = task.outputs;
114 for (ResultDescriptor descriptor in task.descriptor.results) { 117 for (ResultDescriptor descriptor in task.descriptor.results) {
115 expect(outputs, contains(descriptor)); 118 expect(outputs, contains(descriptor));
116 } 119 }
117 } 120 }
118 121
119 AnalysisContextImpl createAnalysisContext() { 122 AnalysisContextImpl createAnalysisContext() {
120 return new AnalysisContextImpl(); 123 return new AnalysisContextImpl();
121 } 124 }
122 125
126 DartSdk createDartSdk() => new MockSdk();
Brian Wilkerson 2016/03/28 16:58:03 It seems strange to create a new SDK when we have
scheglov 2016/03/28 17:03:35 My intention is to test SDK analysis from scratch
127
123 Source newSource(String path, [String content = '']) { 128 Source newSource(String path, [String content = '']) {
124 File file = resourceProvider.newFile(path, content); 129 File file = resourceProvider.newFile(path, content);
125 return file.createSource(); 130 return file.createSource();
126 } 131 }
127 132
128 List<Source> newSources(Map<String, String> sourceMap) { 133 List<Source> newSources(Map<String, String> sourceMap) {
129 List<Source> sources = <Source>[]; 134 List<Source> sources = <Source>[];
130 sourceMap.forEach((String path, String content) { 135 sourceMap.forEach((String path, String content) {
131 Source source = newSource(path, content); 136 Source source = newSource(path, content);
132 sources.add(source); 137 sources.add(source);
133 }); 138 });
134 return sources; 139 return sources;
135 } 140 }
136 141
137 void prepareAnalysisContext([AnalysisOptions options]) { 142 void prepareAnalysisContext([AnalysisOptions options]) {
143 sdk = createDartSdk();
138 sdkResolver = new DartUriResolver(sdk); 144 sdkResolver = new DartUriResolver(sdk);
139 resourceResolver = new ResourceUriResolver(resourceProvider); 145 resourceResolver = new ResourceUriResolver(resourceProvider);
140 sourceFactory = 146 sourceFactory =
141 new SourceFactory(<UriResolver>[sdkResolver, resourceResolver]); 147 new SourceFactory(<UriResolver>[sdkResolver, resourceResolver]);
142 context = createAnalysisContext(); 148 context = createAnalysisContext();
143 if (options != null) { 149 if (options != null) {
144 context.analysisOptions = options; 150 context.analysisOptions = options;
145 } 151 }
146 context.sourceFactory = sourceFactory; 152 context.sourceFactory = sourceFactory;
147 analysisCache = context.analysisCache; 153 analysisCache = context.analysisCache;
(...skipping 26 matching lines...) Expand all
174 class _ElementVisitorFunctionWrapper extends GeneralizingElementVisitor { 180 class _ElementVisitorFunctionWrapper extends GeneralizingElementVisitor {
175 final _ElementVisitorFunction function; 181 final _ElementVisitorFunction function;
176 182
177 _ElementVisitorFunctionWrapper(this.function); 183 _ElementVisitorFunctionWrapper(this.function);
178 184
179 visitElement(Element element) { 185 visitElement(Element element) {
180 function(element); 186 function(element);
181 super.visitElement(element); 187 super.visitElement(element);
182 } 188 }
183 } 189 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_strong_test.dart » ('j') | pkg/analyzer/test/src/task/dart_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698