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

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

Issue 2877193003: Start actually adding incrementality into incremental kernel generator. (Closed)
Patch Set: Fixes for review comments. 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:kernel/ast.dart'; 11 import 'package:kernel/ast.dart';
11 import 'package:kernel/text/ast_to_text.dart'; 12 import 'package:kernel/text/ast_to_text.dart';
12 import 'package:test/test.dart'; 13 import 'package:test/test.dart';
13 import 'package:test_reflective_loader/test_reflective_loader.dart'; 14 import 'package:test_reflective_loader/test_reflective_loader.dart';
14 15
15 import 'src/incremental/mock_sdk.dart'; 16 import 'src/incremental/mock_sdk.dart';
16 17
17 main() { 18 main() {
18 defineReflectiveSuite(() { 19 defineReflectiveSuite(() {
19 defineReflectiveTests(IncrementalKernelGeneratorTest); 20 defineReflectiveTests(IncrementalKernelGeneratorTest);
(...skipping 10 matching lines...) Expand all
30 31
31 /// Compute the initial [Program] for the given [entryPoint]. 32 /// Compute the initial [Program] for the given [entryPoint].
32 Future<Program> getInitialState(Uri entryPoint) async { 33 Future<Program> getInitialState(Uri entryPoint) async {
33 Map<String, Uri> dartLibraries = createSdkFiles(fileSystem); 34 Map<String, Uri> dartLibraries = createSdkFiles(fileSystem);
34 // TODO(scheglov) Builder the SDK kernel and set it into the options. 35 // TODO(scheglov) Builder the SDK kernel and set it into the options.
35 36
36 // TODO(scheglov) Make `.packages` file optional. 37 // TODO(scheglov) Make `.packages` file optional.
37 38
38 var compilerOptions = new CompilerOptions() 39 var compilerOptions = new CompilerOptions()
39 ..fileSystem = fileSystem 40 ..fileSystem = fileSystem
41 ..byteStore = new MemoryByteStore()
42 // ..logger = new PerformanceLog(stdout)
40 ..strongMode = true 43 ..strongMode = true
41 ..chaseDependencies = true 44 ..chaseDependencies = true
42 ..dartLibraries = dartLibraries 45 ..dartLibraries = dartLibraries
43 ..packagesFileUri = Uri.parse('file:///test/.packages'); 46 ..packagesFileUri = Uri.parse('file:///test/.packages');
44 incrementalKernelGenerator = await IncrementalKernelGenerator.newInstance( 47 incrementalKernelGenerator = await IncrementalKernelGenerator.newInstance(
45 compilerOptions, entryPoint); 48 compilerOptions, entryPoint);
46 return (await incrementalKernelGenerator.computeDelta()).newProgram; 49 return (await incrementalKernelGenerator.computeDelta()).newProgram;
47 } 50 }
48 51
52 test_analyze_chain() async {
53 writeFile('/test/.packages', 'test:lib/');
54 String aPath = '/test/lib/a.dart';
55 String bPath = '/test/lib/b.dart';
56 String cPath = '/test/lib/c.dart';
57 writeFile(aPath, 'var a = 1;');
58 Uri bUri = writeFile(
59 bPath,
60 r'''
61 import 'a.dart';
62 var b = a;
63 ''');
64 Uri cUri = writeFile(
65 cPath,
66 r'''
67 import 'a.dart';
68 import 'b.dart';
69 var c1 = a;
70 var c2 = b;
71 ''');
72
73 {
74 Program program = await getInitialState(cUri);
75 Library library = _getLibrary(program, cUri);
76 expect(
77 _getLibraryText(library),
78 r'''
79 library;
80 import self as self;
81 import "dart:core" as core;
82 import "./a.dart" as a;
83 import "./b.dart" as b;
84
85 static field core::int c1 = a::a;
86 static field core::int c2 = b::b;
87 ''');
88 // TODO(scheglov) Check that the program contains all libraries.
89 }
90
91 // Update b.dart and recompile c.dart
92 writeFile(
93 bPath,
94 r'''
95 import 'a.dart';
96 var b = 1.2;
97 ''');
98 incrementalKernelGenerator.invalidate(bUri);
99 {
100 DeltaProgram delta = await incrementalKernelGenerator.computeDelta();
101 var program = delta.newProgram;
102 var library = _getLibrary(program, cUri);
103 expect(
104 _getLibraryText(library),
105 r'''
106 library;
107 import self as self;
108 import "dart:core" as core;
109 import "./a.dart" as a;
110 import "./b.dart" as b;
111
112 static field core::int c1 = a::a;
113 static field core::double c2 = b::b;
114 ''');
115 // TODO(scheglov) Check that the delta contains b.dart and c.dart,
116 // but not a.dart or SDK.
117 // print(_getLibraryText(_getLibrary(program, aUri)));
118 // print(_getLibraryText(_getLibrary(program, bUri)));
119 // print(_getLibraryText(_getLibrary(program, cUri)));
120 }
121 }
122
49 test_updateEntryPoint() async { 123 test_updateEntryPoint() async {
50 writeFile('/test/.packages', 'test:lib/'); 124 writeFile('/test/.packages', 'test:lib/');
51 String path = '/test/lib/test.dart'; 125 String path = '/test/lib/test.dart';
52 Uri uri = writeFile( 126 Uri uri = writeFile(
53 path, 127 path,
54 r''' 128 r'''
55 main() { 129 main() {
56 var v = 1; 130 var v = 1;
57 } 131 }
58 '''); 132 ''');
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 throw fail('No library found with URI "$uri"'); 299 throw fail('No library found with URI "$uri"');
226 } 300 }
227 301
228 String _getLibraryText(Library library) { 302 String _getLibraryText(Library library) {
229 StringBuffer buffer = new StringBuffer(); 303 StringBuffer buffer = new StringBuffer();
230 new Printer(buffer, syntheticNames: new NameSystem()) 304 new Printer(buffer, syntheticNames: new NameSystem())
231 .writeLibraryFile(library); 305 .writeLibraryFile(library);
232 return buffer.toString(); 306 return buffer.toString();
233 } 307 }
234 } 308 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698