| 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/error/error.dart'; | 10 import 'package:analyzer/error/error.dart'; |
| (...skipping 1974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1985 [projPath, optionsFileName], | 1985 [projPath, optionsFileName], |
| 1986 r''' | 1986 r''' |
| 1987 ; | 1987 ; |
| 1988 '''); | 1988 '''); |
| 1989 // Setup context. | 1989 // Setup context. |
| 1990 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | 1990 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); |
| 1991 | 1991 |
| 1992 // No error means success. | 1992 // No error means success. |
| 1993 } | 1993 } |
| 1994 | 1994 |
| 1995 test_configed_options() async { | |
| 1996 // Create files. | |
| 1997 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); | |
| 1998 newFile([projPath, 'test', 'test.dart']); | |
| 1999 newFile( | |
| 2000 [projPath, 'pubspec.yaml'], | |
| 2001 r''' | |
| 2002 dependencies: | |
| 2003 test_pack: any | |
| 2004 analyzer: | |
| 2005 configuration: test_pack/config | |
| 2006 '''); | |
| 2007 | |
| 2008 // Setup .packages file | |
| 2009 newFile( | |
| 2010 [projPath, '.packages'], | |
| 2011 r''' | |
| 2012 test_pack:lib/'''); | |
| 2013 | |
| 2014 // Setup config.yaml. | |
| 2015 newFile( | |
| 2016 [libPath, 'config', 'config.yaml'], | |
| 2017 r''' | |
| 2018 analyzer: | |
| 2019 strong-mode: true | |
| 2020 language: | |
| 2021 enableSuperMixins: true | |
| 2022 errors: | |
| 2023 missing_return: false | |
| 2024 linter: | |
| 2025 rules: | |
| 2026 - avoid_as | |
| 2027 '''); | |
| 2028 | |
| 2029 // Setup analysis options | |
| 2030 newFile( | |
| 2031 [projPath, optionsFileName], | |
| 2032 r''' | |
| 2033 analyzer: | |
| 2034 exclude: | |
| 2035 - 'test/**' | |
| 2036 language: | |
| 2037 enableGenericMethods: true | |
| 2038 errors: | |
| 2039 unused_local_variable: false | |
| 2040 linter: | |
| 2041 rules: | |
| 2042 - camel_case_types | |
| 2043 '''); | |
| 2044 | |
| 2045 // Setup context. | |
| 2046 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | |
| 2047 await pumpEventQueue(); | |
| 2048 | |
| 2049 // Confirm that one context was created. | |
| 2050 var contexts = | |
| 2051 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); | |
| 2052 expect(contexts, isNotNull); | |
| 2053 expect(contexts, hasLength(1)); | |
| 2054 | |
| 2055 var context = contexts.first; | |
| 2056 | |
| 2057 // Verify options. | |
| 2058 // * from `config.yaml`: | |
| 2059 expect(context.analysisOptions.strongMode, isTrue); | |
| 2060 expect(context.analysisOptions.enableSuperMixins, isTrue); | |
| 2061 // * from analysis options: | |
| 2062 expect(context.analysisOptions.enableGenericMethods, isTrue); | |
| 2063 | |
| 2064 // * verify tests are excluded | |
| 2065 expect(callbacks.currentContextFilePaths[projPath].keys, | |
| 2066 unorderedEquals(['/my/proj/$optionsFileName'])); | |
| 2067 | |
| 2068 // Verify filter setup. | |
| 2069 expect(errorProcessors, hasLength(2)); | |
| 2070 | |
| 2071 // * (config.) | |
| 2072 expect(getProcessor(missing_return).severity, isNull); | |
| 2073 | |
| 2074 // * (options.) | |
| 2075 expect(getProcessor(unused_local_variable).severity, isNull); | |
| 2076 | |
| 2077 // Verify lints. | |
| 2078 var lintNames = lints.map((lint) => lint.name); | |
| 2079 expect( | |
| 2080 lintNames, | |
| 2081 unorderedEquals( | |
| 2082 ['avoid_as' /* config */, 'camel_case_types' /* options */])); | |
| 2083 } | |
| 2084 | |
| 2085 test_embedder_and_configed_options() async { | |
| 2086 // Create files. | |
| 2087 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); | |
| 2088 String sdkExtPath = newFolder([projPath, 'sdk_ext']); | |
| 2089 newFile([projPath, 'test', 'test.dart']); | |
| 2090 newFile([sdkExtPath, 'entry.dart']); | |
| 2091 | |
| 2092 // Setup pubspec with configuration. | |
| 2093 newFile( | |
| 2094 [projPath, 'pubspec.yaml'], | |
| 2095 r''' | |
| 2096 dependencies: | |
| 2097 test_pack: any | |
| 2098 analyzer: | |
| 2099 configuration: test_pack/config | |
| 2100 '''); | |
| 2101 | |
| 2102 // Setup _embedder.yaml. | |
| 2103 newFile( | |
| 2104 [libPath, '_embedder.yaml'], | |
| 2105 r''' | |
| 2106 embedded_libs: | |
| 2107 "dart:foobar": "../sdk_ext/entry.dart" | |
| 2108 analyzer: | |
| 2109 strong-mode: true | |
| 2110 language: | |
| 2111 enableSuperMixins: true | |
| 2112 errors: | |
| 2113 missing_return: false | |
| 2114 linter: | |
| 2115 rules: | |
| 2116 - avoid_as | |
| 2117 '''); | |
| 2118 | |
| 2119 // Setup .packages file | |
| 2120 newFile( | |
| 2121 [projPath, '.packages'], | |
| 2122 r''' | |
| 2123 test_pack:lib/'''); | |
| 2124 | |
| 2125 // Setup analysis options | |
| 2126 newFile( | |
| 2127 [projPath, optionsFileName], | |
| 2128 r''' | |
| 2129 analyzer: | |
| 2130 exclude: | |
| 2131 - 'test/**' | |
| 2132 language: | |
| 2133 enableGenericMethods: true | |
| 2134 errors: | |
| 2135 unused_local_variable: false | |
| 2136 linter: | |
| 2137 rules: | |
| 2138 - camel_case_types | |
| 2139 '''); | |
| 2140 | |
| 2141 // Setup config.yaml. | |
| 2142 newFile( | |
| 2143 [libPath, 'config', 'config.yaml'], | |
| 2144 r''' | |
| 2145 analyzer: | |
| 2146 errors: | |
| 2147 missing_required_param: error | |
| 2148 linter: | |
| 2149 rules: | |
| 2150 - always_specify_types | |
| 2151 '''); | |
| 2152 | |
| 2153 // Setup context. | |
| 2154 manager.setRoots(<String>[projPath], <String>[], <String, String>{}); | |
| 2155 await pumpEventQueue(); | |
| 2156 | |
| 2157 // Confirm that one context was created. | |
| 2158 var contexts = | |
| 2159 manager.contextsInAnalysisRoot(resourceProvider.newFolder(projPath)); | |
| 2160 expect(contexts, isNotNull); | |
| 2161 expect(contexts, hasLength(1)); | |
| 2162 var context = contexts[0]; | |
| 2163 | |
| 2164 // Verify options. | |
| 2165 // * from `_embedder.yaml`: | |
| 2166 expect(context.analysisOptions.strongMode, isTrue); | |
| 2167 expect(context.analysisOptions.enableSuperMixins, isTrue); | |
| 2168 // * from analysis options: | |
| 2169 expect(context.analysisOptions.enableGenericMethods, isTrue); | |
| 2170 | |
| 2171 // * verify tests are excluded | |
| 2172 expect( | |
| 2173 callbacks.currentContextFilePaths[projPath].keys, | |
| 2174 unorderedEquals( | |
| 2175 ['/my/proj/sdk_ext/entry.dart', '/my/proj/$optionsFileName'])); | |
| 2176 | |
| 2177 // Verify filter setup. | |
| 2178 expect(errorProcessors, hasLength(3)); | |
| 2179 | |
| 2180 // * (embedder.) | |
| 2181 expect(getProcessor(missing_return).severity, isNull); | |
| 2182 | |
| 2183 // * (config.) | |
| 2184 expect(getProcessor(missing_required_param).severity, ErrorSeverity.ERROR); | |
| 2185 | |
| 2186 // * (options.) | |
| 2187 expect(getProcessor(unused_local_variable).severity, isNull); | |
| 2188 | |
| 2189 // Verify lints. | |
| 2190 var lintNames = lints.map((lint) => lint.name); | |
| 2191 | |
| 2192 expect( | |
| 2193 lintNames, | |
| 2194 unorderedEquals([ | |
| 2195 'avoid_as' /* embedder */, | |
| 2196 'always_specify_types' /* config*/, | |
| 2197 'camel_case_types' /* options */ | |
| 2198 ])); | |
| 2199 | |
| 2200 // Sanity check embedder libs. | |
| 2201 var source = context.sourceFactory.forUri('dart:foobar'); | |
| 2202 expect(source, isNotNull); | |
| 2203 expect(source.fullName, '/my/proj/sdk_ext/entry.dart'); | |
| 2204 } | |
| 2205 | |
| 2206 test_embedder_options() async { | 1995 test_embedder_options() async { |
| 2207 // Create files. | 1996 // Create files. |
| 2208 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); | 1997 String libPath = newFolder([projPath, ContextManagerTest.LIB_NAME]); |
| 2209 String sdkExtPath = newFolder([projPath, 'sdk_ext']); | 1998 String sdkExtPath = newFolder([projPath, 'sdk_ext']); |
| 2210 newFile([projPath, 'test', 'test.dart']); | 1999 newFile([projPath, 'test', 'test.dart']); |
| 2211 newFile([sdkExtPath, 'entry.dart']); | 2000 newFile([sdkExtPath, 'entry.dart']); |
| 2212 // Setup _embedder.yaml. | 2001 // Setup _embedder.yaml. |
| 2213 newFile( | 2002 newFile( |
| 2214 [libPath, '_embedder.yaml'], | 2003 [libPath, '_embedder.yaml'], |
| 2215 r''' | 2004 r''' |
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2804 class TestUriResolver extends UriResolver { | 2593 class TestUriResolver extends UriResolver { |
| 2805 Map<Uri, Source> uriMap; | 2594 Map<Uri, Source> uriMap; |
| 2806 | 2595 |
| 2807 TestUriResolver(this.uriMap); | 2596 TestUriResolver(this.uriMap); |
| 2808 | 2597 |
| 2809 @override | 2598 @override |
| 2810 Source resolveAbsolute(Uri uri, [Uri actualUri]) { | 2599 Source resolveAbsolute(Uri uri, [Uri actualUri]) { |
| 2811 return uriMap[uri]; | 2600 return uriMap[uri]; |
| 2812 } | 2601 } |
| 2813 } | 2602 } |
| OLD | NEW |