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

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

Issue 2939063002: Strong mode cleaning of many dart2js tests. (Closed)
Patch Set: Use ClassElement. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 import 'package:expect/expect.dart'; 6 import 'package:expect/expect.dart';
7 import 'package:async_helper/async_helper.dart'; 7 import 'package:async_helper/async_helper.dart';
8 import 'package:compiler/src/compiler.dart'; 8 import 'package:compiler/src/compiler.dart';
9 import 'package:compiler/src/diagnostics/messages.dart' show MessageKind; 9 import 'package:compiler/src/diagnostics/messages.dart' show MessageKind;
10 import 'package:compiler/src/elements/elements.dart'; 10 import 'package:compiler/src/elements/elements.dart';
(...skipping 21 matching lines...) Expand all
32 compiler.registerSource(uri, "$DEFAULT_PATCH_CORE_SOURCE\n$patch"); 32 compiler.registerSource(uri, "$DEFAULT_PATCH_CORE_SOURCE\n$patch");
33 if (runCompiler) { 33 if (runCompiler) {
34 await compiler.run(null, main); 34 await compiler.run(null, main);
35 } else { 35 } else {
36 await compiler.init(main); 36 await compiler.init(main);
37 } 37 }
38 return compiler; 38 return compiler;
39 } 39 }
40 40
41 void expectHasBody(compiler, ElementX element) { 41 void expectHasBody(compiler, ElementX element) {
42 var node = element.parseNode(compiler.parsingContext); 42 dynamic node = element.parseNode(compiler.parsingContext);
43 Expect.isNotNull(node, "Element isn't parseable, when a body was expected"); 43 Expect.isNotNull(node, "Element isn't parseable, when a body was expected");
44 Expect.isNotNull(node.body); 44 Expect.isNotNull(node.body);
45 // If the element has a body it is either a Block or a Return statement, 45 // If the element has a body it is either a Block or a Return statement,
46 // both with different begin and end tokens. 46 // both with different begin and end tokens.
47 Expect.isTrue(node.body is Block || node.body is Return); 47 Expect.isTrue(node.body is Block || node.body is Return);
48 Expect.notEquals(node.body.getBeginToken(), node.body.getEndToken()); 48 Expect.notEquals(node.body.getBeginToken(), node.body.getEndToken());
49 } 49 }
50 50
51 void expectHasNoBody(compiler, ElementX element) { 51 void expectHasNoBody(compiler, ElementX element) {
52 var node = element.parseNode(compiler.parsingContext); 52 dynamic node = element.parseNode(compiler.parsingContext);
53 Expect.isNotNull(node, "Element isn't parseable, when a body was expected"); 53 Expect.isNotNull(node, "Element isn't parseable, when a body was expected");
54 Expect.isFalse(node.hasBody); 54 Expect.isFalse(node.hasBody);
55 } 55 }
56 56
57 Element ensure(compiler, String name, Element lookup(name), 57 Element ensure(compiler, String name, Element lookup(name),
58 {bool expectIsPatched: false, 58 {bool expectIsPatched: false,
59 bool expectIsPatch: false, 59 bool expectIsPatch: false,
60 bool checkHasBody: false, 60 bool checkHasBody: false,
61 bool expectIsGetter: false, 61 bool expectIsGetter: false,
62 bool expectIsFound: true, 62 bool expectIsFound: true,
63 bool expectIsRegular: false}) { 63 bool expectIsRegular: false}) {
64 var element = lookup(name); 64 dynamic element = lookup(name);
65 if (!expectIsFound) { 65 if (!expectIsFound) {
66 Expect.isNull(element); 66 Expect.isNull(element);
67 return element; 67 return element;
68 } 68 }
69 Expect.isNotNull(element); 69 Expect.isNotNull(element);
70 if (expectIsGetter) { 70 if (expectIsGetter) {
71 Expect.isTrue(element is AbstractFieldElement); 71 Expect.isTrue(element is AbstractFieldElement);
72 Expect.isNotNull(element.getter); 72 Expect.isNotNull(element.getter);
73 element = element.getter; 73 element = element.getter;
74 } 74 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 112
113 if (checkHasBody) { 113 if (checkHasBody) {
114 expectHasBody(compiler, element); 114 expectHasBody(compiler, element);
115 } 115 }
116 } 116 }
117 Expect.isFalse(element.isPatched && element.isPatch); 117 Expect.isFalse(element.isPatched && element.isPatch);
118 return element; 118 return element;
119 } 119 }
120 120
121 Future testPatchFunction() async { 121 Future testPatchFunction() async {
122 var compiler = await applyPatch( 122 dynamic compiler = await applyPatch(
123 "external test();", "@patch test() { return 'string'; } "); 123 "external test();", "@patch test() { return 'string'; } ");
124 ensure(compiler, "test", compiler.resolution.commonElements.coreLibrary.find, 124 ensure(compiler, "test", compiler.resolution.commonElements.coreLibrary.find,
125 expectIsPatched: true, checkHasBody: true); 125 expectIsPatched: true, checkHasBody: true);
126 ensure(compiler, "test", 126 ensure(compiler, "test",
127 compiler.resolution.commonElements.coreLibrary.patch.find, 127 compiler.resolution.commonElements.coreLibrary.patch.find,
128 expectIsPatch: true, checkHasBody: true); 128 expectIsPatch: true, checkHasBody: true);
129 129
130 DiagnosticCollector collector = compiler.diagnosticCollector; 130 DiagnosticCollector collector = compiler.diagnosticCollector;
131 Expect.isTrue( 131 Expect.isTrue(
132 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); 132 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}");
133 Expect.isTrue( 133 Expect.isTrue(
134 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); 134 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}");
135 } 135 }
136 136
137 Future testPatchFunctionMetadata() async { 137 Future testPatchFunctionMetadata() async {
138 var compiler = await applyPatch( 138 dynamic compiler = await applyPatch(
139 """ 139 """
140 const a = 0; 140 const a = 0;
141 @a external test(); 141 @a external test();
142 """, 142 """,
143 """ 143 """
144 const _b = 1; 144 const _b = 1;
145 @patch @_b test() {} 145 @patch @_b test() {}
146 """); 146 """);
147 Element origin = ensure( 147 Element origin = ensure(
148 compiler, "test", compiler.resolution.commonElements.coreLibrary.find, 148 compiler, "test", compiler.resolution.commonElements.coreLibrary.find,
149 expectIsPatched: true, checkHasBody: true); 149 expectIsPatched: true, checkHasBody: true);
150 Element patch = ensure(compiler, "test", 150 Element patch = ensure(compiler, "test",
151 compiler.resolution.commonElements.coreLibrary.patch.find, 151 compiler.resolution.commonElements.coreLibrary.patch.find,
152 expectIsPatch: true, checkHasBody: true); 152 expectIsPatch: true, checkHasBody: true);
153 153
154 DiagnosticCollector collector = compiler.diagnosticCollector; 154 DiagnosticCollector collector = compiler.diagnosticCollector;
155 Expect.isTrue( 155 Expect.isTrue(
156 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); 156 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}");
157 Expect.isTrue( 157 Expect.isTrue(
158 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); 158 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}");
159 159
160 Expect.equals(1, origin.metadata.length, 160 Expect.equals(1, origin.metadata.length,
161 "Unexpected origin metadata: ${origin.metadata}."); 161 "Unexpected origin metadata: ${origin.metadata}.");
162 Expect.equals(3, patch.metadata.length, 162 Expect.equals(3, patch.metadata.length,
163 "Unexpected patch metadata: ${patch.metadata}."); 163 "Unexpected patch metadata: ${patch.metadata}.");
164 } 164 }
165 165
166 Future testPatchFunctionGeneric() async { 166 Future testPatchFunctionGeneric() async {
167 var compiler = await applyPatch( 167 dynamic compiler = await applyPatch(
168 "external T test<T>();", "@patch T test<T>() { return null; } "); 168 "external T test<T>();", "@patch T test<T>() { return null; } ");
169 Element origin = ensure( 169 Element origin = ensure(
170 compiler, "test", compiler.resolution.commonElements.coreLibrary.find, 170 compiler, "test", compiler.resolution.commonElements.coreLibrary.find,
171 expectIsPatched: true, checkHasBody: true); 171 expectIsPatched: true, checkHasBody: true);
172 ensure(compiler, "test", 172 ensure(compiler, "test",
173 compiler.resolution.commonElements.coreLibrary.patch.find, 173 compiler.resolution.commonElements.coreLibrary.patch.find,
174 expectIsPatch: true, checkHasBody: true); 174 expectIsPatch: true, checkHasBody: true);
175 compiler.resolver.resolve(origin); 175 compiler.resolver.resolve(origin);
176 176
177 DiagnosticCollector collector = compiler.diagnosticCollector; 177 DiagnosticCollector collector = compiler.diagnosticCollector;
178 Expect.isTrue( 178 Expect.isTrue(
179 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); 179 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}");
180 Expect.isTrue( 180 Expect.isTrue(
181 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); 181 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}");
182 } 182 }
183 183
184 Future testPatchFunctionGenericExtraTypeVariable() async { 184 Future testPatchFunctionGenericExtraTypeVariable() async {
185 var compiler = await applyPatch( 185 dynamic compiler = await applyPatch(
186 "external T test<T>();", "@patch T test<T, S>() { return null; } "); 186 "external T test<T>();", "@patch T test<T, S>() { return null; } ");
187 Element origin = ensure( 187 Element origin = ensure(
188 compiler, "test", compiler.resolution.commonElements.coreLibrary.find, 188 compiler, "test", compiler.resolution.commonElements.coreLibrary.find,
189 expectIsPatched: true, checkHasBody: true); 189 expectIsPatched: true, checkHasBody: true);
190 ensure(compiler, "test", 190 ensure(compiler, "test",
191 compiler.resolution.commonElements.coreLibrary.patch.find, 191 compiler.resolution.commonElements.coreLibrary.patch.find,
192 expectIsPatch: true, checkHasBody: true); 192 expectIsPatch: true, checkHasBody: true);
193 compiler.resolver.resolve(origin); 193 compiler.resolver.resolve(origin);
194 194
195 DiagnosticCollector collector = compiler.diagnosticCollector; 195 DiagnosticCollector collector = compiler.diagnosticCollector;
196 Expect.isTrue( 196 Expect.isTrue(
197 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); 197 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}");
198 Expect.equals(1, collector.errors.length); 198 Expect.equals(1, collector.errors.length);
199 Expect.isTrue(collector.errors.first.message.kind == 199 Expect.isTrue(collector.errors.first.message.kind ==
200 MessageKind.PATCH_TYPE_VARIABLES_MISMATCH); 200 MessageKind.PATCH_TYPE_VARIABLES_MISMATCH);
201 } 201 }
202 202
203 Future testPatchFunctionGenericDifferentNames() async { 203 Future testPatchFunctionGenericDifferentNames() async {
204 var compiler = await applyPatch( 204 dynamic compiler = await applyPatch(
205 "external T test<T, S>();", "@patch T test<S, T>() { return null; } "); 205 "external T test<T, S>();", "@patch T test<S, T>() { return null; } ");
206 Element origin = ensure( 206 Element origin = ensure(
207 compiler, "test", compiler.resolution.commonElements.coreLibrary.find, 207 compiler, "test", compiler.resolution.commonElements.coreLibrary.find,
208 expectIsPatched: true, checkHasBody: true); 208 expectIsPatched: true, checkHasBody: true);
209 ensure(compiler, "test", 209 ensure(compiler, "test",
210 compiler.resolution.commonElements.coreLibrary.patch.find, 210 compiler.resolution.commonElements.coreLibrary.patch.find,
211 expectIsPatch: true, checkHasBody: true); 211 expectIsPatch: true, checkHasBody: true);
212 compiler.resolver.resolve(origin); 212 compiler.resolver.resolve(origin);
213 213
214 DiagnosticCollector collector = compiler.diagnosticCollector; 214 DiagnosticCollector collector = compiler.diagnosticCollector;
215 Expect.isTrue( 215 Expect.isTrue(
216 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); 216 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}");
217 Expect.equals(1, collector.errors.length); 217 Expect.equals(1, collector.errors.length);
218 Expect.isTrue(collector.errors.first.message.kind == 218 Expect.isTrue(collector.errors.first.message.kind ==
219 MessageKind.PATCH_TYPE_VARIABLES_MISMATCH); 219 MessageKind.PATCH_TYPE_VARIABLES_MISMATCH);
220 } 220 }
221 221
222 Future testPatchConstructor() async { 222 Future testPatchConstructor() async {
223 var compiler = await applyPatch( 223 dynamic compiler = await applyPatch(
224 """ 224 """
225 class Class { 225 class Class {
226 external Class(); 226 external Class();
227 } 227 }
228 """, 228 """,
229 """ 229 """
230 @patch class Class { 230 @patch class Class {
231 @patch Class(); 231 @patch Class();
232 } 232 }
233 """); 233 """);
234 var classOrigin = ensure( 234 dynamic classOrigin = ensure(
235 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, 235 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find,
236 expectIsPatched: true); 236 expectIsPatched: true);
237 classOrigin.ensureResolved(compiler.resolution); 237 classOrigin.ensureResolved(compiler.resolution);
238 var classPatch = ensure(compiler, "Class", 238 dynamic classPatch = ensure(compiler, "Class",
239 compiler.resolution.commonElements.coreLibrary.patch.find, 239 compiler.resolution.commonElements.coreLibrary.patch.find,
240 expectIsPatch: true); 240 expectIsPatch: true);
241 241
242 Expect.equals(classPatch, classOrigin.patch); 242 Expect.equals(classPatch, classOrigin.patch);
243 Expect.equals(classOrigin, classPatch.origin); 243 Expect.equals(classOrigin, classPatch.origin);
244 244
245 var constructorOrigin = ensure( 245 dynamic constructorOrigin = ensure(
246 compiler, "", (name) => classOrigin.localLookup(name), 246 compiler, "", (name) => classOrigin.localLookup(name),
247 expectIsPatched: true); 247 expectIsPatched: true);
248 var constructorPatch = ensure( 248 dynamic constructorPatch = ensure(
249 compiler, "", (name) => classPatch.localLookup(name), 249 compiler, "", (name) => classPatch.localLookup(name),
250 expectIsPatch: true); 250 expectIsPatch: true);
251 251
252 Expect.equals(constructorPatch, constructorOrigin.patch); 252 Expect.equals(constructorPatch, constructorOrigin.patch);
253 Expect.equals(constructorOrigin, constructorPatch.origin); 253 Expect.equals(constructorOrigin, constructorPatch.origin);
254 254
255 DiagnosticCollector collector = compiler.diagnosticCollector; 255 DiagnosticCollector collector = compiler.diagnosticCollector;
256 Expect.isTrue( 256 Expect.isTrue(
257 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); 257 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}");
258 Expect.isTrue( 258 Expect.isTrue(
259 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); 259 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}");
260 } 260 }
261 261
262 Future testPatchRedirectingConstructor() async { 262 Future testPatchRedirectingConstructor() async {
263 var compiler = await applyPatch( 263 dynamic compiler = await applyPatch(
264 """ 264 """
265 class Class { 265 class Class {
266 Class(x) : this._(x, false); 266 Class(x) : this._(x, false);
267 267
268 external Class._(x, y); 268 external Class._(x, y);
269 } 269 }
270 """, 270 """,
271 r""" 271 r"""
272 @patch class Class { 272 @patch class Class {
273 @patch Class._(x, y) { print('$x,$y'); } 273 @patch Class._(x, y) { print('$x,$y'); }
274 } 274 }
275 """); 275 """);
276 var classOrigin = ensure( 276 dynamic classOrigin = ensure(
277 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, 277 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find,
278 expectIsPatched: true); 278 expectIsPatched: true);
279 classOrigin.ensureResolved(compiler.resolution); 279 classOrigin.ensureResolved(compiler.resolution);
280 280
281 var classPatch = ensure(compiler, "Class", 281 dynamic classPatch = ensure(compiler, "Class",
282 compiler.resolution.commonElements.coreLibrary.patch.find, 282 compiler.resolution.commonElements.coreLibrary.patch.find,
283 expectIsPatch: true); 283 expectIsPatch: true);
284 284
285 Expect.equals(classOrigin, classPatch.origin); 285 Expect.equals(classOrigin, classPatch.origin);
286 Expect.equals(classPatch, classOrigin.patch); 286 Expect.equals(classPatch, classOrigin.patch);
287 287
288 var constructorRedirecting = 288 dynamic constructorRedirecting =
289 ensure(compiler, "", (name) => classOrigin.localLookup(name)); 289 ensure(compiler, "", (name) => classOrigin.localLookup(name));
290 var constructorOrigin = ensure( 290 dynamic constructorOrigin = ensure(
291 compiler, "_", (name) => classOrigin.localLookup(name), 291 compiler, "_", (name) => classOrigin.localLookup(name),
292 expectIsPatched: true); 292 expectIsPatched: true);
293 var constructorPatch = ensure( 293 dynamic constructorPatch = ensure(
294 compiler, "_", (name) => classPatch.localLookup(name), 294 compiler, "_", (name) => classPatch.localLookup(name),
295 expectIsPatch: true); 295 expectIsPatch: true);
296 Expect.equals(constructorOrigin, constructorPatch.origin); 296 Expect.equals(constructorOrigin, constructorPatch.origin);
297 Expect.equals(constructorPatch, constructorOrigin.patch); 297 Expect.equals(constructorPatch, constructorOrigin.patch);
298 298
299 compiler.resolver.resolve(constructorRedirecting); 299 compiler.resolver.resolve(constructorRedirecting);
300 300
301 DiagnosticCollector collector = compiler.diagnosticCollector; 301 DiagnosticCollector collector = compiler.diagnosticCollector;
302 Expect.isTrue( 302 Expect.isTrue(
303 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); 303 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}");
304 Expect.isTrue( 304 Expect.isTrue(
305 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); 305 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}");
306 } 306 }
307 307
308 Future testPatchMember() async { 308 Future testPatchMember() async {
309 var compiler = await applyPatch( 309 dynamic compiler = await applyPatch(
310 """ 310 """
311 class Class { 311 class Class {
312 external String toString(); 312 external String toString();
313 } 313 }
314 """, 314 """,
315 """ 315 """
316 @patch class Class { 316 @patch class Class {
317 @patch String toString() => 'string'; 317 @patch String toString() => 'string';
318 } 318 }
319 """); 319 """);
320 var container = ensure( 320 dynamic container = ensure(
321 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, 321 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find,
322 expectIsPatched: true); 322 expectIsPatched: true);
323 container.parseNode(compiler.parsingContext); 323 container.parseNode(compiler.parsingContext);
324 ensure(compiler, "Class", 324 ensure(compiler, "Class",
325 compiler.resolution.commonElements.coreLibrary.patch.find, 325 compiler.resolution.commonElements.coreLibrary.patch.find,
326 expectIsPatch: true); 326 expectIsPatch: true);
327 327
328 ensure(compiler, "toString", container.lookupLocalMember, 328 ensure(compiler, "toString", container.lookupLocalMember,
329 expectIsPatched: true, checkHasBody: true); 329 expectIsPatched: true, checkHasBody: true);
330 ensure(compiler, "toString", container.patch.lookupLocalMember, 330 ensure(compiler, "toString", container.patch.lookupLocalMember,
331 expectIsPatch: true, checkHasBody: true); 331 expectIsPatch: true, checkHasBody: true);
332 332
333 DiagnosticCollector collector = compiler.diagnosticCollector; 333 DiagnosticCollector collector = compiler.diagnosticCollector;
334 Expect.isTrue( 334 Expect.isTrue(
335 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); 335 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}");
336 Expect.isTrue( 336 Expect.isTrue(
337 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); 337 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}");
338 } 338 }
339 339
340 Future testPatchGetter() async { 340 Future testPatchGetter() async {
341 var compiler = await applyPatch( 341 dynamic compiler = await applyPatch(
342 """ 342 """
343 class Class { 343 class Class {
344 external int get field; 344 external int get field;
345 } 345 }
346 """, 346 """,
347 """ 347 """
348 @patch class Class { 348 @patch class Class {
349 @patch int get field => 5; 349 @patch int get field => 5;
350 } 350 }
351 """); 351 """);
352 var container = ensure( 352 dynamic container = ensure(
353 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, 353 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find,
354 expectIsPatched: true); 354 expectIsPatched: true);
355 container.parseNode(compiler.parsingContext); 355 container.parseNode(compiler.parsingContext);
356 ensure(compiler, "field", container.lookupLocalMember, 356 ensure(compiler, "field", container.lookupLocalMember,
357 expectIsGetter: true, expectIsPatched: true, checkHasBody: true); 357 expectIsGetter: true, expectIsPatched: true, checkHasBody: true);
358 ensure(compiler, "field", container.patch.lookupLocalMember, 358 ensure(compiler, "field", container.patch.lookupLocalMember,
359 expectIsGetter: true, expectIsPatch: true, checkHasBody: true); 359 expectIsGetter: true, expectIsPatch: true, checkHasBody: true);
360 360
361 DiagnosticCollector collector = compiler.diagnosticCollector; 361 DiagnosticCollector collector = compiler.diagnosticCollector;
362 Expect.isTrue( 362 Expect.isTrue(
363 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); 363 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}");
364 Expect.isTrue( 364 Expect.isTrue(
365 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); 365 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}");
366 } 366 }
367 367
368 Future testRegularMember() async { 368 Future testRegularMember() async {
369 var compiler = await applyPatch( 369 dynamic compiler = await applyPatch(
370 """ 370 """
371 class Class { 371 class Class {
372 void regular() {} 372 void regular() {}
373 } 373 }
374 """, 374 """,
375 """ 375 """
376 @patch class Class { 376 @patch class Class {
377 } 377 }
378 """); 378 """);
379 var container = ensure( 379 dynamic container = ensure(
380 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, 380 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find,
381 expectIsPatched: true); 381 expectIsPatched: true);
382 container.parseNode(compiler.parsingContext); 382 container.parseNode(compiler.parsingContext);
383 ensure(compiler, "Class", 383 ensure(compiler, "Class",
384 compiler.resolution.commonElements.coreLibrary.patch.find, 384 compiler.resolution.commonElements.coreLibrary.patch.find,
385 expectIsPatch: true); 385 expectIsPatch: true);
386 386
387 ensure(compiler, "regular", container.lookupLocalMember, 387 ensure(compiler, "regular", container.lookupLocalMember,
388 checkHasBody: true, expectIsRegular: true); 388 checkHasBody: true, expectIsRegular: true);
389 ensure(compiler, "regular", container.patch.lookupLocalMember, 389 ensure(compiler, "regular", container.patch.lookupLocalMember,
390 checkHasBody: true, expectIsRegular: true); 390 checkHasBody: true, expectIsRegular: true);
391 391
392 DiagnosticCollector collector = compiler.diagnosticCollector; 392 DiagnosticCollector collector = compiler.diagnosticCollector;
393 Expect.isTrue( 393 Expect.isTrue(
394 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); 394 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}");
395 Expect.isTrue( 395 Expect.isTrue(
396 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); 396 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}");
397 } 397 }
398 398
399 Future testInjectedMember() async { 399 Future testInjectedMember() async {
400 var compiler = await applyPatch( 400 dynamic compiler = await applyPatch(
401 """ 401 """
402 class Class { 402 class Class {
403 } 403 }
404 """, 404 """,
405 """ 405 """
406 @patch class Class { 406 @patch class Class {
407 void _injected() {} 407 void _injected() {}
408 } 408 }
409 """); 409 """);
410 var container = ensure( 410 dynamic container = ensure(
411 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, 411 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find,
412 expectIsPatched: true); 412 expectIsPatched: true);
413 container.parseNode(compiler.parsingContext); 413 container.parseNode(compiler.parsingContext);
414 ensure(compiler, "Class", 414 ensure(compiler, "Class",
415 compiler.resolution.commonElements.coreLibrary.patch.find, 415 compiler.resolution.commonElements.coreLibrary.patch.find,
416 expectIsPatch: true); 416 expectIsPatch: true);
417 417
418 ensure(compiler, "_injected", container.lookupLocalMember, 418 ensure(compiler, "_injected", container.lookupLocalMember,
419 expectIsFound: false); 419 expectIsFound: false);
420 ensure(compiler, "_injected", container.patch.lookupLocalMember, 420 ensure(compiler, "_injected", container.patch.lookupLocalMember,
421 checkHasBody: true, expectIsRegular: true); 421 checkHasBody: true, expectIsRegular: true);
422 422
423 DiagnosticCollector collector = compiler.diagnosticCollector; 423 DiagnosticCollector collector = compiler.diagnosticCollector;
424 Expect.isTrue( 424 Expect.isTrue(
425 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); 425 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}");
426 Expect.isTrue( 426 Expect.isTrue(
427 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); 427 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}");
428 } 428 }
429 429
430 Future testInjectedPublicMember() async { 430 Future testInjectedPublicMember() async {
431 var compiler = await applyPatch( 431 dynamic compiler = await applyPatch(
432 """ 432 """
433 class Class { 433 class Class {
434 } 434 }
435 """, 435 """,
436 """ 436 """
437 @patch class Class { 437 @patch class Class {
438 void injected() {} 438 void injected() {}
439 } 439 }
440 """); 440 """);
441 var container = ensure( 441 dynamic container = ensure(
442 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, 442 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find,
443 expectIsPatched: true); 443 expectIsPatched: true);
444 container.parseNode(compiler.parsingContext); 444 container.parseNode(compiler.parsingContext);
445 ensure(compiler, "Class", 445 ensure(compiler, "Class",
446 compiler.resolution.commonElements.coreLibrary.patch.find, 446 compiler.resolution.commonElements.coreLibrary.patch.find,
447 expectIsPatch: true); 447 expectIsPatch: true);
448 448
449 ensure(compiler, "injected", container.lookupLocalMember, 449 ensure(compiler, "injected", container.lookupLocalMember,
450 expectIsFound: false); 450 expectIsFound: false);
451 ensure(compiler, "injected", container.patch.lookupLocalMember, 451 ensure(compiler, "injected", container.patch.lookupLocalMember,
452 checkHasBody: true, expectIsRegular: true); 452 checkHasBody: true, expectIsRegular: true);
453 453
454 DiagnosticCollector collector = compiler.diagnosticCollector; 454 DiagnosticCollector collector = compiler.diagnosticCollector;
455 Expect.isTrue( 455 Expect.isTrue(
456 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); 456 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}");
457 Expect.equals( 457 Expect.equals(
458 1, collector.errors.length, "Unexpected errors: ${collector.errors}"); 458 1, collector.errors.length, "Unexpected errors: ${collector.errors}");
459 Expect.isTrue(collector.errors.first.message.kind == 459 Expect.isTrue(collector.errors.first.message.kind ==
460 MessageKind.INJECTED_PUBLIC_MEMBER); 460 MessageKind.INJECTED_PUBLIC_MEMBER);
461 } 461 }
462 462
463 Future testInjectedFunction() async { 463 Future testInjectedFunction() async {
464 var compiler = await applyPatch("", "int _function() => 5;"); 464 dynamic compiler = await applyPatch("", "int _function() => 5;");
465 ensure(compiler, "_function", 465 ensure(compiler, "_function",
466 compiler.resolution.commonElements.coreLibrary.find, 466 compiler.resolution.commonElements.coreLibrary.find,
467 expectIsFound: false); 467 expectIsFound: false);
468 ensure(compiler, "_function", 468 ensure(compiler, "_function",
469 compiler.resolution.commonElements.coreLibrary.patch.find, 469 compiler.resolution.commonElements.coreLibrary.patch.find,
470 checkHasBody: true, expectIsRegular: true); 470 checkHasBody: true, expectIsRegular: true);
471 471
472 DiagnosticCollector collector = compiler.diagnosticCollector; 472 DiagnosticCollector collector = compiler.diagnosticCollector;
473 Expect.isTrue( 473 Expect.isTrue(
474 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); 474 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}");
475 Expect.isTrue( 475 Expect.isTrue(
476 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}"); 476 collector.errors.isEmpty, "Unexpected errors: ${collector.errors}");
477 } 477 }
478 478
479 Future testInjectedPublicFunction() async { 479 Future testInjectedPublicFunction() async {
480 var compiler = await applyPatch("", "int function() => 5;"); 480 dynamic compiler = await applyPatch("", "int function() => 5;");
481 ensure( 481 ensure(
482 compiler, "function", compiler.resolution.commonElements.coreLibrary.find, 482 compiler, "function", compiler.resolution.commonElements.coreLibrary.find,
483 expectIsFound: false); 483 expectIsFound: false);
484 ensure(compiler, "function", 484 ensure(compiler, "function",
485 compiler.resolution.commonElements.coreLibrary.patch.find, 485 compiler.resolution.commonElements.coreLibrary.patch.find,
486 checkHasBody: true, expectIsRegular: true); 486 checkHasBody: true, expectIsRegular: true);
487 487
488 DiagnosticCollector collector = compiler.diagnosticCollector; 488 DiagnosticCollector collector = compiler.diagnosticCollector;
489 Expect.isTrue( 489 Expect.isTrue(
490 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); 490 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}");
491 Expect.equals( 491 Expect.equals(
492 1, collector.errors.length, "Unexpected errors: ${collector.errors}"); 492 1, collector.errors.length, "Unexpected errors: ${collector.errors}");
493 Expect.isTrue(collector.errors.first.message.kind == 493 Expect.isTrue(collector.errors.first.message.kind ==
494 MessageKind.INJECTED_PUBLIC_MEMBER); 494 MessageKind.INJECTED_PUBLIC_MEMBER);
495 } 495 }
496 496
497 Future testPatchSignatureCheck() async { 497 Future testPatchSignatureCheck() async {
498 var compiler = await applyPatch( 498 dynamic compiler = await applyPatch(
499 """ 499 """
500 class Class { 500 class Class {
501 external String method1(); 501 external String method1();
502 external void method2(String str); 502 external void method2(String str);
503 external void method3(String s1); 503 external void method3(String s1);
504 external void method4([String str]); 504 external void method4([String str]);
505 external void method5({String str}); 505 external void method5({String str});
506 external void method6({String str}); 506 external void method6({String str});
507 external void method7([String s1]); 507 external void method7([String s1]);
508 external void method8({String s1}); 508 external void method8({String s1});
(...skipping 10 matching lines...) Expand all
519 @patch void method4([String str, int i]) {} 519 @patch void method4([String str, int i]) {}
520 @patch void method5() {} 520 @patch void method5() {}
521 @patch void method6([String str]) {} 521 @patch void method6([String str]) {}
522 @patch void method7([String s2]) {} 522 @patch void method7([String s2]) {}
523 @patch void method8({String s2}) {} 523 @patch void method8({String s2}) {}
524 @patch void method9(int str) {} 524 @patch void method9(int str) {}
525 @patch void method10([int str]) {} 525 @patch void method10([int str]) {}
526 @patch void method11({int str}) {} 526 @patch void method11({int str}) {}
527 } 527 }
528 """); 528 """);
529 var container = ensure( 529 dynamic container = ensure(
530 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, 530 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find,
531 expectIsPatched: true); 531 expectIsPatched: true);
532 container.ensureResolved(compiler.resolution); 532 container.ensureResolved(compiler.resolution);
533 container.parseNode(compiler.parsingContext); 533 container.parseNode(compiler.parsingContext);
534 DiagnosticCollector collector = compiler.diagnosticCollector; 534 DiagnosticCollector collector = compiler.diagnosticCollector;
535 535
536 void expect(String methodName, List infos, List errors) { 536 void expect(String methodName, List infos, List errors) {
537 collector.clear(); 537 collector.clear();
538 compiler.resolver.resolveMethodElement(ensure( 538 compiler.resolver.resolveMethodElement(ensure(
539 compiler, methodName, container.lookupLocalMember, 539 compiler, methodName, container.lookupLocalMember,
(...skipping 24 matching lines...) Expand all
564 [MessageKind.PATCH_PARAMETER_MISMATCH]); 564 [MessageKind.PATCH_PARAMETER_MISMATCH]);
565 expect("method9", [MessageKind.PATCH_POINT_TO_PARAMETER], 565 expect("method9", [MessageKind.PATCH_POINT_TO_PARAMETER],
566 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]); 566 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]);
567 expect("method10", [MessageKind.PATCH_POINT_TO_PARAMETER], 567 expect("method10", [MessageKind.PATCH_POINT_TO_PARAMETER],
568 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]); 568 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]);
569 expect("method11", [MessageKind.PATCH_POINT_TO_PARAMETER], 569 expect("method11", [MessageKind.PATCH_POINT_TO_PARAMETER],
570 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]); 570 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]);
571 } 571 }
572 572
573 Future testExternalWithoutImplementationTopLevel() async { 573 Future testExternalWithoutImplementationTopLevel() async {
574 var compiler = await applyPatch( 574 dynamic compiler = await applyPatch(
575 """ 575 """
576 external void foo(); 576 external void foo();
577 """, 577 """,
578 """ 578 """
579 // @patch void foo() {} 579 // @patch void foo() {}
580 """); 580 """);
581 var function = ensure( 581 dynamic function = ensure(
582 compiler, "foo", compiler.resolution.commonElements.coreLibrary.find); 582 compiler, "foo", compiler.resolution.commonElements.coreLibrary.find);
583 compiler.resolver.resolve(function); 583 compiler.resolver.resolve(function);
584 DiagnosticCollector collector = compiler.diagnosticCollector; 584 DiagnosticCollector collector = compiler.diagnosticCollector;
585 Expect.isTrue( 585 Expect.isTrue(
586 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); 586 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}");
587 print('testExternalWithoutImplementationTopLevel:${collector.errors}'); 587 print('testExternalWithoutImplementationTopLevel:${collector.errors}');
588 Expect.equals(1, collector.errors.length); 588 Expect.equals(1, collector.errors.length);
589 Expect.isTrue(collector.errors.first.message.kind == 589 Expect.isTrue(collector.errors.first.message.kind ==
590 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION); 590 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION);
591 Expect.stringEquals('External method without an implementation.', 591 Expect.stringEquals('External method without an implementation.',
592 collector.errors.first.message.toString()); 592 collector.errors.first.message.toString());
593 } 593 }
594 594
595 Future testExternalWithoutImplementationMember() async { 595 Future testExternalWithoutImplementationMember() async {
596 var compiler = await applyPatch( 596 dynamic compiler = await applyPatch(
597 """ 597 """
598 class Class { 598 class Class {
599 external void foo(); 599 external void foo();
600 } 600 }
601 """, 601 """,
602 """ 602 """
603 @patch class Class { 603 @patch class Class {
604 // @patch void foo() {} 604 // @patch void foo() {}
605 } 605 }
606 """); 606 """);
607 var container = ensure( 607 dynamic container = ensure(
608 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, 608 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find,
609 expectIsPatched: true); 609 expectIsPatched: true);
610 container.parseNode(compiler.parsingContext); 610 container.parseNode(compiler.parsingContext);
611 DiagnosticCollector collector = compiler.diagnosticCollector; 611 DiagnosticCollector collector = compiler.diagnosticCollector;
612 collector.clear(); 612 collector.clear();
613 compiler.resolver.resolveMethodElement( 613 compiler.resolver.resolveMethodElement(
614 ensure(compiler, "foo", container.lookupLocalMember)); 614 ensure(compiler, "foo", container.lookupLocalMember));
615 Expect.isTrue( 615 Expect.isTrue(
616 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); 616 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}");
617 print('testExternalWithoutImplementationMember:${collector.errors}'); 617 print('testExternalWithoutImplementationMember:${collector.errors}');
618 Expect.equals(1, collector.errors.length); 618 Expect.equals(1, collector.errors.length);
619 Expect.isTrue(collector.errors.first.message.kind == 619 Expect.isTrue(collector.errors.first.message.kind ==
620 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION); 620 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION);
621 Expect.stringEquals('External method without an implementation.', 621 Expect.stringEquals('External method without an implementation.',
622 collector.errors.first.message.toString()); 622 collector.errors.first.message.toString());
623 } 623 }
624 624
625 Future testIsSubclass() async { 625 Future testIsSubclass() async {
626 var compiler = await applyPatch( 626 dynamic compiler = await applyPatch(
627 """ 627 """
628 class A {} 628 class A {}
629 """, 629 """,
630 """ 630 """
631 @patch class A {} 631 @patch class A {}
632 """); 632 """);
633 ClassElement cls = ensure( 633 ClassElement cls = ensure(
634 compiler, "A", compiler.resolution.commonElements.coreLibrary.find, 634 compiler, "A", compiler.resolution.commonElements.coreLibrary.find,
635 expectIsPatched: true); 635 expectIsPatched: true);
636 ClassElement patch = cls.patch; 636 ClassElement patch = cls.patch;
637 Expect.isTrue(cls != patch); 637 Expect.isTrue(cls != patch);
638 Expect.isTrue(cls.isSubclassOf(patch)); 638 Expect.isTrue(cls.isSubclassOf(patch));
639 Expect.isTrue(patch.isSubclassOf(cls)); 639 Expect.isTrue(patch.isSubclassOf(cls));
640 } 640 }
641 641
642 Future testPatchNonExistingTopLevel() async { 642 Future testPatchNonExistingTopLevel() async {
643 var compiler = await applyPatch( 643 dynamic compiler = await applyPatch(
644 """ 644 """
645 // class Class {} 645 // class Class {}
646 """, 646 """,
647 """ 647 """
648 @patch class Class {} 648 @patch class Class {}
649 """); 649 """);
650 DiagnosticCollector collector = compiler.diagnosticCollector; 650 DiagnosticCollector collector = compiler.diagnosticCollector;
651 Expect.isTrue( 651 Expect.isTrue(
652 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); 652 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}");
653 print('testPatchNonExistingTopLevel:${collector.errors}'); 653 print('testPatchNonExistingTopLevel:${collector.errors}');
654 Expect.equals(1, collector.errors.length); 654 Expect.equals(1, collector.errors.length);
655 Expect.isTrue( 655 Expect.isTrue(
656 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXISTING); 656 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXISTING);
657 } 657 }
658 658
659 Future testPatchNonExistingMember() async { 659 Future testPatchNonExistingMember() async {
660 var compiler = await applyPatch( 660 dynamic compiler = await applyPatch(
661 """ 661 """
662 class Class {} 662 class Class {}
663 """, 663 """,
664 """ 664 """
665 @patch class Class { 665 @patch class Class {
666 @patch void foo() {} 666 @patch void foo() {}
667 } 667 }
668 """); 668 """);
669 var container = ensure( 669 dynamic container = ensure(
670 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, 670 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find,
671 expectIsPatched: true); 671 expectIsPatched: true);
672 container.parseNode(compiler.parsingContext); 672 container.parseNode(compiler.parsingContext);
673 DiagnosticCollector collector = compiler.diagnosticCollector; 673 DiagnosticCollector collector = compiler.diagnosticCollector;
674 674
675 Expect.isTrue( 675 Expect.isTrue(
676 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); 676 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}");
677 print('testPatchNonExistingMember:${collector.errors}'); 677 print('testPatchNonExistingMember:${collector.errors}');
678 Expect.equals(1, collector.errors.length); 678 Expect.equals(1, collector.errors.length);
679 Expect.isTrue( 679 Expect.isTrue(
680 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXISTING); 680 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXISTING);
681 } 681 }
682 682
683 Future testPatchNonPatchablePatch() async { 683 Future testPatchNonPatchablePatch() async {
684 var compiler = await applyPatch( 684 dynamic compiler = await applyPatch(
685 """ 685 """
686 external get foo; 686 external get foo;
687 """, 687 """,
688 """ 688 """
689 @patch var foo; 689 @patch var foo;
690 """); 690 """);
691 ensure(compiler, "foo", compiler.resolution.commonElements.coreLibrary.find); 691 ensure(compiler, "foo", compiler.resolution.commonElements.coreLibrary.find);
692 692
693 DiagnosticCollector collector = compiler.diagnosticCollector; 693 DiagnosticCollector collector = compiler.diagnosticCollector;
694 Expect.isTrue( 694 Expect.isTrue(
695 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); 695 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}");
696 print('testPatchNonPatchablePatch:${collector.errors}'); 696 print('testPatchNonPatchablePatch:${collector.errors}');
697 Expect.equals(1, collector.errors.length); 697 Expect.equals(1, collector.errors.length);
698 Expect.isTrue( 698 Expect.isTrue(
699 collector.errors.first.message.kind == MessageKind.PATCH_NONPATCHABLE); 699 collector.errors.first.message.kind == MessageKind.PATCH_NONPATCHABLE);
700 } 700 }
701 701
702 Future testPatchNonPatchableOrigin() async { 702 Future testPatchNonPatchableOrigin() async {
703 var compiler = await applyPatch( 703 dynamic compiler = await applyPatch(
704 """ 704 """
705 external var foo; 705 external var foo;
706 """, 706 """,
707 """ 707 """
708 @patch get foo => 0; 708 @patch get foo => 0;
709 """); 709 """);
710 ensure(compiler, "foo", compiler.resolution.commonElements.coreLibrary.find); 710 ensure(compiler, "foo", compiler.resolution.commonElements.coreLibrary.find);
711 711
712 DiagnosticCollector collector = compiler.diagnosticCollector; 712 DiagnosticCollector collector = compiler.diagnosticCollector;
713 Expect.isTrue( 713 Expect.isTrue(
714 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}"); 714 collector.warnings.isEmpty, "Unexpected warnings: ${collector.warnings}");
715 print('testPatchNonPatchableOrigin:${collector.errors}'); 715 print('testPatchNonPatchableOrigin:${collector.errors}');
716 Expect.equals(2, collector.errors.length); 716 Expect.equals(2, collector.errors.length);
717 Expect.equals( 717 Expect.equals(
718 MessageKind.EXTRANEOUS_MODIFIER, collector.errors.first.message.kind); 718 MessageKind.EXTRANEOUS_MODIFIER, collector.errors.first.message.kind);
719 Expect.equals( 719 Expect.equals(
720 // TODO(ahe): Eventually, this error should be removed as it will be 720 // TODO(ahe): Eventually, this error should be removed as it will be
721 // handled by the regular parser. 721 // handled by the regular parser.
722 MessageKind.PATCH_NONPATCHABLE, 722 MessageKind.PATCH_NONPATCHABLE,
723 collector.errors.elementAt(1).message.kind); 723 collector.errors.elementAt(1).message.kind);
724 } 724 }
725 725
726 Future testPatchNonExternalTopLevel() async { 726 Future testPatchNonExternalTopLevel() async {
727 var compiler = await applyPatch( 727 dynamic compiler = await applyPatch(
728 """ 728 """
729 void foo() {} 729 void foo() {}
730 """, 730 """,
731 """ 731 """
732 @patch void foo() {} 732 @patch void foo() {}
733 """); 733 """);
734 DiagnosticCollector collector = compiler.diagnosticCollector; 734 DiagnosticCollector collector = compiler.diagnosticCollector;
735 print('testPatchNonExternalTopLevel.errors:${collector.errors}'); 735 print('testPatchNonExternalTopLevel.errors:${collector.errors}');
736 print('testPatchNonExternalTopLevel.warnings:${collector.warnings}'); 736 print('testPatchNonExternalTopLevel.warnings:${collector.warnings}');
737 Expect.equals(1, collector.errors.length); 737 Expect.equals(1, collector.errors.length);
738 Expect.isTrue( 738 Expect.isTrue(
739 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXTERNAL); 739 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXTERNAL);
740 Expect.equals(0, collector.warnings.length); 740 Expect.equals(0, collector.warnings.length);
741 Expect.equals(1, collector.infos.length); 741 Expect.equals(1, collector.infos.length);
742 Expect.isTrue(collector.infos.first.message.kind == 742 Expect.isTrue(collector.infos.first.message.kind ==
743 MessageKind.PATCH_POINT_TO_FUNCTION); 743 MessageKind.PATCH_POINT_TO_FUNCTION);
744 } 744 }
745 745
746 Future testPatchNonExternalMember() async { 746 Future testPatchNonExternalMember() async {
747 var compiler = await applyPatch( 747 dynamic compiler = await applyPatch(
748 """ 748 """
749 class Class { 749 class Class {
750 void foo() {} 750 void foo() {}
751 } 751 }
752 """, 752 """,
753 """ 753 """
754 @patch class Class { 754 @patch class Class {
755 @patch void foo() {} 755 @patch void foo() {}
756 } 756 }
757 """); 757 """);
758 var container = ensure( 758 dynamic container = ensure(
759 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find, 759 compiler, "Class", compiler.resolution.commonElements.coreLibrary.find,
760 expectIsPatched: true); 760 expectIsPatched: true);
761 container.parseNode(compiler.parsingContext); 761 container.parseNode(compiler.parsingContext);
762 762
763 DiagnosticCollector collector = compiler.diagnosticCollector; 763 DiagnosticCollector collector = compiler.diagnosticCollector;
764 print('testPatchNonExternalMember.errors:${collector.errors}'); 764 print('testPatchNonExternalMember.errors:${collector.errors}');
765 print('testPatchNonExternalMember.warnings:${collector.warnings}'); 765 print('testPatchNonExternalMember.warnings:${collector.warnings}');
766 Expect.equals(1, collector.errors.length); 766 Expect.equals(1, collector.errors.length);
767 Expect.isTrue( 767 Expect.isTrue(
768 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXTERNAL); 768 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXTERNAL);
769 Expect.equals(0, collector.warnings.length); 769 Expect.equals(0, collector.warnings.length);
770 Expect.equals(1, collector.infos.length); 770 Expect.equals(1, collector.infos.length);
771 Expect.isTrue(collector.infos.first.message.kind == 771 Expect.isTrue(collector.infos.first.message.kind ==
772 MessageKind.PATCH_POINT_TO_FUNCTION); 772 MessageKind.PATCH_POINT_TO_FUNCTION);
773 } 773 }
774 774
775 Future testPatchNonClass() async { 775 Future testPatchNonClass() async {
776 var compiler = await applyPatch( 776 dynamic compiler = await applyPatch(
777 """ 777 """
778 external void Class() {} 778 external void Class() {}
779 """, 779 """,
780 """ 780 """
781 @patch class Class {} 781 @patch class Class {}
782 """); 782 """);
783 DiagnosticCollector collector = compiler.diagnosticCollector; 783 DiagnosticCollector collector = compiler.diagnosticCollector;
784 print('testPatchNonClass.errors:${collector.errors}'); 784 print('testPatchNonClass.errors:${collector.errors}');
785 print('testPatchNonClass.warnings:${collector.warnings}'); 785 print('testPatchNonClass.warnings:${collector.warnings}');
786 Expect.equals(1, collector.errors.length); 786 Expect.equals(1, collector.errors.length);
787 Expect.isTrue( 787 Expect.isTrue(
788 collector.errors.first.message.kind == MessageKind.PATCH_NON_CLASS); 788 collector.errors.first.message.kind == MessageKind.PATCH_NON_CLASS);
789 Expect.equals(0, collector.warnings.length); 789 Expect.equals(0, collector.warnings.length);
790 Expect.equals(1, collector.infos.length); 790 Expect.equals(1, collector.infos.length);
791 Expect.isTrue( 791 Expect.isTrue(
792 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_CLASS); 792 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_CLASS);
793 } 793 }
794 794
795 Future testPatchNonGetter() async { 795 Future testPatchNonGetter() async {
796 var compiler = await applyPatch( 796 dynamic compiler = await applyPatch(
797 """ 797 """
798 external void foo() {} 798 external void foo() {}
799 """, 799 """,
800 """ 800 """
801 @patch get foo => 0; 801 @patch get foo => 0;
802 """); 802 """);
803 DiagnosticCollector collector = compiler.diagnosticCollector; 803 DiagnosticCollector collector = compiler.diagnosticCollector;
804 print('testPatchNonClass.errors:${collector.errors}'); 804 print('testPatchNonClass.errors:${collector.errors}');
805 print('testPatchNonClass.warnings:${collector.warnings}'); 805 print('testPatchNonClass.warnings:${collector.warnings}');
806 Expect.equals(1, collector.errors.length); 806 Expect.equals(1, collector.errors.length);
807 Expect.isTrue( 807 Expect.isTrue(
808 collector.errors.first.message.kind == MessageKind.PATCH_NON_GETTER); 808 collector.errors.first.message.kind == MessageKind.PATCH_NON_GETTER);
809 Expect.equals(0, collector.warnings.length); 809 Expect.equals(0, collector.warnings.length);
810 Expect.equals(1, collector.infos.length); 810 Expect.equals(1, collector.infos.length);
811 Expect.isTrue( 811 Expect.isTrue(
812 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_GETTER); 812 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_GETTER);
813 } 813 }
814 814
815 Future testPatchNoGetter() async { 815 Future testPatchNoGetter() async {
816 var compiler = await applyPatch( 816 dynamic compiler = await applyPatch(
817 """ 817 """
818 external set foo(var value) {} 818 external set foo(var value) {}
819 """, 819 """,
820 """ 820 """
821 @patch get foo => 0; 821 @patch get foo => 0;
822 """); 822 """);
823 DiagnosticCollector collector = compiler.diagnosticCollector; 823 DiagnosticCollector collector = compiler.diagnosticCollector;
824 print('testPatchNonClass.errors:${collector.errors}'); 824 print('testPatchNonClass.errors:${collector.errors}');
825 print('testPatchNonClass.warnings:${collector.warnings}'); 825 print('testPatchNonClass.warnings:${collector.warnings}');
826 Expect.equals(1, collector.errors.length); 826 Expect.equals(1, collector.errors.length);
827 Expect.isTrue( 827 Expect.isTrue(
828 collector.errors.first.message.kind == MessageKind.PATCH_NO_GETTER); 828 collector.errors.first.message.kind == MessageKind.PATCH_NO_GETTER);
829 Expect.equals(0, collector.warnings.length); 829 Expect.equals(0, collector.warnings.length);
830 Expect.equals(1, collector.infos.length); 830 Expect.equals(1, collector.infos.length);
831 Expect.isTrue( 831 Expect.isTrue(
832 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_GETTER); 832 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_GETTER);
833 } 833 }
834 834
835 Future testPatchNonSetter() async { 835 Future testPatchNonSetter() async {
836 var compiler = await applyPatch( 836 dynamic compiler = await applyPatch(
837 """ 837 """
838 external void foo() {} 838 external void foo() {}
839 """, 839 """,
840 """ 840 """
841 @patch set foo(var value) {} 841 @patch set foo(var value) {}
842 """); 842 """);
843 DiagnosticCollector collector = compiler.diagnosticCollector; 843 DiagnosticCollector collector = compiler.diagnosticCollector;
844 print('testPatchNonClass.errors:${collector.errors}'); 844 print('testPatchNonClass.errors:${collector.errors}');
845 print('testPatchNonClass.warnings:${collector.warnings}'); 845 print('testPatchNonClass.warnings:${collector.warnings}');
846 Expect.equals(1, collector.errors.length); 846 Expect.equals(1, collector.errors.length);
847 Expect.isTrue( 847 Expect.isTrue(
848 collector.errors.first.message.kind == MessageKind.PATCH_NON_SETTER); 848 collector.errors.first.message.kind == MessageKind.PATCH_NON_SETTER);
849 Expect.equals(0, collector.warnings.length); 849 Expect.equals(0, collector.warnings.length);
850 Expect.equals(1, collector.infos.length); 850 Expect.equals(1, collector.infos.length);
851 Expect.isTrue( 851 Expect.isTrue(
852 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_SETTER); 852 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_SETTER);
853 } 853 }
854 854
855 Future testPatchNoSetter() async { 855 Future testPatchNoSetter() async {
856 var compiler = await applyPatch( 856 dynamic compiler = await applyPatch(
857 """ 857 """
858 external get foo; 858 external get foo;
859 """, 859 """,
860 """ 860 """
861 @patch set foo(var value) {} 861 @patch set foo(var value) {}
862 """); 862 """);
863 DiagnosticCollector collector = compiler.diagnosticCollector; 863 DiagnosticCollector collector = compiler.diagnosticCollector;
864 print('testPatchNonClass.errors:${collector.errors}'); 864 print('testPatchNonClass.errors:${collector.errors}');
865 print('testPatchNonClass.warnings:${collector.warnings}'); 865 print('testPatchNonClass.warnings:${collector.warnings}');
866 Expect.equals(1, collector.errors.length); 866 Expect.equals(1, collector.errors.length);
867 Expect.isTrue( 867 Expect.isTrue(
868 collector.errors.first.message.kind == MessageKind.PATCH_NO_SETTER); 868 collector.errors.first.message.kind == MessageKind.PATCH_NO_SETTER);
869 Expect.equals(0, collector.warnings.length); 869 Expect.equals(0, collector.warnings.length);
870 Expect.equals(1, collector.infos.length); 870 Expect.equals(1, collector.infos.length);
871 Expect.isTrue( 871 Expect.isTrue(
872 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_SETTER); 872 collector.infos.first.message.kind == MessageKind.PATCH_POINT_TO_SETTER);
873 } 873 }
874 874
875 Future testPatchNonFunction() async { 875 Future testPatchNonFunction() async {
876 var compiler = await applyPatch( 876 dynamic compiler = await applyPatch(
877 """ 877 """
878 external get foo; 878 external get foo;
879 """, 879 """,
880 """ 880 """
881 @patch void foo() {} 881 @patch void foo() {}
882 """); 882 """);
883 DiagnosticCollector collector = compiler.diagnosticCollector; 883 DiagnosticCollector collector = compiler.diagnosticCollector;
884 print('testPatchNonClass.errors:${collector.errors}'); 884 print('testPatchNonClass.errors:${collector.errors}');
885 print('testPatchNonClass.warnings:${collector.warnings}'); 885 print('testPatchNonClass.warnings:${collector.warnings}');
886 Expect.equals(1, collector.errors.length); 886 Expect.equals(1, collector.errors.length);
887 Expect.isTrue( 887 Expect.isTrue(
888 collector.errors.first.message.kind == MessageKind.PATCH_NON_FUNCTION); 888 collector.errors.first.message.kind == MessageKind.PATCH_NON_FUNCTION);
889 Expect.equals(0, collector.warnings.length); 889 Expect.equals(0, collector.warnings.length);
890 Expect.equals(1, collector.infos.length); 890 Expect.equals(1, collector.infos.length);
891 Expect.isTrue(collector.infos.first.message.kind == 891 Expect.isTrue(collector.infos.first.message.kind ==
892 MessageKind.PATCH_POINT_TO_FUNCTION); 892 MessageKind.PATCH_POINT_TO_FUNCTION);
893 } 893 }
894 894
895 Future testPatchAndSelector() async { 895 Future testPatchAndSelector() async {
896 var compiler = await applyPatch( 896 dynamic compiler = await applyPatch(
897 """ 897 """
898 class A { 898 class A {
899 external void clear(); 899 external void clear();
900 } 900 }
901 class B extends A { 901 class B extends A {
902 } 902 }
903 """, 903 """,
904 """ 904 """
905 @patch class A { 905 @patch class A {
906 int method() => 0; 906 int method() => 0;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 Expect.isTrue(typeMask.canHit(method, selector, world)); 961 Expect.isTrue(typeMask.canHit(method, selector, world));
962 } 962 }
963 963
964 Future testAnalyzeAllInjectedMembers() async { 964 Future testAnalyzeAllInjectedMembers() async {
965 Future expect(String patchText, [expectedWarnings]) async { 965 Future expect(String patchText, [expectedWarnings]) async {
966 if (expectedWarnings == null) expectedWarnings = []; 966 if (expectedWarnings == null) expectedWarnings = [];
967 if (expectedWarnings is! List) { 967 if (expectedWarnings is! List) {
968 expectedWarnings = <MessageKind>[expectedWarnings]; 968 expectedWarnings = <MessageKind>[expectedWarnings];
969 } 969 }
970 970
971 var compiler = 971 dynamic compiler =
972 await applyPatch('', patchText, analyzeAll: true, analyzeOnly: true); 972 await applyPatch('', patchText, analyzeAll: true, analyzeOnly: true);
973 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')]; 973 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')];
974 await compiler.run(null); 974 await compiler.run(null);
975 DiagnosticCollector collector = compiler.diagnosticCollector; 975 DiagnosticCollector collector = compiler.diagnosticCollector;
976 compareWarningKinds(patchText, expectedWarnings, collector.warnings); 976 compareWarningKinds(patchText, expectedWarnings, collector.warnings);
977 } 977 }
978 978
979 await expect('String s = 0;', MessageKind.NOT_ASSIGNABLE); 979 await expect('String s = 0;', MessageKind.NOT_ASSIGNABLE);
980 await expect('void method() { String s = 0; }', MessageKind.NOT_ASSIGNABLE); 980 await expect('void method() { String s = 0; }', MessageKind.NOT_ASSIGNABLE);
981 await expect( 981 await expect(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 @patch 1023 @patch
1024 factory B.reflectBack() = B.originTarget; 1024 factory B.reflectBack() = B.originTarget;
1025 @patch 1025 @patch
1026 factory B.patchInjected() = _C.injected; 1026 factory B.patchInjected() = _C.injected;
1027 } 1027 }
1028 class _C extends B { 1028 class _C extends B {
1029 _C.injected() : super.patchTarget(); 1029 _C.injected() : super.patchTarget();
1030 } 1030 }
1031 """; 1031 """;
1032 1032
1033 var compiler = await applyPatch(origin, patch, 1033 dynamic compiler = await applyPatch(origin, patch,
1034 analyzeAll: true, analyzeOnly: true, runCompiler: true); 1034 analyzeAll: true, analyzeOnly: true, runCompiler: true);
1035 ClassElement clsA = compiler.resolution.commonElements.coreLibrary.find("A"); 1035 ClassElement clsA = compiler.resolution.commonElements.coreLibrary.find("A");
1036 ClassElement clsB = compiler.resolution.commonElements.coreLibrary.find("B"); 1036 ClassElement clsB = compiler.resolution.commonElements.coreLibrary.find("B");
1037 Expect.isNotNull(clsB);
1037 1038
1038 ConstructorElement forward = clsA.lookupConstructor("forward"); 1039 ConstructorElement forward = clsA.lookupConstructor("forward");
1039 ConstructorElement target = forward.effectiveTarget; 1040 ConstructorElement target = forward.effectiveTarget;
1040 Expect.isTrue(target.isPatched, "Unexpected target $target for $forward"); 1041 Expect.isTrue(target.isPatched, "Unexpected target $target for $forward");
1041 Expect.isFalse(target.isPatch, "Unexpected target $target for $forward"); 1042 Expect.isFalse(target.isPatch, "Unexpected target $target for $forward");
1042 Expect.equals("patchTarget", target.name); 1043 Expect.equals("patchTarget", target.name);
1043 1044
1044 ConstructorElement forwardOne = clsA.lookupConstructor("forwardOne"); 1045 ConstructorElement forwardOne = clsA.lookupConstructor("forwardOne");
1045 target = forwardOne.effectiveTarget; 1046 target = forwardOne.effectiveTarget;
1046 Expect.isFalse(forwardOne.isMalformed); 1047 Expect.isFalse(forwardOne.isMalformed);
(...skipping 14 matching lines...) Expand all
1061 Expect.equals("injected", target.name); 1062 Expect.equals("injected", target.name);
1062 } 1063 }
1063 1064
1064 Future testTypecheckPatchedMembers() async { 1065 Future testTypecheckPatchedMembers() async {
1065 String originText = "external void method();"; 1066 String originText = "external void method();";
1066 String patchText = """ 1067 String patchText = """
1067 @patch void method() { 1068 @patch void method() {
1068 String s = 0; 1069 String s = 0;
1069 } 1070 }
1070 """; 1071 """;
1071 var compiler = await applyPatch(originText, patchText, 1072 dynamic compiler = await applyPatch(originText, patchText,
1072 analyzeAll: true, analyzeOnly: true); 1073 analyzeAll: true, analyzeOnly: true);
1073 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')]; 1074 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')];
1074 await compiler.run(null); 1075 await compiler.run(null);
1075 DiagnosticCollector collector = compiler.diagnosticCollector; 1076 DiagnosticCollector collector = compiler.diagnosticCollector;
1076 compareWarningKinds( 1077 compareWarningKinds(
1077 patchText, [MessageKind.NOT_ASSIGNABLE], collector.warnings); 1078 patchText, [MessageKind.NOT_ASSIGNABLE], collector.warnings);
1078 } 1079 }
1079 1080
1080 main() { 1081 main() {
1081 asyncTest(() async { 1082 asyncTest(() async {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 await testPatchNonFunction(); 1115 await testPatchNonFunction();
1115 1116
1116 await testPatchAndSelector(); 1117 await testPatchAndSelector();
1117 1118
1118 await testEffectiveTarget(); 1119 await testEffectiveTarget();
1119 1120
1120 await testAnalyzeAllInjectedMembers(); 1121 await testAnalyzeAllInjectedMembers();
1121 await testTypecheckPatchedMembers(); 1122 await testTypecheckPatchedMembers();
1122 }); 1123 });
1123 } 1124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698