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

Side by Side Diff: test/codegen_test.dart

Issue 1978983002: Delete stale .js or .err files when generating codegen output. (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /// 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 } 133 }
134 } 134 }
135 135
136 void _writeModule(String outPath, JSModuleFile result) { 136 void _writeModule(String outPath, JSModuleFile result) {
137 new Directory(path.dirname(outPath)).createSync(recursive: true); 137 new Directory(path.dirname(outPath)).createSync(recursive: true);
138 138
139 String errors = result.errors.join('\n'); 139 String errors = result.errors.join('\n');
140 if (errors.isNotEmpty && !errors.endsWith('\n')) errors += '\n'; 140 if (errors.isNotEmpty && !errors.endsWith('\n')) errors += '\n';
141 new File(outPath + '.txt').writeAsStringSync(errors); 141 new File(outPath + '.txt').writeAsStringSync(errors);
142 142
143 var jsFile = new File(outPath + '.js');
144 var errorFile = new File(outPath + '.err');
145
143 if (result.isValid) { 146 if (result.isValid) {
144 new File(outPath + '.js').writeAsStringSync(result.code); 147 jsFile.writeAsStringSync(result.code);
145 if (result.sourceMap != null) { 148 if (result.sourceMap != null) {
146 var mapPath = outPath + '.js.map'; 149 var mapPath = outPath + '.js.map';
147 new File(mapPath) 150 new File(mapPath)
148 .writeAsStringSync(JSON.encode(result.placeSourceMap(mapPath))); 151 .writeAsStringSync(JSON.encode(result.placeSourceMap(mapPath)));
149 } 152 }
153
154 // There are no errors, so delete any stale ".err" file.
155 if (errorFile.existsSync()) {
156 errorFile.deleteSync();
157 }
150 } else { 158 } else {
151 // Also write the errors to a '.err' file for easy counting. 159 // Also write the errors to a '.err' file for easy counting.
152 new File(outPath + '.err').writeAsStringSync(errors); 160 errorFile.writeAsStringSync(errors);
161
162 // There are errors, so delete any stale ".js" file.
163 if (jsFile.existsSync()) {
164 jsFile.deleteSync();
165 }
153 } 166 }
154 } 167 }
155 168
156 void _buildSunflower(ModuleCompiler compiler, String expectDir) { 169 void _buildSunflower(ModuleCompiler compiler, String expectDir) {
157 var baseDir = path.join(inputDir, 'sunflower'); 170 var baseDir = path.join(inputDir, 'sunflower');
158 var files = ['sunflower', 'circle', 'painter'] 171 var files = ['sunflower', 'circle', 'painter']
159 .map((f) => path.join(baseDir, '$f.dart')) 172 .map((f) => path.join(baseDir, '$f.dart'))
160 .toList(); 173 .toList();
161 var input = new BuildUnit('sunflower', baseDir, files, _moduleForLibrary); 174 var input = new BuildUnit('sunflower', baseDir, files, _moduleForLibrary);
162 var options = new CompilerOptions(summarizeApi: false); 175 var options = new CompilerOptions(summarizeApi: false);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 /// Simplified from ParseDartTask.resolveDirective. 319 /// Simplified from ParseDartTask.resolveDirective.
307 String _resolveDirective(UriBasedDirective directive) { 320 String _resolveDirective(UriBasedDirective directive) {
308 StringLiteral uriLiteral = directive.uri; 321 StringLiteral uriLiteral = directive.uri;
309 String uriContent = uriLiteral.stringValue; 322 String uriContent = uriLiteral.stringValue;
310 if (uriContent != null) { 323 if (uriContent != null) {
311 uriContent = uriContent.trim(); 324 uriContent = uriContent.trim();
312 directive.uriContent = uriContent; 325 directive.uriContent = uriContent;
313 } 326 }
314 return directive.validate() == null ? uriContent : null; 327 return directive.validate() == null ? uriContent : null;
315 } 328 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698