Skip to content

Commit 663c55b

Browse files
jensjohaCommit Queue
authored and
Commit Queue
committed
[ package:vm_service ] Deduplicate expression evaluation testing helper
Change-Id: I371ef13859bf73a44e89ffbf0f5f8c042a112e0b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/405362 Reviewed-by: Derek Xu <[email protected]> Commit-Queue: Jens Johansen <[email protected]> Reviewed-by: Ben Konyi <[email protected]>
1 parent 60d98b8 commit 663c55b

File tree

4 files changed

+78
-122
lines changed

4 files changed

+78
-122
lines changed

pkg/vm_service/test/common/service_test_common.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,3 +889,41 @@ IsolateTest expectUnhandledExceptionWithFrames({
889889
}
890890
};
891891
}
892+
893+
/// This helper does 3 things:
894+
/// 1) makes sure it's at the expected frame ([topFrameName]).
895+
/// 2) checks that the expected variables are available (by name)
896+
/// ([availableVariables]).
897+
/// 3) Evaluates the given expression(s) and checks their (valueAsString) result
898+
/// ([evaluations]).
899+
IsolateTest testExpressionEvaluationAndAvailableVariables(
900+
String topFrameName,
901+
List<String> availableVariables,
902+
List<(String evaluate, String evaluationResult)> evaluations,
903+
) {
904+
return (VmService service, IsolateRef isolateRef) async {
905+
final isolateId = isolateRef.id!;
906+
final stack = await service.getStack(isolateId);
907+
908+
// Make sure we are in the right place.
909+
expect(stack.frames!.length, greaterThanOrEqualTo(1));
910+
expect(stack.frames![0].function!.name, topFrameName);
911+
912+
// Check variables.
913+
expect(
914+
(stack.frames![0].vars ?? []).map((v) => v.name).toList(),
915+
equals(availableVariables),
916+
);
917+
918+
// Evaluate.
919+
for (final (expression, expectedResult) in evaluations) {
920+
final result = await service.evaluateInFrame(
921+
isolateId,
922+
/* frame = */ 0,
923+
expression,
924+
) as InstanceRef;
925+
print(result.valueAsString);
926+
expect(result.valueAsString, equals(expectedResult));
927+
}
928+
};
929+
}

pkg/vm_service/test/issue_56911_test.dart

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:developer';
6-
import 'package:test/test.dart';
7-
import 'package:vm_service/vm_service.dart';
86
import 'common/service_test_common.dart';
97
import 'common/test_helper.dart';
108

@@ -14,8 +12,8 @@ import 'common/test_helper.dart';
1412
//
1513
// dart pkg/vm_service/test/update_line_numbers.dart pkg/vm_service/test/issue_56911_test.dart
1614
//
17-
const LINE_A = 28;
18-
const LINE_B = 32;
15+
const LINE_A = 26;
16+
const LINE_B = 30;
1917
// AUTOGENERATED END
2018

2119
extension type ExtensionType._(String s) {
@@ -34,42 +32,10 @@ void code() {
3432
});
3533
}
3634

