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 /// Runs Dart Dev Compiler on all input in the `codegen` directory and checks | 6 /// Runs Dart Dev Compiler on all input in the `codegen` directory and checks |
7 /// that the output is what we expected. | 7 /// that the output is what we expected. |
8 library dev_compiler.test.codegen_test; | 8 library dev_compiler.test.codegen_test; |
9 | 9 |
10 import 'dart:convert' show JSON; | 10 import 'dart:convert' show JSON; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 var generatedSdkDir = | 114 var generatedSdkDir = |
115 path.join(testDirectory, '..', 'tool', 'generated_sdk'); | 115 path.join(testDirectory, '..', 'tool', 'generated_sdk'); |
116 return build_sdk.main(['--dart-sdk', generatedSdkDir, '-o', expectDir]); | 116 return build_sdk.main(['--dart-sdk', generatedSdkDir, '-o', expectDir]); |
117 }); | 117 }); |
118 } | 118 } |
119 } | 119 } |
120 | 120 |
121 void _writeModule(String outPath, JSModuleFile result) { | 121 void _writeModule(String outPath, JSModuleFile result) { |
122 new Directory(path.dirname(outPath)).createSync(recursive: true); | 122 new Directory(path.dirname(outPath)).createSync(recursive: true); |
123 | 123 |
124 result.errors.add(''); // for trailing newline | 124 String errors = result.errors.join('\n'); |
125 new File(outPath + '.txt').writeAsStringSync(result.errors.join('\n')); | 125 if (errors.isNotEmpty && !errors.endsWith('\n')) errors += '\n'; |
| 126 new File(outPath + '.txt').writeAsStringSync(errors); |
126 | 127 |
127 if (result.isValid) { | 128 if (result.isValid) { |
128 new File(outPath + '.js').writeAsStringSync(result.code); | 129 new File(outPath + '.js').writeAsStringSync(result.code); |
129 if (result.sourceMap != null) { | 130 if (result.sourceMap != null) { |
130 var mapPath = outPath + '.js.map'; | 131 var mapPath = outPath + '.js.map'; |
131 new File(mapPath) | 132 new File(mapPath) |
132 .writeAsStringSync(JSON.encode(result.placeSourceMap(mapPath))); | 133 .writeAsStringSync(JSON.encode(result.placeSourceMap(mapPath))); |
133 } | 134 } |
| 135 } else { |
| 136 // Also write the errors to a '.err' file for easy counting. |
| 137 new File(outPath + '.err').writeAsStringSync(errors); |
134 } | 138 } |
135 } | 139 } |
136 | 140 |
137 void _buildSunflower(ModuleCompiler compiler, String expectDir) { | 141 void _buildSunflower(ModuleCompiler compiler, String expectDir) { |
138 var baseDir = path.join(inputDir, 'sunflower'); | 142 var baseDir = path.join(inputDir, 'sunflower'); |
139 var files = ['sunflower', 'circle', 'painter'] | 143 var files = ['sunflower', 'circle', 'painter'] |
140 .map((f) => path.join(baseDir, '$f.dart')) | 144 .map((f) => path.join(baseDir, '$f.dart')) |
141 .toList(); | 145 .toList(); |
142 var input = new BuildUnit('sunflower', baseDir, files, _moduleForLibrary); | 146 var input = new BuildUnit('sunflower', baseDir, files, _moduleForLibrary); |
143 var options = new CompilerOptions(summarizeApi: false); | 147 var options = new CompilerOptions(summarizeApi: false); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 /// Simplified from ParseDartTask.resolveDirective. | 292 /// Simplified from ParseDartTask.resolveDirective. |
289 String _resolveDirective(UriBasedDirective directive) { | 293 String _resolveDirective(UriBasedDirective directive) { |
290 StringLiteral uriLiteral = directive.uri; | 294 StringLiteral uriLiteral = directive.uri; |
291 String uriContent = uriLiteral.stringValue; | 295 String uriContent = uriLiteral.stringValue; |
292 if (uriContent != null) { | 296 if (uriContent != null) { |
293 uriContent = uriContent.trim(); | 297 uriContent = uriContent.trim(); |
294 directive.uriContent = uriContent; | 298 directive.uriContent = uriContent; |
295 } | 299 } |
296 return directive.validate() == null ? uriContent : null; | 300 return directive.validate() == null ? uriContent : null; |
297 } | 301 } |
OLD | NEW |