blob: 9da7dfcbdfaafedd0b873ddc1427084e80c6f134 [file] [log] [blame]
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'package:test/test.dart';
import 'package:vm_service/vm_service.dart';
import 'common/test_helper.dart';
doThrow() {
throw "TheException"; // Line 13.
doCaught() {
try {
} catch (e) {
return "end of doCaught";
doUncaught() {
return "end of doUncaught";
final tests = <IsolateTest>[
(VmService service, IsolateRef isolateRef) async {
final isolate = await service.getIsolate(!);
final lib = await service.getObject(!, isolate.rootLib!.id!);
Completer? onPaused;
Completer? onResume;
final stream = service.onDebugEvent;
final subscription = stream.listen((Event event) {
print("Event $event");
if (event.kind == EventKind.kPauseException) {
if (onPaused == null) throw "Unexpected pause event $event";
final t = onPaused;
onPaused = null;
if (event.kind == EventKind.kResume) {
if (onResume == null) throw "Unexpected resume event $event";
final t = onResume;
onResume = null;
await service.streamListen(EventStreams.kDebug);
test(String pauseMode, String expression, bool shouldPause,
bool shouldBeCaught) async {
print("Evaluating $expression with pause on $pauseMode exception");
await service.setIsolatePauseMode(!,
exceptionPauseMode: pauseMode);
late Completer t;
if (shouldPause) {
t = Completer();
onPaused = t;
final fres = service.evaluate(!,!, expression);
if (shouldPause) {
await t.future;
final stack = await service.getStack(!);
expect(stack.frames![0].function!.name, 'doThrow');
t = Completer();
onResume = t;
await service.resume(!);
await t.future;
dynamic res = await fres;
if (shouldBeCaught) {
expect(res is InstanceRef, true);
expect(res.kind, 'String');
expect(res.valueAsString, equals("end of doCaught"));
} else {
expect(res is ErrorRef, true);
res = await service.getObject(!,!);
expect(res is Error, true);
expect(res.exception.kind, 'String');
expect(res.exception.valueAsString, equals("TheException"));
await test("All", "doCaught()", true, true);
await test("All", "doUncaught()", true, false);
await test("Unhandled", "doCaught()", false, true);
await test("Unhandled", "doUncaught()", true, false);
await test("None", "doCaught()", false, true);
await test("None", "doUncaught()", false, false);
await subscription.cancel();
main([args = const <String>[]]) => runIsolateTests(