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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 61 |
62 tearDown(() { | 62 tearDown(() { |
63 if (loggerSub != null) { | 63 if (loggerSub != null) { |
64 loggerSub.cancel(); | 64 loggerSub.cancel(); |
65 loggerSub = null; | 65 loggerSub = null; |
66 } | 66 } |
67 }); | 67 }); |
68 | 68 |
69 var expectDir = path.join(inputDir, 'expect'); | 69 var expectDir = path.join(inputDir, 'expect'); |
70 | 70 |
71 BatchCompiler createCompiler(DartUriResolver sdkResolver, {bool checkSdk: fals
e, | 71 BatchCompiler createCompiler(DartUriResolver sdkResolver, |
| 72 {bool checkSdk: false, |
72 bool sourceMaps: false, | 73 bool sourceMaps: false, |
73 bool destructureNamedParams: false, | 74 bool destructureNamedParams: false, |
74 bool closure: false, | 75 bool closure: false, |
75 ModuleFormat moduleFormat: ModuleFormat.legacy}) { | 76 ModuleFormat moduleFormat: ModuleFormat.legacy}) { |
76 | |
77 String _testCodegenPath(String p1, [String p2]) => | 77 String _testCodegenPath(String p1, [String p2]) => |
78 path.join(testDirectory, 'codegen', p1, p2); | 78 path.join(testDirectory, 'codegen', p1, p2); |
79 | 79 |
80 var context = createAnalysisContextWithSources(new SourceResolverOptions( | 80 var context = createAnalysisContextWithSources( |
81 customUrlMappings: { | 81 new SourceResolverOptions(customUrlMappings: { |
82 'package:expect/expect.dart': _testCodegenPath('expect.dart'), | 82 'package:expect/expect.dart': _testCodegenPath('expect.dart'), |
83 'package:async_helper/async_helper.dart': | 83 'package:async_helper/async_helper.dart': |
84 _testCodegenPath('async_helper.dart'), | 84 _testCodegenPath('async_helper.dart'), |
85 'package:unittest/unittest.dart': _testCodegenPath('unittest.dart'), | 85 'package:unittest/unittest.dart': _testCodegenPath('unittest.dart'), |
86 'package:dom/dom.dart': _testCodegenPath('sunflower', 'dom.dart') | 86 'package:dom/dom.dart': _testCodegenPath('sunflower', 'dom.dart') |
87 }), sdkResolver: sdkResolver); | 87 }), |
| 88 sdkResolver: sdkResolver); |
88 | 89 |
89 // TODO(jmesserly): add a way to specify flags in the test file, so | 90 // TODO(jmesserly): add a way to specify flags in the test file, so |
90 // they're more self-contained. | 91 // they're more self-contained. |
91 var runtimeDir = path.join(path.dirname(testDirectory), 'lib', 'runtime'); | 92 var runtimeDir = path.join(path.dirname(testDirectory), 'lib', 'runtime'); |
92 var options = new CompilerOptions( | 93 var options = new CompilerOptions( |
93 codegenOptions: new CodegenOptions( | 94 codegenOptions: new CodegenOptions( |
94 outputDir: expectDir, | 95 outputDir: expectDir, |
95 emitSourceMaps: sourceMaps, | 96 emitSourceMaps: sourceMaps, |
96 closure: closure, | 97 closure: closure, |
97 destructureNamedParams: destructureNamedParams, | 98 destructureNamedParams: destructureNamedParams, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 var savedLogger; | 217 var savedLogger; |
217 setUp(() { | 218 setUp(() { |
218 savedLogger = AnalysisEngine.instance.logger; | 219 savedLogger = AnalysisEngine.instance.logger; |
219 AnalysisEngine.instance.logger = new PrintLogger(); | 220 AnalysisEngine.instance.logger = new PrintLogger(); |
220 }); | 221 }); |
221 tearDown(() { | 222 tearDown(() { |
222 AnalysisEngine.instance.logger = savedLogger; | 223 AnalysisEngine.instance.logger = savedLogger; |
223 }); | 224 }); |
224 | 225 |
225 test('devc dart:core', () { | 226 test('devc dart:core', () { |
226 var testSdkResolver = createSdkPathResolver(path.join( | 227 var testSdkResolver = createSdkPathResolver( |
227 testDirectory, '..', 'tool', 'generated_sdk')); | 228 path.join(testDirectory, '..', 'tool', 'generated_sdk')); |
228 | 229 |
229 // Get the test SDK. We use a checked in copy so test expectations can | 230 // Get the test SDK. We use a checked in copy so test expectations can |
230 // be generated against a specific SDK version. | 231 // be generated against a specific SDK version. |
231 var compiler = createCompiler(testSdkResolver, checkSdk: true); | 232 var compiler = createCompiler(testSdkResolver, checkSdk: true); |
232 compile(compiler, 'dart:core'); | 233 compile(compiler, 'dart:core'); |
233 var outFile = new File(path.join(expectDir, 'dart/core.js')); | 234 var outFile = new File(path.join(expectDir, 'dart/core.js')); |
234 expect(outFile.existsSync(), true, | 235 expect(outFile.existsSync(), true, |
235 reason: '${outFile.path} was created for dart:core'); | 236 reason: '${outFile.path} was created for dart:core'); |
236 }); | 237 }); |
237 }); | 238 }); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 /// An implementation of analysis engine's [Logger] that prints. | 278 /// An implementation of analysis engine's [Logger] that prints. |
278 class PrintLogger implements Logger { | 279 class PrintLogger implements Logger { |
279 @override | 280 @override |
280 void logError(String message, [CaughtException exception]) { | 281 void logError(String message, [CaughtException exception]) { |
281 print('[AnalysisEngine] error $message $exception'); | 282 print('[AnalysisEngine] error $message $exception'); |
282 } | 283 } |
283 | 284 |
284 void logInformation(String message, [CaughtException exception]) {} | 285 void logInformation(String message, [CaughtException exception]) {} |
285 void logInformation2(String message, Object exception) {} | 286 void logInformation2(String message, Object exception) {} |
286 } | 287 } |
OLD | NEW |