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

Side by Side Diff: tests/compiler/dart2js/patch_test.dart

Issue 2836733002: dart2js: patch file support cleanup (Closed)
Patch Set: remove js_array change Created 3 years, 8 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
« no previous file with comments | « tests/compiler/dart2js/mock_compiler.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 import 'dart:async'; 5 import 'dart:async';
6 import 'package:expect/expect.dart'; 6 import 'package:expect/expect.dart';
7 import 'package:async_helper/async_helper.dart'; 7 import 'package:async_helper/async_helper.dart';
8 import 'package:compiler/src/compiler.dart'; 8 import 'package:compiler/src/compiler.dart';
9 import 'package:compiler/src/diagnostics/messages.dart' show MessageKind; 9 import 'package:compiler/src/diagnostics/messages.dart' show MessageKind;
10 import 'package:compiler/src/elements/elements.dart'; 10 import 'package:compiler/src/elements/elements.dart';
11 import 'package:compiler/src/elements/modelx.dart'; 11 import 'package:compiler/src/elements/modelx.dart';
12 import 'package:compiler/src/tree/tree.dart'; 12 import 'package:compiler/src/tree/tree.dart';
13 import 'package:compiler/src/types/types.dart'; 13 import 'package:compiler/src/types/types.dart';
14 import 'package:compiler/src/universe/call_structure.dart' show CallStructure; 14 import 'package:compiler/src/universe/call_structure.dart' show CallStructure;
15 import 'package:compiler/src/universe/selector.dart' show Selector; 15 import 'package:compiler/src/universe/selector.dart' show Selector;
16 import 'package:compiler/src/world.dart'; 16 import 'package:compiler/src/world.dart';
17 17
18 import 'mock_compiler.dart'; 18 import 'mock_compiler.dart';
19 import 'mock_libraries.dart'; 19 import 'mock_libraries.dart';
20 20
21 Future<Compiler> applyPatch(String script, String patch, 21 Future<Compiler> applyPatch(String script, String patch,
22 {bool analyzeAll: false, 22 {bool analyzeAll: false,
23 bool analyzeOnly: false, 23 bool analyzeOnly: false,
24 bool runCompiler: false, 24 bool runCompiler: false,
25 String main: "", 25 String main: ""}) async {
26 String patchVersion}) async {
27 Map<String, String> core = <String, String>{'script': script}; 26 Map<String, String> core = <String, String>{'script': script};
28 MockCompiler compiler = new MockCompiler.internal( 27 MockCompiler compiler = new MockCompiler.internal(
29 coreSource: core, 28 coreSource: core, analyzeAll: analyzeAll, analyzeOnly: analyzeOnly);
30 analyzeAll: analyzeAll,
31 analyzeOnly: analyzeOnly,
32 patchVersion: patchVersion);
33 compiler.diagnosticHandler = createHandler(compiler, ''); 29 compiler.diagnosticHandler = createHandler(compiler, '');
34 var uri = Uri.parse("patch:core"); 30 var uri = Uri.parse("patch:core");
35 compiler.registerSource(uri, "$DEFAULT_PATCH_CORE_SOURCE\n$patch"); 31 compiler.registerSource(uri, "$DEFAULT_PATCH_CORE_SOURCE\n$patch");
36 if (runCompiler) { 32 if (runCompiler) {
37 await compiler.run(null, main); 33 await compiler.run(null, main);
38 } else { 34 } else {
39 await compiler.init(main); 35 await compiler.init(main);
40 } 36 }
41 return compiler; 37 return compiler;
42 } 38 }
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 compiler.resolver.resolve(origin); 207 compiler.resolver.resolve(origin);
212 208
213 DiagnosticCollector collector = compiler.diagnosticCollector; 209 DiagnosticCollector collector = compiler.diagnosticCollector;
214 Expect.isTrue( 210 Expect.isTrue(
215 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); 211 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}");
216 Expect.equals(1, collector.errors.length); 212 Expect.equals(1, collector.errors.length);
217 Expect.isTrue(collector.errors.first.message.kind == 213 Expect.isTrue(collector.errors.first.message.kind ==
218 MessageKind.PATCH_TYPE_VARIABLES_MISMATCH); 214 MessageKind.PATCH_TYPE_VARIABLES_MISMATCH);
219 } 215 }
220 216
221 Future testPatchVersioned() async {
222 String fullPatch = "test(){return 'string';}";
223 String lazyPatch = "test(){return 'new and improved string';}";
224
225 String patchSource = """
226 @patch_full $fullPatch
227 @patch_lazy $lazyPatch
228 """;
229
230 Future test(String patchVersion,
231 {String patchText,
232 bool expectIsPatched: true,
233 String expectedError,
234 String defaultPatch: '',
235 String expectedInternalError}) async {
236 return applyPatch(
237 "external test();",
238 """
239 $defaultPatch
240 $patchSource
241 """,
242 patchVersion: patchVersion).then((compiler) {
243 Element origin = ensure(
244 compiler, "test", compiler.commonElements.coreLibrary.find,
245 expectIsPatched: expectIsPatched, checkHasBody: true);
246 if (expectIsPatched) {
247 AstElement patch = ensure(
248 compiler, "test", compiler.commonElements.coreLibrary.patch.find,
249 expectIsPatch: true, checkHasBody: true);
250 Expect.equals(origin.patch, patch);
251 Expect.equals(patch.origin, origin);
252 Expect.equals(patchText, patch.node.toString());
253 }
254
255 compiler.resolution.computeWorldImpact(origin);
256 compiler.enqueuer.resolution.emptyDeferredQueueForTesting();
257
258 DiagnosticCollector collector = compiler.diagnosticCollector;
259 Expect.isTrue(collector.warnings.isEmpty,
260 "Unexpected warnings: ${collector.warnings}");
261 if (expectedError != null) {
262 Expect.equals(expectedError, collector.errors.first.message.toString());
263 } else {
264 Expect.isTrue(
265 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}");
266 }
267 }).catchError((error) {
268 if (expectedInternalError != null) {
269 Expect.equals(
270 'Internal Error: $expectedInternalError', error.toString());
271 } else {
272 throw error;
273 }
274 });
275 }
276
277 await test('full', patchText: fullPatch);
278 await test('lazy', patchText: lazyPatch);
279 await test('unknown',
280 expectIsPatched: false,
281 expectedError: 'External method without an implementation.');
282 await test('full',
283 defaultPatch: "@patch test(){}",
284 expectedInternalError: "Trying to patch a function more than once.");
285 }
286
287 Future testPatchConstructor() async { 217 Future testPatchConstructor() async {
288 var compiler = await applyPatch( 218 var compiler = await applyPatch(
289 """ 219 """
290 class Class { 220 class Class {
291 external Class(); 221 external Class();
292 } 222 }
293 """, 223 """,
294 """ 224 """
295 @patch class Class { 225 @patch class Class {
296 @patch Class(); 226 @patch Class();
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 await testPatchFunctionGenericDifferentNames(); 1074 await testPatchFunctionGenericDifferentNames();
1145 await testPatchMember(); 1075 await testPatchMember();
1146 await testPatchGetter(); 1076 await testPatchGetter();
1147 await testRegularMember(); 1077 await testRegularMember();
1148 await testInjectedMember(); 1078 await testInjectedMember();
1149 await testInjectedPublicMember(); 1079 await testInjectedPublicMember();
1150 await testInjectedFunction(); 1080 await testInjectedFunction();
1151 await testInjectedPublicFunction(); 1081 await testInjectedPublicFunction();
1152 await testPatchSignatureCheck(); 1082 await testPatchSignatureCheck();
1153 1083
1154 await testPatchVersioned();
1155
1156 await testExternalWithoutImplementationTopLevel(); 1084 await testExternalWithoutImplementationTopLevel();
1157 await testExternalWithoutImplementationMember(); 1085 await testExternalWithoutImplementationMember();
1158 1086
1159 await testIsSubclass(); 1087 await testIsSubclass();
1160 1088
1161 await testPatchNonExistingTopLevel(); 1089 await testPatchNonExistingTopLevel();
1162 await testPatchNonExistingMember(); 1090 await testPatchNonExistingMember();
1163 await testPatchNonPatchablePatch(); 1091 await testPatchNonPatchablePatch();
1164 await testPatchNonPatchableOrigin(); 1092 await testPatchNonPatchableOrigin();
1165 await testPatchNonExternalTopLevel(); 1093 await testPatchNonExternalTopLevel();
1166 await testPatchNonExternalMember(); 1094 await testPatchNonExternalMember();
1167 await testPatchNonClass(); 1095 await testPatchNonClass();
1168 await testPatchNonGetter(); 1096 await testPatchNonGetter();
1169 await testPatchNoGetter(); 1097 await testPatchNoGetter();
1170 await testPatchNonSetter(); 1098 await testPatchNonSetter();
1171 await testPatchNoSetter(); 1099 await testPatchNoSetter();
1172 await testPatchNonFunction(); 1100 await testPatchNonFunction();
1173 1101
1174 await testPatchAndSelector(); 1102 await testPatchAndSelector();
1175 1103
1176 await testEffectiveTarget(); 1104 await testEffectiveTarget();
1177 1105
1178 await testAnalyzeAllInjectedMembers(); 1106 await testAnalyzeAllInjectedMembers();
1179 await testTypecheckPatchedMembers(); 1107 await testTypecheckPatchedMembers();
1180 }); 1108 });
1181 } 1109 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/mock_compiler.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698