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

Side by Side Diff: pkg/dev_compiler/test/codegen_test.dart

Issue 2757753002: Migrate DDC to the new analysis driver.
Patch Set: Rebase Created 3 years, 6 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 /// Tests code generation. 5 /// Tests code generation.
6 /// 6 ///
7 /// Runs Dart Dev Compiler on all input in the `codegen` directory and checks 7 /// Runs Dart Dev Compiler on all input in the `codegen` directory and checks
8 /// that the output is what we expected. 8 /// that the output is what we expected.
9 library dev_compiler.test.codegen_test; 9 library dev_compiler.test.codegen_test;
10 10
11 // TODO(rnystrom): This doesn't actually run any tests any more. It just 11 // TODO(rnystrom): This doesn't actually run any tests any more. It just
12 // compiles stuff. This should be changed to not use unittest and just be a 12 // compiles stuff. This should be changed to not use unittest and just be a
13 // regular program that outputs files. 13 // regular program that outputs files.
14 14
15 import 'dart:async';
15 import 'dart:io' show Directory, File, Platform; 16 import 'dart:io' show Directory, File, Platform;
16 import 'package:analyzer/analyzer.dart' 17 import 'package:analyzer/analyzer.dart'
17 show 18 show
18 ExportDirective, 19 ExportDirective,
19 ImportDirective, 20 ImportDirective,
20 StringLiteral, 21 StringLiteral,
21 UriBasedDirective, 22 UriBasedDirective,
22 parseDirectives; 23 parseDirectives;
23 import 'package:analyzer/src/command_line/arguments.dart' 24 import 'package:analyzer/src/command_line/arguments.dart'
24 show defineAnalysisArguments; 25 show defineAnalysisArguments;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 121
121 // Compile each test file to JS and put the result in gen/codegen_output. 122 // Compile each test file to JS and put the result in gen/codegen_output.
122 for (var testFile in testFiles) { 123 for (var testFile in testFiles) {
123 var relativePath = path.relative(testFile, from: codegenTestDir); 124 var relativePath = path.relative(testFile, from: codegenTestDir);
124 125
125 // Only compile the top-level files for generating coverage. 126 // Only compile the top-level files for generating coverage.
126 bool isTopLevelTest = path.dirname(relativePath) == "."; 127 bool isTopLevelTest = path.dirname(relativePath) == ".";
127 if (codeCoverage && !isTopLevelTest) continue; 128 if (codeCoverage && !isTopLevelTest) continue;
128 129
129 var name = path.withoutExtension(relativePath); 130 var name = path.withoutExtension(relativePath);
130 test('dartdevc $name', () { 131 test('dartdevc $name', () async {
131 // Check if we need to use special compile options. 132 // Check if we need to use special compile options.
132 var contents = new File(testFile).readAsStringSync(); 133 var contents = new File(testFile).readAsStringSync();
133 var match = testFileOptionsMatcher.firstMatch(contents); 134 var match = testFileOptionsMatcher.firstMatch(contents);
134 135
135 var args = defaultOptions.toList(); 136 var args = defaultOptions.toList();
136 if (match != null) { 137 if (match != null) {
137 var matchedArgs = match.group(2).split(' '); 138 var matchedArgs = match.group(2).split(' ');
138 args.addAll(matchedArgs.where((s) => !ignoreOptions.contains(s))); 139 args.addAll(matchedArgs.where((s) => !ignoreOptions.contains(s)));
139 } 140 }
140 141
(...skipping 11 matching lines...) Expand all
152 var unit = new BuildUnit( 153 var unit = new BuildUnit(
153 name, path.dirname(testFile), files.toList(), _moduleForLibrary); 154 name, path.dirname(testFile), files.toList(), _moduleForLibrary);
154 155
155 var compiler = sharedCompiler; 156 var compiler = sharedCompiler;
156 if (analyzerOptions.declaredVariables.isNotEmpty) { 157 if (analyzerOptions.declaredVariables.isNotEmpty) {
157 compiler = new ModuleCompiler(analyzerOptions); 158 compiler = new ModuleCompiler(analyzerOptions);
158 } 159 }
159 JSModuleFile module = null; 160 JSModuleFile module = null;
160 var exception, stackTrace; 161 var exception, stackTrace;
161 try { 162 try {
162 module = compiler.compile(unit, options); 163 module = await compiler.compile(unit, options);
163 } catch (e, st) { 164 } catch (e, st) {
164 exception = e; 165 exception = e;
165 stackTrace = st; 166 stackTrace = st;
166 } 167 }
167 168
168 bool expectedCompileTimeError = contents.contains(': compile-time error'); 169 bool expectedCompileTimeError = contents.contains(': compile-time error');
169 bool notStrong = notYetStrongTests.contains(name); 170 bool notStrong = notYetStrongTests.contains(name);
170 bool crashing = _crashingTests.contains(name); 171 bool crashing = _crashingTests.contains(name);
171 bool inconsistent = _inconsistentTests.contains(name); 172 bool inconsistent = _inconsistentTests.contains(name);
172 173
(...skipping 24 matching lines...) Expand all
197 ? "expected" 198 ? "expected"
198 : inconsistent ? "platform consistency" : "untriaged strong mode"; 199 : inconsistent ? "platform consistency" : "untriaged strong mode";
199 expect(expectedCompileTimeError || inconsistent || notStrong, isTrue, 200 expect(expectedCompileTimeError || inconsistent || notStrong, isTrue,
200 reason: "test $name failed to compile due to $reason errors:" 201 reason: "test $name failed to compile due to $reason errors:"
201 "\n\n${module.errors.join('\n')}."); 202 "\n\n${module.errors.join('\n')}.");
202 } 203 }
203 }); 204 });
204 } 205 }
205 206
206 if (filePattern.hasMatch('sunflower')) { 207 if (filePattern.hasMatch('sunflower')) {
207 test('sunflower', () { 208 test('sunflower', () async {
208 _buildSunflower(sharedCompiler, codegenOutputDir, codegenExpectDir); 209 await _buildSunflower(sharedCompiler, codegenOutputDir, codegenExpectDir);
209 }); 210 });
210 } 211 }
211 212
212 if (codeCoverage) { 213 if (codeCoverage) {
213 test('build_sdk code coverage', () { 214 test('build_sdk code coverage', () {
214 return build_sdk.main(['--dart-sdk', sdkDir, '-o', codegenOutputDir]); 215 return build_sdk.main(['--dart-sdk', sdkDir, '-o', codegenOutputDir]);
215 }); 216 });
216 } 217 }
217 } 218 }
218 219
(...skipping 19 matching lines...) Expand all
238 239
239 var expectFile = new File(expectPath + '.js'); 240 var expectFile = new File(expectPath + '.js');
240 if (result.isValid) { 241 if (result.isValid) {
241 result.writeCodeSync(format, expectFile.path); 242 result.writeCodeSync(format, expectFile.path);
242 } else { 243 } else {
243 expectFile.writeAsStringSync("//FAILED TO COMPILE"); 244 expectFile.writeAsStringSync("//FAILED TO COMPILE");
244 } 245 }
245 } 246 }
246 } 247 }
247 248
248 void _buildSunflower( 249 Future<Null> _buildSunflower(
249 ModuleCompiler compiler, String outputDir, String expectDir) { 250 ModuleCompiler compiler, String outputDir, String expectDir) async {
250 var baseDir = path.join(codegenDir, 'sunflower'); 251 var baseDir = path.join(codegenDir, 'sunflower');
251 var files = ['sunflower', 'circle', 'painter'] 252 var files = ['sunflower', 'circle', 'painter']
252 .map((f) => path.join(baseDir, '$f.dart')) 253 .map((f) => path.join(baseDir, '$f.dart'))
253 .toList(); 254 .toList();
254 var input = new BuildUnit('sunflower', baseDir, files, _moduleForLibrary); 255 var input = new BuildUnit('sunflower', baseDir, files, _moduleForLibrary);
255 var options = new CompilerOptions(summarizeApi: false); 256 var options = new CompilerOptions(summarizeApi: false);
256 257
257 var built = compiler.compile(input, options); 258 var built = await compiler.compile(input, options);
258 _writeModule(path.join(outputDir, 'sunflower', 'sunflower'), 259 _writeModule(path.join(outputDir, 'sunflower', 'sunflower'),
259 path.join(expectDir, 'sunflower', 'sunflower'), ModuleFormat.amd, built); 260 path.join(expectDir, 'sunflower', 'sunflower'), ModuleFormat.amd, built);
260 } 261 }
261 262
262 String _moduleForLibrary(Source source) { 263 String _moduleForLibrary(Source source) {
263 var scheme = source.uri.scheme; 264 var scheme = source.uri.scheme;
264 if (scheme == 'package') { 265 if (scheme == 'package') {
265 return source.uri.pathSegments.first; 266 return source.uri.pathSegments.first;
266 } 267 }
267 throw new Exception('Module not found for library "${source.fullName}"'); 268 throw new Exception('Module not found for library "${source.fullName}"');
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 final _crashingTests = new Set<String>.from([ 403 final _crashingTests = new Set<String>.from([
403 // TODO(vsm): Fix these - they import files from a different directory 404 // TODO(vsm): Fix these - they import files from a different directory
404 // - this triggers an invalid library root build error. 405 // - this triggers an invalid library root build error.
405 'lib/html/custom/attribute_changed_callback_test', 406 'lib/html/custom/attribute_changed_callback_test',
406 'lib/html/custom/constructor_calls_created_synchronously_test', 407 'lib/html/custom/constructor_calls_created_synchronously_test',
407 'lib/html/custom/entered_left_view_test', 408 'lib/html/custom/entered_left_view_test',
408 'lib/html/custom/js_custom_test', 409 'lib/html/custom/js_custom_test',
409 'lib/html/custom/mirrors_test', 410 'lib/html/custom/mirrors_test',
410 'lib/html/custom/regress_194523002_test', 411 'lib/html/custom/regress_194523002_test',
411 ].map((p) => p.replaceAll('/', path.separator))); 412 ].map((p) => p.replaceAll('/', path.separator)));
OLDNEW
« no previous file with comments | « pkg/dev_compiler/lib/src/compiler/side_effect_analysis.dart ('k') | pkg/dev_compiler/test/not_yet_strong_tests.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698