|
| 1 | +// Copyright (c) 2024, 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 | + |
| 5 | +import 'dart:developer'; |
| 6 | +import 'package:test/test.dart'; |
| 7 | +import 'package:vm_service/vm_service.dart'; |
| 8 | +import 'common/service_test_common.dart'; |
| 9 | +import 'common/test_helper.dart'; |
| 10 | + |
| 11 | +// AUTOGENERATED START |
| 12 | +// |
| 13 | +// Update these constants by running: |
| 14 | +// |
| 15 | +// dart pkg/vm_service/test/update_line_numbers.dart <test.dart> |
| 16 | +// |
| 17 | +const LINE_CLASS_A = 29; |
| 18 | +const LINE_CLASS_A_NAMED = 34; |
| 19 | +const LINE_CLASS_A_NAMED2_BREAK_1 = 40; |
| 20 | +const LINE_CLASS_A_NAMED2_BREAK_2 = 43; |
| 21 | +const LINE_CLASS_A_NAMED2_BREAK_3 = 46; |
| 22 | +const LINE_CLASS_B = 55; |
| 23 | +// AUTOGENERATED END |
| 24 | + |
| 25 | +class A { |
| 26 | + List list; |
| 27 | + A(this.list) { |
| 28 | + list = [3]; |
| 29 | + debugger(); // LINE_CLASS_A |
| 30 | + print(list); |
| 31 | + } |
| 32 | + A.named(this.list) { |
| 33 | + list = [4]; |
| 34 | + debugger(); // LINE_CLASS_A_NAMED |
| 35 | + print(list); |
| 36 | + } |
| 37 | + A.named2(this.list) { |
| 38 | + { |
| 39 | + final list = [5]; |
| 40 | + debugger(); // LINE_CLASS_A_NAMED2_BREAK_1 |
| 41 | + print(list); |
| 42 | + } |
| 43 | + debugger(); // LINE_CLASS_A_NAMED2_BREAK_2 |
| 44 | + print(list); |
| 45 | + list = [6]; |
| 46 | + debugger(); // LINE_CLASS_A_NAMED2_BREAK_3 |
| 47 | + print(list); |
| 48 | + } |
| 49 | + A.noDebugger(this.list); |
| 50 | +} |
| 51 | + |
| 52 | +class B extends A { |
| 53 | + B(super.list) : super.noDebugger() { |
| 54 | + list = [7]; |
| 55 | + debugger(); // LINE_CLASS_B |
| 56 | + print(list); |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +void code() { |
| 61 | + A([1, 2]); |
| 62 | + A.named([1, 2]); |
| 63 | + A.named2([1, 2]); |
| 64 | + B([1, 2]); |
| 65 | +} |
| 66 | + |
| 67 | +Future<void> Function(VmService, IsolateRef) test( |
| 68 | + String topFrameName, |
| 69 | + List<String> availableVariables, |
| 70 | + List<(String evaluate, String evaluationResult)> evaluations, |
| 71 | +) { |
| 72 | + return (VmService service, IsolateRef isolateRef) async { |
| 73 | + final isolateId = isolateRef.id!; |
| 74 | + final stack = await service.getStack(isolateId); |
| 75 | + |
| 76 | + // Make sure we are in the right place. |
| 77 | + expect(stack.frames!.length, greaterThanOrEqualTo(1)); |
| 78 | + expect(stack.frames![0].function!.name, topFrameName); |
| 79 | + |
| 80 | + // Check variables. |
| 81 | + expect( |
| 82 | + (stack.frames![0].vars ?? []).map((v) => v.name).toList(), |
| 83 | + equals(availableVariables), |
| 84 | + ); |
| 85 | + |
| 86 | + // Evaluate. |
| 87 | + for (final (expression, expectedResult) in evaluations) { |
| 88 | + final dynamic result = await service.evaluateInFrame( |
| 89 | + isolateId, |
| 90 | + /* frame = */ 0, |
| 91 | + expression, |
| 92 | + ); |
| 93 | + print(result.valueAsString); |
| 94 | + expect(result.valueAsString, equals(expectedResult)); |
| 95 | + } |
| 96 | + }; |
| 97 | +} |
| 98 | + |
| 99 | +final tests = <IsolateTest>[ |
| 100 | + hasStoppedAtBreakpoint, |
| 101 | + stoppedAtLine(LINE_CLASS_A), |
| 102 | + test('A', ['this'], [('list.toString()', '[3]')]), |
| 103 | + resumeIsolate, |
| 104 | + hasStoppedAtBreakpoint, |
| 105 | + stoppedAtLine(LINE_CLASS_A_NAMED), |
| 106 | + test('A.named', ['this'], [('list.toString()', '[4]')]), |
| 107 | + resumeIsolate, |
| 108 | + hasStoppedAtBreakpoint, |
| 109 | + stoppedAtLine(LINE_CLASS_A_NAMED2_BREAK_1), |
| 110 | + test( |
| 111 | + 'A.named2', |
| 112 | + ['this', 'list'], |
| 113 | + [ |
| 114 | + ('list.toString()', '[5]'), |
| 115 | + ('this.list.toString()', '[1, 2]'), |
| 116 | + ], |
| 117 | + ), |
| 118 | + resumeIsolate, |
| 119 | + hasStoppedAtBreakpoint, |
| 120 | + stoppedAtLine(LINE_CLASS_A_NAMED2_BREAK_2), |
| 121 | + test('A.named2', ['this'], [('list.toString()', '[1, 2]')]), |
| 122 | + resumeIsolate, |
| 123 | + hasStoppedAtBreakpoint, |
| 124 | + stoppedAtLine(LINE_CLASS_A_NAMED2_BREAK_3), |
| 125 | + test('A.named2', ['this'], [('list.toString()', '[6]')]), |
| 126 | + resumeIsolate, |
| 127 | + hasStoppedAtBreakpoint, |
| 128 | + stoppedAtLine(LINE_CLASS_B), |
| 129 | + test('B', ['this'], [('list.toString()', '[7]')]), |
| 130 | +]; |
| 131 | + |
| 132 | +void main([args = const <String>[]]) => runIsolateTests( |
| 133 | + args, |
| 134 | + tests, |
| 135 | + 'issue_59661.dart', |
| 136 | + testeeConcurrent: code, |
| 137 | + pauseOnStart: false, |
| 138 | + pauseOnExit: true, |
| 139 | + ); |
0 commit comments