Skip to content

Commit 614c732

Browse files
authored
Migrate a handful of tests to null-safety (#1715)
1 parent 5105369 commit 614c732

6 files changed

+121
-125
lines changed

dwds/test/frontend_server_breakpoint_test.dart

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
@TestOn('vm')
86
import 'dart:async';
97

@@ -53,64 +51,68 @@ void main() {
5351

5452
group('breakpoint', () {
5553
VM vm;
56-
Isolate isolate;
54+
late Isolate isolate;
55+
late String isolateId;
5756
ScriptList scripts;
58-
ScriptRef mainScript;
59-
Stream<Event> stream;
57+
late ScriptRef mainScript;
58+
late String mainScriptUri;
59+
late Stream<Event> stream;
6060

6161
setUp(() async {
6262
setCurrentLogWriter(debug: debug);
6363
vm = await service.getVM();
64-
isolate = await service.getIsolate(vm.isolates.first.id);
65-
scripts = await service.getScripts(isolate.id);
64+
isolate = await service.getIsolate(vm.isolates!.first.id!);
65+
isolateId = isolate.id!;
66+
scripts = await service.getScripts(isolateId);
6667

6768
await service.streamListen('Debug');
6869
stream = service.onEvent('Debug');
6970

70-
mainScript = scripts.scripts
71-
.firstWhere((each) => each.uri.contains('main.dart'));
71+
mainScript = scripts.scripts!
72+
.firstWhere((each) => each.uri!.contains('main.dart'));
73+
mainScriptUri = mainScript.uri!;
7274
});
7375

7476
tearDown(() async {
75-
await service.resume(isolate.id);
77+
await service.resume(isolateId);
7678
});
7779

7880
test('set breakpoint', () async {
7981
final line = await context.findBreakpointLine(
80-
'printLocal', isolate.id, mainScript);
82+
'printLocal', isolateId, mainScript);
8183
final bp = await service.addBreakpointWithScriptUri(
82-
isolate.id, mainScript.uri, line);
84+
isolateId, mainScriptUri, line);
8385

8486
await stream.firstWhere(
8587
(Event event) => event.kind == EventKind.kPauseBreakpoint);
8688

8789
expect(bp, isNotNull);
8890

8991
// Remove breakpoint so it doesn't impact other tests.
90-
await service.removeBreakpoint(isolate.id, bp.id);
92+
await service.removeBreakpoint(isolateId, bp.id!);
9193
});
9294

9395
test('set breakpoint again', () async {
9496
final line = await context.findBreakpointLine(
95-
'printLocal', isolate.id, mainScript);
97+
'printLocal', isolateId, mainScript);
9698
final bp = await service.addBreakpointWithScriptUri(
97-
isolate.id, mainScript.uri, line);
99+
isolateId, mainScriptUri, line);
98100

99101
await stream.firstWhere(
100102
(Event event) => event.kind == EventKind.kPauseBreakpoint);
101103

102104
expect(bp, isNotNull);
103105

104106
// Remove breakpoint so it doesn't impact other tests.
105-
await service.removeBreakpoint(isolate.id, bp.id);
107+
await service.removeBreakpoint(isolateId, bp.id!);
106108
});
107109

108110
test('set breakpoint inside a JavaScript line succeeds', () async {
109111
final line = await context.findBreakpointLine(
110-
'printNestedObjectMultiLine', isolate.id, mainScript);
112+
'printNestedObjectMultiLine', isolateId, mainScript);
111113
final column = 0;
112114
final bp = await service.addBreakpointWithScriptUri(
113-
isolate.id, mainScript.uri, line,
115+
isolateId, mainScriptUri, line,
114116
column: column);
115117

116118
await stream.firstWhere(
@@ -125,7 +127,7 @@ void main() {
125127
.having((loc) => loc.column, 'column', greaterThan(column)));
126128

127129
// Remove breakpoint so it doesn't impact other tests.
128-
await service.removeBreakpoint(isolate.id, bp.id);
130+
await service.removeBreakpoint(isolateId, bp.id!);
129131
});
130132
});
131133
});

