From 39d2b206fa81afe87b53c0ec92bd8d2be88bbfb2 Mon Sep 17 00:00:00 2001 From: Nicholas Shahan Date: Wed, 20 Aug 2025 09:26:00 -0700 Subject: [PATCH] [ddc] Add expression eval tests for local consts See: https://dart-review.googlesource.com/c/sdk/+/445461 Change-Id: Ic819199a1afe515dcda05aa04fc3e1664a39055b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/446001 Reviewed-by: Jens Johansen Commit-Queue: Nicholas Shahan --- ...xpression_compiler_e2e_dart_3_10_test.dart | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 pkg/dev_compiler/test/expression_compiler/expression_compiler_e2e_dart_3_10_test.dart diff --git a/pkg/dev_compiler/test/expression_compiler/expression_compiler_e2e_dart_3_10_test.dart b/pkg/dev_compiler/test/expression_compiler/expression_compiler_e2e_dart_3_10_test.dart new file mode 100644 index 00000000000..ed8c938ae88 --- /dev/null +++ b/pkg/dev_compiler/test/expression_compiler/expression_compiler_e2e_dart_3_10_test.dart @@ -0,0 +1,92 @@ +// 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. + +import 'package:dev_compiler/src/compiler/module_builder.dart' + show ModuleFormat; +import 'package:test/test.dart'; + +import '../shared_test_options.dart'; +import 'expression_compiler_e2e_suite.dart'; + +void main(List args) async { + var driver = await ExpressionEvaluationTestDriver.init(); + + group('Dart 3.10 language features', () { + tearDownAll(() async { + await driver.finish(); + }); + + group('(AMD module system)', () { + var setup = SetupCompilerOptions( + moduleFormat: ModuleFormat.amd, + args: args, + ); + runSharedTests(setup, driver); + }); + + group('(DDC module system)', () { + var setup = SetupCompilerOptions( + moduleFormat: ModuleFormat.ddc, + args: args, + ); + runSharedTests(setup, driver); + }); + }); +} + +/// Shared tests for language features introduced in version 3.10.0. +void runSharedTests( + SetupCompilerOptions setup, + ExpressionEvaluationTestDriver driver, +) { + group('local consts', () { + const recordsSource = ''' + void main() { + topLevelMethod(); + + const mainLocalConst = Duration(seconds: 1); + + inlineMethod() { + // The const from the outer scope is not available here during + // evaluation unless there is already a reference within this scope. + var x = mainLocalConst; + // Breakpoint: bp1 + print('hello world'); + } + + inlineMethod(); + } + + void topLevelMethod() { + const methodLocalConst= Duration(seconds: 3); + // Breakpoint: bp2 + print('hello world'); + } + '''; + + setUpAll(() async { + await driver.initSource(setup, recordsSource); + }); + + tearDownAll(() async { + await driver.cleanupTest(); + }); + + test('defined in enclosing scope', () async { + await driver.checkInFrame( + breakpointId: 'bp1', + expression: 'mainLocalConst.toString()', + expectedResult: '0:00:01.000000', + ); + }); + + test('defined in method', () async { + await driver.checkInFrame( + breakpointId: 'bp2', + expression: 'methodLocalConst.toString()', + expectedResult: '0:00:03.000000', + ); + }); + }); +}