OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 test.context.directory.manager; | 5 library test.context.directory.manager; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analysis_server/src/context_manager.dart'; | 9 import 'package:analysis_server/src/context_manager.dart'; |
10 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 void setUp() { | 86 void setUp() { |
87 resourceProvider = new MemoryResourceProvider(); | 87 resourceProvider = new MemoryResourceProvider(); |
88 packageMapProvider = new MockPackageMapProvider(); | 88 packageMapProvider = new MockPackageMapProvider(); |
89 manager = new ContextManagerImpl(resourceProvider, providePackageResolver, | 89 manager = new ContextManagerImpl(resourceProvider, providePackageResolver, |
90 packageMapProvider, InstrumentationService.NULL_SERVICE); | 90 packageMapProvider, InstrumentationService.NULL_SERVICE); |
91 callbacks = new TestContextManagerCallbacks(resourceProvider); | 91 callbacks = new TestContextManagerCallbacks(resourceProvider); |
92 manager.callbacks = callbacks; | 92 manager.callbacks = callbacks; |
93 resourceProvider.newFolder(projPath); | 93 resourceProvider.newFolder(projPath); |
94 } | 94 } |
95 | 95 |
| 96 test_analysis_options_parse_failure() async { |
| 97 // Create files. |
| 98 String libPath = newFolder([projPath, LIB_NAME]); |
| 99 newFile([libPath, 'main.dart']); |
| 100 String sdkExtPath = newFolder([projPath, 'sdk_ext']); |
| 101 newFile([sdkExtPath, 'entry.dart']); |
| 102 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']); |
| 103 newFile([sdkExtSrcPath, 'part.dart']); |
| 104 // Setup analysis options file with ignore list. |
| 105 newFile( |
| 106 [projPath, '.analysis_options'], |
| 107 r''' |
| 108 ; |
| 109 '''); |
| 110 // Setup context. |
| 111 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 112 |
| 113 // No error means success. |
| 114 } |
| 115 |
| 116 void test_contextsInAnalysisRoot_nestedContext() { |
| 117 String subProjPath = posix.join(projPath, 'subproj'); |
| 118 Folder subProjFolder = resourceProvider.newFolder(subProjPath); |
| 119 resourceProvider.newFile( |
| 120 posix.join(subProjPath, 'pubspec.yaml'), 'contents'); |
| 121 String subProjFilePath = posix.join(subProjPath, 'file.dart'); |
| 122 resourceProvider.newFile(subProjFilePath, 'contents'); |
| 123 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 124 // Make sure that there really are contexts for both the main project and |
| 125 // the subproject. |
| 126 Folder projFolder = resourceProvider.getFolder(projPath); |
| 127 ContextInfo projContextInfo = manager.getContextInfoFor(projFolder); |
| 128 expect(projContextInfo, isNotNull); |
| 129 expect(projContextInfo.folder, projFolder); |
| 130 ContextInfo subProjContextInfo = manager.getContextInfoFor(subProjFolder); |
| 131 expect(subProjContextInfo, isNotNull); |
| 132 expect(subProjContextInfo.folder, subProjFolder); |
| 133 expect(projContextInfo.context != subProjContextInfo.context, isTrue); |
| 134 // Check that contextsInAnalysisRoot() works. |
| 135 List<AnalysisContext> contexts = manager.contextsInAnalysisRoot(projFolder); |
| 136 expect(contexts, hasLength(2)); |
| 137 expect(contexts, contains(projContextInfo.context)); |
| 138 expect(contexts, contains(subProjContextInfo.context)); |
| 139 } |
| 140 |
96 test_embedder_options() async { | 141 test_embedder_options() async { |
97 // Create files. | 142 // Create files. |
98 String libPath = newFolder([projPath, LIB_NAME]); | 143 String libPath = newFolder([projPath, LIB_NAME]); |
99 String sdkExtPath = newFolder([projPath, 'sdk_ext']); | 144 String sdkExtPath = newFolder([projPath, 'sdk_ext']); |
100 newFile([projPath, 'test', 'test.dart']); | 145 newFile([projPath, 'test', 'test.dart']); |
101 newFile([sdkExtPath, 'entry.dart']); | 146 newFile([sdkExtPath, 'entry.dart']); |
102 // Setup _embedder.yaml. | 147 // Setup _embedder.yaml. |
103 newFile( | 148 newFile( |
104 [libPath, '_embedder.yaml'], | 149 [libPath, '_embedder.yaml'], |
105 r''' | 150 r''' |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 ['x'] | 205 ['x'] |
161 ])), | 206 ])), |
162 isTrue); | 207 isTrue); |
163 | 208 |
164 // Sanity check embedder libs. | 209 // Sanity check embedder libs. |
165 var source = context.sourceFactory.forUri('dart:foobar'); | 210 var source = context.sourceFactory.forUri('dart:foobar'); |
166 expect(source, isNotNull); | 211 expect(source, isNotNull); |
167 expect(source.fullName, '/my/proj/sdk_ext/entry.dart'); | 212 expect(source.fullName, '/my/proj/sdk_ext/entry.dart'); |
168 } | 213 } |
169 | 214 |
170 test_analysis_options_parse_failure() async { | |
171 // Create files. | |
172 String libPath = newFolder([projPath, LIB_NAME]); | |
173 newFile([libPath, 'main.dart']); | |
174 String sdkExtPath = newFolder([projPath, 'sdk_ext']); | |
175 newFile([sdkExtPath, 'entry.dart']); | |
176 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']); | |
177 newFile([sdkExtSrcPath, 'part.dart']); | |
178 // Setup analysis options file with ignore list. | |
179 newFile( | |
180 [projPath, '.analysis_options'], | |
181 r''' | |
182 ; | |
183 '''); | |
184 // Setup context. | |
185 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | |
186 | |
187 // No error means success. | |
188 } | |
189 | |
190 void test_contextsInAnalysisRoot_nestedContext() { | |
191 String subProjPath = posix.join(projPath, 'subproj'); | |
192 Folder subProjFolder = resourceProvider.newFolder(subProjPath); | |
193 resourceProvider.newFile( | |
194 posix.join(subProjPath, 'pubspec.yaml'), 'contents'); | |
195 String subProjFilePath = posix.join(subProjPath, 'file.dart'); | |
196 resourceProvider.newFile(subProjFilePath, 'contents'); | |
197 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | |
198 // Make sure that there really are contexts for both the main project and | |
199 // the subproject. | |
200 Folder projFolder = resourceProvider.getFolder(projPath); | |
201 ContextInfo projContextInfo = manager.getContextInfoFor(projFolder); | |
202 expect(projContextInfo, isNotNull); | |
203 expect(projContextInfo.folder, projFolder); | |
204 ContextInfo subProjContextInfo = manager.getContextInfoFor(subProjFolder); | |
205 expect(subProjContextInfo, isNotNull); | |
206 expect(subProjContextInfo.folder, subProjFolder); | |
207 expect(projContextInfo.context != subProjContextInfo.context, isTrue); | |
208 // Check that contextsInAnalysisRoot() works. | |
209 List<AnalysisContext> contexts = manager.contextsInAnalysisRoot(projFolder); | |
210 expect(contexts, hasLength(2)); | |
211 expect(contexts, contains(projContextInfo.context)); | |
212 expect(contexts, contains(subProjContextInfo.context)); | |
213 } | |
214 | |
215 test_embedder_packagespec() async { | 215 test_embedder_packagespec() async { |
216 // Create files. | 216 // Create files. |
217 String libPath = newFolder([projPath, LIB_NAME]); | 217 String libPath = newFolder([projPath, LIB_NAME]); |
218 newFile([libPath, 'main.dart']); | 218 newFile([libPath, 'main.dart']); |
219 newFile([libPath, 'nope.dart']); | 219 newFile([libPath, 'nope.dart']); |
220 String sdkExtPath = newFolder([projPath, 'sdk_ext']); | 220 String sdkExtPath = newFolder([projPath, 'sdk_ext']); |
221 newFile([sdkExtPath, 'entry.dart']); | 221 newFile([sdkExtPath, 'entry.dart']); |
222 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']); | 222 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']); |
223 newFile([sdkExtSrcPath, 'part.dart']); | 223 newFile([sdkExtSrcPath, 'part.dart']); |
224 // Setup _embedder.yaml. | 224 // Setup _embedder.yaml. |
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 String fileB = '$project/lib/doc/bar.dart'; | 1136 String fileB = '$project/lib/doc/bar.dart'; |
1137 String fileC = '$project/doc/bar.dart'; | 1137 String fileC = '$project/doc/bar.dart'; |
1138 resourceProvider.newFile(fileA, ''); | 1138 resourceProvider.newFile(fileA, ''); |
1139 resourceProvider.newFile(fileB, ''); | 1139 resourceProvider.newFile(fileB, ''); |
1140 resourceProvider.newFile(fileC, ''); | 1140 resourceProvider.newFile(fileC, ''); |
1141 manager.setRoots(<String>[project], <String>[], <String, String>{}); | 1141 manager.setRoots(<String>[project], <String>[], <String, String>{}); |
1142 callbacks.assertContextPaths([project]); | 1142 callbacks.assertContextPaths([project]); |
1143 callbacks.assertContextFiles(project, [fileA, fileB]); | 1143 callbacks.assertContextFiles(project, [fileA, fileB]); |
1144 } | 1144 } |
1145 | 1145 |
| 1146 void test_setRoots_nested_excludedByOuter() { |
| 1147 String project = '/project'; |
| 1148 String projectPubspec = '$project/pubspec.yaml'; |
| 1149 String example = '$project/example'; |
| 1150 String examplePubspec = '$example/pubspec.yaml'; |
| 1151 // create files |
| 1152 resourceProvider.newFile(projectPubspec, 'name: project'); |
| 1153 resourceProvider.newFile(examplePubspec, 'name: example'); |
| 1154 newFile( |
| 1155 [project, AnalysisEngine.ANALYSIS_OPTIONS_FILE], |
| 1156 r''' |
| 1157 analyzer: |
| 1158 exclude: |
| 1159 - 'example' |
| 1160 '''); |
| 1161 manager.setRoots( |
| 1162 <String>[project, example], <String>[], <String, String>{}); |
| 1163 // verify |
| 1164 { |
| 1165 ContextInfo rootInfo = manager.rootInfo; |
| 1166 expect(rootInfo.children, hasLength(1)); |
| 1167 { |
| 1168 ContextInfo projectInfo = rootInfo.children[0]; |
| 1169 expect(projectInfo.folder.path, project); |
| 1170 expect(projectInfo.children, hasLength(1)); |
| 1171 { |
| 1172 ContextInfo exampleInfo = projectInfo.children[0]; |
| 1173 expect(exampleInfo.folder.path, example); |
| 1174 expect(exampleInfo.children, isEmpty); |
| 1175 } |
| 1176 } |
| 1177 } |
| 1178 expect(callbacks.currentContextPaths, hasLength(2)); |
| 1179 expect(callbacks.currentContextPaths, unorderedEquals([project, example])); |
| 1180 } |
| 1181 |
| 1182 void test_setRoots_nested_excludedByOuter_deep() { |
| 1183 String a = '/a'; |
| 1184 String c = '$a/b/c'; |
| 1185 String aPubspec = '$a/pubspec.yaml'; |
| 1186 String cPubspec = '$c/pubspec.yaml'; |
| 1187 // create files |
| 1188 resourceProvider.newFile(aPubspec, 'name: aaa'); |
| 1189 resourceProvider.newFile(cPubspec, 'name: ccc'); |
| 1190 newFile( |
| 1191 [a, AnalysisEngine.ANALYSIS_OPTIONS_FILE], |
| 1192 r''' |
| 1193 analyzer: |
| 1194 exclude: |
| 1195 - 'b**' |
| 1196 '''); |
| 1197 manager.setRoots(<String>[a, c], <String>[], <String, String>{}); |
| 1198 // verify |
| 1199 { |
| 1200 ContextInfo rootInfo = manager.rootInfo; |
| 1201 expect(rootInfo.children, hasLength(1)); |
| 1202 { |
| 1203 ContextInfo aInfo = rootInfo.children[0]; |
| 1204 expect(aInfo.folder.path, a); |
| 1205 expect(aInfo.children, hasLength(1)); |
| 1206 { |
| 1207 ContextInfo cInfo = aInfo.children[0]; |
| 1208 expect(cInfo.folder.path, c); |
| 1209 expect(cInfo.children, isEmpty); |
| 1210 } |
| 1211 } |
| 1212 } |
| 1213 expect(callbacks.currentContextPaths, hasLength(2)); |
| 1214 expect(callbacks.currentContextPaths, unorderedEquals([a, c])); |
| 1215 } |
| 1216 |
| 1217 void test_setRoots_nested_includedByOuter_innerFirst() { |
| 1218 String project = '/project'; |
| 1219 String projectPubspec = '$project/pubspec.yaml'; |
| 1220 String example = '$project/example'; |
| 1221 String examplePubspec = '$example/pubspec.yaml'; |
| 1222 // create files |
| 1223 resourceProvider.newFile(projectPubspec, 'name: project'); |
| 1224 resourceProvider.newFile(examplePubspec, 'name: example'); |
| 1225 manager.setRoots( |
| 1226 <String>[example, project], <String>[], <String, String>{}); |
| 1227 // verify |
| 1228 { |
| 1229 ContextInfo rootInfo = manager.rootInfo; |
| 1230 expect(rootInfo.children, hasLength(1)); |
| 1231 { |
| 1232 ContextInfo projectInfo = rootInfo.children[0]; |
| 1233 expect(projectInfo.folder.path, project); |
| 1234 expect(projectInfo.children, hasLength(1)); |
| 1235 { |
| 1236 ContextInfo exampleInfo = projectInfo.children[0]; |
| 1237 expect(exampleInfo.folder.path, example); |
| 1238 expect(exampleInfo.children, isEmpty); |
| 1239 } |
| 1240 } |
| 1241 } |
| 1242 expect(callbacks.currentContextPaths, hasLength(2)); |
| 1243 expect(callbacks.currentContextPaths, unorderedEquals([project, example])); |
| 1244 } |
| 1245 |
| 1246 void test_setRoots_nested_includedByOuter_outerPubspec() { |
| 1247 String project = '/project'; |
| 1248 String projectPubspec = '$project/pubspec.yaml'; |
| 1249 String example = '$project/example'; |
| 1250 // create files |
| 1251 resourceProvider.newFile(projectPubspec, 'name: project'); |
| 1252 resourceProvider.newFolder(example); |
| 1253 manager.setRoots( |
| 1254 <String>[project, example], <String>[], <String, String>{}); |
| 1255 // verify |
| 1256 { |
| 1257 ContextInfo rootInfo = manager.rootInfo; |
| 1258 expect(rootInfo.children, hasLength(1)); |
| 1259 { |
| 1260 ContextInfo projectInfo = rootInfo.children[0]; |
| 1261 expect(projectInfo.folder.path, project); |
| 1262 expect(projectInfo.children, isEmpty); |
| 1263 } |
| 1264 } |
| 1265 expect(callbacks.currentContextPaths, hasLength(1)); |
| 1266 expect(callbacks.currentContextPaths, unorderedEquals([project])); |
| 1267 } |
| 1268 |
| 1269 void test_setRoots_nested_includedByOuter_twoPubspecs() { |
| 1270 String project = '/project'; |
| 1271 String projectPubspec = '$project/pubspec.yaml'; |
| 1272 String example = '$project/example'; |
| 1273 String examplePubspec = '$example/pubspec.yaml'; |
| 1274 // create files |
| 1275 resourceProvider.newFile(projectPubspec, 'name: project'); |
| 1276 resourceProvider.newFile(examplePubspec, 'name: example'); |
| 1277 manager.setRoots( |
| 1278 <String>[project, example], <String>[], <String, String>{}); |
| 1279 // verify |
| 1280 { |
| 1281 ContextInfo rootInfo = manager.rootInfo; |
| 1282 expect(rootInfo.children, hasLength(1)); |
| 1283 { |
| 1284 ContextInfo projectInfo = rootInfo.children[0]; |
| 1285 expect(projectInfo.folder.path, project); |
| 1286 expect(projectInfo.children, hasLength(1)); |
| 1287 { |
| 1288 ContextInfo exampleInfo = projectInfo.children[0]; |
| 1289 expect(exampleInfo.folder.path, example); |
| 1290 expect(exampleInfo.children, isEmpty); |
| 1291 } |
| 1292 } |
| 1293 } |
| 1294 expect(callbacks.currentContextPaths, hasLength(2)); |
| 1295 expect(callbacks.currentContextPaths, unorderedEquals([project, example])); |
| 1296 } |
| 1297 |
1146 void test_setRoots_newFolderWithPackageRoot() { | 1298 void test_setRoots_newFolderWithPackageRoot() { |
1147 String packageRootPath = '/package'; | 1299 String packageRootPath = '/package'; |
1148 manager.setRoots(<String>[projPath], <String>[], | 1300 manager.setRoots(<String>[projPath], <String>[], |
1149 <String, String>{projPath: packageRootPath}); | 1301 <String, String>{projPath: packageRootPath}); |
1150 _checkPackageRoot(projPath, equals(packageRootPath)); | 1302 _checkPackageRoot(projPath, equals(packageRootPath)); |
1151 } | 1303 } |
1152 | 1304 |
1153 void test_setRoots_newlyAddedFoldersGetProperPackageMap() { | 1305 void test_setRoots_newlyAddedFoldersGetProperPackageMap() { |
1154 String packagePath = '/package/foo'; | 1306 String packagePath = '/package/foo'; |
1155 Folder packageFolder = resourceProvider.newFolder(packagePath); | 1307 Folder packageFolder = resourceProvider.newFolder(packagePath); |
(...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2135 class TestUriResolver extends UriResolver { | 2287 class TestUriResolver extends UriResolver { |
2136 Map<Uri, Source> uriMap; | 2288 Map<Uri, Source> uriMap; |
2137 | 2289 |
2138 TestUriResolver(this.uriMap); | 2290 TestUriResolver(this.uriMap); |
2139 | 2291 |
2140 @override | 2292 @override |
2141 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 2293 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
2142 return uriMap[uri]; | 2294 return uriMap[uri]; |
2143 } | 2295 } |
2144 } | 2296 } |
OLD | NEW |