OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // VMOptions=--compile_all --error_on_bad_type --error_on_bad_override |
| 5 |
| 6 import 'package:observatory/service_io.dart'; |
| 7 import 'package:unittest/unittest.dart'; |
| 8 import 'test_helper.dart'; |
| 9 import 'dart:async'; |
| 10 import 'dart:developer'; |
| 11 |
| 12 doThrow() { |
| 13 throw "TheException"; // Line 13. |
| 14 return "end of doThrow"; |
| 15 } |
| 16 |
| 17 doCaught() { |
| 18 try { |
| 19 doThrow(); |
| 20 } catch (e) {} |
| 21 return "end of doCaught"; |
| 22 } |
| 23 |
| 24 doUncaught() { |
| 25 doThrow(); |
| 26 return "end of doUncaught"; |
| 27 } |
| 28 |
| 29 var tests = [ |
| 30 |
| 31 (Isolate isolate) async { |
| 32 var lib = await isolate.rootLibrary.reload(); |
| 33 |
| 34 var onPaused = null; |
| 35 var onResume = null; |
| 36 |
| 37 var subscription; |
| 38 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { |
| 39 print("Event $event"); |
| 40 if (event.kind == ServiceEvent.kPauseException) { |
| 41 if (onPaused == null) throw "Unexpected pause event $event"; |
| 42 var t = onPaused; |
| 43 onPaused = null; |
| 44 t.complete(event); |
| 45 } |
| 46 if (event.kind == ServiceEvent.kResume) { |
| 47 if (onResume == null) throw "Unexpected resume event $event"; |
| 48 var t = onResume; |
| 49 onResume = null; |
| 50 t.complete(event); |
| 51 } |
| 52 }); |
| 53 |
| 54 test(String pauseInfo, |
| 55 String expression, |
| 56 bool shouldPause, |
| 57 bool shouldBeCaught) async { |
| 58 print("Evaluating $expression with pause on $pauseInfo exception"); |
| 59 |
| 60 expect((await isolate.setExceptionPauseInfo(pauseInfo)) is DartError, |
| 61 isFalse); |
| 62 |
| 63 var t; |
| 64 if (shouldPause) { |
| 65 t = new Completer(); |
| 66 onPaused = t; |
| 67 } |
| 68 var fres = lib.evaluate(expression); |
| 69 if (shouldPause) { |
| 70 await t.future; |
| 71 |
| 72 var stack = await isolate.getStack(); |
| 73 expect(stack['frames'][0].function.name, equals('doThrow')); |
| 74 // Ugh, no .line. expect(stack['frames'][0].location.line, equals(17)); |
| 75 |
| 76 t = new Completer(); |
| 77 onResume = t; |
| 78 isolate.resume(); |
| 79 await t.future; |
| 80 } |
| 81 |
| 82 var res = await fres; |
| 83 print(res); |
| 84 if (shouldBeCaught) { |
| 85 expect(res.isInstance, isTrue); |
| 86 expect(res.isString, isTrue); |
| 87 expect(res.valueAsString, equals("end of doCaught")); |
| 88 } else { |
| 89 expect(res.isError, isTrue); |
| 90 await res.load(); // Weird? |
| 91 expect(res.exception.isInstance, isTrue); |
| 92 expect(res.exception.isString, isTrue); |
| 93 expect(res.exception.valueAsString, equals("TheException")); |
| 94 } |
| 95 } |
| 96 |
| 97 await test("all", "doCaught()", true, true); |
| 98 await test("all", "doUncaught()", true, false); |
| 99 |
| 100 await test("unhandled", "doCaught()", false, true); |
| 101 await test("unhandled", "doUncaught()", true, false); |
| 102 |
| 103 await test("none", "doCaught()", false, true); |
| 104 await test("none", "doUncaught()", false, false); |
| 105 |
| 106 subscription.cancel(); |
| 107 }, |
| 108 |
| 109 ]; |
| 110 |
| 111 main(args) => runIsolateTests(args, tests); |
OLD | NEW |