OLD | NEW |
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 120 |
120 // Compile each test file to JS and put the result in gen/codegen_output. | 121 // Compile each test file to JS and put the result in gen/codegen_output. |
121 for (var testFile in testFiles) { | 122 for (var testFile in testFiles) { |
122 var relativePath = path.relative(testFile, from: codegenTestDir); | 123 var relativePath = path.relative(testFile, from: codegenTestDir); |
123 | 124 |
124 // Only compile the top-level files for generating coverage. | 125 // Only compile the top-level files for generating coverage. |
125 bool isTopLevelTest = path.dirname(relativePath) == "."; | 126 bool isTopLevelTest = path.dirname(relativePath) == "."; |
126 if (codeCoverage && !isTopLevelTest) continue; | 127 if (codeCoverage && !isTopLevelTest) continue; |
127 | 128 |
128 var name = path.withoutExtension(relativePath); | 129 var name = path.withoutExtension(relativePath); |
129 test('dartdevc $name', () { | 130 test('dartdevc $name', () async { |
130 // Check if we need to use special compile options. | 131 // Check if we need to use special compile options. |
131 var contents = new File(testFile).readAsStringSync(); | 132 var contents = new File(testFile).readAsStringSync(); |
132 var match = testFileOptionsMatcher.firstMatch(contents); | 133 var match = testFileOptionsMatcher.firstMatch(contents); |
133 | 134 |
134 var args = defaultOptions.toList(); | 135 var args = defaultOptions.toList(); |
135 if (match != null) { | 136 if (match != null) { |
136 var matchedArgs = match.group(2).split(' '); | 137 var matchedArgs = match.group(2).split(' '); |
137 args.addAll(matchedArgs.where((s) => !ignoreOptions.contains(s))); | 138 args.addAll(matchedArgs.where((s) => !ignoreOptions.contains(s))); |
138 } | 139 } |
139 | 140 |
(...skipping 11 matching lines...) Expand all Loading... |
151 var unit = new BuildUnit( | 152 var unit = new BuildUnit( |
152 name, path.dirname(testFile), files.toList(), _moduleForLibrary); | 153 name, path.dirname(testFile), files.toList(), _moduleForLibrary); |
153 | 154 |
154 var compiler = sharedCompiler; | 155 var compiler = sharedCompiler; |
155 if (analyzerOptions.declaredVariables.isNotEmpty) { | 156 if (analyzerOptions.declaredVariables.isNotEmpty) { |
156 compiler = new ModuleCompiler(analyzerOptions); | 157 compiler = new ModuleCompiler(analyzerOptions); |
157 } | 158 } |
158 JSModuleFile module = null; | 159 JSModuleFile module = null; |
159 var error, trace; | 160 var error, trace; |
160 try { | 161 try { |
161 module = compiler.compile(unit, options); | 162 module = await compiler.compile(unit, options); |
162 } catch (e, t) { | 163 } catch (e, t) { |
163 error = e; | 164 error = e; |
164 trace = t; | 165 trace = t; |
165 } | 166 } |
166 | 167 |
167 bool expectedCompileTimeError = | 168 bool expectedCompileTimeError = |
168 contents.contains(': compile-time error\n'); | 169 contents.contains(': compile-time error\n'); |
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 | 172 |
(...skipping 19 matching lines...) Expand all Loading... |
191 var reason = | 192 var reason = |
192 expectedCompileTimeError ? "expected" : "untriaged strong mode"; | 193 expectedCompileTimeError ? "expected" : "untriaged strong mode"; |
193 expect(expectedCompileTimeError || notStrong, isTrue, | 194 expect(expectedCompileTimeError || notStrong, isTrue, |
194 reason: "test $name failed to compile due to $reason errors:" | 195 reason: "test $name failed to compile due to $reason errors:" |
195 "\n\n${module.errors.join('\n')}."); | 196 "\n\n${module.errors.join('\n')}."); |
196 } | 197 } |
197 }); | 198 }); |
198 } | 199 } |
199 | 200 |
200 if (filePattern.hasMatch('sunflower')) { | 201 if (filePattern.hasMatch('sunflower')) { |
201 test('sunflower', () { | 202 test('sunflower', () async { |
202 _buildSunflower(sharedCompiler, codegenOutputDir, codegenExpectDir); | 203 await _buildSunflower(sharedCompiler, codegenOutputDir, codegenExpectDir); |
203 }); | 204 }); |
204 } | 205 } |
205 | 206 |
206 if (codeCoverage) { | 207 if (codeCoverage) { |
207 test('build_sdk code coverage', () { | 208 test('build_sdk code coverage', () { |
208 return build_sdk.main(['--dart-sdk', sdkDir, '-o', codegenOutputDir]); | 209 return build_sdk.main(['--dart-sdk', sdkDir, '-o', codegenOutputDir]); |
209 }); | 210 }); |
210 } | 211 } |
211 } | 212 } |
212 | 213 |
(...skipping 19 matching lines...) Expand all Loading... |
232 | 233 |
233 var expectFile = new File(expectPath + '.js'); | 234 var expectFile = new File(expectPath + '.js'); |
234 if (result.isValid) { | 235 if (result.isValid) { |
235 result.writeCodeSync(format, expectFile.path); | 236 result.writeCodeSync(format, expectFile.path); |
236 } else { | 237 } else { |
237 expectFile.writeAsStringSync("//FAILED TO COMPILE"); | 238 expectFile.writeAsStringSync("//FAILED TO COMPILE"); |
238 } | 239 } |
239 } | 240 } |
240 } | 241 } |
241 | 242 |
242 void _buildSunflower( | 243 Future<Null> _buildSunflower( |
243 ModuleCompiler compiler, String outputDir, String expectDir) { | 244 ModuleCompiler compiler, String outputDir, String expectDir) async { |
244 var baseDir = path.join(codegenDir, 'sunflower'); | 245 var baseDir = path.join(codegenDir, 'sunflower'); |
245 var files = ['sunflower', 'circle', 'painter'] | 246 var files = ['sunflower', 'circle', 'painter'] |
246 .map((f) => path.join(baseDir, '$f.dart')) | 247 .map((f) => path.join(baseDir, '$f.dart')) |
247 .toList(); | 248 .toList(); |
248 var input = new BuildUnit('sunflower', baseDir, files, _moduleForLibrary); | 249 var input = new BuildUnit('sunflower', baseDir, files, _moduleForLibrary); |
249 var options = new CompilerOptions(summarizeApi: false); | 250 var options = new CompilerOptions(summarizeApi: false); |
250 | 251 |
251 var built = compiler.compile(input, options); | 252 var built = await compiler.compile(input, options); |
252 _writeModule(path.join(outputDir, 'sunflower', 'sunflower'), | 253 _writeModule(path.join(outputDir, 'sunflower', 'sunflower'), |
253 path.join(expectDir, 'sunflower', 'sunflower'), ModuleFormat.amd, built); | 254 path.join(expectDir, 'sunflower', 'sunflower'), ModuleFormat.amd, built); |
254 } | 255 } |
255 | 256 |
256 String _moduleForLibrary(Source source) { | 257 String _moduleForLibrary(Source source) { |
257 var scheme = source.uri.scheme; | 258 var scheme = source.uri.scheme; |
258 if (scheme == 'package') { | 259 if (scheme == 'package') { |
259 return source.uri.pathSegments.first; | 260 return source.uri.pathSegments.first; |
260 } | 261 } |
261 throw new Exception('Module not found for library "${source.fullName}"'); | 262 throw new Exception('Module not found for library "${source.fullName}"'); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 | 410 |
410 // TODO(vsm): Fix these - they import files from a different directory | 411 // TODO(vsm): Fix these - they import files from a different directory |
411 // - this triggers an invalid library root build error. | 412 // - this triggers an invalid library root build error. |
412 'lib/html/custom/attribute_changed_callback_test', | 413 'lib/html/custom/attribute_changed_callback_test', |
413 'lib/html/custom/constructor_calls_created_synchronously_test', | 414 'lib/html/custom/constructor_calls_created_synchronously_test', |
414 'lib/html/custom/entered_left_view_test', | 415 'lib/html/custom/entered_left_view_test', |
415 'lib/html/custom/js_custom_test', | 416 'lib/html/custom/js_custom_test', |
416 'lib/html/custom/mirrors_test', | 417 'lib/html/custom/mirrors_test', |
417 'lib/html/custom/regress_194523002_test', | 418 'lib/html/custom/regress_194523002_test', |
418 ]); | 419 ]); |
OLD | NEW |