| // Copyright (c) 2024, 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:developer'; |
| import 'package:test/test.dart'; |
| import 'package:vm_service/vm_service.dart'; |
| import 'common/service_test_common.dart'; |
| import 'common/test_helper.dart'; |
| |
| // AUTOGENERATED START |
| // |
| // Update these constants by running: |
| // |
| // dart pkg/vm_service/test/update_line_numbers.dart <test.dart> |
| // |
| const LINE_CLASS_A = 29; |
| const LINE_CLASS_A_NAMED = 34; |
| const LINE_CLASS_A_NAMED2_BREAK_1 = 40; |
| const LINE_CLASS_A_NAMED2_BREAK_2 = 43; |
| const LINE_CLASS_A_NAMED2_BREAK_3 = 46; |
| const LINE_CLASS_B = 55; |
| // AUTOGENERATED END |
| |
| class A { |
| List list; |
| A(this.list) { |
| list = [3]; |
| debugger(); // LINE_CLASS_A |
| print(list); |
| } |
| A.named(this.list) { |
| list = [4]; |
| debugger(); // LINE_CLASS_A_NAMED |
| print(list); |
| } |
| A.named2(this.list) { |
| { |
| final list = [5]; |
| debugger(); // LINE_CLASS_A_NAMED2_BREAK_1 |
| print(list); |
| } |
| debugger(); // LINE_CLASS_A_NAMED2_BREAK_2 |
| print(list); |
| list = [6]; |
| debugger(); // LINE_CLASS_A_NAMED2_BREAK_3 |
| print(list); |
| } |
| A.noDebugger(this.list); |
| } |
| |
| class B extends A { |
| B(super.list) : super.noDebugger() { |
| list = [7]; |
| debugger(); // LINE_CLASS_B |
| print(list); |
| } |
| } |
| |
| void code() { |
| A([1, 2]); |
| A.named([1, 2]); |
| A.named2([1, 2]); |
| B([1, 2]); |
| } |
| |
| Future<void> Function(VmService, IsolateRef) test( |
| String topFrameName, |
| List<String> availableVariables, |
| List<(String evaluate, String evaluationResult)> evaluations, |
| ) { |
| return (VmService service, IsolateRef isolateRef) async { |
| final isolateId = isolateRef.id!; |
| final stack = await service.getStack(isolateId); |
| |
| // Make sure we are in the right place. |
| expect(stack.frames!.length, greaterThanOrEqualTo(1)); |
| expect(stack.frames![0].function!.name, topFrameName); |
| |
| // Check variables. |
| expect( |
| (stack.frames![0].vars ?? []).map((v) => v.name).toList(), |
| equals(availableVariables), |
| ); |
| |
| // Evaluate. |
| for (final (expression, expectedResult) in evaluations) { |
| final dynamic result = await service.evaluateInFrame( |
| isolateId, |
| /* frame = */ 0, |
| expression, |
| ); |
| print(result.valueAsString); |
| expect(result.valueAsString, equals(expectedResult)); |
| } |
| }; |
| } |
| |
| final tests = <IsolateTest>[ |
| hasStoppedAtBreakpoint, |
| stoppedAtLine(LINE_CLASS_A), |
| test('A', ['this'], [('list.toString()', '[3]')]), |
| resumeIsolate, |
| hasStoppedAtBreakpoint, |
| stoppedAtLine(LINE_CLASS_A_NAMED), |
| test('A.named', ['this'], [('list.toString()', '[4]')]), |
| resumeIsolate, |
| hasStoppedAtBreakpoint, |
| stoppedAtLine(LINE_CLASS_A_NAMED2_BREAK_1), |
| test( |
| 'A.named2', |
| ['this', 'list'], |
| [ |
| ('list.toString()', '[5]'), |
| ('this.list.toString()', '[1, 2]'), |
| ], |
| ), |
| resumeIsolate, |
| hasStoppedAtBreakpoint, |
| stoppedAtLine(LINE_CLASS_A_NAMED2_BREAK_2), |
| test('A.named2', ['this'], [('list.toString()', '[1, 2]')]), |
| resumeIsolate, |
| hasStoppedAtBreakpoint, |
| stoppedAtLine(LINE_CLASS_A_NAMED2_BREAK_3), |
| test('A.named2', ['this'], [('list.toString()', '[6]')]), |
| resumeIsolate, |
| hasStoppedAtBreakpoint, |
| stoppedAtLine(LINE_CLASS_B), |
| test('B', ['this'], [('list.toString()', '[7]')]), |
| ]; |
| |
| void main([args = const <String>[]]) => runIsolateTests( |
| args, |
| tests, |
| 'issue_59661_test.dart', |
| testeeConcurrent: code, |
| pauseOnStart: false, |
| pauseOnExit: true, |
| ); |