| 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<api.CompilationResult> compile( | 155 Future<String> compile(Uri script, |
| 156 Uri script, | 156 Uri libraryRoot, |
| 157 Uri libraryRoot, | 157 Uri packageRoot, |
| 158 Uri packageRoot, | 158 api.CompilerInputProvider inputProvider, |
| 159 api.CompilerInputProvider inputProvider, | 159 api.DiagnosticHandler handler, |
| 160 api.DiagnosticHandler handler, | 160 [List<String> options = const [], |
| 161 [List<String> options = const [], | 161 api.CompilerOutputProvider outputProvider, |
| 162 api.CompilerOutputProvider outputProvider, | 162 Map<String, dynamic> environment = const {}]) { |
| 163 Map<String, dynamic> environment = const {}]) { | |
| 164 libraryRoot = Platform.script.resolve('../../../sdk/'); | 163 libraryRoot = Platform.script.resolve('../../../sdk/'); |
| 165 outputProvider = NullSink.outputProvider; | 164 outputProvider = NullSink.outputProvider; |
| 166 // Use this to silence the test when debugging: | 165 // Use this to silence the test when debugging: |
| 167 // handler = (uri, begin, end, message, kind) {}; | 166 // handler = (uri, begin, end, message, kind) {}; |
| 168 Compiler compiler = new TestCompiler(inputProvider, | 167 Compiler compiler = new TestCompiler(inputProvider, |
| 169 outputProvider, | 168 outputProvider, |
| 170 handler, | 169 handler, |
| 171 libraryRoot, | 170 libraryRoot, |
| 172 packageRoot, | 171 packageRoot, |
| 173 options, | 172 options, |
| 174 environment, | 173 environment, |
| 175 marker, | 174 marker, |
| 176 type, | 175 type, |
| 177 onTest); | 176 onTest); |
| 178 return compiler.run(script).then((bool success) { | 177 return compiler.run(script).then((_) { |
| 179 return new api.CompilationResult(compiler, isSuccess: success); | 178 String code = compiler.assembledCode; |
| 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; |
| 180 }); | 190 }); |
| 181 } | 191 } |
| 182 | 192 |
| 183 int foundExitCode; | 193 int foundExitCode; |
| 184 | 194 |
| 185 checkResult() { | 195 checkResult() { |
| 186 Expect.isTrue(testOccurred, 'testExitCode($marker, $type) did not occur'); | 196 Expect.isTrue(testOccurred, 'testExitCode($marker, $type) did not occur'); |
| 187 if (foundExitCode == null) foundExitCode = 0; | 197 if (foundExitCode == null) foundExitCode = 0; |
| 188 print('testExitCode($marker, $type) ' | 198 print('testExitCode($marker, $type) ' |
| 189 'exitCode=$foundExitCode expected=$expectedExitCode'); | 199 'exitCode=$foundExitCode expected=$expectedExitCode'); |
| 190 Expect.equals(expectedExitCode, foundExitCode, | 200 Expect.equals(expectedExitCode, foundExitCode, |
| 191 'testExitCode($marker, $type) ' | 201 'testExitCode($marker, $type) ' |
| 192 'exitCode=$foundExitCode expected=${expectedExitCode}'); | 202 'exitCode=$foundExitCode expected=${expectedExitCode}'); |
| 193 checkedResults++; | 203 checkedResults++; |
| 194 } | 204 } |
| 195 | 205 |
| 196 void exit(exitCode) { | 206 void exit(exitCode) { |
| 197 if (foundExitCode == null) { | 207 if (foundExitCode == null) { |
| 198 foundExitCode = exitCode; | 208 foundExitCode = exitCode; |
| 199 } | 209 } |
| 200 }; | 210 }; |
| 201 | 211 |
| 202 entry.exitFunc = exit; | 212 entry.exitFunc = exit; |
| 203 entry.compileFunc = compile; | 213 entry.compileFunc = compile; |
| 204 | 214 |
| 205 Future result = entry.internalMain( | 215 Future result = entry.internalMain( |
| 206 ["tests/compiler/dart2js/exit_code_helper.dart"]); | 216 ["tests/compiler/dart2js/exit_code_helper.dart"]); |
| 207 return result.catchError((e, s) { | 217 return result.whenComplete(checkResult); |
| 208 // Capture crashes. | |
| 209 }).whenComplete(checkResult); | |
| 210 }); | 218 }); |
| 211 } | 219 } |
| 212 | 220 |
| 213 Future testExitCodes(String marker, Map<String,int> expectedExitCodes) { | 221 Future testExitCodes(String marker, Map<String,int> expectedExitCodes) { |
| 214 return Future.forEach(expectedExitCodes.keys, (String type) { | 222 return Future.forEach(expectedExitCodes.keys, (String type) { |
| 215 return testExitCode(marker, type, expectedExitCodes[type]); | 223 return testExitCode(marker, type, expectedExitCodes[type]); |
| 216 }); | 224 }); |
| 217 } | 225 } |
| 218 | 226 |
| 219 void main() { | 227 void main() { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 int countResults(Map runType) { | 265 int countResults(Map runType) { |
| 258 return runType.length * | 266 return runType.length * |
| 259 tests.values.where((r) => r == runType).length; | 267 tests.values.where((r) => r == runType).length; |
| 260 } | 268 } |
| 261 | 269 |
| 262 Expect.equals(countResults(beforeRun) + countResults(duringRun), | 270 Expect.equals(countResults(beforeRun) + countResults(duringRun), |
| 263 checkedResults); | 271 checkedResults); |
| 264 asyncEnd(); | 272 asyncEnd(); |
| 265 }); | 273 }); |
| 266 } | 274 } |
| OLD | NEW |