| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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:io'; | 10 import 'dart:io'; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 loggerSub.cancel(); | 60 loggerSub.cancel(); |
| 61 loggerSub = null; | 61 loggerSub = null; |
| 62 } | 62 } |
| 63 }); | 63 }); |
| 64 | 64 |
| 65 var expectDir = path.join(inputDir, 'expect'); | 65 var expectDir = path.join(inputDir, 'expect'); |
| 66 | 66 |
| 67 BatchCompiler createCompiler(AnalysisContext context, | 67 BatchCompiler createCompiler(AnalysisContext context, |
| 68 {bool checkSdk: false, | 68 {bool checkSdk: false, |
| 69 bool sourceMaps: false, | 69 bool sourceMaps: false, |
| 70 bool destructureNamedParams: false, |
| 70 bool closure: false, | 71 bool closure: false, |
| 71 ModuleFormat moduleFormat: ModuleFormat.legacy}) { | 72 ModuleFormat moduleFormat: ModuleFormat.legacy}) { |
| 72 // TODO(jmesserly): add a way to specify flags in the test file, so | 73 // TODO(jmesserly): add a way to specify flags in the test file, so |
| 73 // they're more self-contained. | 74 // they're more self-contained. |
| 74 var runtimeDir = path.join(path.dirname(testDirectory), 'lib', 'runtime'); | 75 var runtimeDir = path.join(path.dirname(testDirectory), 'lib', 'runtime'); |
| 75 var options = new CompilerOptions( | 76 var options = new CompilerOptions( |
| 76 codegenOptions: new CodegenOptions( | 77 codegenOptions: new CodegenOptions( |
| 77 outputDir: expectDir, | 78 outputDir: expectDir, |
| 78 emitSourceMaps: sourceMaps, | 79 emitSourceMaps: sourceMaps, |
| 79 closure: closure, | 80 closure: closure, |
| 81 destructureNamedParams: destructureNamedParams, |
| 80 forceCompile: checkSdk, | 82 forceCompile: checkSdk, |
| 81 moduleFormat: moduleFormat), | 83 moduleFormat: moduleFormat), |
| 82 useColors: false, | 84 useColors: false, |
| 83 checkSdk: checkSdk, | 85 checkSdk: checkSdk, |
| 84 runtimeDir: runtimeDir, | 86 runtimeDir: runtimeDir, |
| 85 inputBaseDir: inputDir); | 87 inputBaseDir: inputDir); |
| 86 var reporter = createErrorReporter(context, options); | 88 var reporter = createErrorReporter(context, options); |
| 87 return new BatchCompiler(context, options, reporter: reporter); | 89 return new BatchCompiler(context, options, reporter: reporter); |
| 88 } | 90 } |
| 89 | 91 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 if (multitests.contains(filePath)) continue; | 152 if (multitests.contains(filePath)) continue; |
| 151 | 153 |
| 152 var filename = path.basenameWithoutExtension(filePath); | 154 var filename = path.basenameWithoutExtension(filePath); |
| 153 | 155 |
| 154 test('$filename.dart', () { | 156 test('$filename.dart', () { |
| 155 // TODO(jmesserly): this was added to get some coverage of source maps | 157 // TODO(jmesserly): this was added to get some coverage of source maps |
| 156 // and closure annotations. | 158 // and closure annotations. |
| 157 // We need a more comprehensive strategy to test them. | 159 // We need a more comprehensive strategy to test them. |
| 158 var sourceMaps = filename == 'map_keys'; | 160 var sourceMaps = filename == 'map_keys'; |
| 159 var closure = filename == 'closure'; | 161 var closure = filename == 'closure'; |
| 162 var destructureNamedParams = filename == 'destructuring' || closure; |
| 160 var moduleFormat = filename == 'es6_modules' | 163 var moduleFormat = filename == 'es6_modules' |
| 161 ? ModuleFormat.es6 | 164 ? ModuleFormat.es6 |
| 162 : filename == 'node_modules' | 165 : filename == 'node_modules' |
| 163 ? ModuleFormat.node | 166 ? ModuleFormat.node |
| 164 : ModuleFormat.legacy; | 167 : ModuleFormat.legacy; |
| 165 var success; | 168 var success; |
| 166 // TODO(vsm): Is it okay to reuse the same context here? If there is | 169 // TODO(vsm): Is it okay to reuse the same context here? If there is |
| 167 // overlap between test files, we may need separate ones for each | 170 // overlap between test files, we may need separate ones for each |
| 168 // compiler. | 171 // compiler. |
| 169 var compiler = | 172 var compiler = (sourceMaps || |
| 170 (sourceMaps || closure || moduleFormat != ModuleFormat.legacy) | 173 closure || |
| 171 ? createCompiler(realSdkContext, | 174 destructureNamedParams || |
| 172 sourceMaps: sourceMaps, | 175 moduleFormat != ModuleFormat.legacy) |
| 173 closure: closure, | 176 ? createCompiler(realSdkContext, |
| 174 moduleFormat: moduleFormat) | 177 sourceMaps: sourceMaps, |
| 175 : batchCompiler; | 178 destructureNamedParams: destructureNamedParams, |
| 179 closure: closure, |
| 180 moduleFormat: moduleFormat) |
| 181 : batchCompiler; |
| 176 success = compile(compiler, filePath); | 182 success = compile(compiler, filePath); |
| 177 | 183 |
| 178 var outFile = new File(path.join(outDir.path, '$filename.js')); | 184 var outFile = new File(path.join(outDir.path, '$filename.js')); |
| 179 expect(!success || outFile.existsSync(), true, | 185 expect(!success || outFile.existsSync(), true, |
| 180 reason: '${outFile.path} was created if compilation succeeds'); | 186 reason: '${outFile.path} was created if compilation succeeds'); |
| 181 }); | 187 }); |
| 182 } | 188 } |
| 183 }); | 189 }); |
| 184 } | 190 } |
| 185 | 191 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 | 261 |
| 256 /// An implementation of analysis engine's [Logger] that prints. | 262 /// An implementation of analysis engine's [Logger] that prints. |
| 257 class PrintLogger implements Logger { | 263 class PrintLogger implements Logger { |
| 258 @override void logError(String message, [CaughtException exception]) { | 264 @override void logError(String message, [CaughtException exception]) { |
| 259 print('[AnalysisEngine] error $message $exception'); | 265 print('[AnalysisEngine] error $message $exception'); |
| 260 } | 266 } |
| 261 | 267 |
| 262 void logInformation(String message, [CaughtException exception]) {} | 268 void logInformation(String message, [CaughtException exception]) {} |
| 263 void logInformation2(String message, Object exception) {} | 269 void logInformation2(String message, Object exception) {} |
| 264 } | 270 } |
| OLD | NEW |