|
| 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 members initialized in primary initializer scope can |
| 14 | +/// 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_t03.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_t02.dart |
| 33 | +// |
| 34 | +const LINE_A = 41; |
| 35 | +const LINE_B = 44; |
| 36 | +const LINE_C = 48; |
| 37 | +const LINE_D = 49; |
| 38 | +const LINE_E = 50; |
| 39 | +// AUTOGENERATED END |
| 40 | + |
| 41 | +class C1(var String x); // LINE_A |
| 42 | + |
| 43 | +class C2 { |
| 44 | + this(final String x); // LINE_B |
| 45 | +} |
| 46 | + |
| 47 | +void testeeMain() { |
| 48 | + debugger(); // LINE_C |
| 49 | + C1("xxx"); // LINE_D |
| 50 | + C2("yyy"); // LINE_E |
| 51 | +} |
| 52 | + |
| 53 | +final tests = <IsolateTest>[ |
| 54 | + hasStoppedAtBreakpoint, |
| 55 | + stoppedAtLine(LINE_C), |
| 56 | + stepInto, |
| 57 | + stoppedAtLine(LINE_D), |
| 58 | + stepInto, |
| 59 | + stoppedAtLine(LINE_A), |
| 60 | + (VmService service, IsolateRef isolateRef) async { |
| 61 | + final isolateId = isolateRef.id!; |
| 62 | + final xRef1 = |
| 63 | + await service.evaluateInFrame(isolateId, 0, 'x') as InstanceRef; |
| 64 | + Expect.equals("null", xRef1.valueAsString); |
| 65 | + final xRef2 = |
| 66 | + await service.evaluateInFrame(isolateId, 0, 'this.x') as InstanceRef; |
| 67 | + Expect.equals("null", xRef2.valueAsString); |
| 68 | + }, |
| 69 | + stepInto, |
| 70 | + (VmService service, IsolateRef isolateRef) async { |
| 71 | + final isolateId = isolateRef.id!; |
| 72 | + final xRef1 = |
| 73 | + await service.evaluateInFrame(isolateId, 0, 'x') as InstanceRef; |
| 74 | + Expect.equals('xxx', xRef1.valueAsString); |
| 75 | + final xRef2 = |
| 76 | + await service.evaluateInFrame(isolateId, 0, 'this.x') as InstanceRef; |
| 77 | + Expect.equals('xxx', xRef2.valueAsString); |
| 78 | + }, |
| 79 | + stepInto, |
| 80 | + stoppedAtLine(LINE_E), |
| 81 | + stepInto, |
| 82 | + stoppedAtLine(LINE_B), |
| 83 | + (VmService service, IsolateRef isolateRef) async { |
| 84 | + final isolateId = isolateRef.id!; |
| 85 | + final xRef1 = |
| 86 | + await service.evaluateInFrame(isolateId, 0, 'x') as InstanceRef; |
| 87 | + Expect.equals("null", xRef1.valueAsString); |
| 88 | + final xRef2 = |
| 89 | + await service.evaluateInFrame(isolateId, 0, 'this.x') as InstanceRef; |
| 90 | + Expect.equals("null", xRef2.valueAsString); |
| 91 | + }, |
| 92 | + stepInto, |
| 93 | + (VmService service, IsolateRef isolateRef) async { |
| 94 | + final isolateId = isolateRef.id!; |
| 95 | + final xRef1 = |
| 96 | + await service.evaluateInFrame(isolateId, 0, 'x') as InstanceRef; |
| 97 | + Expect.equals('yyy', xRef1.valueAsString); |
| 98 | + final xRef2 = |
| 99 | + await service.evaluateInFrame(isolateId, 0, 'this.x') as InstanceRef; |
| 100 | + Expect.equals('yyy', xRef2.valueAsString); |
| 101 | + }, |
| 102 | +]; |
| 103 | + |
| 104 | +void main([args = const <String>[]]) => runIsolateTests( |
| 105 | + args, |
| 106 | + tests, |
| 107 | + 'declaring_constructors_t02.dart', |
| 108 | + pauseOnExit: true, |
| 109 | + testeeConcurrent: testeeMain, |
| 110 | +); |
0 commit comments