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

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

Issue 2638423002: Fix incremental kernel builder to handle multiple calls to computeDelta. (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « pkg/front_end/test/incremental_kernel_generator_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
8 import 'package:analyzer/file_system/physical_file_system.dart'; 9 import 'package:analyzer/file_system/physical_file_system.dart';
9 import 'package:analyzer/src/dart/sdk/sdk.dart'; 10 import 'package:analyzer/src/dart/sdk/sdk.dart';
10 import 'package:front_end/compiler_options.dart'; 11 import 'package:front_end/compiler_options.dart';
11 import 'package:front_end/incremental_resolved_ast_generator.dart'; 12 import 'package:front_end/incremental_resolved_ast_generator.dart';
12 import 'package:front_end/memory_file_system.dart'; 13 import 'package:front_end/memory_file_system.dart';
13 import 'package:path/path.dart' as pathos; 14 import 'package:path/path.dart' as pathos;
14 import 'package:test/test.dart'; 15 import 'package:test/test.dart';
15 import 'package:test_reflective_loader/test_reflective_loader.dart'; 16 import 'package:test_reflective_loader/test_reflective_loader.dart';
16 17
17 main() { 18 main() {
(...skipping 29 matching lines...) Expand all
47 incrementalResolvedAstGenerator = new IncrementalResolvedAstGenerator( 48 incrementalResolvedAstGenerator = new IncrementalResolvedAstGenerator(
48 startingUri, 49 startingUri,
49 new CompilerOptions() 50 new CompilerOptions()
50 ..fileSystem = fileSystem 51 ..fileSystem = fileSystem
51 ..chaseDependencies = true 52 ..chaseDependencies = true
52 ..sdkSummary = sdkSummaryUri 53 ..sdkSummary = sdkSummaryUri
53 ..packagesFileUri = new Uri()); 54 ..packagesFileUri = new Uri());
54 return (await incrementalResolvedAstGenerator.computeDelta()).newState; 55 return (await incrementalResolvedAstGenerator.computeDelta()).newState;
55 } 56 }
56 57
57 test_emptyProgram() async { 58 test_incrementalUpdate_referenceToCore() async {
58 writeFiles({'/foo.dart': 'main() {}'}); 59 // TODO(paulberry): test parts.
60 writeFiles({'/foo.dart': 'main() { print(1); }'});
59 var fooUri = Uri.parse('file:///foo.dart'); 61 var fooUri = Uri.parse('file:///foo.dart');
60 var initialProgram = await getInitialProgram(fooUri); 62 var initialProgram = await getInitialProgram(fooUri);
61 expect(initialProgram.keys, unorderedEquals([fooUri])); 63 expect(initialProgram.keys, unorderedEquals([fooUri]));
62 var unit = initialProgram[fooUri].definingCompilationUnit; 64 void _checkMain(CompilationUnit unit, int expectedArgument) {
danrubel 2017/01/18 20:47:36 nit: blank line before inner method helps readabil
Paul Berry 2017/01/18 22:36:31 Done.
63 expect(unit.declarations, hasLength(1)); 65 expect(unit.declarations, hasLength(1));
64 expect(unit.declarations[0], new isInstanceOf<FunctionDeclaration>()); 66 expect(unit.declarations[0], new isInstanceOf<FunctionDeclaration>());
65 var main = unit.declarations[0] as FunctionDeclaration; 67 var main = unit.declarations[0] as FunctionDeclaration;
66 expect(main.name.name, 'main'); 68 expect(main.name.name, 'main');
67 // TODO(paulberry): test that stuff is actually resolved. 69 expect(
68 // TODO(paulberry): test parts. 70 main.functionExpression.body, new isInstanceOf<BlockFunctionBody>());
71 var blockFunctionBody = main.functionExpression.body as BlockFunctionBody;
72 expect(blockFunctionBody.block.statements, hasLength(1));
73 expect(blockFunctionBody.block.statements[0],
74 new isInstanceOf<ExpressionStatement>());
75 var expressionStatement =
76 blockFunctionBody.block.statements[0] as ExpressionStatement;
77 expect(
78 expressionStatement.expression, new isInstanceOf<MethodInvocation>());
79 var methodInvocation = expressionStatement.expression as MethodInvocation;
80 expect(methodInvocation.methodName.name, 'print');
81 var printElement =
82 resolutionMap.staticElementForIdentifier(methodInvocation.methodName);
83 expect(printElement, isNotNull);
84 expect(printElement.library.source.uri, Uri.parse('dart:core'));
85 expect(methodInvocation.argumentList.arguments, hasLength(1));
86 expect(methodInvocation.argumentList.arguments[0],
87 new isInstanceOf<IntegerLiteral>());
88 var integerLiteral =
89 methodInvocation.argumentList.arguments[0] as IntegerLiteral;
90 expect(integerLiteral.value, expectedArgument);
91 }
92
93 _checkMain(initialProgram[fooUri].definingCompilationUnit, 1);
94 writeFiles({'/foo.dart': 'main() { print(2); }'});
95 // TODO(paulberry): verify that the file isn't actually reread until
96 // invalidate is called.
97 // var deltaProgram1 = await incrementalResolvedAstGenerator.computeDelta();
98 // expect(deltaProgram1.newState, isEmpty);
99 incrementalResolvedAstGenerator.invalidateAll();
100 var deltaProgram2 = await incrementalResolvedAstGenerator.computeDelta();
101 expect(deltaProgram2.newState.keys, unorderedEquals([fooUri]));
102 _checkMain(deltaProgram2.newState[fooUri].definingCompilationUnit, 2);
103 }
104
105 test_invalidateAllBeforeInitialProgram() async {
106 incrementalResolvedAstGenerator = new IncrementalResolvedAstGenerator(
107 Uri.parse('file:///foo.dart'),
108 new CompilerOptions()
109 ..fileSystem = fileSystem
110 ..chaseDependencies = true
111 ..packagesFileUri = new Uri());
112 incrementalResolvedAstGenerator.invalidateAll();
69 } 113 }
70 114
71 /// Write the given file contents to the virtual filesystem. 115 /// Write the given file contents to the virtual filesystem.
72 void writeFiles(Map<String, String> contents) { 116 void writeFiles(Map<String, String> contents) {
73 contents.forEach((path, text) { 117 contents.forEach((path, text) {
74 fileSystem 118 fileSystem
75 .entityForUri(Uri.parse('file://$path')) 119 .entityForUri(Uri.parse('file://$path'))
76 .writeAsStringSync(text); 120 .writeAsStringSync(text);
77 }); 121 });
78 } 122 }
79 } 123 }
OLDNEW
« no previous file with comments | « pkg/front_end/test/incremental_kernel_generator_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698