| 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.resynthesize_ast_test; | 5 library analyzer.test.src.summary.resynthesize_ast_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 import 'package:analyzer/src/summary/summarize_ast.dart'; | 22 import 'package:analyzer/src/summary/summarize_ast.dart'; |
| 23 import 'package:analyzer/src/summary/summarize_elements.dart' | 23 import 'package:analyzer/src/summary/summarize_elements.dart' |
| 24 show PackageBundleAssembler; | 24 show PackageBundleAssembler; |
| 25 import 'package:analyzer/task/dart.dart' show PARSED_UNIT; | 25 import 'package:analyzer/task/dart.dart' show PARSED_UNIT; |
| 26 import 'package:analyzer/task/general.dart'; | 26 import 'package:analyzer/task/general.dart'; |
| 27 import 'package:test/test.dart'; | 27 import 'package:test/test.dart'; |
| 28 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 28 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 29 | 29 |
| 30 import '../context/abstract_context.dart'; | 30 import '../context/abstract_context.dart'; |
| 31 import '../task/strong/inferred_type_test.dart'; | 31 import '../task/strong/inferred_type_test.dart'; |
| 32 import 'element_text.dart'; |
| 32 import 'resynthesize_common.dart'; | 33 import 'resynthesize_common.dart'; |
| 33 import 'summary_common.dart'; | 34 import 'summary_common.dart'; |
| 34 | 35 |
| 35 main() { | 36 main() { |
| 36 defineReflectiveSuite(() { | 37 defineReflectiveSuite(() { |
| 37 defineReflectiveTests(ResynthesizeAstSpecTest); | 38 defineReflectiveTests(ResynthesizeAstSpecTest); |
| 38 defineReflectiveTests(ResynthesizeAstStrongTest); | 39 defineReflectiveTests(ResynthesizeAstStrongTest); |
| 39 defineReflectiveTests(AstInferredTypeTest); | 40 defineReflectiveTests(AstInferredTypeTest); |
| 41 defineReflectiveTests(ApplyCheckElementTextReplacements); |
| 40 }); | 42 }); |
| 41 } | 43 } |
| 42 | 44 |
| 43 @reflectiveTest | 45 @reflectiveTest |
| 46 class ApplyCheckElementTextReplacements { |
| 47 test_applyReplacements() { |
| 48 applyCheckElementTextReplacements(); |
| 49 } |
| 50 } |
| 51 |
| 52 @reflectiveTest |
| 44 class AstInferredTypeTest extends AbstractResynthesizeTest | 53 class AstInferredTypeTest extends AbstractResynthesizeTest |
| 45 with _AstResynthesizeTestMixin, InferredTypeMixin { | 54 with _AstResynthesizeTestMixin, InferredTypeMixin { |
| 46 @override | 55 @override |
| 56 bool get isStrongMode => true; |
| 57 |
| 58 @override |
| 47 bool get mayCheckTypesOfLocals => false; | 59 bool get mayCheckTypesOfLocals => false; |
| 48 | 60 |
| 49 @override | 61 @override |
| 50 void addFile(String content, {String name: '/main.dart'}) { | 62 void addFile(String content, {String name: '/main.dart'}) { |
| 51 addLibrarySource(name, content); | 63 addLibrarySource(name, content); |
| 52 } | 64 } |
| 53 | 65 |
| 54 @override | 66 @override |
| 55 Future<CompilationUnitElement> checkFileElement(String content) async { | 67 Future<CompilationUnitElement> checkFileElement(String content) async { |
| 56 Source source = addSource('/main.dart', content); | 68 Source source = addSource('/main.dart', content); |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 resynthesizer.getLibraryElement(source.uri.toString()); | 691 resynthesizer.getLibraryElement(source.uri.toString()); |
| 680 LibraryElementImpl original = context.computeLibraryElement(source); | 692 LibraryElementImpl original = context.computeLibraryElement(source); |
| 681 checkLibraryElements(original, resynthesized); | 693 checkLibraryElements(original, resynthesized); |
| 682 return resynthesized; | 694 return resynthesized; |
| 683 } | 695 } |
| 684 } | 696 } |
| 685 | 697 |
| 686 @reflectiveTest | 698 @reflectiveTest |
| 687 class ResynthesizeAstSpecTest extends _ResynthesizeAstTest { | 699 class ResynthesizeAstSpecTest extends _ResynthesizeAstTest { |
| 688 @override | 700 @override |
| 689 AnalysisOptionsImpl createOptions() => | 701 bool get isStrongMode => false; |
| 690 super.createOptions()..strongMode = false; | |
| 691 } | 702 } |
| 692 | 703 |
| 693 @reflectiveTest | 704 @reflectiveTest |
| 694 class ResynthesizeAstStrongTest extends _ResynthesizeAstTest { | 705 class ResynthesizeAstStrongTest extends _ResynthesizeAstTest { |
| 695 @override | 706 @override |
| 707 bool get isStrongMode => true; |
| 708 |
| 709 @override |
| 696 AnalysisOptionsImpl createOptions() => | 710 AnalysisOptionsImpl createOptions() => |
| 697 super.createOptions()..strongMode = true; | 711 super.createOptions()..strongMode = true; |
| 698 | 712 |
| 699 @override | 713 @override |
| 700 test_instantiateToBounds_boundRefersToItself() async { | 714 test_instantiateToBounds_boundRefersToItself() async { |
| 701 await super.test_instantiateToBounds_boundRefersToItself(); | 715 await super.test_instantiateToBounds_boundRefersToItself(); |
| 702 } | 716 } |
| 703 | 717 |
| 704 @override | 718 @override |
| 705 @failingTest | 719 @failingTest |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 abstract class _AstResynthesizeTestMixinInterface { | 887 abstract class _AstResynthesizeTestMixinInterface { |
| 874 /** | 888 /** |
| 875 * A test should return `true` to indicate that a missing file at the time of | 889 * A test should return `true` to indicate that a missing file at the time of |
| 876 * summary resynthesis shouldn't trigger an error. | 890 * summary resynthesis shouldn't trigger an error. |
| 877 */ | 891 */ |
| 878 bool get allowMissingFiles; | 892 bool get allowMissingFiles; |
| 879 } | 893 } |
| 880 | 894 |
| 881 abstract class _ResynthesizeAstTest extends ResynthesizeTest | 895 abstract class _ResynthesizeAstTest extends ResynthesizeTest |
| 882 with _AstResynthesizeTestMixin { | 896 with _AstResynthesizeTestMixin { |
| 897 bool get isStrongMode; |
| 898 |
| 883 @override | 899 @override |
| 884 LibraryElementImpl checkLibrary(String text, | 900 LibraryElementImpl checkLibrary(String text, |
| 885 {bool allowErrors: false, bool dumpSummaries: false}) { | 901 {bool allowErrors: false, bool dumpSummaries: false}) { |
| 886 Source source = addTestSource(text); | 902 Source source = addTestSource(text); |
| 887 LibraryElementImpl resynthesized = _encodeDecodeLibraryElement(source); | 903 LibraryElementImpl resynthesized = _encodeDecodeLibraryElement(source); |
| 888 LibraryElementImpl original = context.computeLibraryElement(source); | 904 LibraryElementImpl original = context.computeLibraryElement(source); |
| 889 if (!allowErrors) { | 905 if (!allowErrors) { |
| 890 List<AnalysisError> errors = context.computeErrors(source); | 906 List<AnalysisError> errors = context.computeErrors(source); |
| 891 if (errors.where((e) => e.message.startsWith('unused')).isNotEmpty) { | 907 if (errors.where((e) => e.message.startsWith('unused')).isNotEmpty) { |
| 892 fail('Analysis errors: $errors'); | 908 fail('Analysis errors: $errors'); |
| 893 } | 909 } |
| 894 } | 910 } |
| 895 checkLibraryElements(original, resynthesized); | 911 checkLibraryElements(original, resynthesized); |
| 896 return resynthesized; | 912 return resynthesized; |
| 897 } | 913 } |
| 898 | 914 |
| 899 @override | 915 @override |
| 900 void compareLocalElementsOfExecutable(ExecutableElement resynthesized, | 916 void compareLocalElementsOfExecutable(ExecutableElement resynthesized, |
| 901 ExecutableElement original, String desc) { | 917 ExecutableElement original, String desc) { |
| 902 // We don't resynthesize local elements during link. | 918 // We don't resynthesize local elements during link. |
| 903 // So, we should not compare them. | 919 // So, we should not compare them. |
| 904 } | 920 } |
| 905 | 921 |
| 906 @override | 922 @override |
| 907 DartSdk createDartSdk() => AbstractContextTest.SHARED_MOCK_SDK; | 923 DartSdk createDartSdk() => AbstractContextTest.SHARED_MOCK_SDK; |
| 908 | 924 |
| 909 @override | 925 @override |
| 926 AnalysisOptionsImpl createOptions() => |
| 927 super.createOptions()..strongMode = isStrongMode; |
| 928 |
| 929 @override |
| 910 TestSummaryResynthesizer encodeDecodeLibrarySource(Source source) { | 930 TestSummaryResynthesizer encodeDecodeLibrarySource(Source source) { |
| 911 return _encodeLibrary(source); | 931 return _encodeLibrary(source); |
| 912 } | 932 } |
| 913 } | 933 } |
| OLD | NEW |