Skip to content

Migrate a handful of tests to null-safety #1715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 9, 2022
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
40 changes: 21 additions & 19 deletions dwds/test/frontend_server_breakpoint_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +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.

// @dart = 2.9

@TestOn('vm')
import 'dart:async';

Expand Down Expand Up @@ -53,64 +51,68 @@ void main() {

group('breakpoint', () {
VM vm;
Isolate isolate;
late Isolate isolate;
late String isolateId;
ScriptList scripts;
ScriptRef mainScript;
Stream<Event> stream;
late ScriptRef mainScript;
late String mainScriptUri;
late Stream<Event> stream;

setUp(() async {
setCurrentLogWriter(debug: debug);
vm = await service.getVM();
isolate = await service.getIsolate(vm.isolates.first.id);
scripts = await service.getScripts(isolate.id);
isolate = await service.getIsolate(vm.isolates!.first.id!);
isolateId = isolate.id!;
scripts = await service.getScripts(isolateId);

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

mainScript = scripts.scripts
.firstWhere((each) => each.uri.contains('main.dart'));
mainScript = scripts.scripts!
.firstWhere((each) => each.uri!.contains('main.dart'));
mainScriptUri = mainScript.uri!;
});

tearDown(() async {
await service.resume(isolate.id);
await service.resume(isolateId);
});

test('set breakpoint', () async {
final line = await context.findBreakpointLine(
'printLocal', isolate.id, mainScript);
'printLocal', isolateId, mainScript);
final bp = await service.addBreakpointWithScriptUri(
isolate.id, mainScript.uri, line);
isolateId, mainScriptUri, line);

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

expect(bp, isNotNull);

// Remove breakpoint so it doesn't impact other tests.
await service.removeBreakpoint(isolate.id, bp.id);
await service.removeBreakpoint(isolateId, bp.id!);
});

test('set breakpoint again', () async {
final line = await context.findBreakpointLine(
'printLocal', isolate.id, mainScript);
'printLocal', isolateId, mainScript);
final bp = await service.addBreakpointWithScriptUri(
isolate.id, mainScript.uri, line);
isolateId, mainScriptUri, line);

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

expect(bp, isNotNull);

// Remove breakpoint so it doesn't impact other tests.
await service.removeBreakpoint(isolate.id, bp.id);
await service.removeBreakpoint(isolateId, bp.id!);
});

test('set breakpoint inside a JavaScript line succeeds', () async {
final line = await context.findBreakpointLine(
'printNestedObjectMultiLine', isolate.id, mainScript);
'printNestedObjectMultiLine', isolateId, mainScript);
final column = 0;
final bp = await service.addBreakpointWithScriptUri(
isolate.id, mainScript.uri, line,
isolateId, mainScriptUri, line,
column: column);

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

// Remove breakpoint so it doesn't impact other tests.
await service.removeBreakpoint(isolate.id, bp.id);
await service.removeBreakpoint(isolateId, bp.id!);
});
});
});
Expand Down
52 changes: 26 additions & 26 deletions dwds/test/frontend_server_callstack_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +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.

// @dart = 2.9

@TestOn('vm')
import 'dart:async';

Expand Down Expand Up @@ -66,47 +64,49 @@ void main() {
});

