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_embedder_options() async { |
| 97 // Create files. |
| 98 String libPath = newFolder([projPath, LIB_NAME]); |
| 99 String sdkExtPath = newFolder([projPath, 'sdk_ext']); |
| 100 newFile([projPath, 'test', 'test.dart']); |
| 101 newFile([sdkExtPath, 'entry.dart']); |
| 102 // Setup _embedder.yaml. |
| 103 newFile( |
| 104 [libPath, '_embedder.yaml'], |
| 105 r''' |
| 106 embedder_libs: |
| 107 "dart:foobar": "../sdk_ext/entry.dart" |
| 108 analyzer: |
| 109 strong-mode: true |
| 110 language: |
| 111 enableSuperMixins: true |
| 112 '''); |
| 113 // Setup .packages file |
| 114 newFile( |
| 115 [projPath, '.packages'], |
| 116 r''' |
| 117 test_pack:lib/'''); |
| 118 |
| 119 // Setup .analysis_options |
| 120 newFile( |
| 121 [projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE], |
| 122 r''' |
| 123 analyzer: |
| 124 exclude: |
| 125 - 'test/**' |
| 126 language: |
| 127 enableGenericMethods: true |
| 128 errors: |
| 129 unused_local_variable: false |
| 130 '''); |
| 131 |
| 132 // Setup context. |
| 133 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 134 await pumpEventQueue(); |
| 135 |
| 136 // Confirm that one context was created. |
| 137 var contexts = |
| 138 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); |
| 139 expect(contexts, isNotNull); |
| 140 expect(contexts, hasLength(1)); |
| 141 var context = contexts[0]; |
| 142 |
| 143 // Verify options. |
| 144 // * from `_embedder.yaml`: |
| 145 expect(context.analysisOptions.strongMode, isTrue); |
| 146 expect(context.analysisOptions.enableSuperMixins, isTrue); |
| 147 // * from `.analysis_options`: |
| 148 expect(context.analysisOptions.enableGenericMethods, isTrue); |
| 149 // verify tests are excluded |
| 150 expect(callbacks.currentContextFilePaths[projPath].keys, |
| 151 ['/my/proj/sdk_ext/entry.dart']); |
| 152 |
| 153 // Verify filter setup. |
| 154 List<ErrorFilter> filters = |
| 155 callbacks.currentContext.getConfigurationData(CONFIGURED_ERROR_FILTERS); |
| 156 expect(filters, hasLength(1)); |
| 157 expect( |
| 158 filters.first(new AnalysisError( |
| 159 new TestSource(), 0, 1, HintCode.UNUSED_LOCAL_VARIABLE, [ |
| 160 ['x'] |
| 161 ])), |
| 162 isTrue); |
| 163 |
| 164 // Sanity check embedder libs. |
| 165 var source = context.sourceFactory.forUri('dart:foobar'); |
| 166 expect(source, isNotNull); |
| 167 expect(source.fullName, '/my/proj/sdk_ext/entry.dart'); |
| 168 } |
| 169 |
96 test_analysis_options_parse_failure() async { | 170 test_analysis_options_parse_failure() async { |
97 // Create files. | 171 // Create files. |
98 String libPath = newFolder([projPath, LIB_NAME]); | 172 String libPath = newFolder([projPath, LIB_NAME]); |
99 newFile([libPath, 'main.dart']); | 173 newFile([libPath, 'main.dart']); |
100 String sdkExtPath = newFolder([projPath, 'sdk_ext']); | 174 String sdkExtPath = newFolder([projPath, 'sdk_ext']); |
101 newFile([sdkExtPath, 'entry.dart']); | 175 newFile([sdkExtPath, 'entry.dart']); |
102 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']); | 176 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']); |
103 newFile([sdkExtSrcPath, 'part.dart']); | 177 newFile([sdkExtSrcPath, 'part.dart']); |
104 // Setup analysis options file with ignore list. | 178 // Setup analysis options file with ignore list. |
105 newFile( | 179 newFile( |
(...skipping 25 matching lines...) Expand all Loading... |
131 expect(subProjContextInfo, isNotNull); | 205 expect(subProjContextInfo, isNotNull); |
132 expect(subProjContextInfo.folder, subProjFolder); | 206 expect(subProjContextInfo.folder, subProjFolder); |
133 expect(projContextInfo.context != subProjContextInfo.context, isTrue); | 207 expect(projContextInfo.context != subProjContextInfo.context, isTrue); |
134 // Check that contextsInAnalysisRoot() works. | 208 // Check that contextsInAnalysisRoot() works. |
135 List<AnalysisContext> contexts = manager.contextsInAnalysisRoot(projFolder); | 209 List<AnalysisContext> contexts = manager.contextsInAnalysisRoot(projFolder); |
136 expect(contexts, hasLength(2)); | 210 expect(contexts, hasLength(2)); |
137 expect(contexts, contains(projContextInfo.context)); | 211 expect(contexts, contains(projContextInfo.context)); |
138 expect(contexts, contains(subProjContextInfo.context)); | 212 expect(contexts, contains(subProjContextInfo.context)); |
139 } | 213 } |
140 | 214 |
| 215 test_embedder_packagespec() async { |
| 216 // Create files. |
| 217 String libPath = newFolder([projPath, LIB_NAME]); |
| 218 newFile([libPath, 'main.dart']); |
| 219 newFile([libPath, 'nope.dart']); |
| 220 String sdkExtPath = newFolder([projPath, 'sdk_ext']); |
| 221 newFile([sdkExtPath, 'entry.dart']); |
| 222 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']); |
| 223 newFile([sdkExtSrcPath, 'part.dart']); |
| 224 // Setup _embedder.yaml. |
| 225 newFile( |
| 226 [libPath, '_embedder.yaml'], |
| 227 r''' |
| 228 embedder_libs: |
| 229 "dart:foobar": "../sdk_ext/entry.dart" |
| 230 "dart:typed_data": "../sdk_ext/src/part" |
| 231 '''); |
| 232 // Setup .packages file |
| 233 newFile( |
| 234 [projPath, '.packages'], |
| 235 r''' |
| 236 test_pack:lib/'''); |
| 237 // Setup context. |
| 238 |
| 239 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 240 await pumpEventQueue(); |
| 241 // Confirm that one context was created. |
| 242 var contexts = |
| 243 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); |
| 244 expect(contexts, isNotNull); |
| 245 expect(contexts.length, equals(1)); |
| 246 var context = contexts[0]; |
| 247 var source = context.sourceFactory.forUri('dart:foobar'); |
| 248 expect(source, isNotNull); |
| 249 expect(source.fullName, equals('/my/proj/sdk_ext/entry.dart')); |
| 250 // We can't find dart:core because we didn't list it in our |
| 251 // embedder_libs map. |
| 252 expect(context.sourceFactory.forUri('dart:core'), isNull); |
| 253 // We can find dart:typed_data because we listed it in our |
| 254 // embedder_libs map. |
| 255 expect(context.sourceFactory.forUri('dart:typed_data'), isNotNull); |
| 256 } |
| 257 |
141 test_error_filter_analysis_option() async { | 258 test_error_filter_analysis_option() async { |
142 // Create files. | 259 // Create files. |
143 newFile( | 260 newFile( |
144 [projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE], | 261 [projPath, AnalysisEngine.ANALYSIS_OPTIONS_FILE], |
145 r''' | 262 r''' |
146 analyzer: | 263 analyzer: |
147 errors: | 264 errors: |
148 unused_local_variable: ignore | 265 unused_local_variable: ignore |
149 '''); | 266 '''); |
150 // Setup context. | 267 // Setup context. |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 callbacks.now++; | 678 callbacks.now++; |
562 manager.refresh([resourceProvider.getResource(proj2Path)]); | 679 manager.refresh([resourceProvider.getResource(proj2Path)]); |
563 return pumpEventQueue().then((_) { | 680 return pumpEventQueue().then((_) { |
564 expect(callbacks.currentContextPaths.toList(), unorderedEquals(roots)); | 681 expect(callbacks.currentContextPaths.toList(), unorderedEquals(roots)); |
565 expect(callbacks.currentContextTimestamps[projPath], then); | 682 expect(callbacks.currentContextTimestamps[projPath], then); |
566 expect(callbacks.currentContextTimestamps[proj2Path], callbacks.now); | 683 expect(callbacks.currentContextTimestamps[proj2Path], callbacks.now); |
567 }); | 684 }); |
568 }); | 685 }); |
569 } | 686 } |
570 | 687 |
571 test_embedder_packagespec() async { | |
572 // Create files. | |
573 String libPath = newFolder([projPath, LIB_NAME]); | |
574 newFile([libPath, 'main.dart']); | |
575 newFile([libPath, 'nope.dart']); | |
576 String sdkExtPath = newFolder([projPath, 'sdk_ext']); | |
577 newFile([sdkExtPath, 'entry.dart']); | |
578 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']); | |
579 newFile([sdkExtSrcPath, 'part.dart']); | |
580 // Setup _embedder.yaml. | |
581 newFile( | |
582 [libPath, '_embedder.yaml'], | |
583 r''' | |
584 embedder_libs: | |
585 "dart:foobar": "../sdk_ext/entry.dart" | |
586 "dart:typed_data": "../sdk_ext/src/part" | |
587 '''); | |
588 // Setup .packages file | |
589 newFile( | |
590 [projPath, '.packages'], | |
591 r''' | |
592 test_pack:lib/'''); | |
593 // Setup context. | |
594 | |
595 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | |
596 await pumpEventQueue(); | |
597 // Confirm that one context was created. | |
598 var contexts = | |
599 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); | |
600 expect(contexts, isNotNull); | |
601 expect(contexts.length, equals(1)); | |
602 var context = contexts[0]; | |
603 var source = context.sourceFactory.forUri('dart:foobar'); | |
604 expect(source, isNotNull); | |
605 expect(source.fullName, equals('/my/proj/sdk_ext/entry.dart')); | |
606 // We can't find dart:core because we didn't list it in our | |
607 // embedder_libs map. | |
608 expect(context.sourceFactory.forUri('dart:core'), isNull); | |
609 // We can find dart:typed_data because we listed it in our | |
610 // embedder_libs map. | |
611 expect(context.sourceFactory.forUri('dart:typed_data'), isNotNull); | |
612 } | |
613 | |
614 test_sdk_ext_packagespec() async { | 688 test_sdk_ext_packagespec() async { |
615 // Create files. | 689 // Create files. |
616 String libPath = newFolder([projPath, LIB_NAME]); | 690 String libPath = newFolder([projPath, LIB_NAME]); |
617 newFile([libPath, 'main.dart']); | 691 newFile([libPath, 'main.dart']); |
618 newFile([libPath, 'nope.dart']); | 692 newFile([libPath, 'nope.dart']); |
619 String sdkExtPath = newFolder([projPath, 'sdk_ext']); | 693 String sdkExtPath = newFolder([projPath, 'sdk_ext']); |
620 newFile([sdkExtPath, 'entry.dart']); | 694 newFile([sdkExtPath, 'entry.dart']); |
621 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']); | 695 String sdkExtSrcPath = newFolder([projPath, 'sdk_ext', 'src']); |
622 newFile([sdkExtSrcPath, 'part.dart']); | 696 newFile([sdkExtSrcPath, 'part.dart']); |
623 // Setup sdk extension mapping. | 697 // Setup sdk extension mapping. |
(...skipping 1312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1936 */ | 2010 */ |
1937 final ResourceProvider resourceProvider; | 2011 final ResourceProvider resourceProvider; |
1938 | 2012 |
1939 TestContextManagerCallbacks(this.resourceProvider); | 2013 TestContextManagerCallbacks(this.resourceProvider); |
1940 | 2014 |
1941 /** | 2015 /** |
1942 * Iterable of the paths to contexts that currently exist. | 2016 * Iterable of the paths to contexts that currently exist. |
1943 */ | 2017 */ |
1944 Iterable<String> get currentContextPaths => currentContextTimestamps.keys; | 2018 Iterable<String> get currentContextPaths => currentContextTimestamps.keys; |
1945 | 2019 |
1946 /// If [disposition] has a package map, attempt to locate `_embedder.yaml` | |
1947 /// files. | |
1948 void _locateEmbedderYamls(InternalAnalysisContext context, | |
1949 FolderDisposition disposition) { | |
1950 Map<String, List<Folder>> packageMap; | |
1951 if (disposition is PackageMapDisposition) { | |
1952 packageMap = disposition.packageMap; | |
1953 } else if (disposition is PackagesFileDisposition) { | |
1954 packageMap = disposition.buildPackageMap(resourceProvider); | |
1955 } | |
1956 context.embedderYamlLocator.refresh(packageMap); | |
1957 } | |
1958 | |
1959 @override | 2020 @override |
1960 AnalysisContext addContext(Folder folder, FolderDisposition disposition) { | 2021 AnalysisContext addContext(Folder folder, FolderDisposition disposition) { |
1961 String path = folder.path; | 2022 String path = folder.path; |
1962 expect(currentContextPaths, isNot(contains(path))); | 2023 expect(currentContextPaths, isNot(contains(path))); |
1963 currentContextTimestamps[path] = now; | 2024 currentContextTimestamps[path] = now; |
1964 currentContextFilePaths[path] = <String, int>{}; | 2025 currentContextFilePaths[path] = <String, int>{}; |
1965 currentContextSources[path] = new HashSet<Source>(); | 2026 currentContextSources[path] = new HashSet<Source>(); |
1966 currentContextDispositions[path] = disposition; | 2027 currentContextDispositions[path] = disposition; |
1967 currentContext = AnalysisEngine.instance.createAnalysisContext(); | 2028 currentContext = AnalysisEngine.instance.createAnalysisContext(); |
1968 _locateEmbedderYamls(currentContext, disposition); | 2029 _locateEmbedderYamls(currentContext, disposition); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2039 // non-existent file 'username@hostname.pid'. To avoid these dummy links | 2100 // non-existent file 'username@hostname.pid'. To avoid these dummy links |
2040 // causing the analyzer to thrash, just ignore links to non-existent files. | 2101 // causing the analyzer to thrash, just ignore links to non-existent files. |
2041 return file.exists; | 2102 return file.exists; |
2042 } | 2103 } |
2043 | 2104 |
2044 @override | 2105 @override |
2045 void updateContextPackageUriResolver( | 2106 void updateContextPackageUriResolver( |
2046 Folder contextFolder, FolderDisposition disposition) { | 2107 Folder contextFolder, FolderDisposition disposition) { |
2047 currentContextDispositions[contextFolder.path] = disposition; | 2108 currentContextDispositions[contextFolder.path] = disposition; |
2048 } | 2109 } |
| 2110 |
| 2111 /// If [disposition] has a package map, attempt to locate `_embedder.yaml` |
| 2112 /// files. |
| 2113 void _locateEmbedderYamls( |
| 2114 InternalAnalysisContext context, FolderDisposition disposition) { |
| 2115 Map<String, List<Folder>> packageMap; |
| 2116 if (disposition is PackageMapDisposition) { |
| 2117 packageMap = disposition.packageMap; |
| 2118 } else if (disposition is PackagesFileDisposition) { |
| 2119 packageMap = disposition.buildPackageMap(resourceProvider); |
| 2120 } |
| 2121 context.embedderYamlLocator.refresh(packageMap); |
| 2122 } |
2049 } | 2123 } |
2050 | 2124 |
2051 /** | 2125 /** |
2052 * A [Source] that knows it's [fullName]. | 2126 * A [Source] that knows it's [fullName]. |
2053 */ | 2127 */ |
2054 class TestSource implements Source { | 2128 class TestSource implements Source { |
2055 TestSource(); | 2129 TestSource(); |
2056 | 2130 |
2057 @override | 2131 @override |
2058 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 2132 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
2059 } | 2133 } |
2060 | 2134 |
2061 class TestUriResolver extends UriResolver { | 2135 class TestUriResolver extends UriResolver { |
2062 Map<Uri, Source> uriMap; | 2136 Map<Uri, Source> uriMap; |
2063 | 2137 |
2064 TestUriResolver(this.uriMap); | 2138 TestUriResolver(this.uriMap); |
2065 | 2139 |
2066 @override | 2140 @override |
2067 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 2141 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
2068 return uriMap[uri]; | 2142 return uriMap[uri]; |
2069 } | 2143 } |
2070 } | 2144 } |
OLD | NEW |