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

Side by Side Diff: pkg/front_end/test/incremental_kernel_generator_test.dart

Issue 2896493002: Add LimitedBinaryPrinter, tests and switch incremental generator to it. (Closed)
Patch Set: Created 3 years, 7 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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 6
7 import 'package:front_end/compiler_options.dart'; 7 import 'package:front_end/compiler_options.dart';
8 import 'package:front_end/incremental_kernel_generator.dart'; 8 import 'package:front_end/incremental_kernel_generator.dart';
9 import 'package:front_end/memory_file_system.dart'; 9 import 'package:front_end/memory_file_system.dart';
10 import 'package:front_end/src/incremental/byte_store.dart'; 10 import 'package:front_end/src/incremental/byte_store.dart';
11 import 'package:front_end/src/incremental/limited_ast_to_binary.dart';
12 import 'package:front_end/src/incremental_kernel_generator_impl.dart';
11 import 'package:kernel/ast.dart'; 13 import 'package:kernel/ast.dart';
14 import 'package:kernel/binary/ast_from_binary.dart';
12 import 'package:kernel/text/ast_to_text.dart'; 15 import 'package:kernel/text/ast_to_text.dart';
16 import 'package:kernel/verifier.dart';
13 import 'package:test/test.dart'; 17 import 'package:test/test.dart';
14 import 'package:test_reflective_loader/test_reflective_loader.dart'; 18 import 'package:test_reflective_loader/test_reflective_loader.dart';
15 19
16 import 'src/incremental/mock_sdk.dart'; 20 import 'src/incremental/mock_sdk.dart';
17 21
18 main() { 22 main() {
19 defineReflectiveSuite(() { 23 defineReflectiveSuite(() {
20 defineReflectiveTests(IncrementalKernelGeneratorTest); 24 defineReflectiveTests(IncrementalKernelGeneratorTest);
21 }); 25 });
22 } 26 }
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 _getLibraryText(library), 230 _getLibraryText(library),
227 r''' 231 r'''
228 library; 232 library;
229 import self as self; 233 import self as self;
230 import "dart:core" as core; 234 import "dart:core" as core;
231 235
232 static field (core::String) → core::int f; 236 static field (core::String) → core::int f;
233 '''); 237 ''');
234 } 238 }
235 239
240 test_limited_ast_to_binary() async {
241 writeFile('/test/.packages', 'test:lib/');
242 String aPath = '/test/lib/a.dart';
243 String bPath = '/test/lib/b.dart';
244 writeFile(
245 aPath,
246 r'''
247 int topField = 0;
248 int get topGetter => 0;
249 int topFunction({p}) => 0;
250
251 class A {
252 static int staticField;
253 static int get staticGetter => 0;
254 static int staticMethod() => 0;
255
256 int instanceField;
257 int get instanceGetter => 0;
258 int instanceMethod() => 0;
259
260 A();
261 A.named();
262 }
263 ''');
264 Uri bUri = writeFile(
265 bPath,
266 r'''
267 import 'a.dart';
268
269 class B extends A {
270 B() : super();
271 B.named() : super.named();
272
273 void foo() {
274 super.instanceMethod();
275 instanceMethod();
276 }
277
278 int instanceMethod() => 0;
279 }
280
281 main() {
282 topField;
283 topField = 0;
284 var v1 = topGetter;
285 var v2 = topFunction(p: 0);
286
287 A.staticField;
288 A.staticField = 0;
289 var v3 = A.staticGetter;
290 var v4 = A.staticMethod();
291
292 var a = new A();
293 a.instanceField;
294 a.instanceField = 0;
295 var v5 = a.instanceGetter;
296 var v6 = a.instanceMethod();
297 }
298 ''');
299
300 Program initialProgram = await getInitialState(bUri);
301
302 String initialKernelText;
303 List<int> bytes;
304 {
305 Library initialLibrary = _getLibrary(initialProgram, bUri);
306 initialKernelText = _getLibraryText(initialLibrary);
307
308 var byteSink = new ByteSink();
309 var printer = new LimitedBinaryPrinter(
310 byteSink, (library) => library.importUri == bUri);
311 printer.writeProgramFile(initialProgram);
312 bytes = byteSink.builder.takeBytes();
313
314 // Remove b.dart from the initial program.
315 // So, the program is now ready for re-adding the library.
316 initialProgram.libraries.remove(initialLibrary);
317 initialProgram.root.removeChild(initialLibrary.importUri.toString());
318 }
319
ahe 2017/05/22 09:27:05 Can you check that b.dart has been removed here?
scheglov 2017/05/22 20:36:01 I'm not sure what we will verify by doing this. T
ahe 2017/05/24 08:35:59 I guess you're right. I'm just looking for some wa
320 // Load b.dart from bytes using the initial name root, so that
321 // serialized canonical names can be linked to corresponding nodes.
322 Library loadedLibrary;
323 {
324 var programForLoading = new Program(nameRoot: initialProgram.root);
325 var reader = new BinaryBuilder(bytes);
326 reader.readProgram(programForLoading);
327 loadedLibrary = _getLibrary(programForLoading, bUri);
328 }
329
330 // Add the library into the initial program.
331 initialProgram.libraries.add(loadedLibrary);
332 loadedLibrary.parent = initialProgram;
333
334 // The loaded library has the same text.
335 expect(_getLibraryText(loadedLibrary), initialKernelText);
336
337 // The program with re-added library passes verification.
338 verifyProgram(initialProgram);
339 }
340
236 test_updateEntryPoint() async { 341 test_updateEntryPoint() async {
237 writeFile('/test/.packages', 'test:lib/'); 342 writeFile('/test/.packages', 'test:lib/');
238 String path = '/test/lib/test.dart'; 343 String path = '/test/lib/test.dart';
239 Uri uri = writeFile( 344 Uri uri = writeFile(
240 path, 345 path,
241 r''' 346 r'''
242 main() { 347 main() {
243 var v = 1; 348 var v = 1;
244 } 349 }
245 '''); 350 ''');
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 throw fail('No library found with URI "$uri"'); 529 throw fail('No library found with URI "$uri"');
425 } 530 }
426 531
427 String _getLibraryText(Library library) { 532 String _getLibraryText(Library library) {
428 StringBuffer buffer = new StringBuffer(); 533 StringBuffer buffer = new StringBuffer();
429 new Printer(buffer, syntheticNames: new NameSystem()) 534 new Printer(buffer, syntheticNames: new NameSystem())
430 .writeLibraryFile(library); 535 .writeLibraryFile(library);
431 return buffer.toString(); 536 return buffer.toString();
432 } 537 }
433 } 538 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698