Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(506)

Side by Side Diff: pkg/analyzer/test/src/summary/resynthesize_ast_test.dart

Issue 2728883004: Verify resynthesized elements by comparing text presentations. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 'element_text.dart';
9 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/element/element.dart'; 11 import 'package:analyzer/dart/element/element.dart';
11 import 'package:analyzer/error/error.dart'; 12 import 'package:analyzer/error/error.dart';
12 import 'package:analyzer/src/dart/element/element.dart'; 13 import 'package:analyzer/src/dart/element/element.dart';
13 import 'package:analyzer/src/generated/engine.dart' 14 import 'package:analyzer/src/generated/engine.dart'
14 show AnalysisContext, AnalysisOptionsImpl; 15 show AnalysisContext, AnalysisOptionsImpl;
15 import 'package:analyzer/src/generated/sdk.dart'; 16 import 'package:analyzer/src/generated/sdk.dart';
16 import 'package:analyzer/src/generated/source.dart'; 17 import 'package:analyzer/src/generated/source.dart';
17 import 'package:analyzer/src/summary/format.dart'; 18 import 'package:analyzer/src/summary/format.dart';
18 import 'package:analyzer/src/summary/idl.dart'; 19 import 'package:analyzer/src/summary/idl.dart';
19 import 'package:analyzer/src/summary/link.dart'; 20 import 'package:analyzer/src/summary/link.dart';
20 import 'package:analyzer/src/summary/prelink.dart'; 21 import 'package:analyzer/src/summary/prelink.dart';
21 import 'package:analyzer/src/summary/resynthesize.dart'; 22 import 'package:analyzer/src/summary/resynthesize.dart';
22 import 'package:analyzer/src/summary/summarize_ast.dart'; 23 import 'package:analyzer/src/summary/summarize_ast.dart';
23 import 'package:analyzer/src/summary/summarize_elements.dart' 24 import 'package:analyzer/src/summary/summarize_elements.dart'
24 show PackageBundleAssembler; 25 show PackageBundleAssembler;
25 import 'package:analyzer/task/dart.dart' show PARSED_UNIT; 26 import 'package:analyzer/task/dart.dart' show PARSED_UNIT;
26 import 'package:analyzer/task/general.dart'; 27 import 'package:analyzer/task/general.dart';
27 import 'package:test/test.dart'; 28 import 'package:test/test.dart';
28 import 'package:test_reflective_loader/test_reflective_loader.dart'; 29 import 'package:test_reflective_loader/test_reflective_loader.dart';
29 30
30 import '../context/abstract_context.dart'; 31 import '../context/abstract_context.dart';
31 import '../task/strong/inferred_type_test.dart'; 32 import '../task/strong/inferred_type_test.dart';
32 import 'resynthesize_common.dart'; 33 import 'resynthesize_common.dart';
33 import 'summary_common.dart'; 34 import 'summary_common.dart';
34 35
36 @reflectiveTest
37 class ApplyReplacements {
38 test_applyReplacements() {
39 applyReplacements();
40 }
41 }
42
35 main() { 43 main() {
36 defineReflectiveSuite(() { 44 defineReflectiveSuite(() {
37 defineReflectiveTests(ResynthesizeAstSpecTest); 45 defineReflectiveTests(ResynthesizeAstSpecTest);
38 defineReflectiveTests(ResynthesizeAstStrongTest); 46 defineReflectiveTests(ResynthesizeAstStrongTest);
39 defineReflectiveTests(AstInferredTypeTest); 47 // defineReflectiveTests(AstInferredTypeTest);
48 defineReflectiveTests(ApplyReplacements);
Brian Wilkerson 2017/03/03 16:09:33 I assume you'll reverse the commenting before comm
40 }); 49 });
41 } 50 }
42 51
43 @reflectiveTest 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
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698