37-
Future<void> Function(VmService, IsolateRef) test(
38-
String topFrameName,
39-
List<String> availableVariables,
40-
List<(String evaluate, String evaluationResult)> evaluations,
41-
) {
42-
return (VmService service, IsolateRef isolateRef) async {
43-
final isolateId = isolateRef.id!;
44-
final stack = await service.getStack(isolateId);
45-
46-
// Make sure we are in the right place.
47-
expect(stack.frames!.length, greaterThanOrEqualTo(1));
48-
expect(stack.frames![0].function!.name, topFrameName);
49-
50-
// Check variables.
51-
expect(
52-
(stack.frames![0].vars ?? []).map((v) => v.name).toList(),
53-
equals(availableVariables),
54-
);
55-
56-
// Evaluate.
57-
for (final (expression, expectedResult) in evaluations) {
58-
final result = await service.evaluateInFrame(
59-
isolateId,
60-
/* frame = */ 0,
61-
expression,
62-
) as InstanceRef;
63-
print(result.valueAsString);
64-
expect(result.valueAsString, equals(expectedResult));
65-
}
66-
};
67-
}
68-
6935
final tests = <IsolateTest>[
7036
hasStoppedAtBreakpoint,
7137
stoppedAtLine(LINE_A),
72-
test('code', [
38+
testExpressionEvaluationAndAvailableVariables('code', [
7339
'list',
7440
], [
7541
('() { return list.single.value; }()', '48'),
@@ -78,7 +44,7 @@ final tests = <IsolateTest>[
7844
resumeIsolate,
7945
hasStoppedAtBreakpoint,
8046
stoppedAtLine(LINE_B),
81-
test('<anonymous closure>', [
47+
testExpressionEvaluationAndAvailableVariables('<anonymous closure>', [
8248
'input',
8349
], [
8450
('() { return input.value; }()', '48'),

pkg/vm_service/test/issue_57040_test.dart

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:developer';
6-
import 'package:test/test.dart';
7-
import 'package:vm_service/vm_service.dart';
86
import 'common/service_test_common.dart';
97
import 'common/test_helper.dart';
108

@@ -14,8 +12,8 @@ import 'common/test_helper.dart';
1412
//
1513
// dart pkg/vm_service/test/update_line_numbers.dart pkg/vm_service/test/issue_57040_test.dart
1614
//
17-
const LINE_A = 30;
18-
const LINE_B = 33;
15+
const LINE_A = 28;
16+
const LINE_B = 31;
1917
// AUTOGENERATED END
2018

2119
extension on String? {
@@ -34,42 +32,10 @@ void code() {
3432
print(str.isNullOrEmpty);
3533
}
3634

37-
Future<void> Function(VmService, IsolateRef) test(
38-
String topFrameName,
39-
List<String> availableVariables,
40-
List<(String evaluate, String evaluationResult)> evaluations,
41-
) {
42-
return (VmService service, IsolateRef isolateRef) async {
43-
final isolateId = isolateRef.id!;
44-
final stack = await service.getStack(isolateId);
45-
46-
// Make sure we are in the right place.
47-
expect(stack.frames!.length, greaterThanOrEqualTo(1));
48-
expect(stack.frames![0].function!.name, topFrameName);
49-
50-
// Check variables.
51-
expect(
52-
(stack.frames![0].vars ?? []).map((v) => v.name).toList(),
53-
equals(availableVariables),
54-
);
55-
56-
// Evaluate.
57-
for (final (expression, expectedResult) in evaluations) {
58-
final result = await service.evaluateInFrame(
59-
isolateId,
60-
/* frame = */ 0,
61-
expression,
62-
) as InstanceRef;
63-
print(result.valueAsString);
64-
expect(result.valueAsString, equals(expectedResult));
65-
}
66-
};
67-
}
68-
6935
final tests = <IsolateTest>[
7036
hasStoppedAtBreakpoint,
7137
stoppedAtLine(LINE_A),
72-
test('code', [
38+
testExpressionEvaluationAndAvailableVariables('code', [
7339
'str',
7440
], [
7541
('() { return str.isNullOrEmpty; }()', 'false'),
@@ -78,7 +44,7 @@ final tests = <IsolateTest>[
7844
resumeIsolate,
7945
hasStoppedAtBreakpoint,
8046
stoppedAtLine(LINE_B),
81-
test('code', [
47+
testExpressionEvaluationAndAvailableVariables('code', [
8248
'str',
8349
], [
8450
('() { return str.isNullOrEmpty; }()', 'true'),

pkg/vm_service/test/issue_59661_test.dart

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:developer';
6-
import 'package:test/test.dart';
7-
import 'package:vm_service/vm_service.dart';
86
import 'common/service_test_common.dart';
97
import 'common/test_helper.dart';
108

@@ -14,12 +12,12 @@ import 'common/test_helper.dart';
1412
//
1513
// dart pkg/vm_service/test/update_line_numbers.dart pkg/vm_service/test/issue_59661_test.dart
1614
//
17-
const LINE_CLASS_A = 29;
18-
const LINE_CLASS_A_NAMED = 34;
19-
const LINE_CLASS_A_NAMED2_BREAK_1 = 40;
20-
const LINE_CLASS_A_NAMED2_BREAK_2 = 43;
21-
const LINE_CLASS_A_NAMED2_BREAK_3 = 46;
22-
const LINE_CLASS_B = 55;
15+
const LINE_CLASS_A = 27;
16+
const LINE_CLASS_A_NAMED = 32;
17+
const LINE_CLASS_A_NAMED2_BREAK_1 = 38;
18+
const LINE_CLASS_A_NAMED2_BREAK_2 = 41;
19+
const LINE_CLASS_A_NAMED2_BREAK_3 = 44;
20+
const LINE_CLASS_B = 53;
2321
// AUTOGENERATED END
2422

2523
class A {
@@ -64,50 +62,26 @@ void code() {
6462
B([1, 2]);
6563
}
6664

67-
Future<void> Function(VmService, IsolateRef) test(
68-
String topFrameName,
69-
List<String> availableVariables,
70-
List<(String evaluate, String evaluationResult)> evaluations,
71-
) {
72-
return (VmService service, IsolateRef isolateRef) async {
73-
final isolateId = isolateRef.id!;
74-
final stack = await service.getStack(isolateId);
75-
76-
// Make sure we are in the right place.
77-
expect(stack.frames!.length, greaterThanOrEqualTo(1));
78-
expect(stack.frames![0].function!.name, topFrameName);
79-
80-
// Check variables.
81-
expect(
82-
(stack.frames![0].vars ?? []).map((v) => v.name).toList(),
83-
equals(availableVariables),
84-
);
85-
86-
// Evaluate.
87-
for (final (expression, expectedResult) in evaluations) {
88-
final dynamic result = await service.evaluateInFrame(
89-
isolateId,
90-
/* frame = */ 0,
91-
expression,
92-
);
93-
print(result.valueAsString);
94-
expect(result.valueAsString, equals(expectedResult));
95-
}
96-
};
97-
}
98-
9965
final tests = <IsolateTest>[
10066
hasStoppedAtBreakpoint,
10167
stoppedAtLine(LINE_CLASS_A),
102-
test('A', ['this'], [('list.toString()', '[3]')]),
68+
testExpressionEvaluationAndAvailableVariables(
69+
'A',
70+
['this'],
71+
[('list.toString()', '[3]')],
72+
),
10373
resumeIsolate,
10474
hasStoppedAtBreakpoint,
10575
stoppedAtLine(LINE_CLASS_A_NAMED),
106-
test('A.named', ['this'], [('list.toString()', '[4]')]),
76+
testExpressionEvaluationAndAvailableVariables(
77+
'A.named',
78+
['this'],
79+
[('list.toString()', '[4]')],
80+
),
10781
resumeIsolate,
10882
hasStoppedAtBreakpoint,
10983
stoppedAtLine(LINE_CLASS_A_NAMED2_BREAK_1),
110-
test(
84+
testExpressionEvaluationAndAvailableVariables(
11185
'A.named2',
11286
['this', 'list'],
11387
[
@@ -118,15 +92,27 @@ final tests = <IsolateTest>[
11892
resumeIsolate,
11993
hasStoppedAtBreakpoint,
12094
stoppedAtLine(LINE_CLASS_A_NAMED2_BREAK_2),
121-
test('A.named2', ['this'], [('list.toString()', '[1, 2]')]),
95+
testExpressionEvaluationAndAvailableVariables(
96+
'A.named2',
97+
['this'],
98+
[('list.toString()', '[1, 2]')],
99+
),
122100
resumeIsolate,
123101
hasStoppedAtBreakpoint,
124102
stoppedAtLine(LINE_CLASS_A_NAMED2_BREAK_3),
125-
test('A.named2', ['this'], [('list.toString()', '[6]')]),
103+
testExpressionEvaluationAndAvailableVariables(
104+
'A.named2',
105+
['this'],
106+
[('list.toString()', '[6]')],
107+
),
126108
resumeIsolate,
127109
hasStoppedAtBreakpoint,
128110
stoppedAtLine(LINE_CLASS_B),
129-
test('B', ['this'], [('list.toString()', '[7]')]),
111+
testExpressionEvaluationAndAvailableVariables(
112+
'B',
113+
['this'],
114+
[('list.toString()', '[7]')],
115+
),
130116
];
131117

132118
void main([args = const <String>[]]) => runIsolateTests(

0 commit comments

Comments
 (0)