[ 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 <derekx@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
diff --git a/pkg/vm_service/test/common/service_test_common.dart b/pkg/vm_service/test/common/service_test_common.dart
index cf9d9c8..ac6c08f 100644
--- a/pkg/vm_service/test/common/service_test_common.dart
+++ b/pkg/vm_service/test/common/service_test_common.dart
@@ -889,3 +889,41 @@
}
};
}
+
+/// This helper does 3 things:
+/// 1) makes sure it's at the expected frame ([topFrameName]).
+/// 2) checks that the expected variables are available (by name)
+/// ([availableVariables]).
+/// 3) Evaluates the given expression(s) and checks their (valueAsString) result
+/// ([evaluations]).
+IsolateTest testExpressionEvaluationAndAvailableVariables(
+ String topFrameName,
+ List<String> availableVariables,
+ List<(String evaluate, String evaluationResult)> evaluations,
+) {
+ return (VmService service, IsolateRef isolateRef) async {
+ final isolateId = isolateRef.id!;
+ final stack = await service.getStack(isolateId);
+
+ // Make sure we are in the right place.
+ expect(stack.frames!.length, greaterThanOrEqualTo(1));
+ expect(stack.frames![0].function!.name, topFrameName);
+
+ // Check variables.
+ expect(
+ (stack.frames![0].vars ?? []).map((v) => v.name).toList(),
+ equals(availableVariables),
+ );
+
+ // Evaluate.
+ for (final (expression, expectedResult) in evaluations) {
+ final result = await service.evaluateInFrame(
+ isolateId,
+ /* frame = */ 0,
+ expression,
+ ) as InstanceRef;
+ print(result.valueAsString);
+ expect(result.valueAsString, equals(expectedResult));
+ }
+ };
+}
diff --git a/pkg/vm_service/test/issue_56911_test.dart b/pkg/vm_service/test/issue_56911_test.dart
index b46e0fa..a7a9179 100644
--- a/pkg/vm_service/test/issue_56911_test.dart
+++ b/pkg/vm_service/test/issue_56911_test.dart
@@ -3,8 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
import 'dart:developer';
-import 'package:test/test.dart';
-import 'package:vm_service/vm_service.dart';
import 'common/service_test_common.dart';
import 'common/test_helper.dart';
@@ -14,8 +12,8 @@
//
// dart pkg/vm_service/test/update_line_numbers.dart pkg/vm_service/test/issue_56911_test.dart
//
-const LINE_A = 28;
-const LINE_B = 32;
+const LINE_A = 26;
+const LINE_B = 30;
// AUTOGENERATED END
extension type ExtensionType._(String s) {
@@ -34,42 +32,10 @@
});
}
-Future<void> Function(VmService, IsolateRef) test(
- String topFrameName,
- List<String> availableVariables,
- List<(String evaluate, String evaluationResult)> evaluations,
-) {
- return (VmService service, IsolateRef isolateRef) async {
- final isolateId = isolateRef.id!;
- final stack = await service.getStack(isolateId);
-
- // Make sure we are in the right place.
- expect(stack.frames!.length, greaterThanOrEqualTo(1));
- expect(stack.frames![0].function!.name, topFrameName);
-
- // Check variables.
- expect(
- (stack.frames![0].vars ?? []).map((v) => v.name).toList(),
- equals(availableVariables),
- );
-
- // Evaluate.
- for (final (expression, expectedResult) in evaluations) {
- final result = await service.evaluateInFrame(
- isolateId,
- /* frame = */ 0,
- expression,
- ) as InstanceRef;
- print(result.valueAsString);
- expect(result.valueAsString, equals(expectedResult));
- }
- };
-}
-
final tests = <IsolateTest>[
hasStoppedAtBreakpoint,
stoppedAtLine(LINE_A),
- test('code', [
+ testExpressionEvaluationAndAvailableVariables('code', [
'list',
], [
('() { return list.single.value; }()', '48'),
@@ -78,7 +44,7 @@
resumeIsolate,
hasStoppedAtBreakpoint,
stoppedAtLine(LINE_B),
- test('<anonymous closure>', [
+ testExpressionEvaluationAndAvailableVariables('<anonymous closure>', [
'input',
], [
('() { return input.value; }()', '48'),
diff --git a/pkg/vm_service/test/issue_57040_test.dart b/pkg/vm_service/test/issue_57040_test.dart
index e5f3bbe..42426b6 100644
--- a/pkg/vm_service/test/issue_57040_test.dart
+++ b/pkg/vm_service/test/issue_57040_test.dart
@@ -3,8 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
import 'dart:developer';
-import 'package:test/test.dart';
-import 'package:vm_service/vm_service.dart';
import 'common/service_test_common.dart';
import 'common/test_helper.dart';
@@ -14,8 +12,8 @@
//
// dart pkg/vm_service/test/update_line_numbers.dart pkg/vm_service/test/issue_57040_test.dart
//
-const LINE_A = 30;
-const LINE_B = 33;
+const LINE_A = 28;
+const LINE_B = 31;
// AUTOGENERATED END
extension on String? {
@@ -34,42 +32,10 @@
print(str.isNullOrEmpty);
}
-Future<void> Function(VmService, IsolateRef) test(
- String topFrameName,
- List<String> availableVariables,
- List<(String evaluate, String evaluationResult)> evaluations,
-) {
- return (VmService service, IsolateRef isolateRef) async {
- final isolateId = isolateRef.id!;
- final stack = await service.getStack(isolateId);
-
- // Make sure we are in the right place.
- expect(stack.frames!.length, greaterThanOrEqualTo(1));
- expect(stack.frames![0].function!.name, topFrameName);
-
- // Check variables.
- expect(
- (stack.frames![0].vars ?? []).map((v) => v.name).toList(),
- equals(availableVariables),
- );
-
- // Evaluate.
- for (final (expression, expectedResult) in evaluations) {
- final result = await service.evaluateInFrame(
- isolateId,
- /* frame = */ 0,
- expression,
- ) as InstanceRef;
- print(result.valueAsString);
- expect(result.valueAsString, equals(expectedResult));
- }
- };
-}
-
final tests = <IsolateTest>[
hasStoppedAtBreakpoint,
stoppedAtLine(LINE_A),
- test('code', [
+ testExpressionEvaluationAndAvailableVariables('code', [
'str',
], [
('() { return str.isNullOrEmpty; }()', 'false'),
@@ -78,7 +44,7 @@
resumeIsolate,
hasStoppedAtBreakpoint,
stoppedAtLine(LINE_B),
- test('code', [
+ testExpressionEvaluationAndAvailableVariables('code', [
'str',
], [
('() { return str.isNullOrEmpty; }()', 'true'),
diff --git a/pkg/vm_service/test/issue_59661_test.dart b/pkg/vm_service/test/issue_59661_test.dart
index ed22d89..29e24a6 100644
--- a/pkg/vm_service/test/issue_59661_test.dart
+++ b/pkg/vm_service/test/issue_59661_test.dart
@@ -3,8 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
import 'dart:developer';
-import 'package:test/test.dart';
-import 'package:vm_service/vm_service.dart';
import 'common/service_test_common.dart';
import 'common/test_helper.dart';
@@ -14,12 +12,12 @@
//
// dart pkg/vm_service/test/update_line_numbers.dart pkg/vm_service/test/issue_59661_test.dart
//
-const LINE_CLASS_A = 29;
-const LINE_CLASS_A_NAMED = 34;
-const LINE_CLASS_A_NAMED2_BREAK_1 = 40;
-const LINE_CLASS_A_NAMED2_BREAK_2 = 43;
-const LINE_CLASS_A_NAMED2_BREAK_3 = 46;
-const LINE_CLASS_B = 55;
+const LINE_CLASS_A = 27;
+const LINE_CLASS_A_NAMED = 32;
+const LINE_CLASS_A_NAMED2_BREAK_1 = 38;
+const LINE_CLASS_A_NAMED2_BREAK_2 = 41;
+const LINE_CLASS_A_NAMED2_BREAK_3 = 44;
+const LINE_CLASS_B = 53;
// AUTOGENERATED END
class A {
@@ -64,50 +62,26 @@
B([1, 2]);
}
-Future<void> Function(VmService, IsolateRef) test(
- String topFrameName,
- List<String> availableVariables,
- List<(String evaluate, String evaluationResult)> evaluations,
-) {
- return (VmService service, IsolateRef isolateRef) async {
- final isolateId = isolateRef.id!;
- final stack = await service.getStack(isolateId);
-
- // Make sure we are in the right place.
- expect(stack.frames!.length, greaterThanOrEqualTo(1));
- expect(stack.frames![0].function!.name, topFrameName);
-
- // Check variables.
- expect(
- (stack.frames![0].vars ?? []).map((v) => v.name).toList(),
- equals(availableVariables),
- );
-
- // Evaluate.
- for (final (expression, expectedResult) in evaluations) {
- final dynamic result = await service.evaluateInFrame(
- isolateId,
- /* frame = */ 0,
- expression,
- );
- print(result.valueAsString);
- expect(result.valueAsString, equals(expectedResult));
- }
- };
-}
-
final tests = <IsolateTest>[
hasStoppedAtBreakpoint,
stoppedAtLine(LINE_CLASS_A),
- test('A', ['this'], [('list.toString()', '[3]')]),
+ testExpressionEvaluationAndAvailableVariables(
+ 'A',
+ ['this'],
+ [('list.toString()', '[3]')],
+ ),
resumeIsolate,
hasStoppedAtBreakpoint,
stoppedAtLine(LINE_CLASS_A_NAMED),
- test('A.named', ['this'], [('list.toString()', '[4]')]),
+ testExpressionEvaluationAndAvailableVariables(
+ 'A.named',
+ ['this'],
+ [('list.toString()', '[4]')],
+ ),
resumeIsolate,
hasStoppedAtBreakpoint,
stoppedAtLine(LINE_CLASS_A_NAMED2_BREAK_1),
- test(
+ testExpressionEvaluationAndAvailableVariables(
'A.named2',
['this', 'list'],
[
@@ -118,15 +92,27 @@
resumeIsolate,
hasStoppedAtBreakpoint,
stoppedAtLine(LINE_CLASS_A_NAMED2_BREAK_2),
- test('A.named2', ['this'], [('list.toString()', '[1, 2]')]),
+ testExpressionEvaluationAndAvailableVariables(
+ 'A.named2',
+ ['this'],
+ [('list.toString()', '[1, 2]')],
+ ),
resumeIsolate,
hasStoppedAtBreakpoint,
stoppedAtLine(LINE_CLASS_A_NAMED2_BREAK_3),
- test('A.named2', ['this'], [('list.toString()', '[6]')]),
+ testExpressionEvaluationAndAvailableVariables(
+ 'A.named2',
+ ['this'],
+ [('list.toString()', '[6]')],
+ ),
resumeIsolate,
hasStoppedAtBreakpoint,
stoppedAtLine(LINE_CLASS_B),
- test('B', ['this'], [('list.toString()', '[7]')]),
+ testExpressionEvaluationAndAvailableVariables(
+ 'B',
+ ['this'],
+ [('list.toString()', '[7]')],
+ ),
];
void main([args = const <String>[]]) => runIsolateTests(