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

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

Issue 1235563003: Add interfaces for a new compiler API. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Rebased Created 5 years, 5 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 // Test that the additional runtime type support is output to the right 5 // Test that the additional runtime type support is output to the right
6 // Files when using deferred loading. 6 // Files when using deferred loading.
7 7
8 import 'package:async_helper/async_helper.dart';
9 import 'package:compiler/src/dart2jslib.dart';
8 import 'package:expect/expect.dart'; 10 import 'package:expect/expect.dart';
9 import "package:async_helper/async_helper.dart"; 11 import 'memory_compiler.dart';
10 import 'memory_source_file_helper.dart'; 12 import 'output_collector.dart';
11 import "dart:async";
12
13 import 'package:compiler/src/dart2jslib.dart'
14 as dart2js;
15
16 class MemoryOutputSink extends EventSink<String> {
17 StringBuffer mem = new StringBuffer();
18 void add(String event) {
19 mem.write(event);
20 }
21 void addError(String event, [StackTrace stackTrace]) {
22 Expect.isTrue(false);
23 }
24 void close() {}
25 }
26 13
27 void main() { 14 void main() {
28 Uri script = currentDirectory.resolveUri(Platform.script); 15 OutputCollector collector = new OutputCollector();
29 Uri libraryRoot = script.resolve('../../../sdk/'); 16 Compiler compiler = compilerFor(
30 Uri packageRoot = script.resolve('./packages/'); 17 MEMORY_SOURCE_FILES,
31 18 outputProvider: collector);
32 var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES);
33 var handler = new FormattingDiagnosticHandler(provider);
34
35 Map<String, MemoryOutputSink> outputs = new Map<String, MemoryOutputSink>();
36
37 MemoryOutputSink outputSaver(name, extension) {
38 if (name == '') {
39 name = 'main';
40 }
41 return outputs.putIfAbsent("$name.$extension", () {
42 return new MemoryOutputSink();
43 });
44 }
45
46 Compiler compiler = new Compiler(provider.readStringFromUri,
47 outputSaver,
48 handler.diagnosticHandler,
49 libraryRoot,
50 packageRoot,
51 [],
52 {});
53 asyncTest(() => compiler.run(Uri.parse('memory:main.dart')).then((_) { 19 asyncTest(() => compiler.run(Uri.parse('memory:main.dart')).then((_) {
54 lookupLibrary(name) { 20 lookupLibrary(name) {
55 return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); 21 return compiler.libraryLoader.lookupLibrary(Uri.parse(name));
56 } 22 }
57 23
58 var main = compiler.mainApp.find(dart2js.Compiler.MAIN); 24 var main = compiler.mainApp.find(Compiler.MAIN);
59 Expect.isNotNull(main, "Could not find 'main'"); 25 Expect.isNotNull(main, "Could not find 'main'");
60 compiler.deferredLoadTask.onResolutionComplete(main); 26 compiler.deferredLoadTask.onResolutionComplete(main);
61 27
62 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; 28 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement;
63 29
64 var lib1 = lookupLibrary("memory:lib1.dart"); 30 var lib1 = lookupLibrary("memory:lib1.dart");
65 var foo1 = lib1.find("foo"); 31 var foo1 = lib1.find("foo");
66 var ou_lib1 = outputUnitForElement(foo1); 32 var ou_lib1 = outputUnitForElement(foo1);
67 33
68 var lib2 = lookupLibrary("memory:lib2.dart"); 34 var lib2 = lookupLibrary("memory:lib2.dart");
69 var foo2 = lib2.find("foo"); 35 var foo2 = lib2.find("foo");
70 var ou_lib2 = outputUnitForElement(foo2); 36 var ou_lib2 = outputUnitForElement(foo2);
71 37
72 var fooMain = compiler.mainApp.find("foo"); 38 var fooMain = compiler.mainApp.find("foo");
73 var ou_lib1_lib2 = outputUnitForElement(fooMain); 39 var ou_lib1_lib2 = outputUnitForElement(fooMain);
74 40
75 String mainOutput = outputs["main.js"].mem.toString(); 41 String mainOutput = collector.getOutput("","js");
76 String lib1Output = outputs["out_${ou_lib1.name}.part.js"].mem.toString(); 42 String lib1Output = collector.getOutput("out_${ou_lib1.name}", "part.js");
77 String lib2Output = outputs["out_${ou_lib2.name}.part.js"].mem.toString(); 43 String lib2Output = collector.getOutput("out_${ou_lib2.name}", "part.js");
78 String lib12Output = 44 String lib12Output =
79 outputs["out_${ou_lib1_lib2.name}.part.js"].mem.toString(); 45 collector.getOutput("out_${ou_lib1_lib2.name}", "part.js");
80 // Test that the deferred constants are not inlined into the main file. 46 // Test that the deferred constants are not inlined into the main file.
81 RegExp re1 = new RegExp(r"= .string1"); 47 RegExp re1 = new RegExp(r"= .string1");
82 RegExp re2 = new RegExp(r"= .string2"); 48 RegExp re2 = new RegExp(r"= .string2");
83 RegExp re3 = new RegExp(r"= 1010"); 49 RegExp re3 = new RegExp(r"= 1010");
84 Expect.isTrue(re1.hasMatch(lib1Output)); 50 Expect.isTrue(re1.hasMatch(lib1Output));
85 Expect.isTrue(re2.hasMatch(lib1Output)); 51 Expect.isTrue(re2.hasMatch(lib1Output));
86 Expect.isTrue(re3.hasMatch(lib1Output)); 52 Expect.isTrue(re3.hasMatch(lib1Output));
87 Expect.isFalse(re1.hasMatch(mainOutput)); 53 Expect.isFalse(re1.hasMatch(mainOutput));
88 Expect.isFalse(re2.hasMatch(mainOutput)); 54 Expect.isFalse(re2.hasMatch(mainOutput));
89 Expect.isFalse(re3.hasMatch(mainOutput)); 55 Expect.isFalse(re3.hasMatch(mainOutput));
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 """, "lib2.dart": """ 134 """, "lib2.dart": """
169 import "main.dart" as main; 135 import "main.dart" as main;
170 const C4 = "string4"; 136 const C4 = "string4";
171 const C5 = const main.C(1); 137 const C5 = const main.C(1);
172 const C6 = const main.C(2); 138 const C6 = const main.C(2);
173 foo() { 139 foo() {
174 print("lib2"); 140 print("lib2");
175 main.foo(); 141 main.foo();
176 } 142 }
177 """}; 143 """};
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698