dwds/test/frontend_server_callstack_test.dart

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
@TestOn('vm')
86
import 'dart:async';
97

@@ -66,47 +64,49 @@ void main() {
6664
});
6765

6866
group('callStack |', () {
69-
ChromeProxyService service;
67+
late ChromeProxyService service;
7068
VM vm;
71-
Isolate isolate;
69+
late Isolate isolate;
70+
late String isolateId;
7271
ScriptList scripts;
73-
ScriptRef mainScript;
74-
ScriptRef testLibraryScript;
75-
Stream<Event> stream;
72+
late ScriptRef mainScript;
73+
late ScriptRef testLibraryScript;
74+
late Stream<Event> stream;
7675

7776
setUp(() async {
7877
setCurrentLogWriter(debug: debug);
7978
service = setup.service;
8079
vm = await service.getVM();
81-
isolate = await service.getIsolate(vm.isolates.first.id);
82-
scripts = await service.getScripts(isolate.id);
80+
isolate = await service.getIsolate(vm.isolates!.first.id!);
81+
isolateId = isolate.id!;
82+
scripts = await service.getScripts(isolateId);
8383

8484
await service.streamListen('Debug');
8585
stream = service.onEvent('Debug');
8686

8787
final testPackage =
8888
soundNullSafety ? '_test_package_sound' : '_test_package';
8989

90-
mainScript = scripts.scripts
91-
.firstWhere((each) => each.uri.contains('main.dart'));
92-
testLibraryScript = scripts.scripts.firstWhere((each) =>
93-
each.uri.contains('package:$testPackage/test_library.dart'));
90+
mainScript = scripts.scripts!
91+
.firstWhere((each) => each.uri!.contains('main.dart'));
92+
testLibraryScript = scripts.scripts!.firstWhere((each) =>
93+
each.uri!.contains('package:$testPackage/test_library.dart'));
9494
});
9595

9696
tearDown(() async {
97-
await service.resume(isolate.id);
97+
await service.resume(isolateId);
9898
});
9999

100100
Future<void> onBreakPoint(BreakpointTestData breakpoint,
101101
Future<void> Function() body) async {
102-
Breakpoint bp;
102+
Breakpoint? bp;
103103
try {
104104
final bpId = breakpoint.bpId;
105105
final script = breakpoint.script;
106106
final line =
107-
await context.findBreakpointLine(bpId, isolate.id, script);
107+
await context.findBreakpointLine(bpId, isolateId, script);
108108
bp = await setup.service
109-
.addBreakpointWithScriptUri(isolate.id, script.uri, line);
109+
.addBreakpointWithScriptUri(isolateId, script.uri!, line);
110110

111111
expect(bp, isNotNull);
112112
expect(bp.location, _matchBpLocation(script, line, 0));
@@ -118,7 +118,7 @@ void main() {
118118
} finally {
119119
// Remove breakpoint so it doesn't impact other tests or retries.
120120
if (bp != null) {
121-
await setup.service.removeBreakpoint(isolate.id, bp.id);
121+
await setup.service.removeBreakpoint(isolateId, bp.id!);
122122
}
123123
}
124124
}
@@ -127,13 +127,13 @@ void main() {
127127
{int frameIndex = 1}) async {
128128
// Find lines the breakpoints are located on.
129129
final lines = await Future.wait(breakpoints.map((frame) => context
130-
.findBreakpointLine(frame.bpId, isolate.id, frame.script)));
130+
.findBreakpointLine(frame.bpId, isolateId, frame.script)));
131131

132132
// Get current stack.
133-
final stack = await service.getStack(isolate.id);
133+
final stack = await service.getStack(isolateId);
134134

135135
// Verify the stack is correct.
136-
expect(stack.frames.length, greaterThanOrEqualTo(lines.length));
136+
expect(stack.frames!.length, greaterThanOrEqualTo(lines.length));
137137
final expected = [
138138
for (var i = 0; i < lines.length; i++)
139139
_matchFrame(
@@ -143,7 +143,7 @@ void main() {
143143

144144
// Verify that expression evaluation is not failing.
145145
final instance =
146-
await service.evaluateInFrame(isolate.id, frameIndex, 'true');
146+
await service.evaluateInFrame(isolateId, frameIndex, 'true');
147147
expect(instance, isA<InstanceRef>());
148148
}
149149

@@ -236,7 +236,7 @@ void main() {
236236
),
237237
];
238238
await onBreakPoint(breakpoints[0], () async {
239-
await service.resume(isolate.id, step: 'Out');
239+
await service.resume(isolateId, step: 'Out');
240240
await stream.firstWhere(
241241
(Event event) => event.kind == EventKind.kPauseInterrupted);
242242
return testCallStack([breakpoints[1], breakpoints[2]]);
@@ -263,7 +263,7 @@ void main() {
263263
),
264264
];
265265
await onBreakPoint(breakpoints[1], () async {
266-
await service.resume(isolate.id, step: 'Into');
266+
await service.resume(isolateId, step: 'Into');
267267
await stream.firstWhere(
268268
(Event event) => event.kind == EventKind.kPauseInterrupted);
269269
return testCallStack(breakpoints);
@@ -295,7 +295,7 @@ void main() {
295295
final bp = BreakpointTestData(
296296
'printMultiLine', 'printObjectMultiLine', mainScript);
297297
await onBreakPoint(bp, () async {
298-
await service.resume(isolate.id, step: 'Into');
298+
await service.resume(isolateId, step: 'Into');
299299
await stream.firstWhere(
300300
(Event event) => event.kind == EventKind.kPauseInterrupted);
301301
return testCallStack(breakpoints);
@@ -309,7 +309,7 @@ void main() {
309309
}
310310

311311
Matcher _matchFrame(ScriptRef script, String function, int line) => isA<Frame>()
312-
.having((frame) => frame.code.name, 'function', function)
312+
.having((frame) => frame.code!.name, 'function', function)
313313
.having((frame) => frame.location, 'location',
314314
_matchFrameLocation(script, line));
315315

dwds/test/reload_test.dart

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart = 2.9
6-
75
@TestOn('vm')
86
@Timeout(Duration(minutes: 5))
97
import 'package:dwds/src/loaders/strategy.dart';
@@ -180,9 +178,9 @@ void main() {
180178
));
181179

182180
var vm = await client.getVM();
183-
var isolateId = vm.isolates.first.id;
181+
var isolateId = vm.isolates!.first.id!;
184182
var isolate = await client.getIsolate(isolateId);
185-
var library = isolate.rootLib.uri;
183+
var library = isolate.rootLib!.uri!;
186184

187185
await client.evaluate(
188186
isolateId,
@@ -194,9 +192,9 @@ void main() {
194192
const TypeMatcher<Success>());
195193

196194
vm = await client.getVM();
197-
isolateId = vm.isolates.first.id;
195+
isolateId = vm.isolates!.first.id!;
198196
isolate = await client.getIsolate(isolateId);
199-
library = isolate.rootLib.uri;
197+
library = isolate.rootLib!.uri!;
200198

201199
await client.evaluate(
202200
isolateId,
@@ -237,15 +235,15 @@ void main() {
237235
test('can hot restart while paused', () async {
238236
final client = context.debugConnection.vmService;
239237
var vm = await client.getVM();
240-
var isolateId = vm.isolates.first.id;
238+
var isolateId = vm.isolates!.first.id!;
241239
await client.streamListen('Debug');
242240
final stream = client.onEvent('Debug');
243241
final scriptList = await client.getScripts(isolateId);
244-
final main = scriptList.scripts
245-
.firstWhere((script) => script.uri.contains('main.dart'));
242+
final main = scriptList.scripts!
243+
.firstWhere((script) => script.uri!.contains('main.dart'));
246244
final bpLine =
247245
await context.findBreakpointLine('printCount', isolateId, main);
248-
await client.addBreakpoint(isolateId, main.id, bpLine);
246+
await client.addBreakpoint(isolateId, main.id!, bpLine);
249247
await stream
250248
.firstWhere((event) => event.kind == EventKind.kPauseBreakpoint);
251249

@@ -258,57 +256,58 @@ void main() {
258256
expect(source.contains('Gary is awesome!'), isTrue);
259257

260258
vm = await client.getVM();
261-
isolateId = vm.isolates.first.id;
259+
isolateId = vm.isolates!.first.id!;
262260
final isolate = await client.getIsolate(isolateId);
263261

264262
// Previous breakpoint should still exist.
265-
expect(isolate.breakpoints.isNotEmpty, isTrue);
266-
final bp = isolate.breakpoints.first;
263+
expect(isolate.breakpoints!.isNotEmpty, isTrue);
264+
final bp = isolate.breakpoints!.first;
267265

268266
// Should pause eventually.
269267
await stream
270268
.firstWhere((event) => event.kind == EventKind.kPauseBreakpoint);
271269

272-
expect(await client.removeBreakpoint(isolate.id, bp.id), isA<Success>());
273-
expect(await client.resume(isolate.id), isA<Success>());
270+
expect(
271+
await client.removeBreakpoint(isolate.id!, bp.id!), isA<Success>());
272+
expect(await client.resume(isolate.id!), isA<Success>());
274273
});
275274

276275
test('can evaluate expressions after hot restart ', () async {
277276
final client = context.debugConnection.vmService;
278277
var vm = await client.getVM();
279-
var isolateId = vm.isolates.first.id;
278+
var isolateId = vm.isolates!.first.id!;
280279
await client.streamListen('Debug');
281280
final stream = client.onEvent('Debug');
282281
final scriptList = await client.getScripts(isolateId);
283-
final main = scriptList.scripts
284-
.firstWhere((script) => script.uri.contains('main.dart'));
282+
final main = scriptList.scripts!
283+
.firstWhere((script) => script.uri!.contains('main.dart'));
285284
final bpLine =
286285
await context.findBreakpointLine('printCount', isolateId, main);
287-
await client.addBreakpoint(isolateId, main.id, bpLine);
286+
await client.addBreakpoint(isolateId, main.id!, bpLine);
288287
await stream
289288
.firstWhere((event) => event.kind == EventKind.kPauseBreakpoint);
290289

291290
await client.callServiceExtension('hotRestart');
292291

293292
vm = await client.getVM();
294-
isolateId = vm.isolates.first.id;
293+
isolateId = vm.isolates!.first.id!;
295294
final isolate = await client.getIsolate(isolateId);
296-
final library = isolate.rootLib.uri;
297-
final bp = isolate.breakpoints.first;
295+
final library = isolate.rootLib!.uri!;
296+
final bp = isolate.breakpoints!.first;
298297

299298
// Should pause eventually.
300299
final event = await stream
301300
.firstWhere((event) => event.kind == EventKind.kPauseBreakpoint);
302301

303302
// Expression evaluation while paused on a breakpoint should work.
304303
var result = await client.evaluateInFrame(
305-
isolate.id, event.topFrame.index, 'count');
304+
isolate.id!, event.topFrame!.index!, 'count');
306305
expect(
307306
result,
308307
isA<InstanceRef>().having((instance) => instance.valueAsString,
309308
'valueAsString', greaterThanOrEqualTo('0')));
310309

311-
await client.removeBreakpoint(isolateId, bp.id);
310+
await client.removeBreakpoint(isolateId, bp.id!);
312311
await client.resume(isolateId);
313312

314313
// Expression evaluation while running should work.

0 commit comments

Comments
 (0)