Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: runtime/observatory/tests/service/pause_on_exceptions_test.dart

Issue 2767533002: Revert "Fix observatory tests broken by running dartfmt." (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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();
30 28
31 var onPaused = null; 29 (Isolate isolate) async {
32 var onResume = null; 30 var lib = await isolate.rootLibrary.reload();
33 31
34 var stream = await isolate.vm.getEventStream(VM.kDebugStream); 32 var onPaused = null;
35 var subscription; 33 var onResume = null;
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 });
51 34
52 test(String pauseMode, String expression, bool shouldPause, 35 var stream = await isolate.vm.getEventStream(VM.kDebugStream);
53 bool shouldBeCaught) async { 36 var subscription;
54 print("Evaluating $expression with pause on $pauseMode exception"); 37 subscription = stream.listen((ServiceEvent event) {
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 });
55 52
56 expect((await isolate.setExceptionPauseMode(pauseMode)) is DartError, 53 test(String pauseMode,
57 isFalse); 54 String expression,
55 bool shouldPause,
56 bool shouldBeCaught) async {
57 print("Evaluating $expression with pause on $pauseMode exception");
58 58
59 var t; 59 expect((await isolate.setExceptionPauseMode(pauseMode)) is DartError,
60 if (shouldPause) { 60 isFalse);
61 t = new Completer();
62 onPaused = t;
63 }
64 var fres = lib.evaluate(expression);
65 if (shouldPause) {
66 await t.future;
67 61
68 var stack = await isolate.getStack(); 62 var t;
69 expect(stack['frames'][0].function.name, equals('doThrow')); 63 if (shouldPause) {
70 // Ugh, no .line. expect(stack['frames'][0].location.line, equals(17)); 64 t = new Completer();
65 onPaused = t;
66 }
67 var fres = lib.evaluate(expression);
68 if (shouldPause) {
69 await t.future;
71 70
72 t = new Completer(); 71 var stack = await isolate.getStack();
73 onResume = t; 72 expect(stack['frames'][0].function.name, equals('doThrow'));
74 isolate.resume(); 73 // Ugh, no .line. expect(stack['frames'][0].location.line, equals(17));
75 await t.future;
76 }
77 74
78 var res = await fres; 75 t = new Completer();
79 print(res); 76 onResume = t;
80 if (shouldBeCaught) { 77 isolate.resume();
81 expect(res.isInstance, isTrue); 78 await t.future;
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 }
91 } 79 }
92 80
93 await test("All", "doCaught()", true, true); 81 var res = await fres;
94 await test("All", "doUncaught()", true, false); 82 print(res);
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("Unhandled", "doCaught()", false, true); 96 await test("All", "doCaught()", true, true);
97 await test("Unhandled", "doUncaught()", true, false); 97 await test("All", "doUncaught()", true, false);
98 98
99 await test("None", "doCaught()", false, true); 99 await test("Unhandled", "doCaught()", false, true);
100 await test("None", "doUncaught()", false, false); 100 await test("Unhandled", "doUncaught()", true, false);
101 101
102 subscription.cancel(); 102 await test("None", "doCaught()", false, true);
103 }, 103 await test("None", "doUncaught()", false, false);
104
105 subscription.cancel();
106 },
107
104 ]; 108 ];
105 109
106 main(args) => runIsolateTests(args, tests); 110 main(args) => runIsolateTests(args, tests);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698