-
Notifications
You must be signed in to change notification settings - Fork 29
#3203. Add tests for private named parameters #3377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| // Copyright (c) 2025, 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. | ||
|
|
||
| /// @assertion We let users use a private name in a named parameter when the | ||
| /// parameter also initializes or declares a field. The compiler removes the `_` | ||
| /// from the argument name but keeps it for the corresponding field. | ||
| /// | ||
| /// @description Check that private named parameters can be debugged. | ||
| /// @author [email protected] | ||
|
|
||
| // SharedOptions=--enable-experiment=declaring-constructors,private-named-parameters | ||
|
|
||
| import 'dart:developer'; | ||
| import 'package:vm_service/vm_service.dart'; | ||
|
|
||
| import '../../../../pkg/vm_service/test/common/service_test_common.dart'; | ||
| import '../../../../pkg/vm_service/test/common/test_helper.dart'; | ||
| import '../Utils/expect.dart'; | ||
|
|
||
| const String shortFile = 'private_named_parameters_t01.dart'; | ||
|
|
||
| // AUTOGENERATED START | ||
| // | ||
| // Update these constants by running: | ||
| // | ||
| // dart pkg/vm_service/test/update_line_numbers.dart tests/co19/src/VM/private_named_parameters_t01.dart | ||
| // | ||
| const LINE_A = 37; | ||
| const LINE_B = 41; | ||
| const LINE_C = 45; | ||
| const LINE_D = 46; | ||
| const LINE_E = 47; | ||
| // AUTOGENERATED END | ||
|
|
||
| class C1({var String _x}); // LINE_A | ||
|
|
||
| class C2 { | ||
| String _x; | ||
| C2({this._x}); // LINE_B | ||
| } | ||
|
|
||
| void testeeMain() { | ||
| debugger(); // LINE_C | ||
| C1(x: "xxx"); // LINE_D | ||
| C2(x: "yyy"); // LINE_E | ||
| } | ||
|
|
||
| final tests = <IsolateTest>[ | ||
| hasStoppedAtBreakpoint, | ||
| stoppedAtLine(LINE_C), | ||
| stepInto, | ||
| stoppedAtLine(LINE_D), | ||
| stepInto, | ||
| stoppedAtLine(LINE_A), | ||
| (VmService service, IsolateRef isolateRef) async { | ||
| final isolateId = isolateRef.id!; | ||
| final xRef1 = | ||
| await service.evaluateInFrame(isolateId, 0, '_x') as InstanceRef; | ||
| Expect.equals("null", xRef1.valueAsString); | ||
| final xRef2 = | ||
| await service.evaluateInFrame(isolateId, 0, 'this._x') as InstanceRef; | ||
| Expect.equals("null", xRef2.valueAsString); | ||
| }, | ||
| stepInto, | ||
| (VmService service, IsolateRef isolateRef) async { | ||
| final isolateId = isolateRef.id!; | ||
| final xRef1 = | ||
| await service.evaluateInFrame(isolateId, 0, '_x') as InstanceRef; | ||
| Expect.equals('xxx', xRef1.valueAsString); | ||
| final xRef2 = | ||
| await service.evaluateInFrame(isolateId, 0, 'this._x') as InstanceRef; | ||
| Expect.equals('xxx', xRef2.valueAsString); | ||
| final xRef3 = await service.evaluateInFrame(isolateId, 0, 'x'); | ||
| Expect.isTrue(xRef3 is ErrorRef); | ||
| final xRef4 = await service.evaluateInFrame(isolateId, 0, 'this.x'); | ||
| Expect.isTrue(xRef4 is ErrorRef); | ||
eernstg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
eernstg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| stepInto, | ||
| stoppedAtLine(LINE_E), | ||
| stepInto, | ||
| stoppedAtLine(LINE_B), | ||
| (VmService service, IsolateRef isolateRef) async { | ||
| final isolateId = isolateRef.id!; | ||
| final xRef1 = | ||
| await service.evaluateInFrame(isolateId, 0, '_x') as InstanceRef; | ||
| Expect.equals("null", xRef1.valueAsString); | ||
| final xRef2 = | ||
| await service.evaluateInFrame(isolateId, 0, 'this._x') as InstanceRef; | ||
| Expect.equals("null", xRef2.valueAsString); | ||
| }, | ||
| stepInto, | ||
| (VmService service, IsolateRef isolateRef) async { | ||
| final isolateId = isolateRef.id!; | ||
| final xRef1 = | ||
| await service.evaluateInFrame(isolateId, 0, '_x') as InstanceRef; | ||
| Expect.equals('yyy', xRef1.valueAsString); | ||
| final xRef2 = | ||
| await service.evaluateInFrame(isolateId, 0, 'this._x') as InstanceRef; | ||
| Expect.equals('yyy', xRef2.valueAsString); | ||
| final xRef3 = await service.evaluateInFrame(isolateId, 0, 'x'); | ||
| Expect.isTrue(xRef3 is ErrorRef); | ||
| final xRef4 = await service.evaluateInFrame(isolateId, 0, 'this.x'); | ||
| Expect.isTrue(xRef4 is ErrorRef); | ||
| }, | ||
| ]; | ||
|
|
||
| void main([args = const <String>[]]) => runIsolateTests( | ||
| args, | ||
| tests, | ||
| 'private_named_parameters_t01.dart', | ||
| pauseOnExit: true, | ||
| testeeConcurrent: testeeMain, | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // Copyright (c) 2025, 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. | ||
|
|
||
| /// @assertion We let users use a private name in a named parameter when the | ||
| /// parameter also initializes or declares a field. The compiler removes the `_` | ||
| /// from the argument name but keeps it for the corresponding field. | ||
| /// | ||
| /// @description Check that private named parameters are allowed in VM | ||
| /// expression evaluation. | ||
| /// @author [email protected] | ||
|
|
||
| // SharedOptions=--enable-experiment=declaring-constructors,private-named-parameters | ||
|
|
||
| import 'dart:developer'; | ||
|
|
||
| import 'package:vm_service/vm_service.dart'; | ||
|
|
||
| import '../../../../pkg/vm_service/test/common/service_test_common.dart'; | ||
| import '../../../../pkg/vm_service/test/common/test_helper.dart'; | ||
| import '../Utils/expect.dart'; | ||
|
|
||
| class C1({var String _x}); | ||
|
|
||
| class C2 { | ||
| String _x; | ||
| C2({required this._x}); | ||
| } | ||
|
|
||
| void testeeMain() { | ||
| final c1 = C1(x: "one"); | ||
| final c2 = C2(x: "two"); | ||
| debugger(); | ||
| } | ||
|
|
||
| final tests = <IsolateTest>[ | ||
| hasStoppedAtBreakpoint, | ||
|
|
||
| // Test interaction of expression evaluation with private named parameters. | ||
| (VmService service, IsolateRef isolateRef) async { | ||
| final isolateId = isolateRef.id!; | ||
|
|
||
| InstanceRef response = | ||
| await service.evaluateInFrame(isolateId, 0, 'c1._x') as InstanceRef; | ||
| Expect.equals('one', response.valueAsString); | ||
|
|
||
| response = | ||
| await service.evaluateInFrame(isolateId, 0, 'c2._x') as InstanceRef; | ||
| Expect.equals('two', response.valueAsString); | ||
|
|
||
| response = | ||
| await service.evaluateInFrame(isolateId, 0, 'C1(x: "zero")._x') | ||
| as InstanceRef; | ||
| Expect.equals('zero', response.valueAsString); | ||
|
|
||
| response = | ||
| await service.evaluateInFrame(isolateId, 0, 'C2(x: "0")._x') | ||
| as InstanceRef; | ||
| Expect.equals('0', response.valueAsString); | ||
| }, | ||
| ]; | ||
|
|
||
| void main([args = const <String>[]]) => runIsolateTests( | ||
| args, | ||
| tests, | ||
| 'private_named_parameters_t02.dart', | ||
| pauseOnExit: true, | ||
| testeeConcurrent: testeeMain, | ||
| ); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.