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

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

Issue 2871573003: Update DeltaProgram API and documentation. (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:kernel/ast.dart'; 10 import 'package:kernel/ast.dart';
(...skipping 10 matching lines...) Expand all
21 } 21 }
22 22
23 @reflectiveTest 23 @reflectiveTest
24 class IncrementalKernelGeneratorTest { 24 class IncrementalKernelGeneratorTest {
25 /// Virtual filesystem for testing. 25 /// Virtual filesystem for testing.
26 final fileSystem = new MemoryFileSystem(Uri.parse('file:///')); 26 final fileSystem = new MemoryFileSystem(Uri.parse('file:///'));
27 27
28 /// The object under test. 28 /// The object under test.
29 IncrementalKernelGenerator incrementalKernelGenerator; 29 IncrementalKernelGenerator incrementalKernelGenerator;
30 30
31 /// TODO(scheglov) Why do we return a Map? 31 /// Compute the initial [Program] for the given [entryPoint].
32 /// From the discussion yesterday it seems to me that we always have 32 Future<Program> getInitialState(Uri entryPoint) async {
33 /// just one program - with all libraries with code, or with some libraries
34 /// with code and some with only outlines.
35 Future<Map<Uri, Program>> getInitialState(Uri entryPoint) async {
36 Map<String, Uri> dartLibraries = createSdkFiles(fileSystem); 33 Map<String, Uri> dartLibraries = createSdkFiles(fileSystem);
37 // TODO(scheglov) Builder the SDK kernel and set it into the options. 34 // TODO(scheglov) Builder the SDK kernel and set it into the options.
38 35
39 // TODO(scheglov) Make `.packages` file optional. 36 // TODO(scheglov) Make `.packages` file optional.
40 37
41 incrementalKernelGenerator = new IncrementalKernelGenerator( 38 incrementalKernelGenerator = new IncrementalKernelGenerator(
42 entryPoint, 39 entryPoint,
43 new CompilerOptions() 40 new CompilerOptions()
44 ..fileSystem = fileSystem 41 ..fileSystem = fileSystem
45 ..strongMode = true 42 ..strongMode = true
46 ..chaseDependencies = true 43 ..chaseDependencies = true
47 ..dartLibraries = dartLibraries 44 ..dartLibraries = dartLibraries
48 ..packagesFileUri = Uri.parse('file:///test/.packages')); 45 ..packagesFileUri = Uri.parse('file:///test/.packages'));
49 return (await incrementalKernelGenerator.computeDelta()).newState; 46 return (await incrementalKernelGenerator.computeDelta()).newProgram;
50 } 47 }
51 48
52 test_updateEntryPoint() async { 49 test_updateEntryPoint() async {
53 writeFile('/test/.packages', 'test:lib/'); 50 writeFile('/test/.packages', 'test:lib/');
54 String path = '/test/lib/test.dart'; 51 String path = '/test/lib/test.dart';
55 Uri uri = writeFile( 52 Uri uri = writeFile(
56 path, 53 path,
57 r''' 54 r'''
58 main() { 55 main() {
59 var v = 1; 56 var v = 1;
60 } 57 }
61 '''); 58 ''');
62 59
63 // Compute the initial state 60 // Compute the initial state
64 { 61 {
65 Map<Uri, Program> initialState = await getInitialState(uri); 62 Program program = await getInitialState(uri);
66 expect(initialState.keys, unorderedEquals([uri])); 63 Library library = _getLibrary(program, uri);
67
68 Library library = _getLibrary(initialState[uri], uri);
69 expect( 64 expect(
70 _getLibraryText(library), 65 _getLibraryText(library),
71 r''' 66 r'''
72 library; 67 library;
73 import self as self; 68 import self as self;
74 import "dart:core" as core; 69 import "dart:core" as core;
75 70
76 static method main() → dynamic { 71 static method main() → dynamic {
77 core::int v = 1; 72 core::int v = 1;
78 } 73 }
79 '''); 74 ''');
80 } 75 }
81 76
82 // Update the entry point library. 77 // Update the entry point library.
83 writeFile( 78 writeFile(
84 path, 79 path,
85 r''' 80 r'''
86 main() { 81 main() {
87 var v = 2.3; 82 var v = 2.3;
88 } 83 }
89 '''); 84 ''');
90 85
91 // The delta has the updated entry point library. 86 // The delta has the updated entry point library.
92 { 87 {
93 DeltaProgram delta = await incrementalKernelGenerator.computeDelta(); 88 DeltaProgram delta = await incrementalKernelGenerator.computeDelta();
94 expect(delta.newState.keys, unorderedEquals([uri])); 89 Program program = delta.newProgram;
95 90 Library library = _getLibrary(program, uri);
96 Library library = _getLibrary(delta.newState[uri], uri);
97 expect( 91 expect(
98 _getLibraryText(library), 92 _getLibraryText(library),
99 r''' 93 r'''
100 library; 94 library;
101 import self as self; 95 import self as self;
102 import "dart:core" as core; 96 import "dart:core" as core;
103 97
104 static method main() → dynamic { 98 static method main() → dynamic {
105 core::double v = 2.3; 99 core::double v = 2.3;
106 } 100 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 throw fail('No library found with URI "$uri"'); 143 throw fail('No library found with URI "$uri"');
150 } 144 }
151 145
152 String _getLibraryText(Library library) { 146 String _getLibraryText(Library library) {
153 StringBuffer buffer = new StringBuffer(); 147 StringBuffer buffer = new StringBuffer();
154 new Printer(buffer, syntheticNames: new NameSystem()) 148 new Printer(buffer, syntheticNames: new NameSystem())
155 .writeLibraryFile(library); 149 .writeLibraryFile(library);
156 return buffer.toString(); 150 return buffer.toString();
157 } 151 }
158 } 152 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698