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