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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 'corelib', | 43 'corelib', |
44 path.join('lib', 'convert'), | 44 path.join('lib', 'convert'), |
45 path.join('lib', 'html'), | 45 path.join('lib', 'html'), |
46 path.join('lib', 'math'), | 46 path.join('lib', 'math'), |
47 path.join('lib', 'typed_data') | 47 path.join('lib', 'typed_data') |
48 ]; | 48 ]; |
49 | 49 |
50 var multitests = expandMultiTests(testDirs, filePattern); | 50 var multitests = expandMultiTests(testDirs, filePattern); |
51 | 51 |
52 // Build packages tests depend on | 52 // Build packages tests depend on |
53 var generatedSdkDir = path.join(testDirectory, '..', 'tool', 'generated_sdk'); | 53 var sdkSummaryFile = |
| 54 path.join(testDirectory, '..', 'lib', 'runtime', 'dart_sdk.sum'); |
54 var analyzerOptions = new AnalyzerOptions( | 55 var analyzerOptions = new AnalyzerOptions( |
55 customUrlMappings: packageUrlMappings, dartSdkPath: generatedSdkDir); | 56 customUrlMappings: packageUrlMappings, |
| 57 dartSdkSummaryPath: sdkSummaryFile); |
56 var compiler = new ModuleCompiler(analyzerOptions); | 58 var compiler = new ModuleCompiler(analyzerOptions); |
57 | 59 |
58 group('dartdevc package', () { | 60 group('dartdevc package', () { |
59 _buildPackages(compiler, expectDir); | 61 _buildPackages(compiler, expectDir); |
60 | 62 |
61 test('matcher', () { | 63 test('matcher', () { |
62 _buildPackage(compiler, expectDir, "matcher"); | 64 _buildPackage(compiler, expectDir, "matcher"); |
63 }); | 65 }); |
64 | 66 |
65 test('unittest', () { | 67 test('unittest', () { |
66 _buildPackage(compiler, expectDir, "unittest"); | 68 // Only build files applicable to the web - html_*.dart and its |
| 69 // internal dependences. |
| 70 _buildPackage(compiler, expectDir, "unittest", packageFiles: [ |
| 71 'unittest.dart', |
| 72 'html_config.dart', |
| 73 'html_individual_config.dart', |
| 74 'html_enhanced_config.dart' |
| 75 ]); |
67 }); | 76 }); |
68 | 77 |
69 test('stack_trace', () { | 78 test('stack_trace', () { |
70 _buildPackage(compiler, expectDir, "stack_trace"); | 79 _buildPackage(compiler, expectDir, "stack_trace"); |
71 }); | 80 }); |
72 | 81 |
73 test('path', () { | 82 test('path', () { |
74 _buildPackage(compiler, expectDir, "path"); | 83 _buildPackage(compiler, expectDir, "path"); |
75 }); | 84 }); |
76 }); | 85 }); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 moduleName, baseDir, files.toList(), _moduleForLibrary); | 130 moduleName, baseDir, files.toList(), _moduleForLibrary); |
122 var module = compiler.compile(unit, options); | 131 var module = compiler.compile(unit, options); |
123 _writeModule(path.join(outDir.path, filename), module); | 132 _writeModule(path.join(outDir.path, filename), module); |
124 }); | 133 }); |
125 } | 134 } |
126 }); | 135 }); |
127 } | 136 } |
128 | 137 |
129 if (codeCoverage) { | 138 if (codeCoverage) { |
130 test('build_sdk code coverage', () { | 139 test('build_sdk code coverage', () { |
| 140 var generatedSdkDir = |
| 141 path.join(testDirectory, '..', 'tool', 'generated_sdk'); |
131 return build_sdk.main(['--dart-sdk', generatedSdkDir, '-o', expectDir]); | 142 return build_sdk.main(['--dart-sdk', generatedSdkDir, '-o', expectDir]); |
132 }); | 143 }); |
133 } | 144 } |
134 } | 145 } |
135 | 146 |
136 void _writeModule(String outPath, JSModuleFile result) { | 147 void _writeModule(String outPath, JSModuleFile result) { |
137 new Directory(path.dirname(outPath)).createSync(recursive: true); | 148 new Directory(path.dirname(outPath)).createSync(recursive: true); |
138 | 149 |
139 String errors = result.errors.join('\n'); | 150 String errors = result.errors.join('\n'); |
140 if (errors.isNotEmpty && !errors.endsWith('\n')) errors += '\n'; | 151 if (errors.isNotEmpty && !errors.endsWith('\n')) errors += '\n'; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 test(name, () { | 202 test(name, () { |
192 var input = new BuildUnit(name, inputDir, [uri], _moduleForLibrary); | 203 var input = new BuildUnit(name, inputDir, [uri], _moduleForLibrary); |
193 var built = compiler.compile(input, options); | 204 var built = compiler.compile(input, options); |
194 | 205 |
195 var outPath = path.join(expectDir, path.withoutExtension(uriPath)); | 206 var outPath = path.join(expectDir, path.withoutExtension(uriPath)); |
196 _writeModule(outPath, built); | 207 _writeModule(outPath, built); |
197 }); | 208 }); |
198 } | 209 } |
199 } | 210 } |
200 | 211 |
201 void _buildPackage(ModuleCompiler compiler, String expectDir, packageName) { | 212 void _buildPackage(ModuleCompiler compiler, String expectDir, packageName, |
| 213 {List<String> packageFiles}) { |
202 var options = new CompilerOptions(sourceMap: false, summarizeApi: false); | 214 var options = new CompilerOptions(sourceMap: false, summarizeApi: false); |
203 | 215 |
204 var packageRoot = path.join(inputDir, 'packages'); | 216 var packageRoot = path.join(inputDir, 'packages'); |
205 var packageInputDir = path.join(packageRoot, packageName); | 217 var packageInputDir = path.join(packageRoot, packageName); |
206 var files = new Directory(packageInputDir).listSync(recursive: true); | 218 List<String> files; |
| 219 if (packageFiles != null) { |
| 220 // Only collect files transitively reachable from packageFiles |
| 221 var reachable = new Set<String>(); |
| 222 for (var f in packageFiles) { |
| 223 f = path.join(packageInputDir, f); |
| 224 _collectTransitiveImports(new File(f).readAsStringSync(), reachable, |
| 225 packageRoot: packageRoot, from: f); |
| 226 } |
| 227 files = reachable.toList(); |
| 228 } else { |
| 229 // Collect all files in the packages directory |
| 230 files = new Directory(packageInputDir) |
| 231 .listSync(recursive: true) |
| 232 .where((entry) => entry.path.endsWith('.dart')) |
| 233 .map((entry) => entry.path) |
| 234 .toList(); |
| 235 } |
207 | 236 |
208 var unit = new BuildUnit( | 237 var unit = |
209 packageName, | 238 new BuildUnit(packageName, packageInputDir, files, _moduleForLibrary); |
210 packageInputDir, | |
211 files | |
212 .where((entry) => entry.path.endsWith('dart')) | |
213 .map((entry) => entry.path) | |
214 .toList(), | |
215 _moduleForLibrary); | |
216 var module = compiler.compile(unit, options); | 239 var module = compiler.compile(unit, options); |
217 | 240 |
218 var outPath = path.join(expectDir, packageName, packageName); | 241 var outPath = path.join(expectDir, packageName, packageName); |
219 _writeModule(outPath, module); | 242 _writeModule(outPath, module); |
220 } | 243 } |
221 | 244 |
222 String _moduleForLibrary(Source source) { | 245 String _moduleForLibrary(Source source) { |
223 var scheme = source.uri.scheme; | 246 var scheme = source.uri.scheme; |
224 if (scheme == 'package') { | 247 if (scheme == 'package') { |
225 return source.uri.pathSegments.first; | 248 return source.uri.pathSegments.first; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 /// Simplified from ParseDartTask.resolveDirective. | 342 /// Simplified from ParseDartTask.resolveDirective. |
320 String _resolveDirective(UriBasedDirective directive) { | 343 String _resolveDirective(UriBasedDirective directive) { |
321 StringLiteral uriLiteral = directive.uri; | 344 StringLiteral uriLiteral = directive.uri; |
322 String uriContent = uriLiteral.stringValue; | 345 String uriContent = uriLiteral.stringValue; |
323 if (uriContent != null) { | 346 if (uriContent != null) { |
324 uriContent = uriContent.trim(); | 347 uriContent = uriContent.trim(); |
325 directive.uriContent = uriContent; | 348 directive.uriContent = uriContent; |
326 } | 349 } |
327 return directive.validate() == null ? uriContent : null; | 350 return directive.validate() == null ? uriContent : null; |
328 } | 351 } |
OLD | NEW |