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 /// |
6 /// Runs Dart Dev Compiler on all input in the `codegen` directory and checks | 7 /// Runs Dart Dev Compiler on all input in the `codegen` directory and checks |
7 /// that the output is what we expected. | 8 /// that the output is what we expected. |
8 library dev_compiler.test.codegen_test; | 9 library dev_compiler.test.codegen_test; |
9 | 10 |
| 11 // TODO(rnystrom): This doesn't actually run any tests any more. It just |
| 12 // compiles stuff. This should be changed to not use unittest and just be a |
| 13 // regular program that outputs files. |
| 14 |
10 import 'dart:convert' show JSON; | 15 import 'dart:convert' show JSON; |
11 import 'dart:io' show Directory, File, Platform; | 16 import 'dart:io' show Directory, File, Platform; |
12 import 'package:args/args.dart' show ArgParser, ArgResults; | 17 import 'package:args/args.dart' show ArgParser, ArgResults; |
13 import 'package:path/path.dart' as path; | 18 import 'package:path/path.dart' as path; |
14 import 'package:test/test.dart' show group, test; | 19 import 'package:test/test.dart' show group, test; |
15 | 20 |
16 import 'package:analyzer/analyzer.dart' | 21 import 'package:analyzer/analyzer.dart' |
17 show | 22 show |
18 ExportDirective, | 23 ExportDirective, |
19 ImportDirective, | 24 ImportDirective, |
20 StringLiteral, | 25 StringLiteral, |
21 UriBasedDirective, | 26 UriBasedDirective, |
22 parseDirectives; | 27 parseDirectives; |
23 import 'package:analyzer/src/generated/source.dart' show Source; | 28 import 'package:analyzer/src/generated/source.dart' show Source; |
24 import 'package:dev_compiler/src/analyzer/context.dart' show AnalyzerOptions; | 29 import 'package:dev_compiler/src/analyzer/context.dart' show AnalyzerOptions; |
25 import 'package:dev_compiler/src/compiler/compiler.dart' | 30 import 'package:dev_compiler/src/compiler/compiler.dart' |
26 show BuildUnit, CompilerOptions, ModuleCompiler; | 31 show BuildUnit, CompilerOptions, ModuleCompiler; |
27 import 'testing.dart' show testDirectory; | 32 import 'testing.dart' show repoDirectory, testDirectory; |
28 import 'multitest.dart' show extractTestsFromMultitest, isMultiTest; | 33 import 'multitest.dart' show extractTestsFromMultitest, isMultiTest; |
29 import '../tool/build_sdk.dart' as build_sdk; | 34 import '../tool/build_sdk.dart' as build_sdk; |
30 import 'package:dev_compiler/src/compiler/compiler.dart'; | 35 import 'package:dev_compiler/src/compiler/compiler.dart'; |
31 | 36 |
32 final ArgParser argParser = new ArgParser() | 37 final ArgParser argParser = new ArgParser() |
33 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null); | 38 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null); |
34 | 39 |
| 40 /// The `test/codegen` directory. |
| 41 final codegenDir = path.join(testDirectory, 'codegen'); |
| 42 |
| 43 /// The generated directory where tests, expanded multitests, and other test |
| 44 /// support libraries are copied to. |
| 45 /// |
| 46 /// The tests sometimes import utility libraries using a relative path. |
| 47 /// Likewise, the multitests do too, and one multitest even imports its own |
| 48 /// non-expanded form (!). To make that simpler, we copy the entire test tree |
| 49 /// to a generated directory and expand that multitests in there too. |
| 50 final codegenTestDir = path.join(repoDirectory, 'gen', 'codegen_tests'); |
| 51 |
| 52 /// The generated directory where tests and packages compiled to JS are |
| 53 /// output. |
| 54 final codegenOutputDir = path.join(repoDirectory, 'gen', 'codegen_output'); |
| 55 |
| 56 // TODO(jmesserly): switch this to a .packages file. |
| 57 final packageUrlMappings = { |
| 58 'package:expect/expect.dart': path.join(codegenDir, 'expect.dart'), |
| 59 'package:async_helper/async_helper.dart': |
| 60 path.join(codegenDir, 'async_helper.dart'), |
| 61 'package:js/js.dart': path.join(codegenDir, 'packages', 'js', 'js.dart') |
| 62 }; |
| 63 |
| 64 final codeCoverage = Platform.environment.containsKey('COVERALLS_TOKEN'); |
| 65 |
35 main(arguments) { | 66 main(arguments) { |
36 if (arguments == null) arguments = []; | 67 if (arguments == null) arguments = []; |
37 ArgResults args = argParser.parse(arguments); | 68 ArgResults args = argParser.parse(arguments); |
38 var filePattern = new RegExp(args.rest.length > 0 ? args.rest[0] : '.'); | 69 var filePattern = new RegExp(args.rest.length > 0 ? args.rest[0] : '.'); |
39 | 70 |
40 var expectDir = path.join(inputDir, 'expect'); | 71 var sdkDir = path.join(repoDirectory, 'gen', 'patched_sdk'); |
| 72 var sdkSummaryFile = |
| 73 path.join(testDirectory, '..', 'lib', 'runtime', 'dart_sdk.sum'); |
| 74 var analyzerOptions = new AnalyzerOptions( |
| 75 customUrlMappings: packageUrlMappings, |
| 76 dartSdkSummaryPath: sdkSummaryFile); |
| 77 var compiler = new ModuleCompiler(analyzerOptions); |
| 78 |
| 79 // Build packages tests depend on. |
| 80 _buildAllPackages(compiler); |
| 81 |
41 var testDirs = [ | 82 var testDirs = [ |
42 'language', | 83 'language', |
43 'corelib', | 84 'corelib', |
44 path.join('lib', 'convert'), | 85 path.join('lib', 'convert'), |
45 path.join('lib', 'html'), | 86 path.join('lib', 'html'), |
46 path.join('lib', 'math'), | 87 path.join('lib', 'math'), |
47 path.join('lib', 'typed_data') | 88 path.join('lib', 'typed_data') |
48 ]; | 89 ]; |
49 | 90 |
50 var multitests = expandMultiTests(testDirs, filePattern); | 91 // Copy all of the test files and expanded multitest files to |
51 | 92 // gen/codegen_tests. We'll compile from there. |
52 // Build packages tests depend on | 93 var testFiles = _setUpTests(testDirs, filePattern); |
53 var sdkSummaryFile = | |
54 path.join(testDirectory, '..', 'lib', 'runtime', 'dart_sdk.sum'); | |
55 var analyzerOptions = new AnalyzerOptions( | |
56 customUrlMappings: packageUrlMappings, | |
57 dartSdkSummaryPath: sdkSummaryFile); | |
58 var compiler = new ModuleCompiler(analyzerOptions); | |
59 | |
60 group('dartdevc package', () { | |
61 _buildPackages(compiler, expectDir); | |
62 | |
63 test('matcher', () { | |
64 _buildPackage(compiler, expectDir, "matcher"); | |
65 }); | |
66 | |
67 test('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 ]); | |
76 }); | |
77 | |
78 test('stack_trace', () { | |
79 _buildPackage(compiler, expectDir, "stack_trace"); | |
80 }); | |
81 | |
82 test('path', () { | |
83 _buildPackage(compiler, expectDir, "path"); | |
84 }); | |
85 }); | |
86 | |
87 test('dartdevc sunflower', () { | |
88 _buildSunflower(compiler, expectDir); | |
89 }); | |
90 | 94 |
91 // Our default compiler options. Individual tests can override these. | 95 // Our default compiler options. Individual tests can override these. |
92 var defaultOptions = ['--no-source-map', '--no-summarize']; | 96 var defaultOptions = ['--no-source-map', '--no-summarize']; |
93 var compilerArgParser = CompilerOptions.addArguments(new ArgParser()); | 97 var compilerArgParser = CompilerOptions.addArguments(new ArgParser()); |
94 | 98 |
95 var allDirs = [null]; | 99 // Compile each test file to JS and put the result in gen/codegen_output. |
96 allDirs.addAll(testDirs); | 100 for (var testFile in testFiles) { |
97 for (var dir in allDirs) { | 101 var relativePath = path.relative(testFile, from: codegenTestDir); |
98 if (codeCoverage && dir != null) continue; | |
99 | 102 |
100 group('dartdevc ' + path.join('test', 'codegen', dir), () { | 103 // Only compile the top-level files for generating coverage. |
101 var outDir = new Directory(path.join(expectDir, dir)); | 104 if (codeCoverage && path.dirname(relativePath) != ".") continue; |
102 if (!outDir.existsSync()) outDir.createSync(recursive: true); | |
103 | 105 |
104 var baseDir = path.join(inputDir, dir); | 106 var name = path.withoutExtension(relativePath); |
105 var testFiles = _findTests(baseDir, filePattern); | 107 test('dartdevc $name', () { |
106 for (var filePath in testFiles) { | 108 var outDir = path.join(codegenOutputDir, path.dirname(relativePath)); |
107 if (multitests.contains(filePath)) continue; | 109 _ensureDirectory(outDir); |
108 | 110 |
109 var filename = path.basenameWithoutExtension(filePath); | 111 // Check if we need to use special compile options. |
| 112 var contents = new File(testFile).readAsStringSync(); |
| 113 var match = |
| 114 new RegExp(r'// compile options: (.*)').matchAsPrefix(contents); |
110 | 115 |
111 test('$filename.dart', () { | 116 var args = defaultOptions.toList(); |
112 // Check if we need to use special compile options. | 117 if (match != null) { |
113 var contents = new File(filePath).readAsStringSync(); | 118 args.addAll(match.group(1).split(' ')); |
114 var match = | 119 } |
115 new RegExp(r'// compile options: (.*)').matchAsPrefix(contents); | 120 var options = |
| 121 new CompilerOptions.fromArguments(compilerArgParser.parse(args)); |
116 | 122 |
117 var args = new List.from(defaultOptions); | 123 // Collect any other files we've imported. |
118 if (match != null) { | 124 var files = new Set<String>(); |
119 args.addAll(match.group(1).split(' ')); | 125 _collectTransitiveImports(contents, files, from: testFile); |
120 } | 126 var moduleName = |
121 var options = | 127 path.withoutExtension(path.relative(testFile, from: codegenTestDir)); |
122 new CompilerOptions.fromArguments(compilerArgParser.parse(args)); | 128 var unit = new BuildUnit(moduleName, path.dirname(testFile), |
123 | 129 files.toList(), _moduleForLibrary); |
124 // Collect any other files we've imported. | 130 var module = compiler.compile(unit, options); |
125 var files = new Set<String>(); | 131 _writeModule( |
126 _collectTransitiveImports(contents, files, from: filePath); | 132 path.join(outDir, path.basenameWithoutExtension(testFile)), module); |
127 var moduleName = | |
128 path.withoutExtension(path.relative(filePath, from: inputDir)); | |
129 var unit = new BuildUnit( | |
130 moduleName, baseDir, files.toList(), _moduleForLibrary); | |
131 var module = compiler.compile(unit, options); | |
132 _writeModule(path.join(outDir.path, filename), module); | |
133 }); | |
134 } | |
135 }); | 133 }); |
136 } | 134 } |
137 | 135 |
138 if (codeCoverage) { | 136 if (codeCoverage) { |
139 test('build_sdk code coverage', () { | 137 test('build_sdk code coverage', () { |
140 var generatedSdkDir = | 138 return build_sdk.main(['--dart-sdk', sdkDir, '-o', codegenOutputDir]); |
141 path.join(testDirectory, '..', 'tool', 'generated_sdk'); | |
142 return build_sdk.main(['--dart-sdk', generatedSdkDir, '-o', expectDir]); | |
143 }); | 139 }); |
144 } | 140 } |
145 } | 141 } |
146 | 142 |
147 void _writeModule(String outPath, JSModuleFile result) { | 143 void _writeModule(String outPath, JSModuleFile result) { |
148 new Directory(path.dirname(outPath)).createSync(recursive: true); | 144 _ensureDirectory(path.dirname(outPath)); |
149 | 145 |
150 String errors = result.errors.join('\n'); | 146 String errors = result.errors.join('\n'); |
151 if (errors.isNotEmpty && !errors.endsWith('\n')) errors += '\n'; | 147 if (errors.isNotEmpty && !errors.endsWith('\n')) errors += '\n'; |
152 new File(outPath + '.txt').writeAsStringSync(errors); | 148 new File(outPath + '.txt').writeAsStringSync(errors); |
153 | 149 |
154 var jsFile = new File(outPath + '.js'); | 150 var jsFile = new File(outPath + '.js'); |
155 var errorFile = new File(outPath + '.err'); | 151 var errorFile = new File(outPath + '.err'); |
156 | 152 |
157 if (result.isValid) { | 153 if (result.isValid) { |
158 jsFile.writeAsStringSync(result.code); | 154 jsFile.writeAsStringSync(result.code); |
(...skipping 11 matching lines...) Expand all Loading... |
170 // Also write the errors to a '.err' file for easy counting. | 166 // Also write the errors to a '.err' file for easy counting. |
171 errorFile.writeAsStringSync(errors); | 167 errorFile.writeAsStringSync(errors); |
172 | 168 |
173 // There are errors, so delete any stale ".js" file. | 169 // There are errors, so delete any stale ".js" file. |
174 if (jsFile.existsSync()) { | 170 if (jsFile.existsSync()) { |
175 jsFile.deleteSync(); | 171 jsFile.deleteSync(); |
176 } | 172 } |
177 } | 173 } |
178 } | 174 } |
179 | 175 |
180 void _buildSunflower(ModuleCompiler compiler, String expectDir) { | 176 void _buildAllPackages(ModuleCompiler compiler) { |
181 var baseDir = path.join(inputDir, 'sunflower'); | 177 group('dartdevc package', () { |
| 178 _buildPackages(compiler, codegenOutputDir); |
| 179 |
| 180 var packages = ['matcher', 'path', 'stack_trace']; |
| 181 for (var package in packages) { |
| 182 test(package, () { |
| 183 _buildPackage(compiler, codegenOutputDir, package); |
| 184 }); |
| 185 } |
| 186 |
| 187 test('unittest', () { |
| 188 // Only build files applicable to the web - html_*.dart and its |
| 189 // internal dependences. |
| 190 _buildPackage(compiler, codegenOutputDir, "unittest", packageFiles: [ |
| 191 'unittest.dart', |
| 192 'html_config.dart', |
| 193 'html_individual_config.dart', |
| 194 'html_enhanced_config.dart' |
| 195 ]); |
| 196 }); |
| 197 }); |
| 198 |
| 199 test('dartdevc sunflower', () { |
| 200 _buildSunflower(compiler, codegenOutputDir); |
| 201 }); |
| 202 } |
| 203 |
| 204 void _buildSunflower(ModuleCompiler compiler, String outputDir) { |
| 205 var baseDir = path.join(codegenDir, 'sunflower'); |
182 var files = ['sunflower', 'circle', 'painter'] | 206 var files = ['sunflower', 'circle', 'painter'] |
183 .map((f) => path.join(baseDir, '$f.dart')) | 207 .map((f) => path.join(baseDir, '$f.dart')) |
184 .toList(); | 208 .toList(); |
185 var input = new BuildUnit('sunflower', baseDir, files, _moduleForLibrary); | 209 var input = new BuildUnit('sunflower', baseDir, files, _moduleForLibrary); |
186 var options = new CompilerOptions(summarizeApi: false); | 210 var options = new CompilerOptions(summarizeApi: false); |
187 | 211 |
188 var built = compiler.compile(input, options); | 212 var built = compiler.compile(input, options); |
189 _writeModule(path.join(expectDir, 'sunflower', 'sunflower'), built); | 213 _writeModule(path.join(outputDir, 'sunflower', 'sunflower'), built); |
190 } | 214 } |
191 | 215 |
192 void _buildPackages(ModuleCompiler compiler, String expectDir) { | 216 void _buildPackages(ModuleCompiler compiler, String outputDir) { |
193 // Note: we don't summarize these, as we're going to rely on our in-memory | 217 // Note: we don't summarize these, as we're going to rely on our in-memory |
194 // shared analysis context for caching, and `_moduleForLibrary` below | 218 // shared analysis context for caching, and `_moduleForLibrary` below |
195 // understands these are from other modules. | 219 // understands these are from other modules. |
196 var options = new CompilerOptions(sourceMap: false, summarizeApi: false); | 220 var options = new CompilerOptions(sourceMap: false, summarizeApi: false); |
197 | 221 |
198 for (var uri in packageUrlMappings.keys) { | 222 for (var uri in packageUrlMappings.keys) { |
199 assert(uri.startsWith('package:')); | 223 assert(uri.startsWith('package:')); |
200 var uriPath = uri.substring('package:'.length); | 224 var uriPath = uri.substring('package:'.length); |
201 var name = path.basenameWithoutExtension(uriPath); | 225 var name = path.basenameWithoutExtension(uriPath); |
202 test(name, () { | 226 test(name, () { |
203 var input = new BuildUnit(name, inputDir, [uri], _moduleForLibrary); | 227 var input = new BuildUnit(name, codegenDir, [uri], _moduleForLibrary); |
204 var built = compiler.compile(input, options); | 228 var built = compiler.compile(input, options); |
205 | 229 |
206 var outPath = path.join(expectDir, path.withoutExtension(uriPath)); | 230 var outPath = path.join(outputDir, path.withoutExtension(uriPath)); |
207 _writeModule(outPath, built); | 231 _writeModule(outPath, built); |
208 }); | 232 }); |
209 } | 233 } |
210 } | 234 } |
211 | 235 |
212 void _buildPackage(ModuleCompiler compiler, String expectDir, packageName, | 236 void _buildPackage(ModuleCompiler compiler, String outputDir, packageName, |
213 {List<String> packageFiles}) { | 237 {List<String> packageFiles}) { |
214 var options = new CompilerOptions(sourceMap: false, summarizeApi: false); | 238 var options = new CompilerOptions(sourceMap: false, summarizeApi: false); |
215 | 239 |
216 var packageRoot = path.join(inputDir, 'packages'); | 240 var packageRoot = path.join(codegenDir, 'packages'); |
217 var packageInputDir = path.join(packageRoot, packageName); | 241 var packageInputDir = path.join(packageRoot, packageName); |
218 List<String> files; | 242 List<String> files; |
219 if (packageFiles != null) { | 243 if (packageFiles != null) { |
220 // Only collect files transitively reachable from packageFiles | 244 // Only collect files transitively reachable from packageFiles. |
221 var reachable = new Set<String>(); | 245 var reachable = new Set<String>(); |
222 for (var f in packageFiles) { | 246 for (var file in packageFiles) { |
223 f = path.join(packageInputDir, f); | 247 file = path.join(packageInputDir, file); |
224 _collectTransitiveImports(new File(f).readAsStringSync(), reachable, | 248 _collectTransitiveImports(new File(file).readAsStringSync(), reachable, |
225 packageRoot: packageRoot, from: f); | 249 packageRoot: packageRoot, from: file); |
226 } | 250 } |
227 files = reachable.toList(); | 251 files = reachable.toList(); |
228 } else { | 252 } else { |
229 // Collect all files in the packages directory | 253 // Collect all files in the packages directory. |
230 files = new Directory(packageInputDir) | 254 files = new Directory(packageInputDir) |
231 .listSync(recursive: true) | 255 .listSync(recursive: true) |
232 .where((entry) => entry.path.endsWith('.dart')) | 256 .where((entry) => entry.path.endsWith('.dart')) |
233 .map((entry) => entry.path) | 257 .map((entry) => entry.path) |
234 .toList(); | 258 .toList(); |
235 } | 259 } |
236 | 260 |
237 var unit = | 261 var unit = |
238 new BuildUnit(packageName, packageInputDir, files, _moduleForLibrary); | 262 new BuildUnit(packageName, packageInputDir, files, _moduleForLibrary); |
239 var module = compiler.compile(unit, options); | 263 var module = compiler.compile(unit, options); |
240 | 264 |
241 var outPath = path.join(expectDir, packageName, packageName); | 265 var outPath = path.join(outputDir, packageName, packageName); |
242 _writeModule(outPath, module); | 266 _writeModule(outPath, module); |
243 } | 267 } |
244 | 268 |
245 String _moduleForLibrary(Source source) { | 269 String _moduleForLibrary(Source source) { |
246 var scheme = source.uri.scheme; | 270 var scheme = source.uri.scheme; |
247 if (scheme == 'package') { | 271 if (scheme == 'package') { |
248 return source.uri.pathSegments.first; | 272 return source.uri.pathSegments.first; |
249 } | 273 } |
250 throw new Exception('Module not found for library "${source.fullName}"'); | 274 throw new Exception('Module not found for library "${source.fullName}"'); |
251 } | 275 } |
252 | 276 |
253 /// Expands wacky multitests into a bunch of test files. | 277 List<String> _setUpTests(List<String> testDirs, RegExp filePattern) { |
254 /// | 278 var testFiles = []; |
255 /// We'll compile each one as if it was an input. | |
256 /// NOTE: this will write the individual test files to disk. | |
257 Set<String> expandMultiTests(List testDirs, RegExp filePattern) { | |
258 var multitests = new Set<String>(); | |
259 | 279 |
260 for (var testDir in testDirs) { | 280 for (var testDir in testDirs) { |
261 var fullDir = path.join(inputDir, testDir); | 281 for (var file in _listFiles(path.join(codegenDir, testDir), filePattern, |
262 var testFiles = _findTests(fullDir, filePattern); | 282 recursive: true)) { |
| 283 var relativePath = path.relative(file, from: codegenDir); |
| 284 var outputPath = path.join(codegenTestDir, relativePath); |
263 | 285 |
264 for (var filePath in testFiles) { | 286 _ensureDirectory(path.dirname(outputPath)); |
265 if (filePath.endsWith('_multi.dart')) continue; | |
266 | 287 |
267 var contents = new File(filePath).readAsStringSync(); | 288 // Copy it over. We do this even for multitests because import_self_test |
268 if (isMultiTest(contents)) { | 289 // is a multitest, yet imports its own unexpanded form (!). |
269 multitests.add(filePath); | 290 new File(file).copySync(outputPath); |
270 | 291 |
271 var tests = new Map<String, String>(); | 292 if (file.endsWith("_test.dart")) { |
272 var outcomes = new Map<String, Set<String>>(); | 293 var contents = new File(file).readAsStringSync(); |
273 extractTestsFromMultitest(filePath, contents, tests, outcomes); | |
274 | 294 |
275 var filename = path.basenameWithoutExtension(filePath); | 295 if (isMultiTest(contents)) { |
276 tests.forEach((name, contents) { | 296 // It's a multitest, so expand it and add all of the variants. |
277 new File(path.join(fullDir, '${filename}_${name}_multi.dart')) | 297 var tests = <String, String>{}; |
278 .writeAsStringSync(contents); | 298 var outcomes = <String, Set<String>>{}; |
279 }); | 299 extractTestsFromMultitest(file, contents, tests, outcomes); |
| 300 |
| 301 var fileName = path.basenameWithoutExtension(file); |
| 302 var outputDir = path.dirname(outputPath); |
| 303 tests.forEach((name, contents) { |
| 304 var multiFile = |
| 305 path.join(outputDir, '${fileName}_${name}_multi.dart'); |
| 306 testFiles.add(multiFile); |
| 307 |
| 308 new File(multiFile).writeAsStringSync(contents); |
| 309 }); |
| 310 } else { |
| 311 // It's a single test suite. |
| 312 testFiles.add(outputPath); |
| 313 } |
280 } | 314 } |
281 } | 315 } |
282 } | 316 } |
283 return multitests; | 317 |
| 318 // Also include the other special files that live at the top level directory. |
| 319 for (var file in _listFiles(codegenDir, filePattern)) { |
| 320 var relativePath = path.relative(file, from: codegenDir); |
| 321 var outputPath = path.join(codegenTestDir, relativePath); |
| 322 |
| 323 new File(file).copySync(outputPath); |
| 324 if (file.endsWith(".dart")) { |
| 325 testFiles.add(outputPath); |
| 326 } |
| 327 } |
| 328 |
| 329 return testFiles; |
284 } | 330 } |
285 | 331 |
286 // TODO(jmesserly): switch this to a .packages file. | 332 /// Recursively creates [dir] if it doesn't exist. |
287 final packageUrlMappings = { | 333 void _ensureDirectory(String dir) { |
288 'package:expect/expect.dart': path.join(inputDir, 'expect.dart'), | 334 new Directory(dir).createSync(recursive: true); |
289 'package:async_helper/async_helper.dart': | 335 } |
290 path.join(inputDir, 'async_helper.dart'), | |
291 'package:js/js.dart': path.join(inputDir, 'packages', 'js', 'js.dart') | |
292 }; | |
293 | 336 |
294 final codeCoverage = Platform.environment.containsKey('COVERALLS_TOKEN'); | 337 /// Lists all of the files within [dir] that match [filePattern]. |
| 338 Iterable<String> _listFiles(String dir, RegExp filePattern, |
| 339 {bool recursive: false}) { |
| 340 return new Directory(dir) |
| 341 .listSync(recursive: recursive, followLinks: false) |
| 342 .where((entry) { |
| 343 if (entry is! File) return false; |
295 | 344 |
296 final inputDir = path.join(testDirectory, 'codegen'); | 345 var filePath = entry.path; |
| 346 if (!filePattern.hasMatch(filePath)) return false; |
297 | 347 |
298 Iterable<String> _findTests(String dir, RegExp filePattern) { | 348 return true; |
299 var files = new Directory(dir) | 349 }).map((file) => file.path); |
300 .listSync() | |
301 .where((f) => f is File) | |
302 .map((f) => f.path) | |
303 .where((p) => p.endsWith('.dart') && filePattern.hasMatch(p)); | |
304 if (dir != inputDir) { | |
305 files = files | |
306 .where((p) => p.endsWith('_test.dart') || p.endsWith('_multi.dart')); | |
307 } | |
308 return files; | |
309 } | 350 } |
310 | 351 |
311 /// Parse directives from [contents] and find the complete set of transitive | 352 /// Parse directives from [contents] and find the complete set of transitive |
312 /// imports, reading files as needed. | 353 /// imports, reading files as needed. |
313 /// | 354 /// |
314 /// This will not include dart:* libraries, as those are implicitly available. | 355 /// This will not include dart:* libraries, as those are implicitly available. |
315 void _collectTransitiveImports(String contents, Set<String> libraries, | 356 void _collectTransitiveImports(String contents, Set<String> libraries, |
316 {String packageRoot, String from}) { | 357 {String packageRoot, String from}) { |
317 var uri = from; | 358 var uri = from; |
318 if (packageRoot != null && path.isWithin(packageRoot, from)) { | 359 if (packageRoot != null && path.isWithin(packageRoot, from)) { |
(...skipping 23 matching lines...) Expand all Loading... |
342 /// Simplified from ParseDartTask.resolveDirective. | 383 /// Simplified from ParseDartTask.resolveDirective. |
343 String _resolveDirective(UriBasedDirective directive) { | 384 String _resolveDirective(UriBasedDirective directive) { |
344 StringLiteral uriLiteral = directive.uri; | 385 StringLiteral uriLiteral = directive.uri; |
345 String uriContent = uriLiteral.stringValue; | 386 String uriContent = uriLiteral.stringValue; |
346 if (uriContent != null) { | 387 if (uriContent != null) { |
347 uriContent = uriContent.trim(); | 388 uriContent = uriContent.trim(); |
348 directive.uriContent = uriContent; | 389 directive.uriContent = uriContent; |
349 } | 390 } |
350 return directive.validate() == null ? uriContent : null; | 391 return directive.validate() == null ? uriContent : null; |
351 } | 392 } |
OLD | NEW |