Chromium Code Reviews| 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() { | |
|
Brian Wilkerson
2015/11/30 22:52:22
Might be interesting to try a more deeply nested e
| |
| 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_includedByOuter_innerFirst() { | |
| 1183 String project = '/project'; | |
| 1184 String projectPubspec = '$project/pubspec.yaml'; | |
| 1185 String example = '$project/example'; | |
| 1186 String examplePubspec = '$example/pubspec.yaml'; | |
| 1187 // create files | |
| 1188 resourceProvider.newFile(projectPubspec, 'name: project'); | |
| 1189 resourceProvider.newFile(examplePubspec, 'name: example'); | |
| 1190 manager.setRoots( | |
| 1191 <String>[example, project], <String>[], <String, String>{}); | |
| 1192 // verify | |
| 1193 { | |
| 1194 ContextInfo rootInfo = manager.rootInfo; | |
| 1195 expect(rootInfo.children, hasLength(1)); | |
| 1196 { | |
| 1197 ContextInfo projectInfo = rootInfo.children[0]; | |
| 1198 expect(projectInfo.folder.path, project); | |
| 1199 expect(projectInfo.children, hasLength(1)); | |
| 1200 { | |
| 1201 ContextInfo exampleInfo = projectInfo.children[0]; | |
| 1202 expect(exampleInfo.folder.path, example); | |
| 1203 expect(exampleInfo.children, isEmpty); | |
| 1204 } | |
| 1205 } | |
| 1206 } | |
| 1207 expect(callbacks.currentContextPaths, hasLength(2)); | |
| 1208 expect(callbacks.currentContextPaths, unorderedEquals([project, example])); | |
| 1209 } | |
| 1210 | |
| 1211 void test_setRoots_nested_includedByOuter_outerPubspec() { | |
| 1212 String project = '/project'; | |
| 1213 String projectPubspec = '$project/pubspec.yaml'; | |
| 1214 String example = '$project/example'; | |
| 1215 // create files | |
| 1216 resourceProvider.newFile(projectPubspec, 'name: project'); | |
| 1217 resourceProvider.newFolder(example); | |
| 1218 manager.setRoots( | |
| 1219 <String>[project, example], <String>[], <String, String>{}); | |
| 1220 // verify | |
| 1221 { | |
| 1222 ContextInfo rootInfo = manager.rootInfo; | |
| 1223 expect(rootInfo.children, hasLength(1)); | |
| 1224 { | |
| 1225 ContextInfo projectInfo = rootInfo.children[0]; | |
| 1226 expect(projectInfo.folder.path, project); | |
| 1227 expect(projectInfo.children, isEmpty); | |
| 1228 } | |
| 1229 } | |
| 1230 expect(callbacks.currentContextPaths, hasLength(1)); | |
| 1231 expect(callbacks.currentContextPaths, unorderedEquals([project])); | |
| 1232 } | |
| 1233 | |
| 1234 void test_setRoots_nested_includedByOuter_twoPubspecs() { | |
| 1235 String project = '/project'; | |
| 1236 String projectPubspec = '$project/pubspec.yaml'; | |
| 1237 String example = '$project/example'; | |
| 1238 String examplePubspec = '$example/pubspec.yaml'; | |
| 1239 // create files | |
| 1240 resourceProvider.newFile(projectPubspec, 'name: project'); | |
| 1241 resourceProvider.newFile(examplePubspec, 'name: example'); | |
| 1242 manager.setRoots( | |
| 1243 <String>[project, example], <String>[], <String, String>{}); | |
| 1244 // verify | |
| 1245 { | |
| 1246 ContextInfo rootInfo = manager.rootInfo; | |
| 1247 expect(rootInfo.children, hasLength(1)); | |
| 1248 { | |
| 1249 ContextInfo projectInfo = rootInfo.children[0]; | |
| 1250 expect(projectInfo.folder.path, project); | |
| 1251 expect(projectInfo.children, hasLength(1)); | |
| 1252 { | |
| 1253 ContextInfo exampleInfo = projectInfo.children[0]; | |
| 1254 expect(exampleInfo.folder.path, example); | |
| 1255 expect(exampleInfo.children, isEmpty); | |
| 1256 } | |
| 1257 } | |
| 1258 } | |
| 1259 expect(callbacks.currentContextPaths, hasLength(2)); | |
| 1260 expect(callbacks.currentContextPaths, unorderedEquals([project, example])); | |
| 1261 } | |
| 1262 | |
| 1146 void test_setRoots_newFolderWithPackageRoot() { | 1263 void test_setRoots_newFolderWithPackageRoot() { |
| 1147 String packageRootPath = '/package'; | 1264 String packageRootPath = '/package'; |
| 1148 manager.setRoots(<String>[projPath], <String>[], | 1265 manager.setRoots(<String>[projPath], <String>[], |
| 1149 <String, String>{projPath: packageRootPath}); | 1266 <String, String>{projPath: packageRootPath}); |
| 1150 _checkPackageRoot(projPath, equals(packageRootPath)); | 1267 _checkPackageRoot(projPath, equals(packageRootPath)); |
| 1151 } | 1268 } |
| 1152 | 1269 |
| 1153 void test_setRoots_newlyAddedFoldersGetProperPackageMap() { | 1270 void test_setRoots_newlyAddedFoldersGetProperPackageMap() { |
| 1154 String packagePath = '/package/foo'; | 1271 String packagePath = '/package/foo'; |
| 1155 Folder packageFolder = resourceProvider.newFolder(packagePath); | 1272 Folder packageFolder = resourceProvider.newFolder(packagePath); |
| (...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2135 class TestUriResolver extends UriResolver { | 2252 class TestUriResolver extends UriResolver { |
| 2136 Map<Uri, Source> uriMap; | 2253 Map<Uri, Source> uriMap; |
| 2137 | 2254 |
| 2138 TestUriResolver(this.uriMap); | 2255 TestUriResolver(this.uriMap); |
| 2139 | 2256 |
| 2140 @override | 2257 @override |
| 2141 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 2258 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
| 2142 return uriMap[uri]; | 2259 return uriMap[uri]; |
| 2143 } | 2260 } |
| 2144 } | 2261 } |
| OLD | NEW |