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'; |
11 import 'package:analyzer/src/generated/engine.dart' | 11 import 'package:analyzer/src/generated/engine.dart' |
12 show AnalysisContext, AnalysisEngine, Logger; | 12 show AnalysisContext, AnalysisEngine, Logger; |
13 import 'package:analyzer/src/generated/java_engine.dart' show CaughtException; | 13 import 'package:analyzer/src/generated/java_engine.dart' show CaughtException; |
14 import 'package:args/args.dart'; | 14 import 'package:args/args.dart'; |
15 import 'package:logging/logging.dart' show Level; | 15 import 'package:logging/logging.dart' show Level; |
16 import 'package:path/path.dart' as path; | 16 import 'package:path/path.dart' as path; |
17 import 'package:test/test.dart'; | 17 import 'package:test/test.dart'; |
18 | 18 |
19 import 'package:dev_compiler/devc.dart'; | 19 import 'package:dev_compiler/devc.dart'; |
20 import 'package:dev_compiler/strong_mode.dart'; | 20 import 'package:dev_compiler/strong_mode.dart'; |
21 import 'package:dev_compiler/src/compiler.dart' show defaultRuntimeFiles; | 21 import 'package:dev_compiler/src/compiler.dart' show defaultRuntimeFiles; |
22 import 'package:dev_compiler/src/options.dart'; | 22 import 'package:dev_compiler/src/options.dart'; |
23 | 23 |
24 import 'testing.dart' show realSdkContext, testDirectory; | 24 import 'testing.dart' show realSdkContext, testDirectory; |
25 import 'multitest.dart'; | |
25 | 26 |
26 final ArgParser argParser = new ArgParser() | 27 final ArgParser argParser = new ArgParser() |
27 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null); | 28 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null); |
28 | 29 |
30 Iterable<String> _findTests(String dir, RegExp filePattern) { | |
31 return new Directory(dir) | |
32 .listSync() | |
33 .where((f) => f is File) | |
34 .map((f) => f.path) | |
35 .where((p) => p.endsWith('.dart') && filePattern.hasMatch(p)); | |
36 } | |
37 | |
29 main(arguments) { | 38 main(arguments) { |
30 if (arguments == null) arguments = []; | 39 if (arguments == null) arguments = []; |
31 ArgResults args = argParser.parse(arguments); | 40 ArgResults args = argParser.parse(arguments); |
32 var filePattern = new RegExp(args.rest.length > 0 ? args.rest[0] : '.'); | 41 var filePattern = new RegExp(args.rest.length > 0 ? args.rest[0] : '.'); |
33 var compilerMessages = new StringBuffer(); | 42 var compilerMessages = new StringBuffer(); |
34 var loggerSub; | 43 var loggerSub; |
35 | 44 |
36 setUp(() { | 45 setUp(() { |
37 compilerMessages.clear(); | 46 compilerMessages.clear(); |
38 loggerSub = setupLogger(Level.CONFIG, compilerMessages.writeln); | 47 loggerSub = setupLogger(Level.CONFIG, compilerMessages.writeln); |
(...skipping 29 matching lines...) Expand all Loading... | |
68 } | 77 } |
69 | 78 |
70 // Remove old output, and `packages` symlinks which mess up the diff. | 79 // Remove old output, and `packages` symlinks which mess up the diff. |
71 var dir = new Directory(expectDir); | 80 var dir = new Directory(expectDir); |
72 if (dir.existsSync()) dir.deleteSync(recursive: true); | 81 if (dir.existsSync()) dir.deleteSync(recursive: true); |
73 var packagesDirs = new Directory(inputDir) | 82 var packagesDirs = new Directory(inputDir) |
74 .listSync(recursive: true) | 83 .listSync(recursive: true) |
75 .where((d) => d is Directory && path.basename(d.path) == 'packages'); | 84 .where((d) => d is Directory && path.basename(d.path) == 'packages'); |
76 packagesDirs.forEach((d) => d.deleteSync()); | 85 packagesDirs.forEach((d) => d.deleteSync()); |
77 | 86 |
87 var testPathsToSkip = new Set<String>(); | |
88 { | |
89 // Expand wacky multitests into a bunch of test files. | |
90 // We'll compile each one as if it was an input. | |
91 var languageDir = path.join(inputDir, 'language'); | |
92 var testFiles = _findTests(languageDir, filePattern); | |
93 | |
94 for (var filePath in testFiles) { | |
95 if (filePath.endsWith('_multi.dart')) continue; | |
96 | |
97 var contents = new File(filePath).readAsStringSync(); | |
98 if (isMultiTest(contents)) { | |
99 testPathsToSkip.add(filePath); | |
100 | |
101 var tests = new Map<String, String>(); | |
102 var outcomes = new Map<String, Set<String>>(); | |
103 extractTestsFromMultitest(filePath, contents, tests, outcomes); | |
104 | |
105 // For now skip all tests that aren't `ok` or `runtime error` | |
106 outcomes.forEach((name, Set<String> outcomes) { | |
107 // TODO(jmesserly): unfortunately we can't communicate this status | |
108 // to the test runner, so if an error is expected, it's encoded in | |
109 // language-tests.js. We should probably encode expected error in the | |
110 // name, and then have our runner just load all multi tests it finds, | |
111 // using the file name to expect either success or failure. | |
112 outcomes.remove('ok'); | |
113 outcomes.remove('runtime error'); | |
114 if (outcomes.isNotEmpty) { | |
115 // Skip all other outcomes. | |
116 // | |
117 // They are handled by analyzer/static type system, and | |
118 // therefore are not interesting to run. | |
119 tests.remove(name); | |
120 } | |
121 }); | |
122 | |
123 var filename = path.basenameWithoutExtension(filePath); | |
124 tests.forEach((name, contents) { | |
125 new File(path.join(languageDir, '${filename}_${name}_multi.dart')) | |
126 .writeAsStringSync(contents); | |
127 }); | |
128 } | |
129 } | |
130 } | |
131 | |
78 for (var dir in [null, 'language']) { | 132 for (var dir in [null, 'language']) { |
79 group('dartdevc ' + path.join('test', 'codegen', dir), () { | 133 group('dartdevc ' + path.join('test', 'codegen', dir), () { |
80 var testFiles = new Directory(path.join(inputDir, dir)) | 134 var outDir = path.join(expectDir, dir); |
81 .listSync() | |
82 .where((f) => f is File) | |
83 .map((f) => f.path) | |
84 .where((p) => p.endsWith('.dart') && filePattern.hasMatch(p)); | |
85 | 135 |
136 var testFiles = _findTests(path.join(inputDir, dir), filePattern); | |
86 for (var filePath in testFiles) { | 137 for (var filePath in testFiles) { |
138 //!!!if (testPathsToSkip.contains(filePath)) continue; | |
vsm
2015/08/25 21:47:26
Delete or TODO
Jennifer Messerly
2015/08/25 22:13:11
Done.
| |
139 | |
87 var filename = path.basenameWithoutExtension(filePath); | 140 var filename = path.basenameWithoutExtension(filePath); |
88 | 141 |
89 test('$filename.dart', () { | 142 test('$filename.dart', () { |
90 compilerMessages.writeln('// Messages from compiling $filename.dart'); | 143 compilerMessages.writeln('// Messages from compiling $filename.dart'); |
91 | 144 |
92 // TODO(jmesserly): this was added to get some coverage of source maps | 145 // TODO(jmesserly): this was added to get some coverage of source maps |
93 // We need a more comprehensive strategy to test them. | 146 // We need a more comprehensive strategy to test them. |
94 var sourceMaps = filename == 'map_keys'; | 147 var sourceMaps = filename == 'map_keys'; |
95 var success = | 148 var success = |
96 compile(filePath, realSdkContext, sourceMaps: sourceMaps); | 149 compile(filePath, realSdkContext, sourceMaps: sourceMaps); |
97 | 150 |
98 // Write compiler messages to disk. | 151 // Write compiler messages to disk. |
99 var outDir = path.join(expectDir, dir); | |
100 new File(path.join(outDir, '$filename.txt')) | 152 new File(path.join(outDir, '$filename.txt')) |
101 .writeAsStringSync(compilerMessages.toString()); | 153 .writeAsStringSync('$compilerMessages'); |
102 | 154 |
103 var outFile = new File(path.join(outDir, '$filename.js')); | 155 var outFile = new File(path.join(outDir, '$filename.js')); |
104 expect(outFile.existsSync(), success, | 156 expect(outFile.existsSync(), success, |
105 reason: '${outFile.path} was created iff compilation succeeds'); | 157 reason: '${outFile.path} was created iff compilation succeeds'); |
106 | |
107 // TODO(jmesserly): ideally we'd diff the output here. For now it | |
108 // happens in the containing shell script. | |
109 }); | 158 }); |
110 } | 159 } |
111 }); | 160 }); |
112 } | 161 } |
113 | 162 |
114 if (Platform.environment.containsKey('COVERALLS_TOKEN')) { | 163 if (Platform.environment.containsKey('COVERALLS_TOKEN')) { |
115 group('sdk', () { | 164 group('sdk', () { |
116 // The analyzer does not bubble exception messages for certain internal | 165 // The analyzer does not bubble exception messages for certain internal |
117 // dart:* library failures, such as failing to find | 166 // dart:* library failures, such as failing to find |
118 // "_internal/libraries.dart". Instead it produces an opaque "failed to | 167 // "_internal/libraries.dart". Instead it produces an opaque "failed to |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 print('[AnalysisEngine] error $message $exception'); | 248 print('[AnalysisEngine] error $message $exception'); |
200 } | 249 } |
201 | 250 |
202 @override void logError2(String message, Object exception) { | 251 @override void logError2(String message, Object exception) { |
203 print('[AnalysisEngine] error $message $exception'); | 252 print('[AnalysisEngine] error $message $exception'); |
204 } | 253 } |
205 | 254 |
206 void logInformation(String message, [CaughtException exception]) {} | 255 void logInformation(String message, [CaughtException exception]) {} |
207 void logInformation2(String message, Object exception) {} | 256 void logInformation2(String message, Object exception) {} |
208 } | 257 } |
OLD | NEW |