OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // Test the exit code of dart2js in case of exceptions, fatal errors, errors, | 5 // Test the exit code of dart2js in case of exceptions, fatal errors, errors, |
6 // warnings, etc. | 6 // warnings, etc. |
7 | 7 |
8 | 8 |
9 import 'dart:async'; | 9 import 'dart:async'; |
10 import 'dart:io' show Platform; | 10 import 'dart:io' show Platform; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 145 |
146 Future testExitCode(String marker, String type, int expectedExitCode) { | 146 Future testExitCode(String marker, String type, int expectedExitCode) { |
147 bool testOccurred = false; | 147 bool testOccurred = false; |
148 | 148 |
149 void onTest(String testMarker, String testType) { | 149 void onTest(String testMarker, String testType) { |
150 if (testMarker == marker && testType == type) { | 150 if (testMarker == marker && testType == type) { |
151 testOccurred = true; | 151 testOccurred = true; |
152 } | 152 } |
153 } | 153 } |
154 return new Future(() { | 154 return new Future(() { |
155 Future<String> compile(Uri script, | 155 Future<api.CompilationResult> compile( |
156 Uri libraryRoot, | 156 Uri script, |
157 Uri packageRoot, | 157 Uri libraryRoot, |
158 api.CompilerInputProvider inputProvider, | 158 Uri packageRoot, |
159 api.DiagnosticHandler handler, | 159 api.CompilerInputProvider inputProvider, |
160 [List<String> options = const [], | 160 api.DiagnosticHandler handler, |
161 api.CompilerOutputProvider outputProvider, | 161 [List<String> options = const [], |
162 Map<String, dynamic> environment = const {}]) { | 162 api.CompilerOutputProvider outputProvider, |
| 163 Map<String, dynamic> environment = const {}]) { |
163 libraryRoot = Platform.script.resolve('../../../sdk/'); | 164 libraryRoot = Platform.script.resolve('../../../sdk/'); |
164 outputProvider = NullSink.outputProvider; | 165 outputProvider = NullSink.outputProvider; |
165 // Use this to silence the test when debugging: | 166 // Use this to silence the test when debugging: |
166 // handler = (uri, begin, end, message, kind) {}; | 167 // handler = (uri, begin, end, message, kind) {}; |
167 Compiler compiler = new TestCompiler(inputProvider, | 168 Compiler compiler = new TestCompiler(inputProvider, |
168 outputProvider, | 169 outputProvider, |
169 handler, | 170 handler, |
170 libraryRoot, | 171 libraryRoot, |
171 packageRoot, | 172 packageRoot, |
172 options, | 173 options, |
173 environment, | 174 environment, |
174 marker, | 175 marker, |
175 type, | 176 type, |
176 onTest); | 177 onTest); |
177 return compiler.run(script).then((_) { | 178 return compiler.run(script).then((bool success) { |
178 String code = compiler.assembledCode; | 179 return new api.CompilationResult(compiler, isSuccess: success); |
179 if (code != null && outputProvider != null) { | |
180 String outputType = 'js'; | |
181 if (options.contains('--output-type=dart')) { | |
182 outputType = 'dart'; | |
183 } | |
184 outputProvider('', outputType) | |
185 ..add(code) | |
186 ..close(); | |
187 code = ''; // Non-null signals success. | |
188 } | |
189 return code; | |
190 }); | 180 }); |
191 } | 181 } |
192 | 182 |
193 int foundExitCode; | 183 int foundExitCode; |
194 | 184 |
195 checkResult() { | 185 checkResult() { |
196 Expect.isTrue(testOccurred, 'testExitCode($marker, $type) did not occur'); | 186 Expect.isTrue(testOccurred, 'testExitCode($marker, $type) did not occur'); |
197 if (foundExitCode == null) foundExitCode = 0; | 187 if (foundExitCode == null) foundExitCode = 0; |
198 print('testExitCode($marker, $type) ' | 188 print('testExitCode($marker, $type) ' |
199 'exitCode=$foundExitCode expected=$expectedExitCode'); | 189 'exitCode=$foundExitCode expected=$expectedExitCode'); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 int countResults(Map runType) { | 255 int countResults(Map runType) { |
266 return runType.length * | 256 return runType.length * |
267 tests.values.where((r) => r == runType).length; | 257 tests.values.where((r) => r == runType).length; |
268 } | 258 } |
269 | 259 |
270 Expect.equals(countResults(beforeRun) + countResults(duringRun), | 260 Expect.equals(countResults(beforeRun) + countResults(duringRun), |
271 checkedResults); | 261 checkedResults); |
272 asyncEnd(); | 262 asyncEnd(); |
273 }); | 263 }); |
274 } | 264 } |
OLD | NEW |