| 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, errors, warnings, etc. | 5 // Test the exit code of dart2js in case of exceptions, errors, warnings, etc. |
| 6 | 6 |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:io' show Platform; | 9 import 'dart:io' show Platform; |
| 10 | 10 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 TestCompiler get compiler => super.compiler; | 130 TestCompiler get compiler => super.compiler; |
| 131 | 131 |
| 132 void computeClassMembers(ClassElement element) { | 132 void computeClassMembers(ClassElement element) { |
| 133 compiler.test('ResolverTask.computeClassMembers'); | 133 compiler.test('ResolverTask.computeClassMembers'); |
| 134 super.computeClassMembers(element); | 134 super.computeClassMembers(element); |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 | 137 |
| 138 int checkedResults = 0; | 138 int checkedResults = 0; |
| 139 | 139 |
| 140 Future testExitCode(String marker, String type, int expectedExitCode) { | 140 Future testExitCode( |
| 141 String marker, String type, int expectedExitCode, List options) { |
| 141 bool testOccurred = false; | 142 bool testOccurred = false; |
| 142 | 143 |
| 143 void onTest(String testMarker, String testType) { | 144 void onTest(String testMarker, String testType) { |
| 144 if (testMarker == marker && testType == type) { | 145 if (testMarker == marker && testType == type) { |
| 145 testOccurred = true; | 146 testOccurred = true; |
| 146 } | 147 } |
| 147 } | 148 } |
| 148 return new Future(() { | 149 return new Future(() { |
| 149 Future<api.CompilationResult> compile( | 150 Future<api.CompilationResult> compile( |
| 150 Uri script, | 151 Uri script, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 190 |
| 190 void exit(exitCode) { | 191 void exit(exitCode) { |
| 191 if (foundExitCode == null) { | 192 if (foundExitCode == null) { |
| 192 foundExitCode = exitCode; | 193 foundExitCode = exitCode; |
| 193 } | 194 } |
| 194 }; | 195 }; |
| 195 | 196 |
| 196 entry.exitFunc = exit; | 197 entry.exitFunc = exit; |
| 197 entry.compileFunc = compile; | 198 entry.compileFunc = compile; |
| 198 | 199 |
| 199 Future result = entry.internalMain( | 200 List<String> args = new List<String>.from(options) |
| 200 ["tests/compiler/dart2js/exit_code_helper.dart"]); | 201 ..add("tests/compiler/dart2js/exit_code_helper.dart"); |
| 202 Future result = entry.internalMain(args); |
| 201 return result.catchError((e, s) { | 203 return result.catchError((e, s) { |
| 202 // Capture crashes. | 204 // Capture crashes. |
| 203 }).whenComplete(checkResult); | 205 }).whenComplete(checkResult); |
| 204 }); | 206 }); |
| 205 } | 207 } |
| 206 | 208 |
| 207 Future testExitCodes(String marker, Map<String,int> expectedExitCodes) { | 209 Future testExitCodes( |
| 210 String marker, Map<String,int> expectedExitCodes, List<String> options) { |
| 208 return Future.forEach(expectedExitCodes.keys, (String type) { | 211 return Future.forEach(expectedExitCodes.keys, (String type) { |
| 209 return testExitCode(marker, type, expectedExitCodes[type]); | 212 return testExitCode(marker, type, expectedExitCodes[type], options); |
| 210 }); | 213 }); |
| 211 } | 214 } |
| 212 | 215 |
| 213 void main() { | 216 void main() { |
| 214 bool isCheckedMode = false; | 217 bool isCheckedMode = false; |
| 215 assert((isCheckedMode = true)); | 218 assert((isCheckedMode = true)); |
| 216 | 219 |
| 217 final beforeRun = { | 220 Map _expectedExitCode({bool beforeRun: false, bool fatalWarnings: false}) { |
| 218 '': 0, | 221 if (beforeRun) { |
| 219 'NoSuchMethodError': 253, | 222 return { |
| 220 'assert': isCheckedMode ? 253 : 0, | 223 '': 0, |
| 221 'invariant': 253 | 224 'NoSuchMethodError': 253, |
| 222 }; | 225 'assert': isCheckedMode ? 253 : 0, |
| 226 'invariant': 253 |
| 227 }; |
| 228 } |
| 223 | 229 |
| 224 final duringRun = { | 230 // duringRun: |
| 225 '': 0, | 231 return { |
| 226 'NoSuchMethodError': 253, | 232 '': 0, |
| 227 'assert': isCheckedMode ? 253 : 0, | 233 'NoSuchMethodError': 253, |
| 228 'invariant': 253, | 234 'assert': isCheckedMode ? 253 : 0, |
| 229 'warning': 0, | 235 'invariant': 253, |
| 230 'error': 1, | 236 'warning': fatalWarnings ? 1 : 0, |
| 231 'internalError': 253, | 237 'error': 1, |
| 232 }; | 238 'internalError': 253, |
| 239 }; |
| 240 } |
| 233 | 241 |
| 242 const beforeRun = false; |
| 243 const duringRun = true; |
| 234 final tests = { | 244 final tests = { |
| 235 'Compiler': beforeRun, | 245 'Compiler': beforeRun, |
| 236 'Compiler.run': beforeRun, | 246 'Compiler.run': beforeRun, |
| 237 'Compiler.onLibraryScanned': beforeRun, | 247 'Compiler.onLibraryScanned': beforeRun, |
| 238 'Compiler.onLibrariesLoaded': beforeRun, | 248 'Compiler.onLibrariesLoaded': beforeRun, |
| 239 'ScannerTask.scanElements': duringRun, | 249 'ScannerTask.scanElements': duringRun, |
| 240 'Compiler.withCurrentElement': duringRun, | 250 'Compiler.withCurrentElement': duringRun, |
| 241 'Compiler.analyzeElement': duringRun, | 251 'Compiler.analyzeElement': duringRun, |
| 242 'Compiler.codegen': duringRun, | 252 'Compiler.codegen': duringRun, |
| 243 'ResolverTask.computeClassMembers': duringRun, | 253 'ResolverTask.computeClassMembers': duringRun, |
| 244 }; | 254 }; |
| 255 int totalExpectedErrors = 0; |
| 245 | 256 |
| 246 asyncStart(); | 257 asyncTest(() async { |
| 247 Future.forEach(tests.keys, (marker) { | 258 for (String marker in tests.keys) { |
| 248 return testExitCodes(marker, tests[marker]); | 259 var expected = _expectedExitCode(beforeRun: tests[marker]); |
| 249 }).then((_) { | 260 totalExpectedErrors += expected.length; |
| 250 int countResults(Map runType) { | 261 await testExitCodes(marker, expected, []); |
| 251 return runType.length * | 262 |
| 252 tests.values.where((r) => r == runType).length; | 263 expected = _expectedExitCode( |
| 264 beforeRun: tests[marker], fatalWarnings: true); |
| 265 totalExpectedErrors += expected.length; |
| 266 await testExitCodes(marker, expected, ['--fatal-warnings']); |
| 253 } | 267 } |
| 254 | 268 |
| 255 Expect.equals(countResults(beforeRun) + countResults(duringRun), | 269 Expect.equals(totalExpectedErrors, checkedResults); |
| 256 checkedResults); | |
| 257 asyncEnd(); | |
| 258 }); | 270 }); |
| 259 } | 271 } |
| OLD | NEW |