| OLD | NEW |
| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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.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.coreLibrary.patch.find, |
| 136 expectIsPatch: true, checkHasBody: true); | 136 expectIsPatch: true, checkHasBody: true); |
| 137 | 137 |
| 138 Expect.isTrue(compiler.warnings.isEmpty, | 138 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 139 "Unexpected warnings: ${compiler.warnings}"); | 139 Expect.isTrue(collector.warnings.isEmpty, |
| 140 Expect.isTrue(compiler.errors.isEmpty, | 140 "Unexpected warnings: ${collector.warnings}"); |
| 141 "Unexpected errors: ${compiler.errors}"); | 141 Expect.isTrue(collector.errors.isEmpty, |
| 142 "Unexpected errors: ${collector.errors}"); |
| 142 } | 143 } |
| 143 | 144 |
| 144 Future testPatchFunctionMetadata() async { | 145 Future testPatchFunctionMetadata() async { |
| 145 var compiler = await applyPatch( | 146 var compiler = await applyPatch( |
| 146 """ | 147 """ |
| 147 const a = 0; | 148 const a = 0; |
| 148 @a external test(); | 149 @a external test(); |
| 149 """, | 150 """, |
| 150 """ | 151 """ |
| 151 const _b = 1; | 152 const _b = 1; |
| 152 @patch @_b test() {} | 153 @patch @_b test() {} |
| 153 """); | 154 """); |
| 154 Element origin = ensure(compiler, "test", compiler.coreLibrary.find, | 155 Element origin = ensure(compiler, "test", compiler.coreLibrary.find, |
| 155 expectIsPatched: true, checkHasBody: true); | 156 expectIsPatched: true, checkHasBody: true); |
| 156 Element patch = ensure(compiler, "test", compiler.coreLibrary.patch.find, | 157 Element patch = ensure(compiler, "test", compiler.coreLibrary.patch.find, |
| 157 expectIsPatch: true, checkHasBody: true); | 158 expectIsPatch: true, checkHasBody: true); |
| 158 | 159 |
| 159 Expect.isTrue(compiler.warnings.isEmpty, | 160 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 160 "Unexpected warnings: ${compiler.warnings}"); | 161 Expect.isTrue(collector.warnings.isEmpty, |
| 161 Expect.isTrue(compiler.errors.isEmpty, | 162 "Unexpected warnings: ${collector.warnings}"); |
| 162 "Unexpected errors: ${compiler.errors}"); | 163 Expect.isTrue(collector.errors.isEmpty, |
| 164 "Unexpected errors: ${collector.errors}"); |
| 163 | 165 |
| 164 Expect.equals(1, origin.metadata.length, | 166 Expect.equals(1, origin.metadata.length, |
| 165 "Unexpected origin metadata: ${origin.metadata}."); | 167 "Unexpected origin metadata: ${origin.metadata}."); |
| 166 Expect.equals(3, patch.metadata.length, | 168 Expect.equals(3, patch.metadata.length, |
| 167 "Unexpected patch metadata: ${patch.metadata}."); | 169 "Unexpected patch metadata: ${patch.metadata}."); |
| 168 } | 170 } |
| 169 | 171 |
| 170 | 172 |
| 171 Future testPatchVersioned() async { | 173 Future testPatchVersioned() async { |
| 172 String fullPatch = "test(){return 'string';}"; | 174 String fullPatch = "test(){return 'string';}"; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 199 ensure(compiler, "test", compiler.coreLibrary.patch.find, | 201 ensure(compiler, "test", compiler.coreLibrary.patch.find, |
| 200 expectIsPatch: true, checkHasBody: true); | 202 expectIsPatch: true, checkHasBody: true); |
| 201 Expect.equals(origin.patch, patch); | 203 Expect.equals(origin.patch, patch); |
| 202 Expect.equals(patch.origin, origin); | 204 Expect.equals(patch.origin, origin); |
| 203 Expect.equals(patchText, patch.node.toString()); | 205 Expect.equals(patchText, patch.node.toString()); |
| 204 } | 206 } |
| 205 | 207 |
| 206 compiler.analyzeElement(origin); | 208 compiler.analyzeElement(origin); |
| 207 compiler.enqueuer.resolution.emptyDeferredTaskQueue(); | 209 compiler.enqueuer.resolution.emptyDeferredTaskQueue(); |
| 208 | 210 |
| 209 Expect.isTrue(compiler.warnings.isEmpty, | 211 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 210 "Unexpected warnings: ${compiler.warnings}"); | 212 Expect.isTrue(collector.warnings.isEmpty, |
| 213 "Unexpected warnings: ${collector.warnings}"); |
| 211 if (expectedError != null) { | 214 if (expectedError != null) { |
| 212 Expect.equals(expectedError, | 215 Expect.equals(expectedError, |
| 213 compiler.errors[0].message.toString()); | 216 collector.errors.first.message.toString()); |
| 214 } else { | 217 } else { |
| 215 Expect.isTrue(compiler.errors.isEmpty, | 218 Expect.isTrue(collector.errors.isEmpty, |
| 216 "Unexpected errors: ${compiler.errors}"); | 219 "Unexpected errors: ${collector.errors}"); |
| 217 } | 220 } |
| 218 }).catchError((error) { | 221 }).catchError((error) { |
| 219 if (expectedInternalError != null) { | 222 if (expectedInternalError != null) { |
| 220 Expect.equals( | 223 Expect.equals( |
| 221 'Internal Error: $expectedInternalError', error.toString()); | 224 'Internal Error: $expectedInternalError', error.toString()); |
| 222 } else { | 225 } else { |
| 223 throw error; | 226 throw error; |
| 224 } | 227 } |
| 225 }); | 228 }); |
| 226 } | 229 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 var constructorOrigin = ensure(compiler, "", | 261 var constructorOrigin = ensure(compiler, "", |
| 259 (name) => classOrigin.localLookup(name), | 262 (name) => classOrigin.localLookup(name), |
| 260 expectIsPatched: true); | 263 expectIsPatched: true); |
| 261 var constructorPatch = ensure(compiler, "", | 264 var constructorPatch = ensure(compiler, "", |
| 262 (name) => classPatch.localLookup(name), | 265 (name) => classPatch.localLookup(name), |
| 263 expectIsPatch: true); | 266 expectIsPatch: true); |
| 264 | 267 |
| 265 Expect.equals(constructorPatch, constructorOrigin.patch); | 268 Expect.equals(constructorPatch, constructorOrigin.patch); |
| 266 Expect.equals(constructorOrigin, constructorPatch.origin); | 269 Expect.equals(constructorOrigin, constructorPatch.origin); |
| 267 | 270 |
| 268 Expect.isTrue(compiler.warnings.isEmpty, | 271 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 269 "Unexpected warnings: ${compiler.warnings}"); | 272 Expect.isTrue(collector.warnings.isEmpty, |
| 270 Expect.isTrue(compiler.errors.isEmpty, | 273 "Unexpected warnings: ${collector.warnings}"); |
| 271 "Unexpected errors: ${compiler.errors}"); | 274 Expect.isTrue(collector.errors.isEmpty, |
| 275 "Unexpected errors: ${collector.errors}"); |
| 272 } | 276 } |
| 273 | 277 |
| 274 Future testPatchRedirectingConstructor() async { | 278 Future testPatchRedirectingConstructor() async { |
| 275 var compiler = await applyPatch( | 279 var compiler = await applyPatch( |
| 276 """ | 280 """ |
| 277 class Class { | 281 class Class { |
| 278 Class(x) : this._(x, false); | 282 Class(x) : this._(x, false); |
| 279 | 283 |
| 280 external Class._(x, y); | 284 external Class._(x, y); |
| 281 } | 285 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 304 expectIsPatched: true); | 308 expectIsPatched: true); |
| 305 var constructorPatch = | 309 var constructorPatch = |
| 306 ensure(compiler, "_", | 310 ensure(compiler, "_", |
| 307 (name) => classPatch.localLookup(name), | 311 (name) => classPatch.localLookup(name), |
| 308 expectIsPatch: true); | 312 expectIsPatch: true); |
| 309 Expect.equals(constructorOrigin, constructorPatch.origin); | 313 Expect.equals(constructorOrigin, constructorPatch.origin); |
| 310 Expect.equals(constructorPatch, constructorOrigin.patch); | 314 Expect.equals(constructorPatch, constructorOrigin.patch); |
| 311 | 315 |
| 312 compiler.resolver.resolve(constructorRedirecting); | 316 compiler.resolver.resolve(constructorRedirecting); |
| 313 | 317 |
| 314 Expect.isTrue(compiler.warnings.isEmpty, | 318 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 315 "Unexpected warnings: ${compiler.warnings}"); | 319 Expect.isTrue(collector.warnings.isEmpty, |
| 316 Expect.isTrue(compiler.errors.isEmpty, | 320 "Unexpected warnings: ${collector.warnings}"); |
| 317 "Unexpected errors: ${compiler.errors}"); | 321 Expect.isTrue(collector.errors.isEmpty, |
| 322 "Unexpected errors: ${collector.errors}"); |
| 318 } | 323 } |
| 319 | 324 |
| 320 Future testPatchMember() async { | 325 Future testPatchMember() async { |
| 321 var compiler = await applyPatch( | 326 var compiler = await applyPatch( |
| 322 """ | 327 """ |
| 323 class Class { | 328 class Class { |
| 324 external String toString(); | 329 external String toString(); |
| 325 } | 330 } |
| 326 """, | 331 """, |
| 327 """ | 332 """ |
| 328 @patch class Class { | 333 @patch class Class { |
| 329 @patch String toString() => 'string'; | 334 @patch String toString() => 'string'; |
| 330 } | 335 } |
| 331 """); | 336 """); |
| 332 var container = ensure(compiler, "Class", compiler.coreLibrary.find, | 337 var container = ensure(compiler, "Class", compiler.coreLibrary.find, |
| 333 expectIsPatched: true); | 338 expectIsPatched: true); |
| 334 container.parseNode(compiler.parsing); | 339 container.parseNode(compiler.parsing); |
| 335 ensure(compiler, "Class", compiler.coreLibrary.patch.find, | 340 ensure(compiler, "Class", compiler.coreLibrary.patch.find, |
| 336 expectIsPatch: true); | 341 expectIsPatch: true); |
| 337 | 342 |
| 338 ensure(compiler, "toString", container.lookupLocalMember, | 343 ensure(compiler, "toString", container.lookupLocalMember, |
| 339 expectIsPatched: true, checkHasBody: true); | 344 expectIsPatched: true, checkHasBody: true); |
| 340 ensure(compiler, "toString", container.patch.lookupLocalMember, | 345 ensure(compiler, "toString", container.patch.lookupLocalMember, |
| 341 expectIsPatch: true, checkHasBody: true); | 346 expectIsPatch: true, checkHasBody: true); |
| 342 | 347 |
| 343 Expect.isTrue(compiler.warnings.isEmpty, | 348 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 344 "Unexpected warnings: ${compiler.warnings}"); | 349 Expect.isTrue(collector.warnings.isEmpty, |
| 345 Expect.isTrue(compiler.errors.isEmpty, | 350 "Unexpected warnings: ${collector.warnings}"); |
| 346 "Unexpected errors: ${compiler.errors}"); | 351 Expect.isTrue(collector.errors.isEmpty, |
| 352 "Unexpected errors: ${collector.errors}"); |
| 347 } | 353 } |
| 348 | 354 |
| 349 Future testPatchGetter() async { | 355 Future testPatchGetter() async { |
| 350 var compiler = await applyPatch( | 356 var compiler = await applyPatch( |
| 351 """ | 357 """ |
| 352 class Class { | 358 class Class { |
| 353 external int get field; | 359 external int get field; |
| 354 } | 360 } |
| 355 """, | 361 """, |
| 356 """ | 362 """ |
| (...skipping 10 matching lines...) Expand all Loading... |
| 367 expectIsGetter: true, | 373 expectIsGetter: true, |
| 368 expectIsPatched: true, | 374 expectIsPatched: true, |
| 369 checkHasBody: true); | 375 checkHasBody: true); |
| 370 ensure(compiler, | 376 ensure(compiler, |
| 371 "field", | 377 "field", |
| 372 container.patch.lookupLocalMember, | 378 container.patch.lookupLocalMember, |
| 373 expectIsGetter: true, | 379 expectIsGetter: true, |
| 374 expectIsPatch: true, | 380 expectIsPatch: true, |
| 375 checkHasBody: true); | 381 checkHasBody: true); |
| 376 | 382 |
| 377 Expect.isTrue(compiler.warnings.isEmpty, | 383 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 378 "Unexpected warnings: ${compiler.warnings}"); | 384 Expect.isTrue(collector.warnings.isEmpty, |
| 379 Expect.isTrue(compiler.errors.isEmpty, | 385 "Unexpected warnings: ${collector.warnings}"); |
| 380 "Unexpected errors: ${compiler.errors}"); | 386 Expect.isTrue(collector.errors.isEmpty, |
| 387 "Unexpected errors: ${collector.errors}"); |
| 381 } | 388 } |
| 382 | 389 |
| 383 Future testRegularMember() async { | 390 Future testRegularMember() async { |
| 384 var compiler = await applyPatch( | 391 var compiler = await applyPatch( |
| 385 """ | 392 """ |
| 386 class Class { | 393 class Class { |
| 387 void regular() {} | 394 void regular() {} |
| 388 } | 395 } |
| 389 """, | 396 """, |
| 390 """ | 397 """ |
| 391 @patch class Class { | 398 @patch class Class { |
| 392 } | 399 } |
| 393 """); | 400 """); |
| 394 var container = ensure(compiler, "Class", compiler.coreLibrary.find, | 401 var container = ensure(compiler, "Class", compiler.coreLibrary.find, |
| 395 expectIsPatched: true); | 402 expectIsPatched: true); |
| 396 container.parseNode(compiler.parsing); | 403 container.parseNode(compiler.parsing); |
| 397 ensure(compiler, "Class", compiler.coreLibrary.patch.find, | 404 ensure(compiler, "Class", compiler.coreLibrary.patch.find, |
| 398 expectIsPatch: true); | 405 expectIsPatch: true); |
| 399 | 406 |
| 400 ensure(compiler, "regular", container.lookupLocalMember, | 407 ensure(compiler, "regular", container.lookupLocalMember, |
| 401 checkHasBody: true, expectIsRegular: true); | 408 checkHasBody: true, expectIsRegular: true); |
| 402 ensure(compiler, "regular", container.patch.lookupLocalMember, | 409 ensure(compiler, "regular", container.patch.lookupLocalMember, |
| 403 checkHasBody: true, expectIsRegular: true); | 410 checkHasBody: true, expectIsRegular: true); |
| 404 | 411 |
| 405 Expect.isTrue(compiler.warnings.isEmpty, | 412 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 406 "Unexpected warnings: ${compiler.warnings}"); | 413 Expect.isTrue(collector.warnings.isEmpty, |
| 407 Expect.isTrue(compiler.errors.isEmpty, | 414 "Unexpected warnings: ${collector.warnings}"); |
| 408 "Unexpected errors: ${compiler.errors}"); | 415 Expect.isTrue(collector.errors.isEmpty, |
| 416 "Unexpected errors: ${collector.errors}"); |
| 409 } | 417 } |
| 410 | 418 |
| 411 Future testInjectedMember() async { | 419 Future testInjectedMember() async { |
| 412 var compiler = await applyPatch( | 420 var compiler = await applyPatch( |
| 413 """ | 421 """ |
| 414 class Class { | 422 class Class { |
| 415 } | 423 } |
| 416 """, | 424 """, |
| 417 """ | 425 """ |
| 418 @patch class Class { | 426 @patch class Class { |
| 419 void _injected() {} | 427 void _injected() {} |
| 420 } | 428 } |
| 421 """); | 429 """); |
| 422 var container = ensure(compiler, "Class", compiler.coreLibrary.find, | 430 var container = ensure(compiler, "Class", compiler.coreLibrary.find, |
| 423 expectIsPatched: true); | 431 expectIsPatched: true); |
| 424 container.parseNode(compiler.parsing); | 432 container.parseNode(compiler.parsing); |
| 425 ensure(compiler, "Class", compiler.coreLibrary.patch.find, | 433 ensure(compiler, "Class", compiler.coreLibrary.patch.find, |
| 426 expectIsPatch: true); | 434 expectIsPatch: true); |
| 427 | 435 |
| 428 ensure(compiler, "_injected", container.lookupLocalMember, | 436 ensure(compiler, "_injected", container.lookupLocalMember, |
| 429 expectIsFound: false); | 437 expectIsFound: false); |
| 430 ensure(compiler, "_injected", container.patch.lookupLocalMember, | 438 ensure(compiler, "_injected", container.patch.lookupLocalMember, |
| 431 checkHasBody: true, expectIsRegular: true); | 439 checkHasBody: true, expectIsRegular: true); |
| 432 | 440 |
| 433 Expect.isTrue(compiler.warnings.isEmpty, | 441 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 434 "Unexpected warnings: ${compiler.warnings}"); | 442 Expect.isTrue(collector.warnings.isEmpty, |
| 435 Expect.isTrue(compiler.errors.isEmpty, | 443 "Unexpected warnings: ${collector.warnings}"); |
| 436 "Unexpected errors: ${compiler.errors}"); | 444 Expect.isTrue(collector.errors.isEmpty, |
| 445 "Unexpected errors: ${collector.errors}"); |
| 437 } | 446 } |
| 438 | 447 |
| 439 Future testInjectedPublicMember() async { | 448 Future testInjectedPublicMember() async { |
| 440 var compiler = await applyPatch( | 449 var compiler = await applyPatch( |
| 441 """ | 450 """ |
| 442 class Class { | 451 class Class { |
| 443 } | 452 } |
| 444 """, | 453 """, |
| 445 """ | 454 """ |
| 446 @patch class Class { | 455 @patch class Class { |
| 447 void injected() {} | 456 void injected() {} |
| 448 } | 457 } |
| 449 """); | 458 """); |
| 450 var container = ensure(compiler, "Class", compiler.coreLibrary.find, | 459 var container = ensure(compiler, "Class", compiler.coreLibrary.find, |
| 451 expectIsPatched: true); | 460 expectIsPatched: true); |
| 452 container.parseNode(compiler.parsing); | 461 container.parseNode(compiler.parsing); |
| 453 ensure(compiler, "Class", compiler.coreLibrary.patch.find, | 462 ensure(compiler, "Class", compiler.coreLibrary.patch.find, |
| 454 expectIsPatch: true); | 463 expectIsPatch: true); |
| 455 | 464 |
| 456 ensure(compiler, "injected", container.lookupLocalMember, | 465 ensure(compiler, "injected", container.lookupLocalMember, |
| 457 expectIsFound: false); | 466 expectIsFound: false); |
| 458 ensure(compiler, "injected", container.patch.lookupLocalMember, | 467 ensure(compiler, "injected", container.patch.lookupLocalMember, |
| 459 checkHasBody: true, expectIsRegular: true); | 468 checkHasBody: true, expectIsRegular: true); |
| 460 | 469 |
| 461 Expect.isTrue(compiler.warnings.isEmpty, | 470 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 462 "Unexpected warnings: ${compiler.warnings}"); | 471 Expect.isTrue(collector.warnings.isEmpty, |
| 463 Expect.equals(1, compiler.errors.length, | 472 "Unexpected warnings: ${collector.warnings}"); |
| 464 "Unexpected errors: ${compiler.errors}"); | 473 Expect.equals(1, collector.errors.length, |
| 474 "Unexpected errors: ${collector.errors}"); |
| 465 Expect.isTrue( | 475 Expect.isTrue( |
| 466 compiler.errors[0].message.kind == MessageKind.INJECTED_PUBLIC_MEMBER); | 476 collector.errors.first.message.kind == |
| 477 MessageKind.INJECTED_PUBLIC_MEMBER); |
| 467 } | 478 } |
| 468 | 479 |
| 469 Future testInjectedFunction() async { | 480 Future testInjectedFunction() async { |
| 470 var compiler = await applyPatch( | 481 var compiler = await applyPatch( |
| 471 "", | 482 "", |
| 472 "int _function() => 5;"); | 483 "int _function() => 5;"); |
| 473 ensure(compiler, | 484 ensure(compiler, |
| 474 "_function", | 485 "_function", |
| 475 compiler.coreLibrary.find, | 486 compiler.coreLibrary.find, |
| 476 expectIsFound: false); | 487 expectIsFound: false); |
| 477 ensure(compiler, | 488 ensure(compiler, |
| 478 "_function", | 489 "_function", |
| 479 compiler.coreLibrary.patch.find, | 490 compiler.coreLibrary.patch.find, |
| 480 checkHasBody: true, expectIsRegular: true); | 491 checkHasBody: true, expectIsRegular: true); |
| 481 | 492 |
| 482 Expect.isTrue(compiler.warnings.isEmpty, | 493 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 483 "Unexpected warnings: ${compiler.warnings}"); | 494 Expect.isTrue(collector.warnings.isEmpty, |
| 484 Expect.isTrue(compiler.errors.isEmpty, | 495 "Unexpected warnings: ${collector.warnings}"); |
| 485 "Unexpected errors: ${compiler.errors}"); | 496 Expect.isTrue(collector.errors.isEmpty, |
| 497 "Unexpected errors: ${collector.errors}"); |
| 486 } | 498 } |
| 487 | 499 |
| 488 Future testInjectedPublicFunction() async { | 500 Future testInjectedPublicFunction() async { |
| 489 var compiler = await applyPatch( | 501 var compiler = await applyPatch( |
| 490 "", | 502 "", |
| 491 "int function() => 5;"); | 503 "int function() => 5;"); |
| 492 ensure(compiler, | 504 ensure(compiler, |
| 493 "function", | 505 "function", |
| 494 compiler.coreLibrary.find, | 506 compiler.coreLibrary.find, |
| 495 expectIsFound: false); | 507 expectIsFound: false); |
| 496 ensure(compiler, | 508 ensure(compiler, |
| 497 "function", | 509 "function", |
| 498 compiler.coreLibrary.patch.find, | 510 compiler.coreLibrary.patch.find, |
| 499 checkHasBody: true, expectIsRegular: true); | 511 checkHasBody: true, expectIsRegular: true); |
| 500 | 512 |
| 501 Expect.isTrue(compiler.warnings.isEmpty, | 513 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 502 "Unexpected warnings: ${compiler.warnings}"); | 514 Expect.isTrue(collector.warnings.isEmpty, |
| 503 Expect.equals(1, compiler.errors.length, | 515 "Unexpected warnings: ${collector.warnings}"); |
| 504 "Unexpected errors: ${compiler.errors}"); | 516 Expect.equals(1, collector.errors.length, |
| 517 "Unexpected errors: ${collector.errors}"); |
| 505 Expect.isTrue( | 518 Expect.isTrue( |
| 506 compiler.errors[0].message.kind == MessageKind.INJECTED_PUBLIC_MEMBER); | 519 collector.errors.first.message.kind == |
| 520 MessageKind.INJECTED_PUBLIC_MEMBER); |
| 507 } | 521 } |
| 508 | 522 |
| 509 Future testPatchSignatureCheck() async { | 523 Future testPatchSignatureCheck() async { |
| 510 var compiler = await applyPatch( | 524 var compiler = await applyPatch( |
| 511 """ | 525 """ |
| 512 class Class { | 526 class Class { |
| 513 external String method1(); | 527 external String method1(); |
| 514 external void method2(String str); | 528 external void method2(String str); |
| 515 external void method3(String s1); | 529 external void method3(String s1); |
| 516 external void method4([String str]); | 530 external void method4([String str]); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 535 @patch void method8({String s2}) {} | 549 @patch void method8({String s2}) {} |
| 536 @patch void method9(int str) {} | 550 @patch void method9(int str) {} |
| 537 @patch void method10([int str]) {} | 551 @patch void method10([int str]) {} |
| 538 @patch void method11({int str}) {} | 552 @patch void method11({int str}) {} |
| 539 } | 553 } |
| 540 """); | 554 """); |
| 541 var container = ensure(compiler, "Class", compiler.coreLibrary.find, | 555 var container = ensure(compiler, "Class", compiler.coreLibrary.find, |
| 542 expectIsPatched: true); | 556 expectIsPatched: true); |
| 543 container.ensureResolved(compiler.resolution); | 557 container.ensureResolved(compiler.resolution); |
| 544 container.parseNode(compiler.parsing); | 558 container.parseNode(compiler.parsing); |
| 559 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 545 | 560 |
| 546 void expect(String methodName, List infos, List errors) { | 561 void expect(String methodName, List infos, List errors) { |
| 547 compiler.clearMessages(); | 562 collector.clear(); |
| 548 compiler.resolver.resolveMethodElement( | 563 compiler.resolver.resolveMethodElement( |
| 549 ensure(compiler, methodName, container.lookupLocalMember, | 564 ensure(compiler, methodName, container.lookupLocalMember, |
| 550 expectIsPatched: true, checkHasBody: true)); | 565 expectIsPatched: true, checkHasBody: true)); |
| 551 Expect.equals(0, compiler.warnings.length); | 566 Expect.equals(0, collector.warnings.length); |
| 552 Expect.equals(infos.length, compiler.infos.length, | 567 Expect.equals(infos.length, collector.infos.length, |
| 553 "Unexpected infos: ${compiler.infos} on $methodName"); | 568 "Unexpected infos: ${collector.infos} on $methodName"); |
| 554 for (int i = 0 ; i < infos.length ; i++) { | 569 for (int i = 0 ; i < infos.length ; i++) { |
| 555 Expect.equals(infos[i], compiler.infos[i].message.kind); | 570 Expect.equals(infos[i], collector.infos.elementAt(i).message.kind); |
| 556 } | 571 } |
| 557 Expect.equals(errors.length, compiler.errors.length, | 572 Expect.equals(errors.length, collector.errors.length, |
| 558 "Unexpected errors: ${compiler.errors} on $methodName"); | 573 "Unexpected errors: ${collector.errors} on $methodName"); |
| 559 for (int i = 0 ; i < errors.length ; i++) { | 574 for (int i = 0 ; i < errors.length ; i++) { |
| 560 Expect.equals(errors[i], compiler.errors[i].message.kind); | 575 Expect.equals(errors[i], collector.errors.elementAt(i).message.kind); |
| 561 } | 576 } |
| 562 } | 577 } |
| 563 | 578 |
| 564 expect("method1", [], [MessageKind.PATCH_RETURN_TYPE_MISMATCH]); | 579 expect("method1", [], [MessageKind.PATCH_RETURN_TYPE_MISMATCH]); |
| 565 expect("method2", [], | 580 expect("method2", [], |
| 566 [MessageKind.PATCH_REQUIRED_PARAMETER_COUNT_MISMATCH]); | 581 [MessageKind.PATCH_REQUIRED_PARAMETER_COUNT_MISMATCH]); |
| 567 expect("method3", [MessageKind.PATCH_POINT_TO_PARAMETER], | 582 expect("method3", [MessageKind.PATCH_POINT_TO_PARAMETER], |
| 568 [MessageKind.PATCH_PARAMETER_MISMATCH]); | 583 [MessageKind.PATCH_PARAMETER_MISMATCH]); |
| 569 expect("method4", [], | 584 expect("method4", [], |
| 570 [MessageKind.PATCH_OPTIONAL_PARAMETER_COUNT_MISMATCH]); | 585 [MessageKind.PATCH_OPTIONAL_PARAMETER_COUNT_MISMATCH]); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 587 Future testExternalWithoutImplementationTopLevel() async { | 602 Future testExternalWithoutImplementationTopLevel() async { |
| 588 var compiler = await applyPatch( | 603 var compiler = await applyPatch( |
| 589 """ | 604 """ |
| 590 external void foo(); | 605 external void foo(); |
| 591 """, | 606 """, |
| 592 """ | 607 """ |
| 593 // @patch void foo() {} | 608 // @patch void foo() {} |
| 594 """); | 609 """); |
| 595 var function = ensure(compiler, "foo", compiler.coreLibrary.find); | 610 var function = ensure(compiler, "foo", compiler.coreLibrary.find); |
| 596 compiler.resolver.resolve(function); | 611 compiler.resolver.resolve(function); |
| 597 Expect.isTrue(compiler.warnings.isEmpty, | 612 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 598 "Unexpected warnings: ${compiler.warnings}"); | 613 Expect.isTrue(collector.warnings.isEmpty, |
| 599 print('testExternalWithoutImplementationTopLevel:${compiler.errors}'); | 614 "Unexpected warnings: ${collector.warnings}"); |
| 600 Expect.equals(1, compiler.errors.length); | 615 print('testExternalWithoutImplementationTopLevel:${collector.errors}'); |
| 616 Expect.equals(1, collector.errors.length); |
| 601 Expect.isTrue( | 617 Expect.isTrue( |
| 602 compiler.errors[0].message.kind == | 618 collector.errors.first.message.kind == |
| 603 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION); | 619 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION); |
| 604 Expect.stringEquals('External method without an implementation.', | 620 Expect.stringEquals('External method without an implementation.', |
| 605 compiler.errors[0].message.toString()); | 621 collector.errors.first.message.toString()); |
| 606 } | 622 } |
| 607 | 623 |
| 608 Future testExternalWithoutImplementationMember() async { | 624 Future testExternalWithoutImplementationMember() async { |
| 609 var compiler = await applyPatch( | 625 var compiler = await applyPatch( |
| 610 """ | 626 """ |
| 611 class Class { | 627 class Class { |
| 612 external void foo(); | 628 external void foo(); |
| 613 } | 629 } |
| 614 """, | 630 """, |
| 615 """ | 631 """ |
| 616 @patch class Class { | 632 @patch class Class { |
| 617 // @patch void foo() {} | 633 // @patch void foo() {} |
| 618 } | 634 } |
| 619 """); | 635 """); |
| 620 var container = ensure(compiler, "Class", compiler.coreLibrary.find, | 636 var container = ensure(compiler, "Class", compiler.coreLibrary.find, |
| 621 expectIsPatched: true); | 637 expectIsPatched: true); |
| 622 container.parseNode(compiler.parsing); | 638 container.parseNode(compiler.parsing); |
| 623 | 639 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 624 compiler.warnings.clear(); | 640 collector.clear(); |
| 625 compiler.errors.clear(); | |
| 626 compiler.resolver.resolveMethodElement( | 641 compiler.resolver.resolveMethodElement( |
| 627 ensure(compiler, "foo", container.lookupLocalMember)); | 642 ensure(compiler, "foo", container.lookupLocalMember)); |
| 628 Expect.isTrue(compiler.warnings.isEmpty, | 643 Expect.isTrue(collector.warnings.isEmpty, |
| 629 "Unexpected warnings: ${compiler.warnings}"); | 644 "Unexpected warnings: ${collector.warnings}"); |
| 630 print('testExternalWithoutImplementationMember:${compiler.errors}'); | 645 print('testExternalWithoutImplementationMember:${collector.errors}'); |
| 631 Expect.equals(1, compiler.errors.length); | 646 Expect.equals(1, collector.errors.length); |
| 632 Expect.isTrue( | 647 Expect.isTrue( |
| 633 compiler.errors[0].message.kind == | 648 collector.errors.first.message.kind == |
| 634 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION); | 649 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION); |
| 635 Expect.stringEquals('External method without an implementation.', | 650 Expect.stringEquals('External method without an implementation.', |
| 636 compiler.errors[0].message.toString()); | 651 collector.errors.first.message.toString()); |
| 637 } | 652 } |
| 638 | 653 |
| 639 Future testIsSubclass() async { | 654 Future testIsSubclass() async { |
| 640 var compiler = await applyPatch( | 655 var compiler = await applyPatch( |
| 641 """ | 656 """ |
| 642 class A {} | 657 class A {} |
| 643 """, | 658 """, |
| 644 """ | 659 """ |
| 645 @patch class A {} | 660 @patch class A {} |
| 646 """); | 661 """); |
| 647 ClassElement cls = ensure(compiler, "A", compiler.coreLibrary.find, | 662 ClassElement cls = ensure(compiler, "A", compiler.coreLibrary.find, |
| 648 expectIsPatched: true); | 663 expectIsPatched: true); |
| 649 ClassElement patch = cls.patch; | 664 ClassElement patch = cls.patch; |
| 650 Expect.isTrue(cls != patch); | 665 Expect.isTrue(cls != patch); |
| 651 Expect.isTrue(cls.isSubclassOf(patch)); | 666 Expect.isTrue(cls.isSubclassOf(patch)); |
| 652 Expect.isTrue(patch.isSubclassOf(cls)); | 667 Expect.isTrue(patch.isSubclassOf(cls)); |
| 653 } | 668 } |
| 654 | 669 |
| 655 Future testPatchNonExistingTopLevel() async { | 670 Future testPatchNonExistingTopLevel() async { |
| 656 var compiler = await applyPatch( | 671 var compiler = await applyPatch( |
| 657 """ | 672 """ |
| 658 // class Class {} | 673 // class Class {} |
| 659 """, | 674 """, |
| 660 """ | 675 """ |
| 661 @patch class Class {} | 676 @patch class Class {} |
| 662 """); | 677 """); |
| 663 Expect.isTrue(compiler.warnings.isEmpty, | 678 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 664 "Unexpected warnings: ${compiler.warnings}"); | 679 Expect.isTrue(collector.warnings.isEmpty, |
| 665 print('testPatchNonExistingTopLevel:${compiler.errors}'); | 680 "Unexpected warnings: ${collector.warnings}"); |
| 666 Expect.equals(1, compiler.errors.length); | 681 print('testPatchNonExistingTopLevel:${collector.errors}'); |
| 682 Expect.equals(1, collector.errors.length); |
| 667 Expect.isTrue( | 683 Expect.isTrue( |
| 668 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXISTING); | 684 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXISTING); |
| 669 } | 685 } |
| 670 | 686 |
| 671 Future testPatchNonExistingMember() async { | 687 Future testPatchNonExistingMember() async { |
| 672 var compiler = await applyPatch( | 688 var compiler = await applyPatch( |
| 673 """ | 689 """ |
| 674 class Class {} | 690 class Class {} |
| 675 """, | 691 """, |
| 676 """ | 692 """ |
| 677 @patch class Class { | 693 @patch class Class { |
| 678 @patch void foo() {} | 694 @patch void foo() {} |
| 679 } | 695 } |
| 680 """); | 696 """); |
| 681 var container = ensure(compiler, "Class", compiler.coreLibrary.find, | 697 var container = ensure(compiler, "Class", compiler.coreLibrary.find, |
| 682 expectIsPatched: true); | 698 expectIsPatched: true); |
| 683 container.parseNode(compiler.parsing); | 699 container.parseNode(compiler.parsing); |
| 700 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 684 | 701 |
| 685 Expect.isTrue(compiler.warnings.isEmpty, | 702 Expect.isTrue(collector.warnings.isEmpty, |
| 686 "Unexpected warnings: ${compiler.warnings}"); | 703 "Unexpected warnings: ${collector.warnings}"); |
| 687 print('testPatchNonExistingMember:${compiler.errors}'); | 704 print('testPatchNonExistingMember:${collector.errors}'); |
| 688 Expect.equals(1, compiler.errors.length); | 705 Expect.equals(1, collector.errors.length); |
| 689 Expect.isTrue( | 706 Expect.isTrue( |
| 690 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXISTING); | 707 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXISTING); |
| 691 } | 708 } |
| 692 | 709 |
| 693 Future testPatchNonPatchablePatch() async { | 710 Future testPatchNonPatchablePatch() async { |
| 694 var compiler = await applyPatch( | 711 var compiler = await applyPatch( |
| 695 """ | 712 """ |
| 696 external get foo; | 713 external get foo; |
| 697 """, | 714 """, |
| 698 """ | 715 """ |
| 699 @patch var foo; | 716 @patch var foo; |
| 700 """); | 717 """); |
| 701 ensure(compiler, "foo", compiler.coreLibrary.find); | 718 ensure(compiler, "foo", compiler.coreLibrary.find); |
| 702 | 719 |
| 703 Expect.isTrue(compiler.warnings.isEmpty, | 720 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 704 "Unexpected warnings: ${compiler.warnings}"); | 721 Expect.isTrue(collector.warnings.isEmpty, |
| 705 print('testPatchNonPatchablePatch:${compiler.errors}'); | 722 "Unexpected warnings: ${collector.warnings}"); |
| 706 Expect.equals(1, compiler.errors.length); | 723 print('testPatchNonPatchablePatch:${collector.errors}'); |
| 724 Expect.equals(1, collector.errors.length); |
| 707 Expect.isTrue( | 725 Expect.isTrue( |
| 708 compiler.errors[0].message.kind == MessageKind.PATCH_NONPATCHABLE); | 726 collector.errors.first.message.kind == MessageKind.PATCH_NONPATCHABLE); |
| 709 } | 727 } |
| 710 | 728 |
| 711 Future testPatchNonPatchableOrigin() async { | 729 Future testPatchNonPatchableOrigin() async { |
| 712 var compiler = await applyPatch( | 730 var compiler = await applyPatch( |
| 713 """ | 731 """ |
| 714 external var foo; | 732 external var foo; |
| 715 """, | 733 """, |
| 716 """ | 734 """ |
| 717 @patch get foo => 0; | 735 @patch get foo => 0; |
| 718 """); | 736 """); |
| 719 ensure(compiler, "foo", compiler.coreLibrary.find); | 737 ensure(compiler, "foo", compiler.coreLibrary.find); |
| 720 | 738 |
| 721 Expect.isTrue(compiler.warnings.isEmpty, | 739 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 722 "Unexpected warnings: ${compiler.warnings}"); | 740 Expect.isTrue(collector.warnings.isEmpty, |
| 723 print('testPatchNonPatchableOrigin:${compiler.errors}'); | 741 "Unexpected warnings: ${collector.warnings}"); |
| 724 Expect.equals(2, compiler.errors.length); | 742 print('testPatchNonPatchableOrigin:${collector.errors}'); |
| 743 Expect.equals(2, collector.errors.length); |
| 725 Expect.equals( | 744 Expect.equals( |
| 726 MessageKind.EXTRANEOUS_MODIFIER, compiler.errors[0].message.kind); | 745 MessageKind.EXTRANEOUS_MODIFIER, collector.errors.first.message.kind); |
| 727 Expect.equals( | 746 Expect.equals( |
| 728 // TODO(ahe): Eventually, this error should be removed as it will be | 747 // TODO(ahe): Eventually, this error should be removed as it will be |
| 729 // handled by the regular parser. | 748 // handled by the regular parser. |
| 730 MessageKind.PATCH_NONPATCHABLE, compiler.errors[1].message.kind); | 749 MessageKind.PATCH_NONPATCHABLE, |
| 750 collector.errors.elementAt(1).message.kind); |
| 731 } | 751 } |
| 732 | 752 |
| 733 Future testPatchNonExternalTopLevel() async { | 753 Future testPatchNonExternalTopLevel() async { |
| 734 var compiler = await applyPatch( | 754 var compiler = await applyPatch( |
| 735 """ | 755 """ |
| 736 void foo() {} | 756 void foo() {} |
| 737 """, | 757 """, |
| 738 """ | 758 """ |
| 739 @patch void foo() {} | 759 @patch void foo() {} |
| 740 """); | 760 """); |
| 741 print('testPatchNonExternalTopLevel.errors:${compiler.errors}'); | 761 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 742 print('testPatchNonExternalTopLevel.warnings:${compiler.warnings}'); | 762 print('testPatchNonExternalTopLevel.errors:${collector.errors}'); |
| 743 Expect.equals(1, compiler.errors.length); | 763 print('testPatchNonExternalTopLevel.warnings:${collector.warnings}'); |
| 764 Expect.equals(1, collector.errors.length); |
| 744 Expect.isTrue( | 765 Expect.isTrue( |
| 745 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXTERNAL); | 766 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXTERNAL); |
| 746 Expect.equals(0, compiler.warnings.length); | 767 Expect.equals(0, collector.warnings.length); |
| 747 Expect.equals(1, compiler.infos.length); | 768 Expect.equals(1, collector.infos.length); |
| 748 Expect.isTrue(compiler.infos[0].message.kind == | 769 Expect.isTrue(collector.infos.first.message.kind == |
| 749 MessageKind.PATCH_POINT_TO_FUNCTION); | 770 MessageKind.PATCH_POINT_TO_FUNCTION); |
| 750 } | 771 } |
| 751 | 772 |
| 752 Future testPatchNonExternalMember() async { | 773 Future testPatchNonExternalMember() async { |
| 753 var compiler = await applyPatch( | 774 var compiler = await applyPatch( |
| 754 """ | 775 """ |
| 755 class Class { | 776 class Class { |
| 756 void foo() {} | 777 void foo() {} |
| 757 } | 778 } |
| 758 """, | 779 """, |
| 759 """ | 780 """ |
| 760 @patch class Class { | 781 @patch class Class { |
| 761 @patch void foo() {} | 782 @patch void foo() {} |
| 762 } | 783 } |
| 763 """); | 784 """); |
| 764 var container = ensure(compiler, "Class", compiler.coreLibrary.find, | 785 var container = ensure(compiler, "Class", compiler.coreLibrary.find, |
| 765 expectIsPatched: true); | 786 expectIsPatched: true); |
| 766 container.parseNode(compiler.parsing); | 787 container.parseNode(compiler.parsing); |
| 767 | 788 |
| 768 print('testPatchNonExternalMember.errors:${compiler.errors}'); | 789 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 769 print('testPatchNonExternalMember.warnings:${compiler.warnings}'); | 790 print('testPatchNonExternalMember.errors:${collector.errors}'); |
| 770 Expect.equals(1, compiler.errors.length); | 791 print('testPatchNonExternalMember.warnings:${collector.warnings}'); |
| 792 Expect.equals(1, collector.errors.length); |
| 771 Expect.isTrue( | 793 Expect.isTrue( |
| 772 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXTERNAL); | 794 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXTERNAL); |
| 773 Expect.equals(0, compiler.warnings.length); | 795 Expect.equals(0, collector.warnings.length); |
| 774 Expect.equals(1, compiler.infos.length); | 796 Expect.equals(1, collector.infos.length); |
| 775 Expect.isTrue(compiler.infos[0].message.kind == | 797 Expect.isTrue(collector.infos.first.message.kind == |
| 776 MessageKind.PATCH_POINT_TO_FUNCTION); | 798 MessageKind.PATCH_POINT_TO_FUNCTION); |
| 777 } | 799 } |
| 778 | 800 |
| 779 Future testPatchNonClass() async { | 801 Future testPatchNonClass() async { |
| 780 var compiler = await applyPatch( | 802 var compiler = await applyPatch( |
| 781 """ | 803 """ |
| 782 external void Class() {} | 804 external void Class() {} |
| 783 """, | 805 """, |
| 784 """ | 806 """ |
| 785 @patch class Class {} | 807 @patch class Class {} |
| 786 """); | 808 """); |
| 787 print('testPatchNonClass.errors:${compiler.errors}'); | 809 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 788 print('testPatchNonClass.warnings:${compiler.warnings}'); | 810 print('testPatchNonClass.errors:${collector.errors}'); |
| 789 Expect.equals(1, compiler.errors.length); | 811 print('testPatchNonClass.warnings:${collector.warnings}'); |
| 812 Expect.equals(1, collector.errors.length); |
| 790 Expect.isTrue( | 813 Expect.isTrue( |
| 791 compiler.errors[0].message.kind == MessageKind.PATCH_NON_CLASS); | 814 collector.errors.first.message.kind == MessageKind.PATCH_NON_CLASS); |
| 792 Expect.equals(0, compiler.warnings.length); | 815 Expect.equals(0, collector.warnings.length); |
| 793 Expect.equals(1, compiler.infos.length); | 816 Expect.equals(1, collector.infos.length); |
| 794 Expect.isTrue( | 817 Expect.isTrue( |
| 795 compiler.infos[0].message.kind == MessageKind.PATCH_POINT_TO_CLASS); | 818 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_CLASS); |
| 796 } | 819 } |
| 797 | 820 |
| 798 Future testPatchNonGetter() async { | 821 Future testPatchNonGetter() async { |
| 799 var compiler = await applyPatch( | 822 var compiler = await applyPatch( |
| 800 """ | 823 """ |
| 801 external void foo() {} | 824 external void foo() {} |
| 802 """, | 825 """, |
| 803 """ | 826 """ |
| 804 @patch get foo => 0; | 827 @patch get foo => 0; |
| 805 """); | 828 """); |
| 806 print('testPatchNonClass.errors:${compiler.errors}'); | 829 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 807 print('testPatchNonClass.warnings:${compiler.warnings}'); | 830 print('testPatchNonClass.errors:${collector.errors}'); |
| 808 Expect.equals(1, compiler.errors.length); | 831 print('testPatchNonClass.warnings:${collector.warnings}'); |
| 832 Expect.equals(1, collector.errors.length); |
| 809 Expect.isTrue( | 833 Expect.isTrue( |
| 810 compiler.errors[0].message.kind == MessageKind.PATCH_NON_GETTER); | 834 collector.errors.first.message.kind == MessageKind.PATCH_NON_GETTER); |
| 811 Expect.equals(0, compiler.warnings.length); | 835 Expect.equals(0, collector.warnings.length); |
| 812 Expect.equals(1, compiler.infos.length); | 836 Expect.equals(1, collector.infos.length); |
| 813 Expect.isTrue( | 837 Expect.isTrue( |
| 814 compiler.infos[0].message.kind == MessageKind.PATCH_POINT_TO_GETTER); | 838 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_GETTER); |
| 815 } | 839 } |
| 816 | 840 |
| 817 Future testPatchNoGetter() async { | 841 Future testPatchNoGetter() async { |
| 818 var compiler = await applyPatch( | 842 var compiler = await applyPatch( |
| 819 """ | 843 """ |
| 820 external set foo(var value) {} | 844 external set foo(var value) {} |
| 821 """, | 845 """, |
| 822 """ | 846 """ |
| 823 @patch get foo => 0; | 847 @patch get foo => 0; |
| 824 """); | 848 """); |
| 825 print('testPatchNonClass.errors:${compiler.errors}'); | 849 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 826 print('testPatchNonClass.warnings:${compiler.warnings}'); | 850 print('testPatchNonClass.errors:${collector.errors}'); |
| 827 Expect.equals(1, compiler.errors.length); | 851 print('testPatchNonClass.warnings:${collector.warnings}'); |
| 852 Expect.equals(1, collector.errors.length); |
| 828 Expect.isTrue( | 853 Expect.isTrue( |
| 829 compiler.errors[0].message.kind == MessageKind.PATCH_NO_GETTER); | 854 collector.errors.first.message.kind == MessageKind.PATCH_NO_GETTER); |
| 830 Expect.equals(0, compiler.warnings.length); | 855 Expect.equals(0, collector.warnings.length); |
| 831 Expect.equals(1, compiler.infos.length); | 856 Expect.equals(1, collector.infos.length); |
| 832 Expect.isTrue( | 857 Expect.isTrue( |
| 833 compiler.infos[0].message.kind == MessageKind.PATCH_POINT_TO_GETTER); | 858 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_GETTER); |
| 834 } | 859 } |
| 835 | 860 |
| 836 Future testPatchNonSetter() async { | 861 Future testPatchNonSetter() async { |
| 837 var compiler = await applyPatch( | 862 var compiler = await applyPatch( |
| 838 """ | 863 """ |
| 839 external void foo() {} | 864 external void foo() {} |
| 840 """, | 865 """, |
| 841 """ | 866 """ |
| 842 @patch set foo(var value) {} | 867 @patch set foo(var value) {} |
| 843 """); | 868 """); |
| 844 print('testPatchNonClass.errors:${compiler.errors}'); | 869 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 845 print('testPatchNonClass.warnings:${compiler.warnings}'); | 870 print('testPatchNonClass.errors:${collector.errors}'); |
| 846 Expect.equals(1, compiler.errors.length); | 871 print('testPatchNonClass.warnings:${collector.warnings}'); |
| 872 Expect.equals(1, collector.errors.length); |
| 847 Expect.isTrue( | 873 Expect.isTrue( |
| 848 compiler.errors[0].message.kind == MessageKind.PATCH_NON_SETTER); | 874 collector.errors.first.message.kind == MessageKind.PATCH_NON_SETTER); |
| 849 Expect.equals(0, compiler.warnings.length); | 875 Expect.equals(0, collector.warnings.length); |
| 850 Expect.equals(1, compiler.infos.length); | 876 Expect.equals(1, collector.infos.length); |
| 851 Expect.isTrue( | 877 Expect.isTrue( |
| 852 compiler.infos[0].message.kind == MessageKind.PATCH_POINT_TO_SETTER); | 878 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_SETTER); |
| 853 } | 879 } |
| 854 | 880 |
| 855 Future testPatchNoSetter() async { | 881 Future testPatchNoSetter() async { |
| 856 var compiler = await applyPatch( | 882 var compiler = await applyPatch( |
| 857 """ | 883 """ |
| 858 external get foo; | 884 external get foo; |
| 859 """, | 885 """, |
| 860 """ | 886 """ |
| 861 @patch set foo(var value) {} | 887 @patch set foo(var value) {} |
| 862 """); | 888 """); |
| 863 print('testPatchNonClass.errors:${compiler.errors}'); | 889 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 864 print('testPatchNonClass.warnings:${compiler.warnings}'); | 890 print('testPatchNonClass.errors:${collector.errors}'); |
| 865 Expect.equals(1, compiler.errors.length); | 891 print('testPatchNonClass.warnings:${collector.warnings}'); |
| 892 Expect.equals(1, collector.errors.length); |
| 866 Expect.isTrue( | 893 Expect.isTrue( |
| 867 compiler.errors[0].message.kind == MessageKind.PATCH_NO_SETTER); | 894 collector.errors.first.message.kind == MessageKind.PATCH_NO_SETTER); |
| 868 Expect.equals(0, compiler.warnings.length); | 895 Expect.equals(0, collector.warnings.length); |
| 869 Expect.equals(1, compiler.infos.length); | 896 Expect.equals(1, collector.infos.length); |
| 870 Expect.isTrue( | 897 Expect.isTrue( |
| 871 compiler.infos[0].message.kind == MessageKind.PATCH_POINT_TO_SETTER); | 898 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_SETTER); |
| 872 } | 899 } |
| 873 | 900 |
| 874 Future testPatchNonFunction() async { | 901 Future testPatchNonFunction() async { |
| 875 var compiler = await applyPatch( | 902 var compiler = await applyPatch( |
| 876 """ | 903 """ |
| 877 external get foo; | 904 external get foo; |
| 878 """, | 905 """, |
| 879 """ | 906 """ |
| 880 @patch void foo() {} | 907 @patch void foo() {} |
| 881 """); | 908 """); |
| 882 print('testPatchNonClass.errors:${compiler.errors}'); | 909 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 883 print('testPatchNonClass.warnings:${compiler.warnings}'); | 910 print('testPatchNonClass.errors:${collector.errors}'); |
| 884 Expect.equals(1, compiler.errors.length); | 911 print('testPatchNonClass.warnings:${collector.warnings}'); |
| 912 Expect.equals(1, collector.errors.length); |
| 885 Expect.isTrue( | 913 Expect.isTrue( |
| 886 compiler.errors[0].message.kind == MessageKind.PATCH_NON_FUNCTION); | 914 collector.errors.first.message.kind == MessageKind.PATCH_NON_FUNCTION); |
| 887 Expect.equals(0, compiler.warnings.length); | 915 Expect.equals(0, collector.warnings.length); |
| 888 Expect.equals(1, compiler.infos.length); | 916 Expect.equals(1, collector.infos.length); |
| 889 Expect.isTrue( | 917 Expect.isTrue( |
| 890 compiler.infos[0].message.kind == | 918 collector.infos.first.message.kind == |
| 891 MessageKind.PATCH_POINT_TO_FUNCTION); | 919 MessageKind.PATCH_POINT_TO_FUNCTION); |
| 892 } | 920 } |
| 893 | 921 |
| 894 Future testPatchAndSelector() async { | 922 Future testPatchAndSelector() async { |
| 895 var compiler = await applyPatch( | 923 var compiler = await applyPatch( |
| 896 """ | 924 """ |
| 897 class A { | 925 class A { |
| 898 external void clear(); | 926 external void clear(); |
| 899 } | 927 } |
| 900 class B extends A { | 928 class B extends A { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 Future expect(String patchText, [expectedWarnings]) async { | 989 Future expect(String patchText, [expectedWarnings]) async { |
| 962 if (expectedWarnings == null) expectedWarnings = []; | 990 if (expectedWarnings == null) expectedWarnings = []; |
| 963 if (expectedWarnings is! List) { | 991 if (expectedWarnings is! List) { |
| 964 expectedWarnings = <MessageKind>[expectedWarnings]; | 992 expectedWarnings = <MessageKind>[expectedWarnings]; |
| 965 } | 993 } |
| 966 | 994 |
| 967 var compiler = await applyPatch('', patchText, analyzeAll: true, | 995 var compiler = await applyPatch('', patchText, analyzeAll: true, |
| 968 analyzeOnly: true); | 996 analyzeOnly: true); |
| 969 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')]; | 997 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')]; |
| 970 await compiler.run(null); | 998 await compiler.run(null); |
| 971 compareWarningKinds(patchText, expectedWarnings, compiler.warnings); | 999 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 1000 compareWarningKinds(patchText, expectedWarnings, collector.warnings); |
| 972 } | 1001 } |
| 973 | 1002 |
| 974 await expect('String s = 0;', MessageKind.NOT_ASSIGNABLE); | 1003 await expect('String s = 0;', MessageKind.NOT_ASSIGNABLE); |
| 975 await expect('void method() { String s = 0; }', MessageKind.NOT_ASSIGNABLE); | 1004 await expect('void method() { String s = 0; }', MessageKind.NOT_ASSIGNABLE); |
| 976 await expect(''' | 1005 await expect(''' |
| 977 class Class { | 1006 class Class { |
| 978 String s = 0; | 1007 String s = 0; |
| 979 } | 1008 } |
| 980 ''', | 1009 ''', |
| 981 MessageKind.NOT_ASSIGNABLE); | 1010 MessageKind.NOT_ASSIGNABLE); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 String originText = "external void method();"; | 1062 String originText = "external void method();"; |
| 1034 String patchText = """ | 1063 String patchText = """ |
| 1035 @patch void method() { | 1064 @patch void method() { |
| 1036 String s = 0; | 1065 String s = 0; |
| 1037 } | 1066 } |
| 1038 """; | 1067 """; |
| 1039 var compiler = await applyPatch(originText, patchText, | 1068 var compiler = await applyPatch(originText, patchText, |
| 1040 analyzeAll: true, analyzeOnly: true); | 1069 analyzeAll: true, analyzeOnly: true); |
| 1041 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')]; | 1070 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')]; |
| 1042 await compiler.run(null); | 1071 await compiler.run(null); |
| 1072 DiagnosticCollector collector = compiler.diagnosticCollector; |
| 1043 compareWarningKinds(patchText, | 1073 compareWarningKinds(patchText, |
| 1044 [MessageKind.NOT_ASSIGNABLE], compiler.warnings); | 1074 [MessageKind.NOT_ASSIGNABLE], collector.warnings); |
| 1045 } | 1075 } |
| 1046 | 1076 |
| 1047 main() { | 1077 main() { |
| 1048 asyncTest(() async { | 1078 asyncTest(() async { |
| 1049 await testPatchConstructor(); | 1079 await testPatchConstructor(); |
| 1050 await testPatchRedirectingConstructor(); | 1080 await testPatchRedirectingConstructor(); |
| 1051 await testPatchFunction(); | 1081 await testPatchFunction(); |
| 1052 await testPatchFunctionMetadata(); | 1082 await testPatchFunctionMetadata(); |
| 1053 await testPatchMember(); | 1083 await testPatchMember(); |
| 1054 await testPatchGetter(); | 1084 await testPatchGetter(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1080 await testPatchNonFunction(); | 1110 await testPatchNonFunction(); |
| 1081 | 1111 |
| 1082 await testPatchAndSelector(); | 1112 await testPatchAndSelector(); |
| 1083 | 1113 |
| 1084 await testEffectiveTarget(); | 1114 await testEffectiveTarget(); |
| 1085 | 1115 |
| 1086 await testAnalyzeAllInjectedMembers(); | 1116 await testAnalyzeAllInjectedMembers(); |
| 1087 await testTypecheckPatchedMembers(); | 1117 await testTypecheckPatchedMembers(); |
| 1088 }); | 1118 }); |
| 1089 } | 1119 } |
| OLD | NEW |