Skip to content

Commit 8e2093c

Browse files
authored
#3330. Add debugger tests for static extensions (#3383)
Add debugger tests for static extensions
1 parent e4ea9b4 commit 8e2093c

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed

VM/static_extensions_t01.dart

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 Consider an expression `e` which is a member invocation with
6+
/// syntactic receiver `C` and an associated member name `m`. Assume that `m` is
7+
/// a static member declared by `D`. The static analysis and dynamic semantics
8+
/// of this expression is the same as in Dart before the introduction of this
9+
/// feature.
10+
/// ...
11+
/// Assume that it is an extension `E` that declares a static member named `m`.
12+
/// The invocation is then treated as `E.m()`.
13+
///
14+
/// @description Check that `C.m()` is treated as `E.m()`.
15+
/// @author [email protected]
16+
17+
// SharedOptions=--enable-experiment=static-extensions
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+
class C {}
27+
28+
extension ExtC on C {
29+
static String foo() => "ExtC";
30+
}
31+
32+
void testeeMain() {
33+
debugger();
34+
}
35+
36+
final tests = <IsolateTest>[
37+
hasStoppedAtBreakpoint,
38+
39+
// Test interaction of expression evaluation with static extensions.
40+
(VmService service, IsolateRef isolateRef) async {
41+
final isolateId = isolateRef.id!;
42+
43+
InstanceRef response =
44+
await service.evaluateInFrame(isolateId, 0, 'C.foo()') as InstanceRef;
45+
Expect.equals('ExtC', response.valueAsString);
46+
},
47+
];
48+
49+
void main([args = const <String>[]]) => runIsolateTests(
50+
args,
51+
tests,
52+
'static_extensions_t01.dart',
53+
pauseOnExit: true,
54+
testeeConcurrent: testeeMain,
55+
);

VM/static_extensions_t02.dart

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 Consider an expression `e` which is a member invocation with
6+
/// syntactic receiver `C` and an associated member name `m`. Assume that `m` is
7+
/// a static member declared by `D`. The static analysis and dynamic semantics
8+
/// of this expression is the same as in Dart before the introduction of this
9+
/// feature.
10+
/// ...
11+
/// Assume that it is an extension `E` that declares a static member named `m`.
12+
/// The invocation is then treated as `E.m()`.
13+
///
14+
/// @description Check that `C.m()` is treated as `E.m()`.
15+
/// @author [email protected]
16+
17+
// SharedOptions=--enable-experiment=static-extensions
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+
// AUTOGENERATED START
27+
//
28+
// Update these constants by running:
29+
//
30+
// dart pkg/vm_service/test/update_line_numbers.dart tests/co19/src/VM/static_extensions_t02.dart
31+
//
32+
const LINE_A = 40;
33+
const LINE_B = 44;
34+
const LINE_C = 45;
35+
// AUTOGENERATED END
36+
37+
class C {}
38+
39+
extension ExtC on C {
40+
static String foo() => "ExtC"; // LINE_A
41+
}
42+
43+
void testeeMain() {
44+
debugger(); // LINE_B
45+
C.foo(); // LINE_C
46+
}
47+
48+
final tests = <IsolateTest>[
49+
hasStoppedAtBreakpoint,
50+
stoppedAtLine(LINE_B),
51+
stepInto,
52+
stoppedAtLine(LINE_C),
53+
stepInto,
54+
stoppedAtLine(LINE_A),
55+
];
56+
57+
void main([args = const <String>[]]) => runIsolateTests(
58+
args,
59+
tests,
60+
'static_extensions_t02.dart',
61+
pauseOnExit: true,
62+
testeeConcurrent: testeeMain,
63+
);

0 commit comments

Comments
 (0)