group('callStack |', () {
ChromeProxyService service;
late ChromeProxyService service;
VM vm;
Isolate isolate;
late Isolate isolate;
late String isolateId;
ScriptList scripts;
ScriptRef mainScript;
ScriptRef testLibraryScript;
Stream<Event> stream;
late ScriptRef mainScript;
late ScriptRef testLibraryScript;
late Stream<Event> stream;

setUp(() async {
setCurrentLogWriter(debug: debug);
service = setup.service;
vm = await service.getVM();
isolate = await service.getIsolate(vm.isolates.first.id);
scripts = await service.getScripts(isolate.id);
isolate = await service.getIsolate(vm.isolates!.first.id!);
isolateId = isolate.id!;
scripts = await service.getScripts(isolateId);

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

final testPackage =
soundNullSafety ? '_test_package_sound' : '_test_package';

mainScript = scripts.scripts
.firstWhere((each) => each.uri.contains('main.dart'));
testLibraryScript = scripts.scripts.firstWhere((each) =>
each.uri.contains('package:$testPackage/test_library.dart'));
mainScript = scripts.scripts!
.firstWhere((each) => each.uri!.contains('main.dart'));
testLibraryScript = scripts.scripts!.firstWhere((each) =>
each.uri!.contains('package:$testPackage/test_library.dart'));
});

tearDown(() async {
await service.resume(isolate.id);
await service.resume(isolateId);
});

Future<void> onBreakPoint(BreakpointTestData breakpoint,
Future<void> Function() body) async {
Breakpoint bp;
Breakpoint? bp;
try {
final bpId = breakpoint.bpId;
final script = breakpoint.script;
final line =
await context.findBreakpointLine(bpId, isolate.id, script);
await context.findBreakpointLine(bpId, isolateId, script);
bp = await setup.service
.addBreakpointWithScriptUri(isolate.id, script.uri, line);
.addBreakpointWithScriptUri(isolateId, script.uri!, line);

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

// Get current stack.
final stack = await service.getStack(isolate.id);
final stack = await service.getStack(isolateId);

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

// Verify that expression evaluation is not failing.
final instance =
await service.evaluateInFrame(isolate.id, frameIndex, 'true');
await service.evaluateInFrame(isolateId, frameIndex, 'true');
expect(instance, isA<InstanceRef>());
}

Expand Down Expand Up @@ -236,7 +236,7 @@ void main() {
),
];
await onBreakPoint(breakpoints[0], () async {
await service.resume(isolate.id, step: 'Out');
await service.resume(isolateId, step: 'Out');
await stream.firstWhere(
(Event event) => event.kind == EventKind.kPauseInterrupted);
return testCallStack([breakpoints[1], breakpoints[2]]);
Expand All @@ -263,7 +263,7 @@ void main() {
),
];
await onBreakPoint(breakpoints[1], () async {
await service.resume(isolate.id, step: 'Into');
await service.resume(isolateId, step: 'Into');
await stream.firstWhere(
(Event event) => event.kind == EventKind.kPauseInterrupted);
return testCallStack(breakpoints);
Expand Down Expand Up @@ -295,7 +295,7 @@ void main() {
final bp = BreakpointTestData(
'printMultiLine', 'printObjectMultiLine', mainScript);
await onBreakPoint(bp, () async {
await service.resume(isolate.id, step: 'Into');
await service.resume(isolateId, step: 'Into');
await stream.firstWhere(
(Event event) => event.kind == EventKind.kPauseInterrupted);
return testCallStack(breakpoints);
Expand All @@ -309,7 +309,7 @@ void main() {
}

Matcher _matchFrame(ScriptRef script, String function, int line) => isA<Frame>()
.having((frame) => frame.code.name, 'function', function)
.having((frame) => frame.code!.name, 'function', function)
.having((frame) => frame.location, 'location',
_matchFrameLocation(script, line));

Expand Down
47 changes: 23 additions & 24 deletions dwds/test/reload_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +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.

// @dart = 2.9

@TestOn('vm')
@Timeout(Duration(minutes: 5))
import 'package:dwds/src/loaders/strategy.dart';
Expand Down Expand Up @@ -180,9 +178,9 @@ void main() {
));

var vm = await client.getVM();
var isolateId = vm.isolates.first.id;
var isolateId = vm.isolates!.first.id!;
var isolate = await client.getIsolate(isolateId);
var library = isolate.rootLib.uri;
var library = isolate.rootLib!.uri!;

await client.evaluate(
isolateId,
Expand All @@ -194,9 +192,9 @@ void main() {
const TypeMatcher<Success>());

vm = await client.getVM();
isolateId = vm.isolates.first.id;
isolateId = vm.isolates!.first.id!;
isolate = await client.getIsolate(isolateId);
library = isolate.rootLib.uri;
library = isolate.rootLib!.uri!;

await client.evaluate(
isolateId,
Expand Down Expand Up @@ -237,15 +235,15 @@ void main() {
test('can hot restart while paused', () async {
final client = context.debugConnection.vmService;
var vm = await client.getVM();
var isolateId = vm.isolates.first.id;
var isolateId = vm.isolates!.first.id!;
await client.streamListen('Debug');
final stream = client.onEvent('Debug');
final scriptList = await client.getScripts(isolateId);
final main = scriptList.scripts
.firstWhere((script) => script.uri.contains('main.dart'));
final main = scriptList.scripts!
.firstWhere((script) => script.uri!.contains('main.dart'));
final bpLine =
await context.findBreakpointLine('printCount', isolateId, main);
await client.addBreakpoint(isolateId, main.id, bpLine);
await client.addBreakpoint(isolateId, main.id!, bpLine);
await stream
.firstWhere((event) => event.kind == EventKind.kPauseBreakpoint);

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

vm = await client.getVM();
isolateId = vm.isolates.first.id;
isolateId = vm.isolates!.first.id!;
final isolate = await client.getIsolate(isolateId);

// Previous breakpoint should still exist.
expect(isolate.breakpoints.isNotEmpty, isTrue);
final bp = isolate.breakpoints.first;
expect(isolate.breakpoints!.isNotEmpty, isTrue);
final bp = isolate.breakpoints!.first;

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

expect(await client.removeBreakpoint(isolate.id, bp.id), isA<Success>());
expect(await client.resume(isolate.id), isA<Success>());
expect(
await client.removeBreakpoint(isolate.id!, bp.id!), isA<Success>());
expect(await client.resume(isolate.id!), isA<Success>());
});

test('can evaluate expressions after hot restart ', () async {
final client = context.debugConnection.vmService;
var vm = await client.getVM();
var isolateId = vm.isolates.first.id;
var isolateId = vm.isolates!.first.id!;
await client.streamListen('Debug');
final stream = client.onEvent('Debug');
final scriptList = await client.getScripts(isolateId);
final main = scriptList.scripts
.firstWhere((script) => script.uri.contains('main.dart'));
final main = scriptList.scripts!
.firstWhere((script) => script.uri!.contains('main.dart'));
final bpLine =
await context.findBreakpointLine('printCount', isolateId, main);
await client.addBreakpoint(isolateId, main.id, bpLine);
await client.addBreakpoint(isolateId, main.id!, bpLine);
await stream
.firstWhere((event) => event.kind == EventKind.kPauseBreakpoint);

await client.callServiceExtension('hotRestart');

vm = await client.getVM();
isolateId = vm.isolates.first.id;
isolateId = vm.isolates!.first.id!;
final isolate = await client.getIsolate(isolateId);
final library = isolate.rootLib.uri;
final bp = isolate.breakpoints.first;
final library = isolate.rootLib!.uri!;
final bp = isolate.breakpoints!.first;

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

// Expression evaluation while paused on a breakpoint should work.
var result = await client.evaluateInFrame(
isolate.id, event.topFrame.index, 'count');
isolate.id!, event.topFrame!.index!, 'count');
expect(
result,
isA<InstanceRef>().having((instance) => instance.valueAsString,
'valueAsString', greaterThanOrEqualTo('0')));

await client.removeBreakpoint(isolateId, bp.id);
await client.removeBreakpoint(isolateId, bp.id!);
await client.resume(isolateId);

// Expression evaluation while running should work.
Expand Down
Loading