diff --git a/pkg/vm_service/test/common/service_test_common.dart b/pkg/vm_service/test/common/service_test_common.dart index cf9d9c861ac4..ac6c08f30ff2 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 @@ IsolateTest expectUnhandledExceptionWithFrames({ } }; } + +/// 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 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 b46e0fae91ec..a7a91793ba8d 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 @@ import 'common/test_helper.dart'; // // 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 @@ void code() { }); } -Future Function(VmService, IsolateRef) test( - String topFrameName, - List 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 = [ hasStoppedAtBreakpoint, stoppedAtLine(LINE_A), - test('code', [ + testExpressionEvaluationAndAvailableVariables('code', [ 'list', ], [ ('() { return list.single.value; }()', '48'), @@ -78,7 +44,7 @@ final tests = [ resumeIsolate, hasStoppedAtBreakpoint, stoppedAtLine(LINE_B), - test('', [ + testExpressionEvaluationAndAvailableVariables('', [ '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 e5f3bbe1d38f..42426b6e740e 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 @@ import 'common/test_helper.dart'; // // 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 @@ void code() { print(str.isNullOrEmpty); } -Future Function(VmService, IsolateRef) test( - String topFrameName, - List 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 = [ hasStoppedAtBreakpoint, stoppedAtLine(LINE_A), - test('code', [ + testExpressionEvaluationAndAvailableVariables('code', [ 'str', ], [ ('() { return str.isNullOrEmpty; }()', 'false'), @@ -78,7 +44,7 @@ final tests = [ 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 ed22d896fca0..29e24a657755 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 @@ import 'common/test_helper.dart'; // // 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 @@ void code() { B([1, 2]); } -Future Function(VmService, IsolateRef) test( - String topFrameName, - List 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 = [ 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 @@ final tests = [ 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 []]) => runIsolateTests(