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

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

Issue 2846433003: Run closed_world2_test using the normal compiler pipeline. (Closed)
Patch Set: Updated cf. 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 library compiler_helper; 5 library compiler_helper;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import "package:expect/expect.dart"; 8 import "package:expect/expect.dart";
9 9
10 import 'package:compiler/compiler_new.dart'; 10 import 'package:compiler/compiler_new.dart';
11 11
12 import 'package:compiler/src/elements/elements.dart' as lego; 12 import 'package:compiler/src/elements/elements.dart';
13 export 'package:compiler/src/elements/elements.dart'; 13 export 'package:compiler/src/elements/elements.dart';
14 14
15 import 'package:compiler/src/js_backend/js_backend.dart' as js; 15 import 'package:compiler/src/js_backend/js_backend.dart' as js;
16 16
17 import 'package:compiler/src/commandline_options.dart'; 17 import 'package:compiler/src/commandline_options.dart';
18 import 'package:compiler/src/common/codegen.dart'; 18 import 'package:compiler/src/common/codegen.dart';
19 import 'package:compiler/src/common/resolution.dart'; 19 import 'package:compiler/src/common/resolution.dart';
20 20
21 export 'package:compiler/src/diagnostics/messages.dart'; 21 export 'package:compiler/src/diagnostics/messages.dart';
22 export 'package:compiler/src/diagnostics/source_span.dart'; 22 export 'package:compiler/src/diagnostics/source_span.dart';
23 export 'package:compiler/src/diagnostics/spannable.dart'; 23 export 'package:compiler/src/diagnostics/spannable.dart';
24 24
25 import 'package:compiler/src/types/types.dart' as types;
26 export 'package:compiler/src/types/types.dart' show TypeMask; 25 export 'package:compiler/src/types/types.dart' show TypeMask;
27 26
28 import 'package:compiler/src/util/util.dart'; 27 import 'package:compiler/src/util/util.dart';
29 export 'package:compiler/src/util/util.dart'; 28 export 'package:compiler/src/util/util.dart';
30 29
31 import 'package:compiler/src/compiler.dart' show Compiler; 30 import 'package:compiler/src/compiler.dart' show Compiler;
32 31
33 export 'package:compiler/src/tree/tree.dart'; 32 export 'package:compiler/src/tree/tree.dart';
34 33
35 import 'mock_compiler.dart'; 34 import 'mock_compiler.dart';
(...skipping 28 matching lines...) Expand all
64 enableTypeAssertions: enableTypeAssertions, 63 enableTypeAssertions: enableTypeAssertions,
65 // Type inference does not run when manually 64 // Type inference does not run when manually
66 // compiling a method. 65 // compiling a method.
67 disableTypeInference: true, 66 disableTypeInference: true,
68 enableMinification: minify, 67 enableMinification: minify,
69 disableInlining: disableInlining, 68 disableInlining: disableInlining,
70 trustJSInteropTypeAnnotations: trustJSInteropTypeAnnotations, 69 trustJSInteropTypeAnnotations: trustJSInteropTypeAnnotations,
71 outputProvider: outputCollector); 70 outputProvider: outputCollector);
72 await compiler.init(); 71 await compiler.init();
73 compiler.parseScript(code); 72 compiler.parseScript(code);
74 lego.Element element = compiler.mainApp.find(entry); 73 LibraryElement mainApp = compiler.mainApp;
74 MethodElement element = mainApp.find(entry);
75 if (element == null) return null; 75 if (element == null) return null;
76 compiler.phase = Compiler.PHASE_RESOLVING; 76 compiler.phase = Compiler.PHASE_RESOLVING;
77 compiler.processQueue(compiler.enqueuer.resolution, element, 77 compiler.processQueue(compiler.enqueuer.resolution, element,
78 compiler.libraryLoader.libraries); 78 compiler.libraryLoader.libraries);
79 ResolutionWorkItem resolutionWork = 79 ResolutionWorkItem resolutionWork =
80 new ResolutionWorkItem(compiler.resolution, element); 80 new ResolutionWorkItem(compiler.resolution, element);
81 resolutionWork.run(); 81 resolutionWork.run();
82 compiler.closeResolution(); 82 compiler.closeResolution();
83 CodegenWorkItem work = new CodegenWorkItem(compiler.backend, element); 83 CodegenWorkItem work = new CodegenWorkItem(compiler.backend, element);
84 compiler.phase = Compiler.PHASE_COMPILING; 84 compiler.phase = Compiler.PHASE_COMPILING;
(...skipping 29 matching lines...) Expand all
114 } else { 114 } else {
115 source = {'main.dart': code}; 115 source = {'main.dart': code};
116 } 116 }
117 117
118 CompilationResult result = await runCompiler( 118 CompilationResult result = await runCompiler(
119 memorySourceFiles: source, 119 memorySourceFiles: source,
120 options: options, 120 options: options,
121 outputProvider: outputCollector); 121 outputProvider: outputCollector);
122 Expect.isTrue(result.isSuccess); 122 Expect.isTrue(result.isSuccess);
123 Compiler compiler = result.compiler; 123 Compiler compiler = result.compiler;
124 lego.Element element = compiler.mainApp.find(entry); 124 LibraryElement mainApp = compiler.mainApp;
125 Element element = mainApp.find(entry);
125 js.JavaScriptBackend backend = compiler.backend; 126 js.JavaScriptBackend backend = compiler.backend;
126 String generated = backend.getGeneratedCode(element); 127 String generated = backend.getGeneratedCode(element);
127 if (check != null) { 128 if (check != null) {
128 check(generated); 129 check(generated);
129 } 130 }
130 return returnAll ? outputCollector.getOutput('', OutputType.js) : generated; 131 return returnAll ? outputCollector.getOutput('', OutputType.js) : generated;
131 } 132 }
132 } 133 }
133 134
134 Future<String> compileAll(String code, 135 Future<String> compileAll(String code,
(...skipping 16 matching lines...) Expand all
151 compiler.diagnosticHandler = createHandler(compiler, code); 152 compiler.diagnosticHandler = createHandler(compiler, code);
152 return compiler.run(uri).then((compilationSucceded) { 153 return compiler.run(uri).then((compilationSucceded) {
153 Expect.isTrue( 154 Expect.isTrue(
154 compilationSucceded, 155 compilationSucceded,
155 'Unexpected compilation error(s): ' 156 'Unexpected compilation error(s): '
156 '${compiler.diagnosticCollector.errors}'); 157 '${compiler.diagnosticCollector.errors}');
157 return outputCollector.getOutput('', OutputType.js); 158 return outputCollector.getOutput('', OutputType.js);
158 }); 159 });
159 } 160 }
160 161
161 Future analyzeAndCheck(String code, String name, 162 Future analyzeAndCheck(
162 check(MockCompiler compiler, lego.Element element), 163 String code, String name, check(MockCompiler compiler, Element element),
163 {int expectedErrors, int expectedWarnings}) { 164 {int expectedErrors, int expectedWarnings}) {
164 Uri uri = new Uri(scheme: 'source'); 165 Uri uri = new Uri(scheme: 'source');
165 MockCompiler compiler = compilerFor(code, uri, 166 MockCompiler compiler = compilerFor(code, uri,
166 expectedErrors: expectedErrors, 167 expectedErrors: expectedErrors,
167 expectedWarnings: expectedWarnings, 168 expectedWarnings: expectedWarnings,
168 analyzeOnly: true); 169 analyzeOnly: true);
169 return compiler.run(uri).then((_) { 170 return compiler.run(uri).then((_) {
170 lego.Element element = findElement(compiler, name); 171 Element element = findElement(compiler, name);
171 return check(compiler, element); 172 return check(compiler, element);
172 }); 173 });
173 } 174 }
174 175
175 Future compileSources( 176 Future compileSources(
176 Map<String, String> sources, check(MockCompiler compiler)) { 177 Map<String, String> sources, check(MockCompiler compiler)) {
177 Uri base = new Uri(scheme: 'source', path: '/'); 178 Uri base = new Uri(scheme: 'source', path: '/');
178 Uri mainUri = base.resolve('main.dart'); 179 Uri mainUri = base.resolve('main.dart');
179 String mainCode = sources['main.dart']; 180 String mainCode = sources['main.dart'];
180 Expect.isNotNull(mainCode, 'No source code found for "main.dart"'); 181 Expect.isNotNull(mainCode, 'No source code found for "main.dart"');
181 MockCompiler compiler = compilerFor(mainCode, mainUri); 182 MockCompiler compiler = compilerFor(mainCode, mainUri);
182 sources.forEach((String path, String code) { 183 sources.forEach((String path, String code) {
183 if (path == 'main.dart') return; 184 if (path == 'main.dart') return;
184 compiler.registerSource(base.resolve(path), code); 185 compiler.registerSource(base.resolve(path), code);
185 }); 186 });
186 187
187 return compiler.run(mainUri).then((_) { 188 return compiler.run(mainUri).then((_) {
188 return check(compiler); 189 return check(compiler);
189 }); 190 });
190 } 191 }
191 192
192 lego.Element findElement(compiler, String name, [Uri library]) { 193 Element findElement(compiler, String name, [Uri library]) {
193 lego.LibraryElement lib = compiler.mainApp; 194 LibraryElement lib = compiler.mainApp;
194 if (library != null) { 195 if (library != null) {
195 lib = compiler.libraryLoader.lookupLibrary(library); 196 lib = compiler.libraryLoader.lookupLibrary(library);
196 Expect.isNotNull(lib, 'Could not locate library $library.'); 197 Expect.isNotNull(lib, 'Could not locate library $library.');
197 } 198 }
198 var element = lib.find(name); 199 var element = lib.find(name);
199 Expect.isNotNull(element, 'Could not locate $name.'); 200 Expect.isNotNull(element, 'Could not locate $name.');
200 return element; 201 return element;
201 } 202 }
202 203
203 String anyIdentifier = "[a-zA-Z][a-zA-Z0-9]*"; 204 String anyIdentifier = "[a-zA-Z][a-zA-Z0-9]*";
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 } 293 }
293 } 294 }
294 295
295 return checker; 296 return checker;
296 } 297 }
297 298
298 RegExp _directivePattern = new RegExp( 299 RegExp _directivePattern = new RegExp(
299 // \1 \2 \3 300 // \1 \2 \3
300 r'''// *(present|absent): *(?:"([^"]*)"|'([^'']*)')''', 301 r'''// *(present|absent): *(?:"([^"]*)"|'([^'']*)')''',
301 multiLine: true); 302 multiLine: true);
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/assert_message_throw_test.dart ('k') | tests/compiler/dart2js/compiler_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698