| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 var multitests = expandMultiTests(testDirs, filePattern); | 48 var multitests = expandMultiTests(testDirs, filePattern); |
| 49 | 49 |
| 50 // Build packages tests depend on | 50 // Build packages tests depend on |
| 51 var compiler = new ModuleCompiler( | 51 var compiler = new ModuleCompiler( |
| 52 new AnalyzerOptions(customUrlMappings: packageUrlMappings)); | 52 new AnalyzerOptions(customUrlMappings: packageUrlMappings)); |
| 53 | 53 |
| 54 group('dartdevc package', () { | 54 group('dartdevc package', () { |
| 55 _buildPackages(compiler, expectDir); | 55 _buildPackages(compiler, expectDir); |
| 56 | 56 |
| 57 test('matcher', () { | 57 test('matcher', () { |
| 58 _buildMatcher(compiler, expectDir); | 58 _buildPackage(compiler, expectDir, "matcher"); |
| 59 }); |
| 60 |
| 61 test('unittest', () { |
| 62 _buildPackage(compiler, expectDir, "unittest"); |
| 63 }); |
| 64 |
| 65 test('stack_trace', () { |
| 66 _buildPackage(compiler, expectDir, "stack_trace"); |
| 67 }); |
| 68 |
| 69 test('path', () { |
| 70 _buildPackage(compiler, expectDir, "path"); |
| 59 }); | 71 }); |
| 60 }); | 72 }); |
| 61 | 73 |
| 62 test('dartdevc sunflower', () { | 74 test('dartdevc sunflower', () { |
| 63 _buildSunflower(compiler, expectDir); | 75 _buildSunflower(compiler, expectDir); |
| 64 }); | 76 }); |
| 65 | 77 |
| 66 // Our default compiler options. Individual tests can override these. | 78 // Our default compiler options. Individual tests can override these. |
| 67 var defaultOptions = ['--no-source-map', '--no-summarize']; | 79 var defaultOptions = ['--no-source-map', '--no-summarize']; |
| 68 var compilerArgParser = CompilerOptions.addArguments(new ArgParser()); | 80 var compilerArgParser = CompilerOptions.addArguments(new ArgParser()); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 test(name, () { | 176 test(name, () { |
| 165 var input = new BuildUnit(name, inputDir, [uri], _moduleForLibrary); | 177 var input = new BuildUnit(name, inputDir, [uri], _moduleForLibrary); |
| 166 var built = compiler.compile(input, options); | 178 var built = compiler.compile(input, options); |
| 167 | 179 |
| 168 var outPath = path.join(expectDir, path.withoutExtension(uriPath)); | 180 var outPath = path.join(expectDir, path.withoutExtension(uriPath)); |
| 169 _writeModule(outPath, built); | 181 _writeModule(outPath, built); |
| 170 }); | 182 }); |
| 171 } | 183 } |
| 172 } | 184 } |
| 173 | 185 |
| 174 void _buildMatcher(ModuleCompiler compiler, String expectDir) { | 186 void _buildPackage(ModuleCompiler compiler, String expectDir, packageName) { |
| 175 var options = new CompilerOptions(sourceMap: false, summarizeApi: false); | 187 var options = new CompilerOptions(sourceMap: false, summarizeApi: false); |
| 176 | 188 |
| 177 var packageRoot = path.join(inputDir, 'packages'); | 189 var packageRoot = path.join(inputDir, 'packages'); |
| 178 var filePath = path.join(packageRoot, 'matcher', 'matcher.dart'); | 190 var packageInputDir = path.join(packageRoot, packageName); |
| 179 var contents = new File(filePath).readAsStringSync(); | 191 var files = new Directory(packageInputDir).listSync(recursive: true); |
| 180 | |
| 181 // Collect any other files we've imported. | |
| 182 var files = new Set<String>(); | |
| 183 _collectTransitiveImports(contents, files, | |
| 184 packageRoot: packageRoot, from: filePath); | |
| 185 | 192 |
| 186 var unit = | 193 var unit = |
| 187 new BuildUnit('matcher', inputDir, files.toList(), _moduleForLibrary); | 194 new BuildUnit(packageName, packageInputDir, files.where((entry) => entry.p
ath.endsWith('dart')).map((entry) => entry.path).toList(), _moduleForLibrary); |
| 188 var module = compiler.compile(unit, options); | 195 var module = compiler.compile(unit, options); |
| 189 | 196 |
| 190 var outPath = path.join(expectDir, 'matcher', 'matcher'); | 197 var outPath = path.join(expectDir, packageName, packageName); |
| 191 _writeModule(outPath, module); | 198 _writeModule(outPath, module); |
| 192 } | 199 } |
| 193 | 200 |
| 194 String _moduleForLibrary(Source source) { | 201 String _moduleForLibrary(Source source) { |
| 195 var scheme = source.uri.scheme; | 202 var scheme = source.uri.scheme; |
| 196 if (scheme == 'package') { | 203 if (scheme == 'package') { |
| 197 return source.uri.pathSegments.first; | 204 return source.uri.pathSegments.first; |
| 198 } | 205 } |
| 199 throw new Exception('Module not found for library "${source.fullName}"'); | 206 throw new Exception('Module not found for library "${source.fullName}"'); |
| 200 } | 207 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 230 } | 237 } |
| 231 } | 238 } |
| 232 return multitests; | 239 return multitests; |
| 233 } | 240 } |
| 234 | 241 |
| 235 // TODO(jmesserly): switch this to a .packages file. | 242 // TODO(jmesserly): switch this to a .packages file. |
| 236 final packageUrlMappings = { | 243 final packageUrlMappings = { |
| 237 'package:expect/expect.dart': path.join(inputDir, 'expect.dart'), | 244 'package:expect/expect.dart': path.join(inputDir, 'expect.dart'), |
| 238 'package:async_helper/async_helper.dart': | 245 'package:async_helper/async_helper.dart': |
| 239 path.join(inputDir, 'async_helper.dart'), | 246 path.join(inputDir, 'async_helper.dart'), |
| 240 'package:unittest/unittest.dart': path.join(inputDir, 'unittest.dart'), | |
| 241 'package:unittest/html_config.dart': path.join(inputDir, 'html_config.dart'), | |
| 242 'package:js/js.dart': path.join(inputDir, 'packages', 'js', 'js.dart') | 247 'package:js/js.dart': path.join(inputDir, 'packages', 'js', 'js.dart') |
| 243 }; | 248 }; |
| 244 | 249 |
| 245 final codeCoverage = Platform.environment.containsKey('COVERALLS_TOKEN'); | 250 final codeCoverage = Platform.environment.containsKey('COVERALLS_TOKEN'); |
| 246 | 251 |
| 247 final inputDir = path.join(testDirectory, 'codegen'); | 252 final inputDir = path.join(testDirectory, 'codegen'); |
| 248 | 253 |
| 249 Iterable<String> _findTests(String dir, RegExp filePattern) { | 254 Iterable<String> _findTests(String dir, RegExp filePattern) { |
| 250 var files = new Directory(dir) | 255 var files = new Directory(dir) |
| 251 .listSync() | 256 .listSync() |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 /// Simplified from ParseDartTask.resolveDirective. | 298 /// Simplified from ParseDartTask.resolveDirective. |
| 294 String _resolveDirective(UriBasedDirective directive) { | 299 String _resolveDirective(UriBasedDirective directive) { |
| 295 StringLiteral uriLiteral = directive.uri; | 300 StringLiteral uriLiteral = directive.uri; |
| 296 String uriContent = uriLiteral.stringValue; | 301 String uriContent = uriLiteral.stringValue; |
| 297 if (uriContent != null) { | 302 if (uriContent != null) { |
| 298 uriContent = uriContent.trim(); | 303 uriContent = uriContent.trim(); |
| 299 directive.uriContent = uriContent; | 304 directive.uriContent = uriContent; |
| 300 } | 305 } |
| 301 return directive.validate() == null ? uriContent : null; | 306 return directive.validate() == null ? uriContent : null; |
| 302 } | 307 } |
| OLD | NEW |