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