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

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

Issue 17759007: First pass at asynchronous input loading in dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased Created 7 years, 3 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 | Annotate | Revision Log
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 "package:expect/expect.dart"; 6 import "package:expect/expect.dart";
7 import "../../async_helper.dart";
6 import "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart"; 8 import "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart";
7 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t"; 9 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t";
8 import "../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart"; 10 import "../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart";
9 import "../../../sdk/lib/_internal/compiler/implementation/util/util.dart"; 11 import "../../../sdk/lib/_internal/compiler/implementation/util/util.dart";
10 import "mock_compiler.dart"; 12 import "mock_compiler.dart";
11 import "parser_helper.dart"; 13 import "parser_helper.dart";
12 14
13 Compiler applyPatch(String script, String patch, 15 Future<Compiler> applyPatch(String script, String patch,
14 {bool analyzeAll: false, bool analyzeOnly: false}) { 16 {bool analyzeAll: false, bool analyzeOnly: false}) {
15 String core = "$DEFAULT_CORELIB\n$script"; 17 String core = "$DEFAULT_CORELIB\n$script";
16 MockCompiler compiler = new MockCompiler(coreSource: core, 18 MockCompiler compiler = new MockCompiler(coreSource: core,
17 analyzeAll: analyzeAll, 19 analyzeAll: analyzeAll,
18 analyzeOnly: analyzeOnly); 20 analyzeOnly: analyzeOnly);
19 var uri = Uri.parse("core.dartp"); 21 var uri = Uri.parse("core.dartp");
20 compiler.sourceFiles[uri.toString()] = new MockFile(patch); 22 compiler.sourceFiles[uri.toString()] = new MockFile(patch);
21 var handler = new LibraryDependencyHandler(compiler); 23 var handler = new LibraryDependencyHandler(compiler);
22 compiler.patchParser.patchLibrary(handler, uri, compiler.coreLibrary); 24 return compiler.patchParser.patchLibrary(handler, uri, compiler.coreLibrary)
23 handler.computeExports(); 25 .then((_) {
24 return compiler; 26 handler.computeExports();
27 return compiler;
28 });
25 } 29 }
26 30
27 void expectHasBody(compiler, Element element) { 31 void expectHasBody(compiler, Element element) {
28 var node = element.parseNode(compiler); 32 var node = element.parseNode(compiler);
29 Expect.isNotNull(node, "Element isn't parseable, when a body was expected"); 33 Expect.isNotNull(node, "Element isn't parseable, when a body was expected");
30 Expect.isNotNull(node.body); 34 Expect.isNotNull(node.body);
31 // If the element has a body it is either a Block or a Return statement, 35 // If the element has a body it is either a Block or a Return statement,
32 // both with different begin and end tokens. 36 // both with different begin and end tokens.
33 Expect.isTrue(node.body is Block || node.body is Return); 37 Expect.isTrue(node.body is Block || node.body is Return);
34 Expect.notEquals(node.body.getBeginToken(), node.body.getEndToken()); 38 Expect.notEquals(node.body.getBeginToken(), node.body.getEndToken());
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 103
100 if (checkHasBody) { 104 if (checkHasBody) {
101 expectHasBody(compiler, element); 105 expectHasBody(compiler, element);
102 } 106 }
103 } 107 }
104 Expect.isFalse(element.isPatched && element.isPatch); 108 Expect.isFalse(element.isPatched && element.isPatch);
105 return element; 109 return element;
106 } 110 }
107 111
108 testPatchFunction() { 112 testPatchFunction() {
109 var compiler = applyPatch( 113 asyncTest(() => applyPatch(
110 "external test();", 114 "external test();",
111 "patch test() { return 'string'; } "); 115 "patch test() { return 'string'; } ").then((compiler) {
112 ensure(compiler, "test", compiler.coreLibrary.find, 116 ensure(compiler, "test", compiler.coreLibrary.find,
113 expectIsPatched: true, checkHasBody: true); 117 expectIsPatched: true, checkHasBody: true);
114 ensure(compiler, "test", compiler.coreLibrary.patch.find, 118 ensure(compiler, "test", compiler.coreLibrary.patch.find,
115 expectIsPatch: true, checkHasBody: true); 119 expectIsPatch: true, checkHasBody: true);
116 120
117 Expect.isTrue(compiler.warnings.isEmpty, 121 Expect.isTrue(compiler.warnings.isEmpty,
118 "Unexpected warnings: ${compiler.warnings}"); 122 "Unexpected warnings: ${compiler.warnings}");
119 Expect.isTrue(compiler.errors.isEmpty, 123 Expect.isTrue(compiler.errors.isEmpty,
120 "Unexpected errors: ${compiler.errors}"); 124 "Unexpected errors: ${compiler.errors}");
125 }));
121 } 126 }
122 127
123 testPatchConstructor() { 128 testPatchConstructor() {
124 var compiler = applyPatch( 129 asyncTest(() => applyPatch(
125 """ 130 """
126 class Class { 131 class Class {
127 external Class(); 132 external Class();
128 } 133 }
129 """, 134 """,
130 """ 135 """
131 patch class Class { 136 patch class Class {
132 patch Class(); 137 patch Class();
133 } 138 }
134 """); 139 """).then((compiler) {
135 var classOrigin = ensure(compiler, "Class", compiler.coreLibrary.find, 140 var classOrigin = ensure(compiler, "Class", compiler.coreLibrary.find,
136 expectIsPatched: true); 141 expectIsPatched: true);
137 classOrigin.ensureResolved(compiler); 142 classOrigin.ensureResolved(compiler);
138 var classPatch = ensure(compiler, "Class", compiler.coreLibrary.patch.find, 143 var classPatch = ensure(compiler, "Class", compiler.coreLibrary.patch.find,
139 expectIsPatch: true); 144 expectIsPatch: true);
140 145
141 Expect.equals(classPatch, classOrigin.patch); 146 Expect.equals(classPatch, classOrigin.patch);
142 Expect.equals(classOrigin, classPatch.origin); 147 Expect.equals(classOrigin, classPatch.origin);
143 148
144 var constructorOrigin = ensure(compiler, "", 149 var constructorOrigin = ensure(compiler, "",
145 (name) => classOrigin.localLookup(name), 150 (name) => classOrigin.localLookup(name),
146 expectIsPatched: true); 151 expectIsPatched: true);
147 var constructorPatch = ensure(compiler, "", 152 var constructorPatch = ensure(compiler, "",
148 (name) => classPatch.localLookup(name), 153 (name) => classPatch.localLookup(name),
149 expectIsPatch: true); 154 expectIsPatch: true);
150 155
151 Expect.equals(constructorPatch, constructorOrigin.patch); 156 Expect.equals(constructorPatch, constructorOrigin.patch);
152 Expect.equals(constructorOrigin, constructorPatch.origin); 157 Expect.equals(constructorOrigin, constructorPatch.origin);
153 158
154 Expect.isTrue(compiler.warnings.isEmpty, 159 Expect.isTrue(compiler.warnings.isEmpty,
155 "Unexpected warnings: ${compiler.warnings}"); 160 "Unexpected warnings: ${compiler.warnings}");
156 Expect.isTrue(compiler.errors.isEmpty, 161 Expect.isTrue(compiler.errors.isEmpty,
157 "Unexpected errors: ${compiler.errors}"); 162 "Unexpected errors: ${compiler.errors}");
163 }));
158 } 164 }
159 165
160 testPatchMember() { 166 testPatchMember() {
161 var compiler = applyPatch( 167 asyncTest(() => applyPatch(
162 """ 168 """
163 class Class { 169 class Class {
164 external String toString(); 170 external String toString();
165 } 171 }
166 """, 172 """,
167 """ 173 """
168 patch class Class { 174 patch class Class {
169 patch String toString() => 'string'; 175 patch String toString() => 'string';
170 } 176 }
171 """); 177 """).then((compiler) {
172 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 178 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
173 expectIsPatched: true); 179 expectIsPatched: true);
174 container.parseNode(compiler); 180 container.parseNode(compiler);
175 ensure(compiler, "Class", compiler.coreLibrary.patch.find, 181 ensure(compiler, "Class", compiler.coreLibrary.patch.find,
176 expectIsPatch: true); 182 expectIsPatch: true);
177 183
178 ensure(compiler, "toString", container.lookupLocalMember, 184 ensure(compiler, "toString", container.lookupLocalMember,
179 expectIsPatched: true, checkHasBody: true); 185 expectIsPatched: true, checkHasBody: true);
180 ensure(compiler, "toString", container.patch.lookupLocalMember, 186 ensure(compiler, "toString", container.patch.lookupLocalMember,
181 expectIsPatch: true, checkHasBody: true); 187 expectIsPatch: true, checkHasBody: true);
182 188
183 Expect.isTrue(compiler.warnings.isEmpty, 189 Expect.isTrue(compiler.warnings.isEmpty,
184 "Unexpected warnings: ${compiler.warnings}"); 190 "Unexpected warnings: ${compiler.warnings}");
185 Expect.isTrue(compiler.errors.isEmpty, 191 Expect.isTrue(compiler.errors.isEmpty,
186 "Unexpected errors: ${compiler.errors}"); 192 "Unexpected errors: ${compiler.errors}");
193 }));
187 } 194 }
188 195
189 testPatchGetter() { 196 testPatchGetter() {
190 var compiler = applyPatch( 197 asyncTest(() => applyPatch(
191 """ 198 """
192 class Class { 199 class Class {
193 external int get field; 200 external int get field;
194 } 201 }
195 """, 202 """,
196 """ 203 """
197 patch class Class { 204 patch class Class {
198 patch int get field => 5; 205 patch int get field => 5;
199 } 206 }
200 """); 207 """).then((compiler) {
201 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 208 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
202 expectIsPatched: true); 209 expectIsPatched: true);
203 container.parseNode(compiler); 210 container.parseNode(compiler);
204 ensure(compiler, 211 ensure(compiler,
205 "field", 212 "field",
206 container.lookupLocalMember, 213 container.lookupLocalMember,
207 expectIsGetter: true, 214 expectIsGetter: true,
208 expectIsPatched: true, 215 expectIsPatched: true,
209 checkHasBody: true); 216 checkHasBody: true);
210 ensure(compiler, 217 ensure(compiler,
211 "field", 218 "field",
212 container.patch.lookupLocalMember, 219 container.patch.lookupLocalMember,
213 expectIsGetter: true, 220 expectIsGetter: true,
214 expectIsPatch: true, 221 expectIsPatch: true,
215 checkHasBody: true); 222 checkHasBody: true);
216 223
217 Expect.isTrue(compiler.warnings.isEmpty, 224 Expect.isTrue(compiler.warnings.isEmpty,
218 "Unexpected warnings: ${compiler.warnings}"); 225 "Unexpected warnings: ${compiler.warnings}");
219 Expect.isTrue(compiler.errors.isEmpty, 226 Expect.isTrue(compiler.errors.isEmpty,
220 "Unexpected errors: ${compiler.errors}"); 227 "Unexpected errors: ${compiler.errors}");
228 }));
221 } 229 }
222 230
223 testRegularMember() { 231 testRegularMember() {
224 var compiler = applyPatch( 232 asyncTest(() => applyPatch(
225 """ 233 """
226 class Class { 234 class Class {
227 void regular() {} 235 void regular() {}
228 } 236 }
229 """, 237 """,
230 """ 238 """
231 patch class Class { 239 patch class Class {
232 } 240 }
233 """); 241 """).then((compiler) {
234 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 242 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
235 expectIsPatched: true); 243 expectIsPatched: true);
236 container.parseNode(compiler); 244 container.parseNode(compiler);
237 ensure(compiler, "Class", compiler.coreLibrary.patch.find, 245 ensure(compiler, "Class", compiler.coreLibrary.patch.find,
238 expectIsPatch: true); 246 expectIsPatch: true);
239 247
240 ensure(compiler, "regular", container.lookupLocalMember, 248 ensure(compiler, "regular", container.lookupLocalMember,
241 checkHasBody: true, expectIsRegular: true); 249 checkHasBody: true, expectIsRegular: true);
242 ensure(compiler, "regular", container.patch.lookupLocalMember, 250 ensure(compiler, "regular", container.patch.lookupLocalMember,
243 checkHasBody: true, expectIsRegular: true); 251 checkHasBody: true, expectIsRegular: true);
244 252
245 Expect.isTrue(compiler.warnings.isEmpty, 253 Expect.isTrue(compiler.warnings.isEmpty,
246 "Unexpected warnings: ${compiler.warnings}"); 254 "Unexpected warnings: ${compiler.warnings}");
247 Expect.isTrue(compiler.errors.isEmpty, 255 Expect.isTrue(compiler.errors.isEmpty,
248 "Unexpected errors: ${compiler.errors}"); 256 "Unexpected errors: ${compiler.errors}");
257 }));
249 } 258 }
250 259
251 testGhostMember() { 260 testGhostMember() {
252 var compiler = applyPatch( 261 asyncTest(() => applyPatch(
253 """ 262 """
254 class Class { 263 class Class {
255 } 264 }
256 """, 265 """,
257 """ 266 """
258 patch class Class { 267 patch class Class {
259 void ghost() {} 268 void ghost() {}
260 } 269 }
261 """); 270 """).then((compiler) {
262 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 271 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
263 expectIsPatched: true); 272 expectIsPatched: true);
264 container.parseNode(compiler); 273 container.parseNode(compiler);
265 ensure(compiler, "Class", compiler.coreLibrary.patch.find, 274 ensure(compiler, "Class", compiler.coreLibrary.patch.find,
266 expectIsPatch: true); 275 expectIsPatch: true);
267 276
268 ensure(compiler, "ghost", container.lookupLocalMember, 277 ensure(compiler, "ghost", container.lookupLocalMember,
269 expectIsFound: false); 278 expectIsFound: false);
270 ensure(compiler, "ghost", container.patch.lookupLocalMember, 279 ensure(compiler, "ghost", container.patch.lookupLocalMember,
271 checkHasBody: true, expectIsRegular: true); 280 checkHasBody: true, expectIsRegular: true);
272 281
273 Expect.isTrue(compiler.warnings.isEmpty, 282 Expect.isTrue(compiler.warnings.isEmpty,
274 "Unexpected warnings: ${compiler.warnings}"); 283 "Unexpected warnings: ${compiler.warnings}");
275 Expect.isTrue(compiler.errors.isEmpty, 284 Expect.isTrue(compiler.errors.isEmpty,
276 "Unexpected errors: ${compiler.errors}"); 285 "Unexpected errors: ${compiler.errors}");
286 }));
277 } 287 }
278 288
279 testInjectFunction() { 289 testInjectFunction() {
280 var compiler = applyPatch( 290 asyncTest(() => applyPatch(
281 "", 291 "",
282 "int _function() => 5;"); 292 "int _function() => 5;").then((compiler) {
283 ensure(compiler, 293 ensure(compiler,
284 "_function", 294 "_function",
285 compiler.coreLibrary.find, 295 compiler.coreLibrary.find,
286 expectIsFound: false); 296 expectIsFound: false);
287 ensure(compiler, 297 ensure(compiler,
288 "_function", 298 "_function",
289 compiler.coreLibrary.patch.find, 299 compiler.coreLibrary.patch.find,
290 checkHasBody: true, expectIsRegular: true); 300 checkHasBody: true, expectIsRegular: true);
291 301
292 Expect.isTrue(compiler.warnings.isEmpty, 302 Expect.isTrue(compiler.warnings.isEmpty,
293 "Unexpected warnings: ${compiler.warnings}"); 303 "Unexpected warnings: ${compiler.warnings}");
294 Expect.isTrue(compiler.errors.isEmpty, 304 Expect.isTrue(compiler.errors.isEmpty,
295 "Unexpected errors: ${compiler.errors}"); 305 "Unexpected errors: ${compiler.errors}");
306 }));
296 } 307 }
297 308
298 testPatchSignatureCheck() { 309 testPatchSignatureCheck() {
299 var compiler = applyPatch( 310 asyncTest(() => applyPatch(
300 """ 311 """
301 class Class { 312 class Class {
302 external String method1(); 313 external String method1();
303 external void method2(String str); 314 external void method2(String str);
304 external void method3(String s1); 315 external void method3(String s1);
305 external void method4([String str]); 316 external void method4([String str]);
306 external void method5({String str}); 317 external void method5({String str});
307 external void method6({String str}); 318 external void method6({String str});
308 external void method7([String s1]); 319 external void method7([String s1]);
309 external void method8({String s1}); 320 external void method8({String s1});
310 external void method9(String str); 321 external void method9(String str);
311 external void method10([String str]); 322 external void method10([String str]);
312 external void method11({String str}); 323 external void method11({String str});
313 } 324 }
314 """, 325 """,
315 """ 326 """
316 patch class Class { 327 patch class Class {
317 patch int method1() => 0; 328 patch int method1() => 0;
318 patch void method2() {} 329 patch void method2() {}
319 patch void method3(String s2) {} 330 patch void method3(String s2) {}
320 patch void method4([String str, int i]) {} 331 patch void method4([String str, int i]) {}
321 patch void method5() {} 332 patch void method5() {}
322 patch void method6([String str]) {} 333 patch void method6([String str]) {}
323 patch void method7([String s2]) {} 334 patch void method7([String s2]) {}
324 patch void method8({String s2}) {} 335 patch void method8({String s2}) {}
325 patch void method9(int str) {} 336 patch void method9(int str) {}
326 patch void method10([int str]) {} 337 patch void method10([int str]) {}
327 patch void method11({int str}) {} 338 patch void method11({int str}) {}
328 } 339 }
329 """); 340 """).then((compiler) {
330 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 341 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
331 expectIsPatched: true); 342 expectIsPatched: true);
332 container.ensureResolved(compiler); 343 container.ensureResolved(compiler);
333 container.parseNode(compiler); 344 container.parseNode(compiler);
334 345
335 void expect(String methodName, List warnings, List errors) { 346 void expect(String methodName, List warnings, List errors) {
336 compiler.warnings.clear(); 347 compiler.warnings.clear();
337 compiler.errors.clear(); 348 compiler.errors.clear();
338 compiler.resolver.resolveMethodElement( 349 compiler.resolver.resolveMethodElement(
339 ensure(compiler, methodName, container.lookupLocalMember, 350 ensure(compiler, methodName, container.lookupLocalMember,
340 expectIsPatched: true, checkHasBody: true)); 351 expectIsPatched: true, checkHasBody: true));
341 Expect.equals(warnings.length, compiler.warnings.length, 352 Expect.equals(warnings.length, compiler.warnings.length,
342 "Unexpected warnings: ${compiler.warnings} on $methodName"); 353 "Unexpected warnings: ${compiler.warnings} on $methodName");
343 for (int i = 0 ; i < warnings.length ; i++) { 354 for (int i = 0 ; i < warnings.length ; i++) {
344 Expect.equals(warnings[i], compiler.warnings[i].message.kind); 355 Expect.equals(warnings[i], compiler.warnings[i].message.kind);
356 }
357 Expect.equals(errors.length, compiler.errors.length,
358 "Unexpected errors: ${compiler.errors} on $methodName");
359 for (int i = 0 ; i < errors.length ; i++) {
360 Expect.equals(errors[i], compiler.errors[i].message.kind);
361 }
345 } 362 }
346 Expect.equals(errors.length, compiler.errors.length,
347 "Unexpected errors: ${compiler.errors} on $methodName");
348 for (int i = 0 ; i < errors.length ; i++) {
349 Expect.equals(errors[i], compiler.errors[i].message.kind);
350 }
351 }
352 363
353 expect("method1", [], [MessageKind.PATCH_RETURN_TYPE_MISMATCH]); 364 expect("method1", [], [MessageKind.PATCH_RETURN_TYPE_MISMATCH]);
354 expect("method2", [], [MessageKind.PATCH_REQUIRED_PARAMETER_COUNT_MISMATCH]); 365 expect("method2", [],
355 expect("method3", [MessageKind.PATCH_POINT_TO_PARAMETER], 366 [MessageKind.PATCH_REQUIRED_PARAMETER_COUNT_MISMATCH]);
356 [MessageKind.PATCH_PARAMETER_MISMATCH]); 367 expect("method3", [MessageKind.PATCH_POINT_TO_PARAMETER],
357 expect("method4", [], [MessageKind.PATCH_OPTIONAL_PARAMETER_COUNT_MISMATCH]); 368 [MessageKind.PATCH_PARAMETER_MISMATCH]);
358 expect("method5", [], [MessageKind.PATCH_OPTIONAL_PARAMETER_COUNT_MISMATCH]); 369 expect("method4", [],
359 expect("method6", [], [MessageKind.PATCH_OPTIONAL_PARAMETER_NAMED_MISMATCH]); 370 [MessageKind.PATCH_OPTIONAL_PARAMETER_COUNT_MISMATCH]);
360 expect("method7", [MessageKind.PATCH_POINT_TO_PARAMETER], 371 expect("method5", [],
361 [MessageKind.PATCH_PARAMETER_MISMATCH]); 372 [MessageKind.PATCH_OPTIONAL_PARAMETER_COUNT_MISMATCH]);
362 expect("method8", [MessageKind.PATCH_POINT_TO_PARAMETER], 373 expect("method6", [],
363 [MessageKind.PATCH_PARAMETER_MISMATCH]); 374 [MessageKind.PATCH_OPTIONAL_PARAMETER_NAMED_MISMATCH]);
364 expect("method9", [MessageKind.PATCH_POINT_TO_PARAMETER], 375 expect("method7", [MessageKind.PATCH_POINT_TO_PARAMETER],
365 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]); 376 [MessageKind.PATCH_PARAMETER_MISMATCH]);
366 expect("method10", [MessageKind.PATCH_POINT_TO_PARAMETER], 377 expect("method8", [MessageKind.PATCH_POINT_TO_PARAMETER],
367 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]); 378 [MessageKind.PATCH_PARAMETER_MISMATCH]);
368 expect("method11", [MessageKind.PATCH_POINT_TO_PARAMETER], 379 expect("method9", [MessageKind.PATCH_POINT_TO_PARAMETER],
369 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]); 380 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]);
381 expect("method10", [MessageKind.PATCH_POINT_TO_PARAMETER],
382 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]);
383 expect("method11", [MessageKind.PATCH_POINT_TO_PARAMETER],
384 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]);
385 }));
370 } 386 }
371 387
372 testExternalWithoutImplementationTopLevel() { 388 testExternalWithoutImplementationTopLevel() {
373 var compiler = applyPatch( 389 asyncTest(() => applyPatch(
374 """ 390 """
375 external void foo(); 391 external void foo();
376 """, 392 """,
377 """ 393 """
378 // patch void foo() {} 394 // patch void foo() {}
379 """); 395 """).then((compiler) {
380 var function = ensure(compiler, "foo", compiler.coreLibrary.find); 396 var function = ensure(compiler, "foo", compiler.coreLibrary.find);
381 compiler.resolver.resolve(function); 397 compiler.resolver.resolve(function);
382 Expect.isTrue(compiler.warnings.isEmpty, 398 Expect.isTrue(compiler.warnings.isEmpty,
383 "Unexpected warnings: ${compiler.warnings}"); 399 "Unexpected warnings: ${compiler.warnings}");
384 print('testExternalWithoutImplementationTopLevel:${compiler.errors}'); 400 print('testExternalWithoutImplementationTopLevel:${compiler.errors}');
385 Expect.equals(1, compiler.errors.length); 401 Expect.equals(1, compiler.errors.length);
386 Expect.isTrue( 402 Expect.isTrue(
387 compiler.errors[0].message.kind == 403 compiler.errors[0].message.kind ==
388 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION); 404 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION);
389 Expect.stringEquals('Error: External method without an implementation.', 405 Expect.stringEquals('Error: External method without an implementation.',
390 compiler.errors[0].message.toString()); 406 compiler.errors[0].message.toString());
407 }));
391 } 408 }
392 409
393 testExternalWithoutImplementationMember() { 410 testExternalWithoutImplementationMember() {
394 var compiler = applyPatch( 411 asyncTest(() => applyPatch(
395 """ 412 """
396 class Class { 413 class Class {
397 external void foo(); 414 external void foo();
398 } 415 }
399 """, 416 """,
400 """ 417 """
401 patch class Class { 418 patch class Class {
402 // patch void foo() {} 419 // patch void foo() {}
403 } 420 }
404 """); 421 """).then((compiler) {
405 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 422 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
406 expectIsPatched: true); 423 expectIsPatched: true);
407 container.parseNode(compiler); 424 container.parseNode(compiler);
408 425
409 compiler.warnings.clear(); 426 compiler.warnings.clear();
410 compiler.errors.clear(); 427 compiler.errors.clear();
411 compiler.resolver.resolveMethodElement( 428 compiler.resolver.resolveMethodElement(
412 ensure(compiler, "foo", container.lookupLocalMember)); 429 ensure(compiler, "foo", container.lookupLocalMember));
413 Expect.isTrue(compiler.warnings.isEmpty, 430 Expect.isTrue(compiler.warnings.isEmpty,
414 "Unexpected warnings: ${compiler.warnings}"); 431 "Unexpected warnings: ${compiler.warnings}");
415 print('testExternalWithoutImplementationMember:${compiler.errors}'); 432 print('testExternalWithoutImplementationMember:${compiler.errors}');
416 Expect.equals(1, compiler.errors.length); 433 Expect.equals(1, compiler.errors.length);
417 Expect.isTrue( 434 Expect.isTrue(
418 compiler.errors[0].message.kind == 435 compiler.errors[0].message.kind ==
419 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION); 436 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION);
420 Expect.stringEquals('Error: External method without an implementation.', 437 Expect.stringEquals('Error: External method without an implementation.',
421 compiler.errors[0].message.toString()); 438 compiler.errors[0].message.toString());
439 }));
422 } 440 }
423 441
424 testIsSubclass() { 442 testIsSubclass() {
425 var compiler = applyPatch( 443 asyncTest(() => applyPatch(
426 """ 444 """
427 class A {} 445 class A {}
428 """, 446 """,
429 """ 447 """
430 patch class A {} 448 patch class A {}
431 """); 449 """).then((compiler) {
432 ClassElement cls = ensure(compiler, "A", compiler.coreLibrary.find, 450 ClassElement cls = ensure(compiler, "A", compiler.coreLibrary.find,
433 expectIsPatched: true); 451 expectIsPatched: true);
434 ClassElement patch = cls.patch; 452 ClassElement patch = cls.patch;
435 Expect.isTrue(cls != patch); 453 Expect.isTrue(cls != patch);
436 Expect.isTrue(cls.isSubclassOf(patch)); 454 Expect.isTrue(cls.isSubclassOf(patch));
437 Expect.isTrue(patch.isSubclassOf(cls)); 455 Expect.isTrue(patch.isSubclassOf(cls));
456 }));
438 } 457 }
439 458
440 testPatchNonExistingTopLevel() { 459 testPatchNonExistingTopLevel() {
441 var compiler = applyPatch( 460 asyncTest(() => applyPatch(
442 """ 461 """
443 // class Class {} 462 // class Class {}
444 """, 463 """,
445 """ 464 """
446 patch class Class {} 465 patch class Class {}
447 """); 466 """).then((compiler) {
448 Expect.isTrue(compiler.warnings.isEmpty, 467 Expect.isTrue(compiler.warnings.isEmpty,
449 "Unexpected warnings: ${compiler.warnings}"); 468 "Unexpected warnings: ${compiler.warnings}");
450 print('testPatchNonExistingTopLevel:${compiler.errors}'); 469 print('testPatchNonExistingTopLevel:${compiler.errors}');
451 Expect.equals(1, compiler.errors.length); 470 Expect.equals(1, compiler.errors.length);
452 Expect.isTrue( 471 Expect.isTrue(
453 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXISTING); 472 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXISTING);
473 }));
454 } 474 }
455 475
456 testPatchNonExistingMember() { 476 testPatchNonExistingMember() {
457 var compiler = applyPatch( 477 asyncTest(() => applyPatch(
458 """ 478 """
459 class Class {} 479 class Class {}
460 """, 480 """,
461 """ 481 """
462 patch class Class { 482 patch class Class {
463 patch void foo() {} 483 patch void foo() {}
464 } 484 }
465 """); 485 """).then((compiler) {
466 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 486 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
467 expectIsPatched: true); 487 expectIsPatched: true);
468 container.parseNode(compiler); 488 container.parseNode(compiler);
469 489
470 Expect.isTrue(compiler.warnings.isEmpty, 490 Expect.isTrue(compiler.warnings.isEmpty,
471 "Unexpected warnings: ${compiler.warnings}"); 491 "Unexpected warnings: ${compiler.warnings}");
472 print('testPatchNonExistingMember:${compiler.errors}'); 492 print('testPatchNonExistingMember:${compiler.errors}');
473 Expect.equals(1, compiler.errors.length); 493 Expect.equals(1, compiler.errors.length);
474 Expect.isTrue( 494 Expect.isTrue(
475 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXISTING); 495 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXISTING);
496 }));
476 } 497 }
477 498
478 testPatchNonPatchablePatch() { 499 testPatchNonPatchablePatch() {
479 var compiler = applyPatch( 500 asyncTest(() => applyPatch(
480 """ 501 """
481 external get foo; 502 external get foo;
482 """, 503 """,
483 """ 504 """
484 patch var foo; 505 patch var foo;
485 """); 506 """).then((compiler) {
486 ensure(compiler, "foo", compiler.coreLibrary.find); 507 ensure(compiler, "foo", compiler.coreLibrary.find);
487 508
488 Expect.isTrue(compiler.warnings.isEmpty, 509 Expect.isTrue(compiler.warnings.isEmpty,
489 "Unexpected warnings: ${compiler.warnings}"); 510 "Unexpected warnings: ${compiler.warnings}");
490 print('testPatchNonPatchablePatch:${compiler.errors}'); 511 print('testPatchNonPatchablePatch:${compiler.errors}');
491 Expect.equals(1, compiler.errors.length); 512 Expect.equals(1, compiler.errors.length);
492 Expect.isTrue( 513 Expect.isTrue(
493 compiler.errors[0].message.kind == MessageKind.PATCH_NONPATCHABLE); 514 compiler.errors[0].message.kind == MessageKind.PATCH_NONPATCHABLE);
515 }));
494 } 516 }
495 517
496 testPatchNonPatchableOrigin() { 518 testPatchNonPatchableOrigin() {
497 var compiler = applyPatch( 519 asyncTest(() => applyPatch(
498 """ 520 """
499 external var foo; 521 external var foo;
500 """, 522 """,
501 """ 523 """
502 patch get foo => 0; 524 patch get foo => 0;
503 """); 525 """).then((compiler) {
504 ensure(compiler, "foo", compiler.coreLibrary.find); 526 ensure(compiler, "foo", compiler.coreLibrary.find);
505 527
506 Expect.isTrue(compiler.warnings.isEmpty, 528 Expect.isTrue(compiler.warnings.isEmpty,
507 "Unexpected warnings: ${compiler.warnings}"); 529 "Unexpected warnings: ${compiler.warnings}");
508 print('testPatchNonPatchableOrigin:${compiler.errors}'); 530 print('testPatchNonPatchableOrigin:${compiler.errors}');
509 Expect.equals(1, compiler.errors.length); 531 Expect.equals(1, compiler.errors.length);
510 Expect.isTrue( 532 Expect.isTrue(
511 compiler.errors[0].message.kind == MessageKind.PATCH_NONPATCHABLE); 533 compiler.errors[0].message.kind == MessageKind.PATCH_NONPATCHABLE);
534 }));
512 } 535 }
513 536
514 testPatchNonExternalTopLevel() { 537 testPatchNonExternalTopLevel() {
515 var compiler = applyPatch( 538 asyncTest(() => applyPatch(
516 """ 539 """
517 void foo() {} 540 void foo() {}
518 """, 541 """,
519 """ 542 """
520 patch void foo() {} 543 patch void foo() {}
521 """); 544 """).then((compiler) {
522 print('testPatchNonExternalTopLevel.errors:${compiler.errors}'); 545 print('testPatchNonExternalTopLevel.errors:${compiler.errors}');
523 print('testPatchNonExternalTopLevel.warnings:${compiler.warnings}'); 546 print('testPatchNonExternalTopLevel.warnings:${compiler.warnings}');
524 Expect.equals(1, compiler.errors.length); 547 Expect.equals(1, compiler.errors.length);
525 Expect.isTrue( 548 Expect.isTrue(
526 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXTERNAL); 549 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXTERNAL);
527 Expect.equals(1, compiler.warnings.length); 550 Expect.equals(1, compiler.warnings.length);
528 Expect.isTrue( 551 Expect.isTrue(compiler.warnings[0].message.kind ==
529 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_FUNCTION); 552 MessageKind.PATCH_POINT_TO_FUNCTION);
553 }));
530 } 554 }
531 555
532 testPatchNonExternalMember() { 556 testPatchNonExternalMember() {
533 var compiler = applyPatch( 557 asyncTest(() => applyPatch(
534 """ 558 """
535 class Class { 559 class Class {
536 void foo() {} 560 void foo() {}
537 } 561 }
538 """, 562 """,
539 """ 563 """
540 patch class Class { 564 patch class Class {
541 patch void foo() {} 565 patch void foo() {}
542 } 566 }
543 """); 567 """).then((compiler) {
544 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 568 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
545 expectIsPatched: true); 569 expectIsPatched: true);
546 container.parseNode(compiler); 570 container.parseNode(compiler);
547 571
548 print('testPatchNonExternalMember.errors:${compiler.errors}'); 572 print('testPatchNonExternalMember.errors:${compiler.errors}');
549 print('testPatchNonExternalMember.warnings:${compiler.warnings}'); 573 print('testPatchNonExternalMember.warnings:${compiler.warnings}');
550 Expect.equals(1, compiler.errors.length); 574 Expect.equals(1, compiler.errors.length);
551 Expect.isTrue( 575 Expect.isTrue(
552 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXTERNAL); 576 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXTERNAL);
553 Expect.equals(1, compiler.warnings.length); 577 Expect.equals(1, compiler.warnings.length);
554 Expect.isTrue( 578 Expect.isTrue(compiler.warnings[0].message.kind ==
555 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_FUNCTION); 579 MessageKind.PATCH_POINT_TO_FUNCTION);
580 }));
556 } 581 }
557 582
558 testPatchNonClass() { 583 testPatchNonClass() {
559 var compiler = applyPatch( 584 asyncTest(() => applyPatch(
560 """ 585 """
561 external void Class() {} 586 external void Class() {}
562 """, 587 """,
563 """ 588 """
564 patch class Class {} 589 patch class Class {}
565 """); 590 """).then((compiler) {
566 print('testPatchNonClass.errors:${compiler.errors}'); 591 print('testPatchNonClass.errors:${compiler.errors}');
567 print('testPatchNonClass.warnings:${compiler.warnings}'); 592 print('testPatchNonClass.warnings:${compiler.warnings}');
568 Expect.equals(1, compiler.errors.length); 593 Expect.equals(1, compiler.errors.length);
569 Expect.isTrue( 594 Expect.isTrue(
570 compiler.errors[0].message.kind == MessageKind.PATCH_NON_CLASS); 595 compiler.errors[0].message.kind == MessageKind.PATCH_NON_CLASS);
571 Expect.equals(1, compiler.warnings.length); 596 Expect.equals(1, compiler.warnings.length);
572 Expect.isTrue( 597 Expect.isTrue(
573 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_CLASS); 598 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_CLASS);
599 }));
574 } 600 }
575 601
576 testPatchNonGetter() { 602 testPatchNonGetter() {
577 var compiler = applyPatch( 603 asyncTest(() => applyPatch(
578 """ 604 """
579 external void foo() {} 605 external void foo() {}
580 """, 606 """,
581 """ 607 """
582 patch get foo => 0; 608 patch get foo => 0;
583 """); 609 """).then((compiler) {
584 print('testPatchNonClass.errors:${compiler.errors}'); 610 print('testPatchNonClass.errors:${compiler.errors}');
585 print('testPatchNonClass.warnings:${compiler.warnings}'); 611 print('testPatchNonClass.warnings:${compiler.warnings}');
586 Expect.equals(1, compiler.errors.length); 612 Expect.equals(1, compiler.errors.length);
587 Expect.isTrue( 613 Expect.isTrue(
588 compiler.errors[0].message.kind == MessageKind.PATCH_NON_GETTER); 614 compiler.errors[0].message.kind == MessageKind.PATCH_NON_GETTER);
589 Expect.equals(1, compiler.warnings.length); 615 Expect.equals(1, compiler.warnings.length);
590 Expect.isTrue( 616 Expect.isTrue(
591 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_GETTER); 617 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_GETTER);
618 }));
592 } 619 }
593 620
594 testPatchNoGetter() { 621 testPatchNoGetter() {
595 var compiler = applyPatch( 622 asyncTest(() => applyPatch(
596 """ 623 """
597 external set foo(var value) {} 624 external set foo(var value) {}
598 """, 625 """,
599 """ 626 """
600 patch get foo => 0; 627 patch get foo => 0;
601 """); 628 """).then((compiler) {
602 print('testPatchNonClass.errors:${compiler.errors}'); 629 print('testPatchNonClass.errors:${compiler.errors}');
603 print('testPatchNonClass.warnings:${compiler.warnings}'); 630 print('testPatchNonClass.warnings:${compiler.warnings}');
604 Expect.equals(1, compiler.errors.length); 631 Expect.equals(1, compiler.errors.length);
605 Expect.isTrue( 632 Expect.isTrue(
606 compiler.errors[0].message.kind == MessageKind.PATCH_NO_GETTER); 633 compiler.errors[0].message.kind == MessageKind.PATCH_NO_GETTER);
607 Expect.equals(1, compiler.warnings.length); 634 Expect.equals(1, compiler.warnings.length);
608 Expect.isTrue( 635 Expect.isTrue(
609 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_GETTER); 636 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_GETTER);
637 }));
610 } 638 }
611 639
612 testPatchNonSetter() { 640 testPatchNonSetter() {
613 var compiler = applyPatch( 641 asyncTest(() => applyPatch(
614 """ 642 """
615 external void foo() {} 643 external void foo() {}
616 """, 644 """,
617 """ 645 """
618 patch set foo(var value) {} 646 patch set foo(var value) {}
619 """); 647 """).then((compiler) {
620 print('testPatchNonClass.errors:${compiler.errors}'); 648 print('testPatchNonClass.errors:${compiler.errors}');
621 print('testPatchNonClass.warnings:${compiler.warnings}'); 649 print('testPatchNonClass.warnings:${compiler.warnings}');
622 Expect.equals(1, compiler.errors.length); 650 Expect.equals(1, compiler.errors.length);
623 Expect.isTrue( 651 Expect.isTrue(
624 compiler.errors[0].message.kind == MessageKind.PATCH_NON_SETTER); 652 compiler.errors[0].message.kind == MessageKind.PATCH_NON_SETTER);
625 Expect.equals(1, compiler.warnings.length); 653 Expect.equals(1, compiler.warnings.length);
626 Expect.isTrue( 654 Expect.isTrue(
627 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_SETTER); 655 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_SETTER);
656 }));
628 } 657 }
629 658
630 testPatchNoSetter() { 659 testPatchNoSetter() {
631 var compiler = applyPatch( 660 asyncTest(() => applyPatch(
632 """ 661 """
633 external get foo; 662 external get foo;
634 """, 663 """,
635 """ 664 """
636 patch set foo(var value) {} 665 patch set foo(var value) {}
637 """); 666 """).then((compiler) {
638 print('testPatchNonClass.errors:${compiler.errors}'); 667 print('testPatchNonClass.errors:${compiler.errors}');
639 print('testPatchNonClass.warnings:${compiler.warnings}'); 668 print('testPatchNonClass.warnings:${compiler.warnings}');
640 Expect.equals(1, compiler.errors.length); 669 Expect.equals(1, compiler.errors.length);
641 Expect.isTrue( 670 Expect.isTrue(
642 compiler.errors[0].message.kind == MessageKind.PATCH_NO_SETTER); 671 compiler.errors[0].message.kind == MessageKind.PATCH_NO_SETTER);
643 Expect.equals(1, compiler.warnings.length); 672 Expect.equals(1, compiler.warnings.length);
644 Expect.isTrue( 673 Expect.isTrue(
645 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_SETTER); 674 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_SETTER);
675 }));
646 } 676 }
647 677
648 testPatchNonFunction() { 678 testPatchNonFunction() {
649 var compiler = applyPatch( 679 asyncTest(() => applyPatch(
650 """ 680 """
651 external get foo; 681 external get foo;
652 """, 682 """,
653 """ 683 """
654 patch void foo() {} 684 patch void foo() {}
655 """); 685 """).then((compiler) {
656 print('testPatchNonClass.errors:${compiler.errors}'); 686 print('testPatchNonClass.errors:${compiler.errors}');
657 print('testPatchNonClass.warnings:${compiler.warnings}'); 687 print('testPatchNonClass.warnings:${compiler.warnings}');
658 Expect.equals(1, compiler.errors.length); 688 Expect.equals(1, compiler.errors.length);
659 Expect.isTrue( 689 Expect.isTrue(
660 compiler.errors[0].message.kind == MessageKind.PATCH_NON_FUNCTION); 690 compiler.errors[0].message.kind == MessageKind.PATCH_NON_FUNCTION);
661 Expect.equals(1, compiler.warnings.length); 691 Expect.equals(1, compiler.warnings.length);
662 Expect.isTrue( 692 Expect.isTrue(
663 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_FUNCTION); 693 compiler.warnings[0].message.kind ==
694 MessageKind.PATCH_POINT_TO_FUNCTION);
695 }));
664 } 696 }
665 697
666 testPatchAndSelector() { 698 testPatchAndSelector() {
667 var compiler = applyPatch( 699 asyncTest(() => applyPatch(
668 """ 700 """
669 class A { 701 class A {
670 external void clear(); 702 external void clear();
671 } 703 }
672 class B extends A { 704 class B extends A {
673 } 705 }
674 """, 706 """,
675 """ 707 """
676 patch class A { 708 patch class A {
677 int method() => 0; 709 int method() => 0;
678 patch void clear() {} 710 patch void clear() {}
679 } 711 }
680 """); 712 """).then((compiler) {
681 ClassElement cls = ensure(compiler, "A", compiler.coreLibrary.find, 713 ClassElement cls = ensure(compiler, "A", compiler.coreLibrary.find,
682 expectIsPatched: true); 714 expectIsPatched: true);
683 cls.ensureResolved(compiler); 715 cls.ensureResolved(compiler);
684 716
685 ensure(compiler, "method", cls.patch.lookupLocalMember, 717 ensure(compiler, "method", cls.patch.lookupLocalMember,
686 checkHasBody: true, expectIsRegular: true); 718 checkHasBody: true, expectIsRegular: true);
687 719
688 ensure(compiler, "clear", cls.lookupLocalMember, 720 ensure(compiler, "clear", cls.lookupLocalMember,
689 checkHasBody: true, expectIsPatched: true); 721 checkHasBody: true, expectIsPatched: true);
690 722
691 compiler.phase = Compiler.PHASE_DONE_RESOLVING; 723 compiler.phase = Compiler.PHASE_DONE_RESOLVING;
692 724
693 // Check that a method just in the patch class is a target for a 725 // Check that a method just in the patch class is a target for a
694 // typed selector. 726 // typed selector.
695 var selector = new Selector.call( 727 var selector = new Selector.call(
696 buildSourceString('method'), compiler.coreLibrary, 0); 728 buildSourceString('method'), compiler.coreLibrary, 0);
697 var typedSelector = new TypedSelector.exact(cls.rawType, selector); 729 var typedSelector = new TypedSelector.exact(cls.rawType, selector);
698 Element method = 730 Element method =
699 cls.implementation.lookupLocalMember(buildSourceString('method')); 731 cls.implementation.lookupLocalMember(buildSourceString('method'));
700 Expect.isTrue(selector.applies(method, compiler)); 732 Expect.isTrue(selector.applies(method, compiler));
701 Expect.isTrue(typedSelector.applies(method, compiler)); 733 Expect.isTrue(typedSelector.applies(method, compiler));
702 734
703 // Check that the declaration method in the declaration class is a target 735 // Check that the declaration method in the declaration class is a target
704 // for a typed selector. 736 // for a typed selector.
705 selector = new Selector.call( 737 selector = new Selector.call(
706 buildSourceString('clear'), compiler.coreLibrary, 0); 738 buildSourceString('clear'), compiler.coreLibrary, 0);
707 typedSelector = new TypedSelector.exact(cls.rawType, selector); 739 typedSelector = new TypedSelector.exact(cls.rawType, selector);
708 method = cls.lookupLocalMember(buildSourceString('clear')); 740 method = cls.lookupLocalMember(buildSourceString('clear'));
709 Expect.isTrue(selector.applies(method, compiler)); 741 Expect.isTrue(selector.applies(method, compiler));
710 Expect.isTrue(typedSelector.applies(method, compiler)); 742 Expect.isTrue(typedSelector.applies(method, compiler));
711 743
712 // Check that the declaration method in the declaration class is a target 744 // Check that the declaration method in the declaration class is a target
713 // for a typed selector on a subclass. 745 // for a typed selector on a subclass.
714 cls = ensure(compiler, "B", compiler.coreLibrary.find); 746 cls = ensure(compiler, "B", compiler.coreLibrary.find);
715 cls.ensureResolved(compiler); 747 cls.ensureResolved(compiler);
716 typedSelector = new TypedSelector.exact(cls.rawType, selector); 748 typedSelector = new TypedSelector.exact(cls.rawType, selector);
717 Expect.isTrue(selector.applies(method, compiler)); 749 Expect.isTrue(selector.applies(method, compiler));
718 Expect.isTrue(typedSelector.applies(method, compiler)); 750 Expect.isTrue(typedSelector.applies(method, compiler));
751 }));
719 } 752 }
720 753
721 void testAnalyzeAllInjectedMembers() { 754 void testAnalyzeAllInjectedMembers() {
722 void expect(String patchText, [expectedWarnings]) { 755 void expect(String patchText, [expectedWarnings]) {
723 if (expectedWarnings == null) expectedWarnings = []; 756 if (expectedWarnings == null) expectedWarnings = [];
724 if (expectedWarnings is! List) { 757 if (expectedWarnings is! List) {
725 expectedWarnings = <MessageKind>[expectedWarnings]; 758 expectedWarnings = <MessageKind>[expectedWarnings];
726 } 759 }
727 760
728 var compiler = applyPatch('', patchText, 761 asyncTest(() => applyPatch('', patchText, analyzeAll: true,
729 analyzeAll: true, analyzeOnly: true); 762 analyzeOnly: true).then((compiler) {
730 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')]; 763 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')];
731 compiler.runCompiler(null); 764 return compiler.runCompiler(null).then((_) {
732 compareWarningKinds(patchText, expectedWarnings, compiler.warnings); 765 compareWarningKinds(patchText, expectedWarnings, compiler.warnings);
766 });
767 }));
733 } 768 }
734 769
735 expect('String s = 0;', MessageKind.NOT_ASSIGNABLE.warning); 770 expect('String s = 0;', MessageKind.NOT_ASSIGNABLE.warning);
736 expect('void method() { String s = 0; }', MessageKind.NOT_ASSIGNABLE.warning); 771 expect('void method() { String s = 0; }', MessageKind.NOT_ASSIGNABLE.warning);
737 expect(''' 772 expect('''
738 class Class { 773 class Class {
739 String s = 0; 774 String s = 0;
740 } 775 }
741 ''', 776 ''',
742 MessageKind.NOT_ASSIGNABLE.warning); 777 MessageKind.NOT_ASSIGNABLE.warning);
743 expect(''' 778 expect('''
744 class Class { 779 class Class {
745 void method() { 780 void method() {
746 String s = 0; 781 String s = 0;
747 } 782 }
748 } 783 }
749 ''', 784 ''',
750 MessageKind.NOT_ASSIGNABLE.warning); 785 MessageKind.NOT_ASSIGNABLE.warning);
751 } 786 }
752 787
753 void testTypecheckPatchedMembers() { 788 void testTypecheckPatchedMembers() {
754 String originText = "external void method();"; 789 String originText = "external void method();";
755 String patchText = """ 790 String patchText = """
756 patch void method() { 791 patch void method() {
757 String s = 0; 792 String s = 0;
758 } 793 }
759 """; 794 """;
760 var compiler = applyPatch(originText, patchText, 795 asyncTest(() => applyPatch(originText, patchText,
761 analyzeAll: true, analyzeOnly: true); 796 analyzeAll: true, analyzeOnly: true).then((compiler) {
762 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')]; 797 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')];
763 compiler.runCompiler(null); 798 return compiler.runCompiler(null).then((_) {
764 compareWarningKinds(patchText, 799 compareWarningKinds(patchText,
765 [MessageKind.NOT_ASSIGNABLE.warning], compiler.warnings); 800 [MessageKind.NOT_ASSIGNABLE.warning], compiler.warnings);
801 });
802 }));
766 } 803 }
767 804
768 main() { 805 main() {
769 testPatchConstructor(); 806 testPatchConstructor();
770 testPatchFunction(); 807 testPatchFunction();
771 testPatchMember(); 808 testPatchMember();
772 testPatchGetter(); 809 testPatchGetter();
773 testRegularMember(); 810 testRegularMember();
774 testGhostMember(); 811 testGhostMember();
775 testInjectFunction(); 812 testInjectFunction();
(...skipping 15 matching lines...) Expand all
791 testPatchNoGetter(); 828 testPatchNoGetter();
792 testPatchNonSetter(); 829 testPatchNonSetter();
793 testPatchNoSetter(); 830 testPatchNoSetter();
794 testPatchNonFunction(); 831 testPatchNonFunction();
795 832
796 testPatchAndSelector(); 833 testPatchAndSelector();
797 834
798 testAnalyzeAllInjectedMembers(); 835 testAnalyzeAllInjectedMembers();
799 testTypecheckPatchedMembers(); 836 testTypecheckPatchedMembers();
800 } 837 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698