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

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

Issue 2265473004: Introduce "CommonElements" (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: cl Created 4 years, 4 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) 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 9 import 'package:compiler/src/diagnostics/messages.dart' show
10 MessageKind; 10 MessageKind;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 } 123 }
124 } 124 }
125 Expect.isFalse(element.isPatched && element.isPatch); 125 Expect.isFalse(element.isPatched && element.isPatch);
126 return element; 126 return element;
127 } 127 }
128 128
129 Future testPatchFunction() async { 129 Future testPatchFunction() async {
130 var compiler = await applyPatch( 130 var compiler = await applyPatch(
131 "external test();", 131 "external test();",
132 "@patch test() { return 'string'; } "); 132 "@patch test() { return 'string'; } ");
133 ensure(compiler, "test", compiler.coreLibrary.find, 133 ensure(compiler, "test", compiler.commonElements.coreLibrary.find,
134 expectIsPatched: true, checkHasBody: true); 134 expectIsPatched: true, checkHasBody: true);
135 ensure(compiler, "test", compiler.coreLibrary.patch.find, 135 ensure(compiler, "test", compiler.commonElements.coreLibrary.patch.find,
136 expectIsPatch: true, checkHasBody: true); 136 expectIsPatch: true, checkHasBody: true);
137 137
138 DiagnosticCollector collector = compiler.diagnosticCollector; 138 DiagnosticCollector collector = compiler.diagnosticCollector;
139 Expect.isTrue(collector.warnings.isEmpty, 139 Expect.isTrue(collector.warnings.isEmpty,
140 "Unexpected warnings: ${collector.warnings}"); 140 "Unexpected warnings: ${collector.warnings}");
141 Expect.isTrue(collector.errors.isEmpty, 141 Expect.isTrue(collector.errors.isEmpty,
142 "Unexpected errors: ${collector.errors}"); 142 "Unexpected errors: ${collector.errors}");
143 } 143 }
144 144
145 Future testPatchFunctionMetadata() async { 145 Future testPatchFunctionMetadata() async {
146 var compiler = await applyPatch( 146 var compiler = await applyPatch(
147 """ 147 """
148 const a = 0; 148 const a = 0;
149 @a external test(); 149 @a external test();
150 """, 150 """,
151 """ 151 """
152 const _b = 1; 152 const _b = 1;
153 @patch @_b test() {} 153 @patch @_b test() {}
154 """); 154 """);
155 Element origin = ensure(compiler, "test", compiler.coreLibrary.find, 155 Element origin = ensure(compiler, "test",
156 expectIsPatched: true, checkHasBody: true); 156 compiler.commonElements.coreLibrary.find,
157 Element patch = ensure(compiler, "test", compiler.coreLibrary.patch.find, 157 expectIsPatched: true, checkHasBody: true);
158 expectIsPatch: true, checkHasBody: true); 158 Element patch = ensure(compiler, "test",
159 compiler.commonElements.coreLibrary.patch.find,
160 expectIsPatch: true, checkHasBody: true);
159 161
160 DiagnosticCollector collector = compiler.diagnosticCollector; 162 DiagnosticCollector collector = compiler.diagnosticCollector;
161 Expect.isTrue(collector.warnings.isEmpty, 163 Expect.isTrue(collector.warnings.isEmpty,
162 "Unexpected warnings: ${collector.warnings}"); 164 "Unexpected warnings: ${collector.warnings}");
163 Expect.isTrue(collector.errors.isEmpty, 165 Expect.isTrue(collector.errors.isEmpty,
164 "Unexpected errors: ${collector.errors}"); 166 "Unexpected errors: ${collector.errors}");
165 167
166 Expect.equals(1, origin.metadata.length, 168 Expect.equals(1, origin.metadata.length,
167 "Unexpected origin metadata: ${origin.metadata}."); 169 "Unexpected origin metadata: ${origin.metadata}.");
168 Expect.equals(3, patch.metadata.length, 170 Expect.equals(3, patch.metadata.length,
(...skipping 17 matching lines...) Expand all
186 String expectedError, 188 String expectedError,
187 String defaultPatch: '', 189 String defaultPatch: '',
188 String expectedInternalError}) async { 190 String expectedInternalError}) async {
189 return applyPatch( 191 return applyPatch(
190 "external test();", 192 "external test();",
191 """ 193 """
192 $defaultPatch 194 $defaultPatch
193 $patchSource 195 $patchSource
194 """, 196 """,
195 patchVersion: patchVersion).then((compiler) { 197 patchVersion: patchVersion).then((compiler) {
196 Element origin = 198 Element origin = ensure(compiler, "test",
197 ensure(compiler, "test", compiler.coreLibrary.find, 199 compiler.commonElements.coreLibrary.find,
198 expectIsPatched: expectIsPatched, checkHasBody: true); 200 expectIsPatched: expectIsPatched, checkHasBody: true);
199 if (expectIsPatched) { 201 if (expectIsPatched) {
200 AstElement patch = 202 AstElement patch = ensure(compiler, "test",
201 ensure(compiler, "test", compiler.coreLibrary.patch.find, 203 compiler.commonElements.coreLibrary.patch.find,
202 expectIsPatch: true, checkHasBody: true); 204 expectIsPatch: true, checkHasBody: true);
203 Expect.equals(origin.patch, patch); 205 Expect.equals(origin.patch, patch);
204 Expect.equals(patch.origin, origin); 206 Expect.equals(patch.origin, origin);
205 Expect.equals(patchText, patch.node.toString()); 207 Expect.equals(patchText, patch.node.toString());
206 } 208 }
207 209
208 compiler.analyzeElement(origin); 210 compiler.analyzeElement(origin);
209 compiler.enqueuer.resolution.emptyDeferredQueueForTesting(); 211 compiler.enqueuer.resolution.emptyDeferredQueueForTesting();
210 212
211 DiagnosticCollector collector = compiler.diagnosticCollector; 213 DiagnosticCollector collector = compiler.diagnosticCollector;
212 Expect.isTrue(collector.warnings.isEmpty, 214 Expect.isTrue(collector.warnings.isEmpty,
(...skipping 29 matching lines...) Expand all
242 """ 244 """
243 class Class { 245 class Class {
244 external Class(); 246 external Class();
245 } 247 }
246 """, 248 """,
247 """ 249 """
248 @patch class Class { 250 @patch class Class {
249 @patch Class(); 251 @patch Class();
250 } 252 }
251 """); 253 """);
252 var classOrigin = ensure(compiler, "Class", compiler.coreLibrary.find, 254 var classOrigin = ensure(compiler, "Class",
253 expectIsPatched: true); 255 compiler.commonElements.coreLibrary.find, expectIsPatched: true);
254 classOrigin.ensureResolved(compiler.resolution); 256 classOrigin.ensureResolved(compiler.resolution);
255 var classPatch = ensure(compiler, "Class", compiler.coreLibrary.patch.find, 257 var classPatch = ensure(compiler, "Class",
256 expectIsPatch: true); 258 compiler.commonElements.coreLibrary.patch.find, expectIsPatch: true);
257 259
258 Expect.equals(classPatch, classOrigin.patch); 260 Expect.equals(classPatch, classOrigin.patch);
259 Expect.equals(classOrigin, classPatch.origin); 261 Expect.equals(classOrigin, classPatch.origin);
260 262
261 var constructorOrigin = ensure(compiler, "", 263 var constructorOrigin = ensure(compiler, "",
262 (name) => classOrigin.localLookup(name), 264 (name) => classOrigin.localLookup(name),
263 expectIsPatched: true); 265 expectIsPatched: true);
264 var constructorPatch = ensure(compiler, "", 266 var constructorPatch = ensure(compiler, "",
265 (name) => classPatch.localLookup(name), 267 (name) => classPatch.localLookup(name),
266 expectIsPatch: true); 268 expectIsPatch: true);
(...skipping 15 matching lines...) Expand all
282 Class(x) : this._(x, false); 284 Class(x) : this._(x, false);
283 285
284 external Class._(x, y); 286 external Class._(x, y);
285 } 287 }
286 """, 288 """,
287 r""" 289 r"""
288 @patch class Class { 290 @patch class Class {
289 @patch Class._(x, y) { print('$x,$y'); } 291 @patch Class._(x, y) { print('$x,$y'); }
290 } 292 }
291 """); 293 """);
292 var classOrigin = ensure(compiler, "Class", compiler.coreLibrary.find, 294 var classOrigin = ensure(compiler, "Class",
293 expectIsPatched: true); 295 compiler.commonElements.coreLibrary.find, expectIsPatched: true);
294 classOrigin.ensureResolved(compiler.resolution); 296 classOrigin.ensureResolved(compiler.resolution);
295 297
296 var classPatch = ensure(compiler, "Class", compiler.coreLibrary.patch.find, 298 var classPatch = ensure(compiler, "Class",
297 expectIsPatch: true); 299 compiler.commonElements.coreLibrary.patch.find, expectIsPatch: true);
298 300
299 Expect.equals(classOrigin, classPatch.origin); 301 Expect.equals(classOrigin, classPatch.origin);
300 Expect.equals(classPatch, classOrigin.patch); 302 Expect.equals(classPatch, classOrigin.patch);
301 303
302 var constructorRedirecting = 304 var constructorRedirecting =
303 ensure(compiler, "", 305 ensure(compiler, "",
304 (name) => classOrigin.localLookup(name)); 306 (name) => classOrigin.localLookup(name));
305 var constructorOrigin = 307 var constructorOrigin =
306 ensure(compiler, "_", 308 ensure(compiler, "_",
307 (name) => classOrigin.localLookup(name), 309 (name) => classOrigin.localLookup(name),
(...skipping 19 matching lines...) Expand all
327 """ 329 """
328 class Class { 330 class Class {
329 external String toString(); 331 external String toString();
330 } 332 }
331 """, 333 """,
332 """ 334 """
333 @patch class Class { 335 @patch class Class {
334 @patch String toString() => 'string'; 336 @patch String toString() => 'string';
335 } 337 }
336 """); 338 """);
337 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 339 var container = ensure(compiler, "Class",
338 expectIsPatched: true); 340 compiler.commonElements.coreLibrary.find, expectIsPatched: true);
339 container.parseNode(compiler.parsingContext); 341 container.parseNode(compiler.parsingContext);
340 ensure(compiler, "Class", compiler.coreLibrary.patch.find, 342 ensure(compiler, "Class", compiler.commonElements.coreLibrary.patch.find,
341 expectIsPatch: true); 343 expectIsPatch: true);
342 344
343 ensure(compiler, "toString", container.lookupLocalMember, 345 ensure(compiler, "toString", container.lookupLocalMember,
344 expectIsPatched: true, checkHasBody: true); 346 expectIsPatched: true, checkHasBody: true);
345 ensure(compiler, "toString", container.patch.lookupLocalMember, 347 ensure(compiler, "toString", container.patch.lookupLocalMember,
346 expectIsPatch: true, checkHasBody: true); 348 expectIsPatch: true, checkHasBody: true);
347 349
348 DiagnosticCollector collector = compiler.diagnosticCollector; 350 DiagnosticCollector collector = compiler.diagnosticCollector;
349 Expect.isTrue(collector.warnings.isEmpty, 351 Expect.isTrue(collector.warnings.isEmpty,
350 "Unexpected warnings: ${collector.warnings}"); 352 "Unexpected warnings: ${collector.warnings}");
351 Expect.isTrue(collector.errors.isEmpty, 353 Expect.isTrue(collector.errors.isEmpty,
352 "Unexpected errors: ${collector.errors}"); 354 "Unexpected errors: ${collector.errors}");
353 } 355 }
354 356
355 Future testPatchGetter() async { 357 Future testPatchGetter() async {
356 var compiler = await applyPatch( 358 var compiler = await applyPatch(
357 """ 359 """
358 class Class { 360 class Class {
359 external int get field; 361 external int get field;
360 } 362 }
361 """, 363 """,
362 """ 364 """
363 @patch class Class { 365 @patch class Class {
364 @patch int get field => 5; 366 @patch int get field => 5;
365 } 367 }
366 """); 368 """);
367 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 369 var container = ensure(compiler, "Class",
368 expectIsPatched: true); 370 compiler.commonElements.coreLibrary.find, expectIsPatched: true);
369 container.parseNode(compiler.parsingContext); 371 container.parseNode(compiler.parsingContext);
370 ensure(compiler, 372 ensure(compiler,
371 "field", 373 "field",
372 container.lookupLocalMember, 374 container.lookupLocalMember,
373 expectIsGetter: true, 375 expectIsGetter: true,
374 expectIsPatched: true, 376 expectIsPatched: true,
375 checkHasBody: true); 377 checkHasBody: true);
376 ensure(compiler, 378 ensure(compiler,
377 "field", 379 "field",
378 container.patch.lookupLocalMember, 380 container.patch.lookupLocalMember,
(...skipping 12 matching lines...) Expand all
391 var compiler = await applyPatch( 393 var compiler = await applyPatch(
392 """ 394 """
393 class Class { 395 class Class {
394 void regular() {} 396 void regular() {}
395 } 397 }
396 """, 398 """,
397 """ 399 """
398 @patch class Class { 400 @patch class Class {
399 } 401 }
400 """); 402 """);
401 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 403 var container = ensure(compiler, "Class",
402 expectIsPatched: true); 404 compiler.commonElements.coreLibrary.find, expectIsPatched: true);
403 container.parseNode(compiler.parsingContext); 405 container.parseNode(compiler.parsingContext);
404 ensure(compiler, "Class", compiler.coreLibrary.patch.find, 406 ensure(compiler, "Class", compiler.commonElements.coreLibrary.patch.find,
405 expectIsPatch: true); 407 expectIsPatch: true);
406 408
407 ensure(compiler, "regular", container.lookupLocalMember, 409 ensure(compiler, "regular", container.lookupLocalMember,
408 checkHasBody: true, expectIsRegular: true); 410 checkHasBody: true, expectIsRegular: true);
409 ensure(compiler, "regular", container.patch.lookupLocalMember, 411 ensure(compiler, "regular", container.patch.lookupLocalMember,
410 checkHasBody: true, expectIsRegular: true); 412 checkHasBody: true, expectIsRegular: true);
411 413
412 DiagnosticCollector collector = compiler.diagnosticCollector; 414 DiagnosticCollector collector = compiler.diagnosticCollector;
413 Expect.isTrue(collector.warnings.isEmpty, 415 Expect.isTrue(collector.warnings.isEmpty,
414 "Unexpected warnings: ${collector.warnings}"); 416 "Unexpected warnings: ${collector.warnings}");
415 Expect.isTrue(collector.errors.isEmpty, 417 Expect.isTrue(collector.errors.isEmpty,
416 "Unexpected errors: ${collector.errors}"); 418 "Unexpected errors: ${collector.errors}");
417 } 419 }
418 420
419 Future testInjectedMember() async { 421 Future testInjectedMember() async {
420 var compiler = await applyPatch( 422 var compiler = await applyPatch(
421 """ 423 """
422 class Class { 424 class Class {
423 } 425 }
424 """, 426 """,
425 """ 427 """
426 @patch class Class { 428 @patch class Class {
427 void _injected() {} 429 void _injected() {}
428 } 430 }
429 """); 431 """);
430 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 432 var container = ensure(compiler, "Class",
431 expectIsPatched: true); 433 compiler.commonElements.coreLibrary.find, expectIsPatched: true);
432 container.parseNode(compiler.parsingContext); 434 container.parseNode(compiler.parsingContext);
433 ensure(compiler, "Class", compiler.coreLibrary.patch.find, 435 ensure(compiler, "Class", compiler.commonElements.coreLibrary.patch.find,
434 expectIsPatch: true); 436 expectIsPatch: true);
435 437
436 ensure(compiler, "_injected", container.lookupLocalMember, 438 ensure(compiler, "_injected", container.lookupLocalMember,
437 expectIsFound: false); 439 expectIsFound: false);
438 ensure(compiler, "_injected", container.patch.lookupLocalMember, 440 ensure(compiler, "_injected", container.patch.lookupLocalMember,
439 checkHasBody: true, expectIsRegular: true); 441 checkHasBody: true, expectIsRegular: true);
440 442
441 DiagnosticCollector collector = compiler.diagnosticCollector; 443 DiagnosticCollector collector = compiler.diagnosticCollector;
442 Expect.isTrue(collector.warnings.isEmpty, 444 Expect.isTrue(collector.warnings.isEmpty,
443 "Unexpected warnings: ${collector.warnings}"); 445 "Unexpected warnings: ${collector.warnings}");
444 Expect.isTrue(collector.errors.isEmpty, 446 Expect.isTrue(collector.errors.isEmpty,
445 "Unexpected errors: ${collector.errors}"); 447 "Unexpected errors: ${collector.errors}");
446 } 448 }
447 449
448 Future testInjectedPublicMember() async { 450 Future testInjectedPublicMember() async {
449 var compiler = await applyPatch( 451 var compiler = await applyPatch(
450 """ 452 """
451 class Class { 453 class Class {
452 } 454 }
453 """, 455 """,
454 """ 456 """
455 @patch class Class { 457 @patch class Class {
456 void injected() {} 458 void injected() {}
457 } 459 }
458 """); 460 """);
459 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 461 var container = ensure(compiler, "Class",
460 expectIsPatched: true); 462 compiler.commonElements.coreLibrary.find, expectIsPatched: true);
461 container.parseNode(compiler.parsingContext); 463 container.parseNode(compiler.parsingContext);
462 ensure(compiler, "Class", compiler.coreLibrary.patch.find, 464 ensure(compiler, "Class", compiler.commonElements.coreLibrary.patch.find,
463 expectIsPatch: true); 465 expectIsPatch: true);
464 466
465 ensure(compiler, "injected", container.lookupLocalMember, 467 ensure(compiler, "injected", container.lookupLocalMember,
466 expectIsFound: false); 468 expectIsFound: false);
467 ensure(compiler, "injected", container.patch.lookupLocalMember, 469 ensure(compiler, "injected", container.patch.lookupLocalMember,
468 checkHasBody: true, expectIsRegular: true); 470 checkHasBody: true, expectIsRegular: true);
469 471
470 DiagnosticCollector collector = compiler.diagnosticCollector; 472 DiagnosticCollector collector = compiler.diagnosticCollector;
471 Expect.isTrue(collector.warnings.isEmpty, 473 Expect.isTrue(collector.warnings.isEmpty,
472 "Unexpected warnings: ${collector.warnings}"); 474 "Unexpected warnings: ${collector.warnings}");
473 Expect.equals(1, collector.errors.length, 475 Expect.equals(1, collector.errors.length,
474 "Unexpected errors: ${collector.errors}"); 476 "Unexpected errors: ${collector.errors}");
475 Expect.isTrue( 477 Expect.isTrue(
476 collector.errors.first.message.kind == 478 collector.errors.first.message.kind ==
477 MessageKind.INJECTED_PUBLIC_MEMBER); 479 MessageKind.INJECTED_PUBLIC_MEMBER);
478 } 480 }
479 481
480 Future testInjectedFunction() async { 482 Future testInjectedFunction() async {
481 var compiler = await applyPatch( 483 var compiler = await applyPatch(
482 "", 484 "",
483 "int _function() => 5;"); 485 "int _function() => 5;");
484 ensure(compiler, 486 ensure(compiler,
485 "_function", 487 "_function",
486 compiler.coreLibrary.find, 488 compiler.commonElements.coreLibrary.find,
487 expectIsFound: false); 489 expectIsFound: false);
488 ensure(compiler, 490 ensure(compiler,
489 "_function", 491 "_function",
490 compiler.coreLibrary.patch.find, 492 compiler.commonElements.coreLibrary.patch.find,
491 checkHasBody: true, expectIsRegular: true); 493 checkHasBody: true, expectIsRegular: true);
492 494
493 DiagnosticCollector collector = compiler.diagnosticCollector; 495 DiagnosticCollector collector = compiler.diagnosticCollector;
494 Expect.isTrue(collector.warnings.isEmpty, 496 Expect.isTrue(collector.warnings.isEmpty,
495 "Unexpected warnings: ${collector.warnings}"); 497 "Unexpected warnings: ${collector.warnings}");
496 Expect.isTrue(collector.errors.isEmpty, 498 Expect.isTrue(collector.errors.isEmpty,
497 "Unexpected errors: ${collector.errors}"); 499 "Unexpected errors: ${collector.errors}");
498 } 500 }
499 501
500 Future testInjectedPublicFunction() async { 502 Future testInjectedPublicFunction() async {
501 var compiler = await applyPatch( 503 var compiler = await applyPatch(
502 "", 504 "",
503 "int function() => 5;"); 505 "int function() => 5;");
504 ensure(compiler, 506 ensure(compiler,
505 "function", 507 "function",
506 compiler.coreLibrary.find, 508 compiler.commonElements.coreLibrary.find,
507 expectIsFound: false); 509 expectIsFound: false);
508 ensure(compiler, 510 ensure(compiler,
509 "function", 511 "function",
510 compiler.coreLibrary.patch.find, 512 compiler.commonElements.coreLibrary.patch.find,
511 checkHasBody: true, expectIsRegular: true); 513 checkHasBody: true, expectIsRegular: true);
512 514
513 DiagnosticCollector collector = compiler.diagnosticCollector; 515 DiagnosticCollector collector = compiler.diagnosticCollector;
514 Expect.isTrue(collector.warnings.isEmpty, 516 Expect.isTrue(collector.warnings.isEmpty,
515 "Unexpected warnings: ${collector.warnings}"); 517 "Unexpected warnings: ${collector.warnings}");
516 Expect.equals(1, collector.errors.length, 518 Expect.equals(1, collector.errors.length,
517 "Unexpected errors: ${collector.errors}"); 519 "Unexpected errors: ${collector.errors}");
518 Expect.isTrue( 520 Expect.isTrue(
519 collector.errors.first.message.kind == 521 collector.errors.first.message.kind ==
520 MessageKind.INJECTED_PUBLIC_MEMBER); 522 MessageKind.INJECTED_PUBLIC_MEMBER);
(...skipping 24 matching lines...) Expand all
545 @patch void method4([String str, int i]) {} 547 @patch void method4([String str, int i]) {}
546 @patch void method5() {} 548 @patch void method5() {}
547 @patch void method6([String str]) {} 549 @patch void method6([String str]) {}
548 @patch void method7([String s2]) {} 550 @patch void method7([String s2]) {}
549 @patch void method8({String s2}) {} 551 @patch void method8({String s2}) {}
550 @patch void method9(int str) {} 552 @patch void method9(int str) {}
551 @patch void method10([int str]) {} 553 @patch void method10([int str]) {}
552 @patch void method11({int str}) {} 554 @patch void method11({int str}) {}
553 } 555 }
554 """); 556 """);
555 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 557 var container = ensure(compiler, "Class",
556 expectIsPatched: true); 558 compiler.commonElements.coreLibrary.find, expectIsPatched: true);
557 container.ensureResolved(compiler.resolution); 559 container.ensureResolved(compiler.resolution);
558 container.parseNode(compiler.parsingContext); 560 container.parseNode(compiler.parsingContext);
559 DiagnosticCollector collector = compiler.diagnosticCollector; 561 DiagnosticCollector collector = compiler.diagnosticCollector;
560 562
561 void expect(String methodName, List infos, List errors) { 563 void expect(String methodName, List infos, List errors) {
562 collector.clear(); 564 collector.clear();
563 compiler.resolver.resolveMethodElement( 565 compiler.resolver.resolveMethodElement(
564 ensure(compiler, methodName, container.lookupLocalMember, 566 ensure(compiler, methodName, container.lookupLocalMember,
565 expectIsPatched: true, checkHasBody: true)); 567 expectIsPatched: true, checkHasBody: true));
566 Expect.equals(0, collector.warnings.length); 568 Expect.equals(0, collector.warnings.length);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 } 602 }
601 603
602 Future testExternalWithoutImplementationTopLevel() async { 604 Future testExternalWithoutImplementationTopLevel() async {
603 var compiler = await applyPatch( 605 var compiler = await applyPatch(
604 """ 606 """
605 external void foo(); 607 external void foo();
606 """, 608 """,
607 """ 609 """
608 // @patch void foo() {} 610 // @patch void foo() {}
609 """); 611 """);
610 var function = ensure(compiler, "foo", compiler.coreLibrary.find); 612 var function = ensure(compiler, "foo",
613 compiler.commonElements.coreLibrary.find);
611 compiler.resolver.resolve(function); 614 compiler.resolver.resolve(function);
612 DiagnosticCollector collector = compiler.diagnosticCollector; 615 DiagnosticCollector collector = compiler.diagnosticCollector;
613 Expect.isTrue(collector.warnings.isEmpty, 616 Expect.isTrue(collector.warnings.isEmpty,
614 "Unexpected warnings: ${collector.warnings}"); 617 "Unexpected warnings: ${collector.warnings}");
615 print('testExternalWithoutImplementationTopLevel:${collector.errors}'); 618 print('testExternalWithoutImplementationTopLevel:${collector.errors}');
616 Expect.equals(1, collector.errors.length); 619 Expect.equals(1, collector.errors.length);
617 Expect.isTrue( 620 Expect.isTrue(
618 collector.errors.first.message.kind == 621 collector.errors.first.message.kind ==
619 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION); 622 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION);
620 Expect.stringEquals('External method without an implementation.', 623 Expect.stringEquals('External method without an implementation.',
621 collector.errors.first.message.toString()); 624 collector.errors.first.message.toString());
622 } 625 }
623 626
624 Future testExternalWithoutImplementationMember() async { 627 Future testExternalWithoutImplementationMember() async {
625 var compiler = await applyPatch( 628 var compiler = await applyPatch(
626 """ 629 """
627 class Class { 630 class Class {
628 external void foo(); 631 external void foo();
629 } 632 }
630 """, 633 """,
631 """ 634 """
632 @patch class Class { 635 @patch class Class {
633 // @patch void foo() {} 636 // @patch void foo() {}
634 } 637 }
635 """); 638 """);
636 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 639 var container = ensure(compiler, "Class",
637 expectIsPatched: true); 640 compiler.commonElements.coreLibrary.find, expectIsPatched: true);
638 container.parseNode(compiler.parsingContext); 641 container.parseNode(compiler.parsingContext);
639 DiagnosticCollector collector = compiler.diagnosticCollector; 642 DiagnosticCollector collector = compiler.diagnosticCollector;
640 collector.clear(); 643 collector.clear();
641 compiler.resolver.resolveMethodElement( 644 compiler.resolver.resolveMethodElement(
642 ensure(compiler, "foo", container.lookupLocalMember)); 645 ensure(compiler, "foo", container.lookupLocalMember));
643 Expect.isTrue(collector.warnings.isEmpty, 646 Expect.isTrue(collector.warnings.isEmpty,
644 "Unexpected warnings: ${collector.warnings}"); 647 "Unexpected warnings: ${collector.warnings}");
645 print('testExternalWithoutImplementationMember:${collector.errors}'); 648 print('testExternalWithoutImplementationMember:${collector.errors}');
646 Expect.equals(1, collector.errors.length); 649 Expect.equals(1, collector.errors.length);
647 Expect.isTrue( 650 Expect.isTrue(
648 collector.errors.first.message.kind == 651 collector.errors.first.message.kind ==
649 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION); 652 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION);
650 Expect.stringEquals('External method without an implementation.', 653 Expect.stringEquals('External method without an implementation.',
651 collector.errors.first.message.toString()); 654 collector.errors.first.message.toString());
652 } 655 }
653 656
654 Future testIsSubclass() async { 657 Future testIsSubclass() async {
655 var compiler = await applyPatch( 658 var compiler = await applyPatch(
656 """ 659 """
657 class A {} 660 class A {}
658 """, 661 """,
659 """ 662 """
660 @patch class A {} 663 @patch class A {}
661 """); 664 """);
662 ClassElement cls = ensure(compiler, "A", compiler.coreLibrary.find, 665 ClassElement cls = ensure(compiler, "A",
663 expectIsPatched: true); 666 compiler.commonElements.coreLibrary.find, expectIsPatched: true);
664 ClassElement patch = cls.patch; 667 ClassElement patch = cls.patch;
665 Expect.isTrue(cls != patch); 668 Expect.isTrue(cls != patch);
666 Expect.isTrue(cls.isSubclassOf(patch)); 669 Expect.isTrue(cls.isSubclassOf(patch));
667 Expect.isTrue(patch.isSubclassOf(cls)); 670 Expect.isTrue(patch.isSubclassOf(cls));
668 } 671 }
669 672
670 Future testPatchNonExistingTopLevel() async { 673 Future testPatchNonExistingTopLevel() async {
671 var compiler = await applyPatch( 674 var compiler = await applyPatch(
672 """ 675 """
673 // class Class {} 676 // class Class {}
(...skipping 13 matching lines...) Expand all
687 Future testPatchNonExistingMember() async { 690 Future testPatchNonExistingMember() async {
688 var compiler = await applyPatch( 691 var compiler = await applyPatch(
689 """ 692 """
690 class Class {} 693 class Class {}
691 """, 694 """,
692 """ 695 """
693 @patch class Class { 696 @patch class Class {
694 @patch void foo() {} 697 @patch void foo() {}
695 } 698 }
696 """); 699 """);
697 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 700 var container = ensure(compiler, "Class",
698 expectIsPatched: true); 701 compiler.commonElements.coreLibrary.find, expectIsPatched: true);
699 container.parseNode(compiler.parsingContext); 702 container.parseNode(compiler.parsingContext);
700 DiagnosticCollector collector = compiler.diagnosticCollector; 703 DiagnosticCollector collector = compiler.diagnosticCollector;
701 704
702 Expect.isTrue(collector.warnings.isEmpty, 705 Expect.isTrue(collector.warnings.isEmpty,
703 "Unexpected warnings: ${collector.warnings}"); 706 "Unexpected warnings: ${collector.warnings}");
704 print('testPatchNonExistingMember:${collector.errors}'); 707 print('testPatchNonExistingMember:${collector.errors}');
705 Expect.equals(1, collector.errors.length); 708 Expect.equals(1, collector.errors.length);
706 Expect.isTrue( 709 Expect.isTrue(
707 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXISTING); 710 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXISTING);
708 } 711 }
709 712
710 Future testPatchNonPatchablePatch() async { 713 Future testPatchNonPatchablePatch() async {
711 var compiler = await applyPatch( 714 var compiler = await applyPatch(
712 """ 715 """
713 external get foo; 716 external get foo;
714 """, 717 """,
715 """ 718 """
716 @patch var foo; 719 @patch var foo;
717 """); 720 """);
718 ensure(compiler, "foo", compiler.coreLibrary.find); 721 ensure(compiler, "foo", compiler.commonElements.coreLibrary.find);
719 722
720 DiagnosticCollector collector = compiler.diagnosticCollector; 723 DiagnosticCollector collector = compiler.diagnosticCollector;
721 Expect.isTrue(collector.warnings.isEmpty, 724 Expect.isTrue(collector.warnings.isEmpty,
722 "Unexpected warnings: ${collector.warnings}"); 725 "Unexpected warnings: ${collector.warnings}");
723 print('testPatchNonPatchablePatch:${collector.errors}'); 726 print('testPatchNonPatchablePatch:${collector.errors}');
724 Expect.equals(1, collector.errors.length); 727 Expect.equals(1, collector.errors.length);
725 Expect.isTrue( 728 Expect.isTrue(
726 collector.errors.first.message.kind == MessageKind.PATCH_NONPATCHABLE); 729 collector.errors.first.message.kind == MessageKind.PATCH_NONPATCHABLE);
727 } 730 }
728 731
729 Future testPatchNonPatchableOrigin() async { 732 Future testPatchNonPatchableOrigin() async {
730 var compiler = await applyPatch( 733 var compiler = await applyPatch(
731 """ 734 """
732 external var foo; 735 external var foo;
733 """, 736 """,
734 """ 737 """
735 @patch get foo => 0; 738 @patch get foo => 0;
736 """); 739 """);
737 ensure(compiler, "foo", compiler.coreLibrary.find); 740 ensure(compiler, "foo", compiler.commonElements.coreLibrary.find);
738 741
739 DiagnosticCollector collector = compiler.diagnosticCollector; 742 DiagnosticCollector collector = compiler.diagnosticCollector;
740 Expect.isTrue(collector.warnings.isEmpty, 743 Expect.isTrue(collector.warnings.isEmpty,
741 "Unexpected warnings: ${collector.warnings}"); 744 "Unexpected warnings: ${collector.warnings}");
742 print('testPatchNonPatchableOrigin:${collector.errors}'); 745 print('testPatchNonPatchableOrigin:${collector.errors}');
743 Expect.equals(2, collector.errors.length); 746 Expect.equals(2, collector.errors.length);
744 Expect.equals( 747 Expect.equals(
745 MessageKind.EXTRANEOUS_MODIFIER, collector.errors.first.message.kind); 748 MessageKind.EXTRANEOUS_MODIFIER, collector.errors.first.message.kind);
746 Expect.equals( 749 Expect.equals(
747 // TODO(ahe): Eventually, this error should be removed as it will be 750 // TODO(ahe): Eventually, this error should be removed as it will be
(...skipping 27 matching lines...) Expand all
775 """ 778 """
776 class Class { 779 class Class {
777 void foo() {} 780 void foo() {}
778 } 781 }
779 """, 782 """,
780 """ 783 """
781 @patch class Class { 784 @patch class Class {
782 @patch void foo() {} 785 @patch void foo() {}
783 } 786 }
784 """); 787 """);
785 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 788 var container = ensure(compiler, "Class",
786 expectIsPatched: true); 789 compiler.commonElements.coreLibrary.find, expectIsPatched: true);
787 container.parseNode(compiler.parsingContext); 790 container.parseNode(compiler.parsingContext);
788 791
789 DiagnosticCollector collector = compiler.diagnosticCollector; 792 DiagnosticCollector collector = compiler.diagnosticCollector;
790 print('testPatchNonExternalMember.errors:${collector.errors}'); 793 print('testPatchNonExternalMember.errors:${collector.errors}');
791 print('testPatchNonExternalMember.warnings:${collector.warnings}'); 794 print('testPatchNonExternalMember.warnings:${collector.warnings}');
792 Expect.equals(1, collector.errors.length); 795 Expect.equals(1, collector.errors.length);
793 Expect.isTrue( 796 Expect.isTrue(
794 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXTERNAL); 797 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXTERNAL);
795 Expect.equals(0, collector.warnings.length); 798 Expect.equals(0, collector.warnings.length);
796 Expect.equals(1, collector.infos.length); 799 Expect.equals(1, collector.infos.length);
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 main: """ 940 main: """
938 main () { 941 main () {
939 new A(); // ensure A and B are instantiated 942 new A(); // ensure A and B are instantiated
940 new B(); 943 new B();
941 } 944 }
942 """, 945 """,
943 runCompiler: true, analyzeOnly: true); 946 runCompiler: true, analyzeOnly: true);
944 World world = compiler.world; 947 World world = compiler.world;
945 world.populate(); 948 world.populate();
946 949
947 ClassElement cls = ensure(compiler, "A", compiler.coreLibrary.find, 950 ClassElement cls = ensure(compiler, "A",
948 expectIsPatched: true); 951 compiler.commonElements.coreLibrary.find, expectIsPatched: true);
949 cls.ensureResolved(compiler.resolution); 952 cls.ensureResolved(compiler.resolution);
950 953
951 ensure(compiler, "method", cls.patch.lookupLocalMember, 954 ensure(compiler, "method", cls.patch.lookupLocalMember,
952 checkHasBody: true, expectIsRegular: true); 955 checkHasBody: true, expectIsRegular: true);
953 956
954 ensure(compiler, "clear", cls.lookupLocalMember, 957 ensure(compiler, "clear", cls.lookupLocalMember,
955 checkHasBody: true, expectIsPatched: true); 958 checkHasBody: true, expectIsPatched: true);
956 959
957 compiler.phase = Compiler.PHASE_DONE_RESOLVING; 960 compiler.phase = Compiler.PHASE_DONE_RESOLVING;
958 961
(...skipping 12 matching lines...) Expand all
971 selector = 974 selector =
972 new Selector.call(const PublicName('clear'), CallStructure.NO_ARGS); 975 new Selector.call(const PublicName('clear'), CallStructure.NO_ARGS);
973 typeMask = new TypeMask.exact(cls, world); 976 typeMask = new TypeMask.exact(cls, world);
974 method = cls.lookupLocalMember('clear'); 977 method = cls.lookupLocalMember('clear');
975 method.computeType(compiler.resolution); 978 method.computeType(compiler.resolution);
976 Expect.isTrue(selector.applies(method, world)); 979 Expect.isTrue(selector.applies(method, world));
977 Expect.isTrue(typeMask.canHit(method, selector, world)); 980 Expect.isTrue(typeMask.canHit(method, selector, world));
978 981
979 // Check that the declaration method in the declaration class is a target 982 // Check that the declaration method in the declaration class is a target
980 // for a typed selector on a subclass. 983 // for a typed selector on a subclass.
981 cls = ensure(compiler, "B", compiler.coreLibrary.find); 984 cls = ensure(compiler, "B", compiler.commonElements.coreLibrary.find);
982 cls.ensureResolved(compiler.resolution); 985 cls.ensureResolved(compiler.resolution);
983 typeMask = new TypeMask.exact(cls, world); 986 typeMask = new TypeMask.exact(cls, world);
984 Expect.isTrue(selector.applies(method, world)); 987 Expect.isTrue(selector.applies(method, world));
985 Expect.isTrue(typeMask.canHit(method, selector, world)); 988 Expect.isTrue(typeMask.canHit(method, selector, world));
986 } 989 }
987 990
988 Future testAnalyzeAllInjectedMembers() async { 991 Future testAnalyzeAllInjectedMembers() async {
989 Future expect(String patchText, [expectedWarnings]) async { 992 Future expect(String patchText, [expectedWarnings]) async {
990 if (expectedWarnings == null) expectedWarnings = []; 993 if (expectedWarnings == null) expectedWarnings = [];
991 if (expectedWarnings is! List) { 994 if (expectedWarnings is! List) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 @patch 1050 @patch
1048 factory B.patchInjected() = _C.injected; 1051 factory B.patchInjected() = _C.injected;
1049 } 1052 }
1050 class _C extends B { 1053 class _C extends B {
1051 _C.injected() : super.patchTarget(); 1054 _C.injected() : super.patchTarget();
1052 } 1055 }
1053 """; 1056 """;
1054 1057
1055 var compiler = await applyPatch(origin, patch, analyzeAll: true, 1058 var compiler = await applyPatch(origin, patch, analyzeAll: true,
1056 analyzeOnly: true, runCompiler: true); 1059 analyzeOnly: true, runCompiler: true);
1057 ClassElement clsA = compiler.coreLibrary.find("A"); 1060 ClassElement clsA = compiler.commonElements.coreLibrary.find("A");
1058 ClassElement clsB = compiler.coreLibrary.find("B"); 1061 ClassElement clsB = compiler.commonElements.coreLibrary.find("B");
1059 1062
1060 ConstructorElement forward = clsA.lookupConstructor("forward"); 1063 ConstructorElement forward = clsA.lookupConstructor("forward");
1061 ConstructorElement target = forward.effectiveTarget; 1064 ConstructorElement target = forward.effectiveTarget;
1062 Expect.isTrue(target.isPatched, "Unexpected target $target for $forward"); 1065 Expect.isTrue(target.isPatched, "Unexpected target $target for $forward");
1063 Expect.isFalse(target.isPatch, "Unexpected target $target for $forward"); 1066 Expect.isFalse(target.isPatch, "Unexpected target $target for $forward");
1064 Expect.equals("patchTarget", target.name); 1067 Expect.equals("patchTarget", target.name);
1065 1068
1066 ConstructorElement forwardOne = clsA.lookupConstructor("forwardOne"); 1069 ConstructorElement forwardOne = clsA.lookupConstructor("forwardOne");
1067 target = forwardOne.effectiveTarget; 1070 target = forwardOne.effectiveTarget;
1068 Expect.isFalse(forwardOne.isMalformed); 1071 Expect.isFalse(forwardOne.isMalformed);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 await testPatchNonFunction(); 1138 await testPatchNonFunction();
1136 1139
1137 await testPatchAndSelector(); 1140 await testPatchAndSelector();
1138 1141
1139 await testEffectiveTarget(); 1142 await testEffectiveTarget();
1140 1143
1141 await testAnalyzeAllInjectedMembers(); 1144 await testAnalyzeAllInjectedMembers();
1142 await testTypecheckPatchedMembers(); 1145 await testTypecheckPatchedMembers();
1143 }); 1146 });
1144 } 1147 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/minimal_resolution_test.dart ('k') | tests/compiler/dart2js/type_combination_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698