| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.src.task.dart_test; | 5 library test.src.task.dart_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/context/cache.dart'; | 7 import 'package:analyzer/src/context/cache.dart'; |
| 8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
| 9 import 'package:analyzer/src/generated/constant.dart'; | 9 import 'package:analyzer/src/generated/constant.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
| 11 import 'package:analyzer/src/generated/engine.dart' show CacheState; |
| 11 import 'package:analyzer/src/generated/error.dart'; | 12 import 'package:analyzer/src/generated/error.dart'; |
| 12 import 'package:analyzer/src/generated/resolver.dart'; | 13 import 'package:analyzer/src/generated/resolver.dart'; |
| 13 import 'package:analyzer/src/generated/source.dart'; | 14 import 'package:analyzer/src/generated/source.dart'; |
| 14 import 'package:analyzer/src/task/dart.dart'; | 15 import 'package:analyzer/src/task/dart.dart'; |
| 15 import 'package:analyzer/task/dart.dart'; | 16 import 'package:analyzer/task/dart.dart'; |
| 16 import 'package:analyzer/task/general.dart'; | 17 import 'package:analyzer/task/general.dart'; |
| 17 import 'package:analyzer/task/model.dart'; | 18 import 'package:analyzer/task/model.dart'; |
| 18 import 'package:unittest/unittest.dart'; | 19 import 'package:unittest/unittest.dart'; |
| 19 | 20 |
| 20 import '../../generated/test_support.dart'; | 21 import '../../generated/test_support.dart'; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 expect(task, new isInstanceOf<BuildClassConstructorsTask>()); | 156 expect(task, new isInstanceOf<BuildClassConstructorsTask>()); |
| 156 _fillErrorListener(CONSTRUCTORS_ERRORS); | 157 _fillErrorListener(CONSTRUCTORS_ERRORS); |
| 157 errorListener.assertErrorsWithCodes( | 158 errorListener.assertErrorsWithCodes( |
| 158 <ErrorCode>[CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); | 159 <ErrorCode>[CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); |
| 159 } | 160 } |
| 160 } | 161 } |
| 161 | 162 |
| 162 @reflectiveTest | 163 @reflectiveTest |
| 163 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { | 164 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { |
| 164 Source source; | 165 Source source; |
| 166 LibrarySpecificUnit target; |
| 165 | 167 |
| 166 test_buildInputs() { | 168 test_buildInputs() { |
| 167 LibrarySpecificUnit target = | 169 LibrarySpecificUnit target = |
| 168 new LibrarySpecificUnit(emptySource, emptySource); | 170 new LibrarySpecificUnit(emptySource, emptySource); |
| 169 Map<String, TaskInput> inputs = | 171 Map<String, TaskInput> inputs = |
| 170 BuildCompilationUnitElementTask.buildInputs(target); | 172 BuildCompilationUnitElementTask.buildInputs(target); |
| 171 expect(inputs, isNotNull); | 173 expect(inputs, isNotNull); |
| 172 expect(inputs.keys, unorderedEquals( | 174 expect(inputs.keys, unorderedEquals( |
| 173 [BuildCompilationUnitElementTask.PARSED_UNIT_INPUT_NAME])); | 175 [BuildCompilationUnitElementTask.PARSED_UNIT_INPUT_NAME])); |
| 174 } | 176 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 part 'part.dart'; | 239 part 'part.dart'; |
| 238 class A {} | 240 class A {} |
| 239 class B = Object with A; | 241 class B = Object with A; |
| 240 '''); | 242 '''); |
| 241 expect(outputs, hasLength(3)); | 243 expect(outputs, hasLength(3)); |
| 242 expect(outputs[COMPILATION_UNIT_ELEMENT], isNotNull); | 244 expect(outputs[COMPILATION_UNIT_ELEMENT], isNotNull); |
| 243 expect(outputs[RESOLVED_UNIT1], isNotNull); | 245 expect(outputs[RESOLVED_UNIT1], isNotNull); |
| 244 expect(outputs[COMPILATION_UNIT_CONSTANTS], isNotNull); | 246 expect(outputs[COMPILATION_UNIT_CONSTANTS], isNotNull); |
| 245 } | 247 } |
| 246 | 248 |
| 249 test_perform_reuseElement() { |
| 250 _performBuildTask(r''' |
| 251 library lib; |
| 252 class A {} |
| 253 class B = Object with A; |
| 254 '''); |
| 255 CompilationUnit unit = outputs[RESOLVED_UNIT1]; |
| 256 CompilationUnitElement unitElement = outputs[COMPILATION_UNIT_ELEMENT]; |
| 257 expect(unit, isNotNull); |
| 258 expect(unitElement, isNotNull); |
| 259 // invalidate RESOLVED_UNIT1 |
| 260 CacheEntry cacheEntry = analysisCache.get(target); |
| 261 cacheEntry.setState(RESOLVED_UNIT1, CacheState.INVALID); |
| 262 // compute again |
| 263 _computeResult(target, RESOLVED_UNIT1); |
| 264 expect(outputs[COMPILATION_UNIT_ELEMENT], same(unitElement)); |
| 265 expect(outputs[RESOLVED_UNIT1], isNot(same(unit))); |
| 266 } |
| 267 |
| 247 void _performBuildTask(String content) { | 268 void _performBuildTask(String content) { |
| 248 source = newSource('/test.dart', content); | 269 source = newSource('/test.dart', content); |
| 249 AnalysisTarget target = new LibrarySpecificUnit(source, source); | 270 target = new LibrarySpecificUnit(source, source); |
| 250 _computeResult(target, RESOLVED_UNIT1); | 271 _computeResult(target, RESOLVED_UNIT1); |
| 251 expect(task, new isInstanceOf<BuildCompilationUnitElementTask>()); | 272 expect(task, new isInstanceOf<BuildCompilationUnitElementTask>()); |
| 252 } | 273 } |
| 253 } | 274 } |
| 254 | 275 |
| 255 @reflectiveTest | 276 @reflectiveTest |
| 256 class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest { | 277 class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest { |
| 257 test_constructor() { | 278 test_constructor() { |
| 258 BuildDirectiveElementsTask task = | 279 BuildDirectiveElementsTask task = |
| 259 new BuildDirectiveElementsTask(context, emptySource); | 280 new BuildDirectiveElementsTask(context, emptySource); |
| (...skipping 2214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2474 /** | 2495 /** |
| 2475 * Fill [errorListener] with [result] errors in the current [task]. | 2496 * Fill [errorListener] with [result] errors in the current [task]. |
| 2476 */ | 2497 */ |
| 2477 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 2498 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 2478 List<AnalysisError> errors = task.outputs[result]; | 2499 List<AnalysisError> errors = task.outputs[result]; |
| 2479 expect(errors, isNotNull, reason: result.name); | 2500 expect(errors, isNotNull, reason: result.name); |
| 2480 errorListener = new GatheringErrorListener(); | 2501 errorListener = new GatheringErrorListener(); |
| 2481 errorListener.addAll(errors); | 2502 errorListener.addAll(errors); |
| 2482 } | 2503 } |
| 2483 } | 2504 } |
| OLD | NEW |