Skip to content

Commit 6a3f609

Browse files
authored
Migrate fakes.dart to null-safety (#1699)
1 parent 27cc5c9 commit 6a3f609

File tree

8 files changed

+174
-174
lines changed

8 files changed

+174
-174
lines changed

dwds/test/dart_uri_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import 'package:path/path.dart' as p;
1414
import 'package:test/test.dart';
1515

1616
import 'fixtures/logging.dart';
17-
import 'fixtures/migrated_fakes.dart';
17+
import 'fixtures/fakes.dart';
1818

1919
class TestStrategy extends FakeStrategy {
2020
@override

dwds/test/debugger_test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'
2121
import 'fixtures/context.dart';
2222
import 'fixtures/debugger_data.dart';
2323
import 'fixtures/fakes.dart';
24-
import 'fixtures/migrated_fakes.dart';
2524

2625
final context = TestContext();
2726
AppInspector inspector;
@@ -98,7 +97,7 @@ void main() async {
9897
skipLists,
9998
root,
10099
);
101-
inspector = FakeInspector();
100+
inspector = FakeInspector(fakeIsolate: simpleIsolate);
102101
debugger.updateInspector(inspector);
103102
});
104103

dwds/test/fixtures/fakes.dart

Lines changed: 168 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@
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
import 'dart:async';
86

7+
import 'package:dwds/asset_reader.dart';
8+
import 'package:dwds/expression_compiler.dart';
99
import 'package:dwds/src/debugging/classes.dart';
1010
import 'package:dwds/src/debugging/execution_context.dart';
1111
import 'package:dwds/src/debugging/inspector.dart';
1212
import 'package:dwds/src/debugging/instance.dart';
1313
import 'package:dwds/src/debugging/libraries.dart';
14+
import 'package:dwds/src/debugging/metadata/provider.dart';
1415
import 'package:dwds/src/debugging/modules.dart';
1516
import 'package:dwds/src/debugging/remote_debugger.dart';
1617
import 'package:dwds/src/debugging/webkit_debugger.dart';
1718
import 'package:dwds/src/handlers/socket_connections.dart';
1819
import 'package:dwds/src/loaders/require.dart';
1920
import 'package:dwds/src/loaders/strategy.dart';
21+
import 'package:shelf/shelf.dart' as shelf;
2022
import 'package:vm_service/vm_service.dart';
2123

2224
/// A library of fake/stub implementations of our classes and their supporting
@@ -44,44 +46,48 @@ Isolate get simpleIsolate => Isolate(
4446
);
4547

4648
class FakeInspector implements AppInspector {
47-
FakeInspector({this.fakeIsolate});
49+
FakeInspector({required this.fakeIsolate});
4850

4951
Isolate fakeIsolate;
5052

51-
final _instanceHelper = InstanceHelper(null, null);
52-
5353
@override
5454
Object noSuchMethod(Invocation invocation) {
5555
throw UnsupportedError('This is a fake');
5656
}
5757

5858
@override
5959
Future<void> initialize(LibraryHelper libraryHelper, ClassHelper classHelper,
60-
InstanceHelper instanceHelper) =>
61-
null;
60+
InstanceHelper instanceHelper) async =>
61+
{};
6262

6363
@override
64-
Future<InstanceRef> instanceRefFor(Object value) =>
65-
_instanceHelper.instanceRefFor(value);
64+
Future<InstanceRef?> instanceRefFor(Object value) async =>
65+
InstanceHelper.kNullInstanceRef;
6666

6767
@override
68-
Future<Obj> getObject(String objectId, {int offset, int count}) => null;
68+
Future<Obj> getObject(String objectId, {int? offset, int? count}) async =>
69+
Obj.parse({})!;
6970

7071
@override
71-
Future<ScriptList> getScripts() => null;
72+
Future<ScriptList> getScripts() async => ScriptList(scripts: []);
7273

7374
@override
74-
Future<ScriptRef> scriptRefFor(String uri) =>
75-
Future.value(ScriptRef(id: 'fake', uri: 'fake://uri'));
75+
Future<ScriptRef> scriptRefFor(String uri) async =>
76+
ScriptRef(id: 'fake', uri: 'fake://uri');
7677

7778
@override
78-
ScriptRef scriptWithId(String scriptId) => null;
79+
ScriptRef? scriptWithId(String? scriptId) => null;
7980

8081
@override
8182
Isolate get isolate => fakeIsolate;
8283

8384
@override
84-
IsolateRef get isolateRef => null;
85+
IsolateRef get isolateRef => IsolateRef(
86+
id: fakeIsolate.id,
87+
number: fakeIsolate.number,
88+
name: fakeIsolate.name,
89+
isSystemIsolate: fakeIsolate.isSystemIsolate,
90+
);
8591
}
8692

