|
| 1 | +// Copyright (c) 2025, 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 | +/// @assertion A declaring constructor declaration is a declaration that |
| 6 | +/// contains a `<declaringConstructorSignature>` with a |
| 7 | +/// `<declaringParameterList>`, or a declaration that contains a |
| 8 | +/// `<declaringConstantConstructorSignature>`, or it is a |
| 9 | +/// `<primaryConstructorNoConst>` in the header of a class, enum, or extension |
| 10 | +/// type declaration, together with a declaration in the body that contains a |
| 11 | +/// `<declaringConstructorSignature>`. |
| 12 | +/// |
| 13 | +/// @description Check that declaring constructors invocation and declaration |
| 14 | +/// can be debugged. |
| 15 | + |
| 16 | +
|
| 17 | +// SharedOptions=--enable-experiment=declaring-constructors |
| 18 | + |
| 19 | +import 'dart:developer'; |
| 20 | +import 'package:vm_service/vm_service.dart'; |
| 21 | + |
| 22 | +import '../../../../pkg/vm_service/test/common/service_test_common.dart'; |
| 23 | +import '../../../../pkg/vm_service/test/common/test_helper.dart'; |
| 24 | +import '../Utils/expect.dart'; |
| 25 | + |
| 26 | +const String shortFile = 'declaring_constructors_t01.dart'; |
| 27 | + |
| 28 | +// AUTOGENERATED START |
| 29 | +// |
| 30 | +// Update these constants by running: |
| 31 | +// |
| 32 | +// dart pkg/vm_service/test/update_line_numbers.dart tests/co19/src/VM/declaring_constructors_t01.dart |
| 33 | +// |
| 34 | +const LINE_A = 44; |
| 35 | +const LINE_B = 47; |
| 36 | +const LINE_C = 53; |
| 37 | +const LINE_D = 59; |
| 38 | +const LINE_E = 64; |
| 39 | +const LINE_F = 65; |
| 40 | +const LINE_G = 66; |
| 41 | +const LINE_H = 67; |
| 42 | +// AUTOGENERATED END |
| 43 | + |
| 44 | +class C1(var int v1, final int v2); // LINE_A |
| 45 | + |
| 46 | +class C2 { |
| 47 | + this(var int v1, final int v2); // LINE_B |
| 48 | +} |
| 49 | + |
| 50 | +class C3(int v1, int v2) { |
| 51 | + int v1; |
| 52 | + final int v2; |
| 53 | + this: v1 = v1, v2 = v2; // LINE_C |
| 54 | +} |
| 55 | + |
| 56 | +class C4 { |
| 57 | + int v1; |
| 58 | + final int v2; |
| 59 | + this(int v1, int v2) : v1 = v1, v2 = v2; // LINE_D |
| 60 | +} |
| 61 | + |
| 62 | +void testeeMain() { |
| 63 | + debugger(); |
| 64 | + var c1 = C1(1, 2); // LINE_E |
| 65 | + var c2 = C2(3, 4); // LINE_F |
| 66 | + var c3 = C3(5, 6); // LINE_G |
| 67 | + var c4 = C4(7, 8); // LINE_H |
| 68 | +} |
| 69 | + |
| 70 | +List<String> stops = []; |
| 71 | + |
| 72 | +const List<String> expected = [ |
| 73 | + '$shortFile:$LINE_E:10', // on '=' |
| 74 | + '$shortFile:$LINE_E:12', // on 'C1' |
| 75 | + '$shortFile:$LINE_A:32', // on 'v2' |
| 76 | + '$shortFile:$LINE_A:35', // on ';' |
| 77 | + '$shortFile:$LINE_F:10', // on '=' |
| 78 | + '$shortFile:$LINE_F:12', // on 'C2' |
| 79 | + '$shortFile:$LINE_B:30', // on 'v2' |
| 80 | + '$shortFile:$LINE_B:33', // on ';' |
| 81 | + '$shortFile:$LINE_G:10', // on '=' |
| 82 | + '$shortFile:$LINE_G:12', // on 'C3' |
| 83 | + '$shortFile:$LINE_C:18', // on 'v2' |
| 84 | + '$shortFile:$LINE_C:25', // on ';' |
| 85 | + '$shortFile:$LINE_H:10', // on '=' |
| 86 | + '$shortFile:$LINE_H:12', // on 'C4' |
| 87 | + '$shortFile:$LINE_D:35', // on 'v2' |
| 88 | + '$shortFile:$LINE_D:42', // on ';' |
| 89 | +]; |
| 90 | + |
| 91 | +final tests = <IsolateTest>[ |
| 92 | + hasStoppedAtBreakpoint, |
| 93 | + |
| 94 | + // Test interaction of expression evaluation with declaring constructors invocation |
| 95 | + (VmService service, IsolateRef isolateRef) async { |
| 96 | + final isolateId = isolateRef.id!; |
| 97 | + |
| 98 | + InstanceRef response = |
| 99 | + await service.evaluateInFrame(isolateId, 0, 'C1(1, 2).v1') |
| 100 | + as InstanceRef; |
| 101 | + Expect.equals('1', response.valueAsString); |
| 102 | + |
| 103 | + response = |
| 104 | + await service.evaluateInFrame(isolateId, 0, 'C2(3, 4).v2') |
| 105 | + as InstanceRef; |
| 106 | + Expect.equals('4', response.valueAsString); |
| 107 | + |
| 108 | + response = |
| 109 | + await service.evaluateInFrame(isolateId, 0, 'C3(5, 6).v1') |
| 110 | + as InstanceRef; |
| 111 | + Expect.equals('5', response.valueAsString); |
| 112 | + |
| 113 | + response = |
| 114 | + await service.evaluateInFrame(isolateId, 0, 'C4(7, 8).v2') |
| 115 | + as InstanceRef; |
| 116 | + Expect.equals('8', response.valueAsString); |
| 117 | + }, |
| 118 | + |
| 119 | + // Test interaction of breakpoints with declaring constructors. |
| 120 | + (VmService service, IsolateRef isolateRef) async { |
| 121 | + final isolateId = isolateRef.id!; |
| 122 | + final isolate = await service.getIsolate(isolateId); |
| 123 | + final lib = |
| 124 | + (await service.getObject(isolateId, isolate.rootLib!.id!)) as Library; |
| 125 | + final scriptId = lib.scripts!.first.id!; |
| 126 | + |
| 127 | + var breakpoint = await service.addBreakpoint(isolateId, scriptId, LINE_E); |
| 128 | + var (_, (line, column)) = await breakpoint.getLocation(service, isolateRef); |
| 129 | + Expect.isTrue(breakpoint.enabled); |
| 130 | + Expect.equals(LINE_E, line); |
| 131 | + Expect.equals(10, column); // on '=' |
| 132 | + |
| 133 | + breakpoint = await service.addBreakpoint(isolateId, scriptId, LINE_F); |
| 134 | + var (_, (line, column)) = await breakpoint.getLocation(service, isolateRef); |
| 135 | + Expect.isTrue(breakpoint.enabled); |
| 136 | + Expect.equals(LINE_F, line); |
| 137 | + Expect.equals(10, column); // on '=' |
| 138 | + await service.removeBreakpoint(isolateId, breakpoint.id!); |
| 139 | + |
| 140 | + breakpoint = await service.addBreakpoint(isolateId, scriptId, LINE_G); |
| 141 | + var (_, (line, column)) = await breakpoint.getLocation(service, isolateRef); |
| 142 | + Expect.isTrue(breakpoint.enabled); |
| 143 | + Expect.equals(LINE_G, line); |
| 144 | + Expect.equals(10, column); // on '=' |
| 145 | + await service.removeBreakpoint(isolateId, breakpoint.id!); |
| 146 | + |
| 147 | + breakpoint = await service.addBreakpoint(isolateId, scriptId, LINE_H); |
| 148 | + var (_, (line, column)) = await breakpoint.getLocation(service, isolateRef); |
| 149 | + Expect.isTrue(breakpoint.enabled); |
| 150 | + Expect.equals(LINE_H, line); |
| 151 | + Expect.equals(10, column); // on '=' |
| 152 | + await service.removeBreakpoint(isolateId, breakpoint.id!); |
| 153 | + }, |
| 154 | + |
| 155 | + // Test interaction of single-stepping with declaring constructors. |
| 156 | + runStepIntoThroughProgramRecordingStops(stops), |
| 157 | + checkRecordedStops(stops, expected), |
| 158 | +]; |
| 159 | + |
| 160 | +void main([args = const <String>[]]) => runIsolateTests( |
| 161 | + args, |
| 162 | + tests, |
| 163 | + 'declaring_constructors_t01.dart', |
| 164 | + pauseOnExit: true, |
| 165 | + testeeConcurrent: testeeMain, |
| 166 | +); |
0 commit comments