| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.summary.summarize_ast_test; | 5 library analyzer.test.src.summary.summarize_ast_test; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/dart/ast/ast.dart'; | 8 import 'package:analyzer/dart/ast/ast.dart'; |
| 9 import 'package:analyzer/dart/ast/token.dart'; | 9 import 'package:analyzer/dart/ast/token.dart'; |
| 10 import 'package:analyzer/src/dart/scanner/reader.dart'; | 10 import 'package:analyzer/src/dart/scanner/reader.dart'; |
| 11 import 'package:analyzer/src/dart/scanner/scanner.dart'; | 11 import 'package:analyzer/src/dart/scanner/scanner.dart'; |
| 12 import 'package:analyzer/src/generated/error.dart'; | 12 import 'package:analyzer/src/generated/error.dart'; |
| 13 import 'package:analyzer/src/generated/parser.dart'; | 13 import 'package:analyzer/src/generated/parser.dart'; |
| 14 import 'package:analyzer/src/summary/idl.dart'; | 14 import 'package:analyzer/src/summary/idl.dart'; |
| 15 import 'package:analyzer/src/summary/link.dart'; | 15 import 'package:analyzer/src/summary/link.dart'; |
| 16 import 'package:analyzer/src/summary/summarize_ast.dart'; | 16 import 'package:analyzer/src/summary/summarize_ast.dart'; |
| 17 import 'package:unittest/unittest.dart'; | 17 import 'package:unittest/unittest.dart'; |
| 18 | 18 |
| 19 import '../../reflective_tests.dart'; | 19 import '../../reflective_tests.dart'; |
| 20 import 'summary_common.dart'; | 20 import 'summary_common.dart'; |
| 21 | 21 |
| 22 main() { | 22 main() { |
| 23 groupSep = ' | '; | 23 groupSep = ' | '; |
| 24 runReflectiveTests(LinkedSummarizeAstTest); | 24 runReflectiveTests(LinkedSummarizeAstSpecTest); |
| 25 } | 25 } |
| 26 | 26 |
| 27 /** | |
| 28 * Override of [SummaryTest] which creates unlinked summaries directly from the | |
| 29 * AST. | |
| 30 */ | |
| 31 @reflectiveTest | 27 @reflectiveTest |
| 32 class LinkedSummarizeAstTest extends Object with SummaryTest { | 28 class LinkedSummarizeAstSpecTest extends LinkedSummarizeAstTest { |
| 33 @override | |
| 34 LinkedLibrary linked; | |
| 35 | |
| 36 @override | |
| 37 List<UnlinkedUnit> unlinkedUnits; | |
| 38 | |
| 39 /** | |
| 40 * Map from absolute URI to the [UnlinkedUnit] for each compilation unit | |
| 41 * passed to [addNamedSource]. | |
| 42 */ | |
| 43 Map<String, UnlinkedUnit> uriToUnit = <String, UnlinkedUnit>{}; | |
| 44 | |
| 45 @override | |
| 46 bool get checkAstDerivedData => true; | |
| 47 | |
| 48 @override | |
| 49 bool get expectAbsoluteUrisInDependencies => false; | |
| 50 | |
| 51 @override | |
| 52 bool get skipFullyLinkedData => false; | |
| 53 | |
| 54 @override | 29 @override |
| 55 bool get strongMode => false; | 30 bool get strongMode => false; |
| 56 | 31 |
| 57 @override | 32 @override |
| 58 addNamedSource(String filePath, String contents) { | |
| 59 CompilationUnit unit = _parseText(contents); | |
| 60 UnlinkedUnit unlinkedUnit = | |
| 61 new UnlinkedUnit.fromBuffer(serializeAstUnlinked(unit).toBuffer()); | |
| 62 uriToUnit[absUri(filePath)] = unlinkedUnit; | |
| 63 } | |
| 64 | |
| 65 @override | |
| 66 void serializeLibraryText(String text, {bool allowErrors: false}) { | |
| 67 Uri testDartUri = Uri.parse(absUri('/test.dart')); | |
| 68 CompilationUnit unit = _parseText(text); | |
| 69 UnlinkedUnit definingUnit = | |
| 70 new UnlinkedUnit.fromBuffer(serializeAstUnlinked(unit).toBuffer()); | |
| 71 uriToUnit[testDartUri.toString()] = definingUnit; | |
| 72 LinkedLibrary getDependency(String absoluteUri) { | |
| 73 Map<String, LinkedLibrary> sdkLibraries = | |
| 74 SerializedMockSdk.instance.uriToLinkedLibrary; | |
| 75 LinkedLibrary linkedLibrary = sdkLibraries[absoluteUri]; | |
| 76 if (linkedLibrary == null && !allowMissingFiles) { | |
| 77 fail('Linker unexpectedly requested LinkedLibrary for "$absoluteUri".' | |
| 78 ' Libraries available: ${sdkLibraries.keys}'); | |
| 79 } | |
| 80 return linkedLibrary; | |
| 81 } | |
| 82 UnlinkedUnit getUnit(String absoluteUri) { | |
| 83 UnlinkedUnit unit = uriToUnit[absoluteUri] ?? | |
| 84 SerializedMockSdk.instance.uriToUnlinkedUnit[absoluteUri]; | |
| 85 if (unit == null && !allowMissingFiles) { | |
| 86 fail('Linker unexpectedly requested unit for "$absoluteUri".'); | |
| 87 } | |
| 88 return unit; | |
| 89 } | |
| 90 linked = link(uriToUnit.keys.toSet(), getDependency, getUnit)[ | |
| 91 testDartUri.toString()]; | |
| 92 expect(linked, isNotNull); | |
| 93 validateLinkedLibrary(linked); | |
| 94 unlinkedUnits = <UnlinkedUnit>[definingUnit]; | |
| 95 for (String relativeUri in definingUnit.publicNamespace.parts) { | |
| 96 UnlinkedUnit unit = uriToUnit[ | |
| 97 resolveRelativeUri(testDartUri, Uri.parse(relativeUri)).toString()]; | |
| 98 if (unit == null) { | |
| 99 if (!allowMissingFiles) { | |
| 100 fail('Test referred to unknown unit $relativeUri'); | |
| 101 } | |
| 102 } else { | |
| 103 unlinkedUnits.add(unit); | |
| 104 } | |
| 105 } | |
| 106 } | |
| 107 | |
| 108 @override | |
| 109 test_bottom_reference_shared() { | 33 test_bottom_reference_shared() { |
| 110 // TODO(paulberry): fix. | 34 // TODO(paulberry): fix. |
| 111 } | 35 } |
| 112 | 36 |
| 113 test_class_no_superclass() { | |
| 114 UnlinkedClass cls = serializeClassText('part of dart.core; class Object {}', | |
| 115 className: 'Object'); | |
| 116 expect(cls.supertype, isNull); | |
| 117 expect(cls.hasNoSupertype, isTrue); | |
| 118 } | |
| 119 | |
| 120 @override | 37 @override |
| 121 test_closure_executable_with_bottom_return_type() { | 38 test_closure_executable_with_bottom_return_type() { |
| 122 // TODO(paulberry): fix. | 39 // TODO(paulberry): fix. |
| 123 } | 40 } |
| 124 | 41 |
| 125 @override | 42 @override |
| 126 test_closure_executable_with_imported_return_type() { | 43 test_closure_executable_with_imported_return_type() { |
| 127 // TODO(paulberry): fix. | 44 // TODO(paulberry): fix. |
| 128 } | 45 } |
| 129 | 46 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 136 |
| 220 @override | 137 @override |
| 221 test_variable_propagated_type_new_reference() { | 138 test_variable_propagated_type_new_reference() { |
| 222 // TODO(paulberry): fix. | 139 // TODO(paulberry): fix. |
| 223 } | 140 } |
| 224 | 141 |
| 225 @override | 142 @override |
| 226 test_variable_propagated_type_omit_dynamic() { | 143 test_variable_propagated_type_omit_dynamic() { |
| 227 // TODO(paulberry): fix. | 144 // TODO(paulberry): fix. |
| 228 } | 145 } |
| 146 } |
| 147 |
| 148 /** |
| 149 * Override of [SummaryTest] which creates linked summaries directly from the |
| 150 * AST. |
| 151 */ |
| 152 @reflectiveTest |
| 153 abstract class LinkedSummarizeAstTest extends Object with SummaryTest { |
| 154 @override |
| 155 LinkedLibrary linked; |
| 156 |
| 157 @override |
| 158 List<UnlinkedUnit> unlinkedUnits; |
| 159 |
| 160 /** |
| 161 * Map from absolute URI to the [UnlinkedUnit] for each compilation unit |
| 162 * passed to [addNamedSource]. |
| 163 */ |
| 164 Map<String, UnlinkedUnit> uriToUnit = <String, UnlinkedUnit>{}; |
| 165 |
| 166 @override |
| 167 bool get checkAstDerivedData => true; |
| 168 |
| 169 @override |
| 170 bool get expectAbsoluteUrisInDependencies => false; |
| 171 |
| 172 @override |
| 173 bool get skipFullyLinkedData => false; |
| 174 |
| 175 @override |
| 176 addNamedSource(String filePath, String contents) { |
| 177 CompilationUnit unit = _parseText(contents); |
| 178 UnlinkedUnit unlinkedUnit = |
| 179 new UnlinkedUnit.fromBuffer(serializeAstUnlinked(unit).toBuffer()); |
| 180 uriToUnit[absUri(filePath)] = unlinkedUnit; |
| 181 } |
| 182 |
| 183 @override |
| 184 void serializeLibraryText(String text, {bool allowErrors: false}) { |
| 185 Uri testDartUri = Uri.parse(absUri('/test.dart')); |
| 186 CompilationUnit unit = _parseText(text); |
| 187 UnlinkedUnit definingUnit = |
| 188 new UnlinkedUnit.fromBuffer(serializeAstUnlinked(unit).toBuffer()); |
| 189 uriToUnit[testDartUri.toString()] = definingUnit; |
| 190 LinkedLibrary getDependency(String absoluteUri) { |
| 191 Map<String, LinkedLibrary> sdkLibraries = |
| 192 SerializedMockSdk.instance.uriToLinkedLibrary; |
| 193 LinkedLibrary linkedLibrary = sdkLibraries[absoluteUri]; |
| 194 if (linkedLibrary == null && !allowMissingFiles) { |
| 195 fail('Linker unexpectedly requested LinkedLibrary for "$absoluteUri".' |
| 196 ' Libraries available: ${sdkLibraries.keys}'); |
| 197 } |
| 198 return linkedLibrary; |
| 199 } |
| 200 UnlinkedUnit getUnit(String absoluteUri) { |
| 201 UnlinkedUnit unit = uriToUnit[absoluteUri] ?? |
| 202 SerializedMockSdk.instance.uriToUnlinkedUnit[absoluteUri]; |
| 203 if (unit == null && !allowMissingFiles) { |
| 204 fail('Linker unexpectedly requested unit for "$absoluteUri".'); |
| 205 } |
| 206 return unit; |
| 207 } |
| 208 linked = link(uriToUnit.keys.toSet(), getDependency, getUnit)[ |
| 209 testDartUri.toString()]; |
| 210 expect(linked, isNotNull); |
| 211 validateLinkedLibrary(linked); |
| 212 unlinkedUnits = <UnlinkedUnit>[definingUnit]; |
| 213 for (String relativeUri in definingUnit.publicNamespace.parts) { |
| 214 UnlinkedUnit unit = uriToUnit[ |
| 215 resolveRelativeUri(testDartUri, Uri.parse(relativeUri)).toString()]; |
| 216 if (unit == null) { |
| 217 if (!allowMissingFiles) { |
| 218 fail('Test referred to unknown unit $relativeUri'); |
| 219 } |
| 220 } else { |
| 221 unlinkedUnits.add(unit); |
| 222 } |
| 223 } |
| 224 } |
| 225 |
| 226 test_class_no_superclass() { |
| 227 UnlinkedClass cls = serializeClassText('part of dart.core; class Object {}', |
| 228 className: 'Object'); |
| 229 expect(cls.supertype, isNull); |
| 230 expect(cls.hasNoSupertype, isTrue); |
| 231 } |
| 229 | 232 |
| 230 CompilationUnit _parseText(String text) { | 233 CompilationUnit _parseText(String text) { |
| 231 CharSequenceReader reader = new CharSequenceReader(text); | 234 CharSequenceReader reader = new CharSequenceReader(text); |
| 232 Scanner scanner = | 235 Scanner scanner = |
| 233 new Scanner(null, reader, AnalysisErrorListener.NULL_LISTENER); | 236 new Scanner(null, reader, AnalysisErrorListener.NULL_LISTENER); |
| 234 Token token = scanner.tokenize(); | 237 Token token = scanner.tokenize(); |
| 235 Parser parser = new Parser(null, AnalysisErrorListener.NULL_LISTENER); | 238 Parser parser = new Parser(null, AnalysisErrorListener.NULL_LISTENER); |
| 236 parser.parseGenericMethods = true; | 239 parser.parseGenericMethods = true; |
| 237 return parser.parseCompilationUnit(token); | 240 return parser.parseCompilationUnit(token); |
| 238 } | 241 } |
| 239 } | 242 } |
| OLD | NEW |