8793
class FakeSseConnection implements SseSocketConnection {
@@ -130,105 +136,108 @@ class FakeModules implements Modules {
130136
}
131137

132138
class FakeWebkitDebugger implements WebkitDebugger {
133-
final Map<String, WipScript> _scripts;
139+
final Map<String, WipScript>? _scripts;
134140
@override
135-
Future disable() => null;
141+
Future disable() async => null;
136142

137143
@override
138-
Future enable() => null;
144+
Future enable() async => null;
139145

140-
FakeWebkitDebugger({Map<String, WipScript> scripts}) : _scripts = scripts {
146+
FakeWebkitDebugger({Map<String, WipScript>? scripts}) : _scripts = scripts {
141147
globalLoadStrategy = RequireStrategy(
142-
ReloadConfiguration.none,
143-
(_) async => {},
144-
(_) async => {},
145-
(_, __) async => null,
146-
(_, __) async => null,
147-
(_, __) async => null,
148-
null,
149-
(_) async => null,
150-
null);
148+
ReloadConfiguration.none,
149+
(_) async => {},
150+
(_) async => {},
151+
(_, __) async => null,
152+
(MetadataProvider _, String __) async => '',
153+
(MetadataProvider _, String __) async => '',
154+
(String _) => '',
155+
(MetadataProvider _) async => <String, ModuleInfo>{},
156+
FakeAssetReader(),
157+
);
151158
}
152159

153160
@override
154161
Stream<T> eventStream<T>(String method, WipEventTransformer<T> transformer) =>
155-
null;
162+
Stream.empty();
156163

157164
@override
158-
Future<String> getScriptSource(String scriptId) => null;
165+
Future<String> getScriptSource(String scriptId) async => '';
159166

160-
Stream<WipDomain> get onClosed => null;
167+
Stream<WipDomain>? get onClosed => null;
161168

162169
@override
163-
Stream<GlobalObjectClearedEvent> get onGlobalObjectCleared => null;
170+
Stream<GlobalObjectClearedEvent> get onGlobalObjectCleared => Stream.empty();
164171

165172
@override
166-
Stream<DebuggerPausedEvent> onPaused;
173+
late Stream<DebuggerPausedEvent> onPaused;
167174

168175
@override
169-
Stream<DebuggerResumedEvent> get onResumed => null;
176+
Stream<DebuggerResumedEvent> get onResumed => Stream.empty();
170177

171178
@override
172-
Stream<ScriptParsedEvent> get onScriptParsed => null;
179+
Stream<ScriptParsedEvent> get onScriptParsed => Stream.empty();
173180

174181
@override
175-
Stream<TargetCrashedEvent> get onTargetCrashed => null;
182+
Stream<TargetCrashedEvent> get onTargetCrashed => Stream.empty();
176183

177184
@override
178-
Future<WipResponse> pause() => null;
185+
Future<WipResponse> pause() async => WipResponse({});
179186

180187
@override
181-
Future<WipResponse> resume() => null;
188+
Future<WipResponse> resume() async => WipResponse({});
182189

183190
@override
184-
Map<String, WipScript> get scripts => _scripts;
191+
Map<String, WipScript> get scripts => _scripts!;
185192

186193
List<WipResponse> results = variables1;
187194
int resultsReturned = 0;
188195

189196
@override
190-
Future<WipResponse> sendCommand(
191-
String method, {
192-
Map<String, dynamic> params,
193-
}) async {
197+
Future<WipResponse> sendCommand(String command,
198+
{Map<String, dynamic>? params}) async {
194199
// Force the results that we expect for looking up the variables.
195-
if (method == 'Runtime.getProperties') {
200+
if (command == 'Runtime.getProperties') {
196201
return results[resultsReturned++];
197202
}
198-
return null;
203+
return WipResponse({});
199204
}
200205

201206
@override
202-
Future<WipResponse> setPauseOnExceptions(PauseState state) => null;
207+
Future<WipResponse> setPauseOnExceptions(PauseState state) async =>
208+
WipResponse({});
203209

204210
@override
205-
Future<WipResponse> removeBreakpoint(String breakpointId) => null;
211+
Future<WipResponse> removeBreakpoint(String breakpointId) async =>
212+
WipResponse({});
206213

207214
@override
208-
Future<WipResponse> stepInto({Map<String, dynamic> params}) => null;
215+
Future<WipResponse> stepInto({Map<String, dynamic>? params}) async =>
216+
WipResponse({});
209217

210218
@override
211-
Future<WipResponse> stepOut() => null;
219+
Future<WipResponse> stepOut() async => WipResponse({});
212220

213221
@override
214-
Future<WipResponse> stepOver({Map<String, dynamic> params}) => null;
222+
Future<WipResponse> stepOver({Map<String, dynamic>? params}) async =>
223+
WipResponse({});
215224

216225
@override
217-
Stream<ConsoleAPIEvent> get onConsoleAPICalled => null;
226+
Stream<ConsoleAPIEvent> get onConsoleAPICalled => Stream.empty();
218227

219228
@override
220-
Stream<ExceptionThrownEvent> get onExceptionThrown => null;
229+
Stream<ExceptionThrownEvent> get onExceptionThrown => Stream.empty();
221230

222231
@override
223232
void close() {}
224233

225234
@override
226-
Stream<WipConnection> get onClose => null;
235+
Stream<WipConnection> get onClose => Stream.empty();
227236

228237
@override
229238
Future<RemoteObject> evaluate(String expression,
230-
{bool returnByValue, int contextId}) =>
231-
null;
239+
{bool? returnByValue, int? contextId}) async =>
240+
RemoteObject({});
232241

233242
@override
234243
Future<RemoteObject> evaluateOnCallFrame(
@@ -237,14 +246,15 @@ class FakeWebkitDebugger implements WebkitDebugger {
237246
}
238247

239248
@override
240-
Future<List<WipBreakLocation>> getPossibleBreakpoints(WipLocation start) =>
241-
null;
249+
Future<List<WipBreakLocation>> getPossibleBreakpoints(
250+
WipLocation start) async =>
251+
[];
242252

243253
@override
244-
Future<WipResponse> enablePage() => null;
254+
Future<WipResponse> enablePage() async => WipResponse({});
245255

246256
@override
247-
Future<WipResponse> pageReload() => null;
257+
Future<WipResponse> pageReload() async => WipResponse({});
248258
}
249259

250260
/// Fake execution context that is needed for id only
@@ -256,3 +266,102 @@ class FakeExecutionContext extends ExecutionContext {
256266

257267
FakeExecutionContext();
258268
}
269+
270+
class FakeStrategy implements LoadStrategy {
271+
@override
272+
Future<String> bootstrapFor(String entrypoint) async => 'dummy_bootstrap';
273+
274+
@override
275+
shelf.Handler get handler =>
276+
(request) => (request.url.path == 'someDummyPath')
277+
? shelf.Response.ok('some dummy response')
278+
: shelf.Response.notFound('someDummyPath');
279+
280+
@override
281+
String get id => 'dummy-id';
282+
283+
@override
284+
String get moduleFormat => 'dummy-format';
285+
286+
@override
287+
String get loadLibrariesModule => '';
288+
289+
@override
290+
String get loadLibrariesSnippet => '';
291+
292+
@override
293+
String loadLibrarySnippet(String libraryUri) => '';
294+
295+
@override
296+
String get loadModuleSnippet => '';
297+
298+
@override
299+
ReloadConfiguration get reloadConfiguration => ReloadConfiguration.none;
300+
301+
@override
302+
String loadClientSnippet(String clientScript) => 'dummy-load-client-snippet';
303+
304+
@override
305+
Future<String> moduleForServerPath(
306+
String entrypoint, String serverPath) async =>
307+
'';
308+
309+
@override
310+
Future<String> serverPathForModule(String entrypoint, String module) async =>
311+
'';
312+
313+
@override
314+
Future<String> sourceMapPathForModule(
315+
String entrypoint, String module) async =>
316+
'';
317+
318+
@override
319+
String serverPathForAppUri(String appUri) => '';
320+
321+
@override
322+
MetadataProvider metadataProviderFor(String entrypoint) =>
323+
MetadataProvider(entrypoint, FakeAssetReader());
324+
325+
@override
326+
void trackEntrypoint(String entrypoint) {}
327+
328+
@override
329+
Future<Map<String, ModuleInfo>> moduleInfoForEntrypoint(String entrypoint) =>
330+
throw UnimplementedError();
331+
}
332+
333+
class FakeAssetReader implements AssetReader {
334+
final String? _metadata;
335+
final String? _dartSource;
336+
final String? _sourceMap;
337+
FakeAssetReader({
338+
metadata,
339+
dartSource,
340+
sourceMap,
341+
}) : _metadata = metadata,
342+
_dartSource = dartSource,
343+
_sourceMap = sourceMap;
344+
345+
@override
346+
Future<String> dartSourceContents(String serverPath) {
347+
return _throwUnimplementedOrReturnContents(_dartSource);
348+
}
349+
350+
@override
351+
Future<String> metadataContents(String serverPath) {
352+
return _throwUnimplementedOrReturnContents(_metadata);
353+
}
354+
355+
@override
356+
Future<String> sourceMapContents(String serverPath) {
357+
return _throwUnimplementedOrReturnContents(_sourceMap);
358+
}
359+
360+
@override
361+
Future<void> close() async {}
362+
363+
Future<String> _throwUnimplementedOrReturnContents(String? contents) async {
364+
if (contents == null) throw UnimplementedError();
365+
return contents;
366+
}
367+
}

0 commit comments

Comments
 (0)