Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions dwds/test/fixtures/project.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ class TestProject {
htmlEntryFileName: 'index.html',
);

static final testDotShorthands = TestProject._(
packageName: '_test_dot_shorthands',
packageDirectory: '_test_dot_shorthands',
webAssetsPath: 'web',
dartEntryFileName: 'main.dart',
htmlEntryFileName: 'index.html',
);

static final testHotRestart1 = TestProject._(
packageName: '_test_hot_restart1',
packageDirectory: '_test_hot_restart1',
Expand Down
54 changes: 38 additions & 16 deletions dwds/test/instances/common/dot_shorthands_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// 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:dwds/src/services/expression_compiler.dart' show ModuleFormat;
import 'package:path/path.dart' show basename;
import 'package:test/test.dart';
import 'package:test_common/logging.dart';
Expand All @@ -20,7 +19,7 @@ void runTests({
required bool canaryFeatures,
required bool debug,
}) {
final context = TestContext(TestProject.testExperiment, provider);
final context = TestContext(TestProject.testDotShorthands, provider);
final testInspector = TestInspector(context);

late VmService service;
Expand Down Expand Up @@ -73,8 +72,8 @@ void runTests({
await context.tearDown();
});

test('expression evaluation and single-stepping', () async {
await onBreakpoint('testDotShorthands', (event) async {
test('expression evaluation', () async {
final bp = onBreakpoint('testDotShorthands', (event) async {
final frame = event.topFrame!.index!;

var instanceRef = await getInstanceRef(frame, '(c = .two).value');
Expand All @@ -86,22 +85,36 @@ void runTests({
instanceRef = await getInstanceRef(frame, '(c = .four()).value');
expect(instanceRef.valueAsString, '4');

await service.resume(isolateId);
});
final isolate = await service.getIsolate(isolateId);
await service.evaluate(
isolateId,
isolate.rootLib!.id!,
'testDotShorthands()',
);
await bp;
});

test('single-stepping', () async {
final bp = onBreakpoint('testDotShorthands', (event) async {
final scriptBasename = basename(mainScript.uri!);

const lineA = 116;
const lineB = 118;
const lineC = 119;
const lineD = 120;
const lineE = 127;
const lineF = 129;
const lineG = 131;
const lineH = 132;
const lineA = 9;
const lineB = 11;
const lineC = 12;
const lineD = 13;
const lineE = 20;
const lineF = 22;
const lineG = 24;
const lineH = 25;

final expected = [
'$scriptBasename:$lineE:3', // on 'c'
// TODO(2638): Investigate why this conditional exclusion is needed.
if (provider.ddcModuleFormat == ModuleFormat.ddc)
'$scriptBasename:$lineB:20', // on '2'
'$scriptBasename:$lineB:15', // on 'C'
'$scriptBasename:$lineA:10', // on 'v' of 'value'
'$scriptBasename:$lineA:16', // on ';'
'$scriptBasename:$lineB:20', // on '2'
'$scriptBasename:$lineF:3', // on 'c'
'$scriptBasename:$lineC:25', // on 'C'
'$scriptBasename:$lineA:10', // on 'v' of 'value'
Expand All @@ -119,11 +132,20 @@ void runTests({
await testInspector.runStepIntoThroughProgramRecordingStops(
isolateId,
stops,
provider.ddcModuleFormat == ModuleFormat.ddc ? 13 : 12,
expected.length,
);

expect(stops, expected);

await service.resume(isolateId);
});
final isolate = await service.getIsolate(isolateId);
await service.evaluate(
isolateId,
isolate.rootLib!.id!,
'testDotShorthands()',
);
await bp;
});
});
}
37 changes: 6 additions & 31 deletions fixtures/_experiment/web/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

import 'dart:async';
import 'dart:core';
// TODO: https://github.com/dart-lang/webdev/issues/2508
// ignore: deprecated_member_use
import 'dart:html';
import 'dart:js_interop';

@JS('document.body.append')
external void append(String text);

void main() {
// for evaluation
Expand All @@ -26,11 +27,9 @@ void main() {
testPattern2();
print('Classes');
testClass();
print('Dot shorthands');
testDotShorthands();
});

document.body!.appendText('Program is running!');
append('Program is running!');
}

void printSimpleLocalRecord() {
Expand Down Expand Up @@ -93,10 +92,7 @@ class GreeterClass {
final String greeteeName;
final bool useFrench;

GreeterClass({
this.greeteeName = 'Snoopy',
this.useFrench = false,
});
GreeterClass({this.greeteeName = 'Snoopy', this.useFrench = false});

void sayHello() {
useFrench ? greetInFrench() : greetInEnglish();
Expand All @@ -110,24 +106,3 @@ class GreeterClass {
print('Bonjour $greeteeName');
}
}

class C {
int value;
C(this.value); // lineA

static C two = C(2); // lineB
static C get three => C(3); // lineC
static C four() => C(4); // lineD
}

void testDotShorthands() {
C c = C(1);
print('breakpoint'); // Breakpoint: testDotShorthands
// ignore: experiment_not_enabled
c = .two; // lineE
// ignore: experiment_not_enabled
c = .three; // lineF
// ignore: experiment_not_enabled
c = .four(); // lineG
print(c.value); // lineH
}
12 changes: 12 additions & 0 deletions fixtures/_test_dot_shorthands/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: _test_dot_shorthands
version: 1.0.0
description: >-
A fake package used for testing dot shorthands.
publish_to: none

environment:
sdk: ^3.9.0

dev_dependencies:
build_runner: ^2.5.0
build_web_compilers: ^4.0.4
7 changes: 7 additions & 0 deletions fixtures/_test_dot_shorthands/web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html>

<head>
<script defer src="main.dart.js"></script>
</head>

</html>
28 changes: 28 additions & 0 deletions fixtures/_test_dot_shorthands/web/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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.

// @dart = 3.9

class C {
int value;
C(this.value); // lineA

static C two = C(2); // lineB
static C get three => C(3); // lineC
static C four() => C(4); // lineD
}

void testDotShorthands() {
C c = C(1);
print('breakpoint'); // Breakpoint: testDotShorthands
// ignore: experiment_not_enabled
c = .two; // lineE
// ignore: experiment_not_enabled
c = .three; // lineF
// ignore: experiment_not_enabled
c = .four(); // lineG
print(c.value); // lineH
}

void main() {}
Loading