From 45fb1ccfa0efc40258e34c9e037de080ac9a3dec Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Fri, 5 Aug 2022 16:57:38 -0700 Subject: [PATCH 1/2] Migrate inspector test to null-safety --- dwds/test/inspector_test.dart | 38 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/dwds/test/inspector_test.dart b/dwds/test/inspector_test.dart index 24abc75f3..45c57ffb0 100644 --- a/dwds/test/inspector_test.dart +++ b/dwds/test/inspector_test.dart @@ -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 'package:dwds/dwds.dart'; import 'package:dwds/src/connections/debug_connection.dart'; @@ -23,8 +21,8 @@ final context = TestContext( WipConnection get tabConnection => context.tabConnection; void main() { - AppInspector inspector; - Debugger debugger; + late AppInspector inspector; + late Debugger debugger; setUpAll(() async { await context.setUp(); @@ -60,7 +58,7 @@ void main() { () => inspector.jsEvaluate('<'), throwsA(isA() .having((e) => e.text, 'text', 'Uncaught') - .having((e) => e.exception.description, 'description', + .having((e) => e.exception?.description, 'description', contains('SyntaxError')) .having((e) => e.stackTrace, 'stackTrace', isNull) .having((e) => e.evalContents, 'evalContents', '<'))); @@ -78,9 +76,9 @@ void main() { '''), throwsA(isA() .having((e) => e.text, 'text', 'Uncaught') - .having((e) => e.exception.description, 'description', + .having((e) => e.exception?.description, 'description', contains('ReferenceError')) - .having((e) => e.stackTrace.printFrames()[0], 'stackTrace', + .having((e) => e.stackTrace?.printFrames()[0], 'stackTrace', contains('foo()')) .having((e) => e.evalContents, 'evalContents', contains('foo')))); }); @@ -89,7 +87,7 @@ void main() { test('send toString', () async { final remoteObject = await libraryPublicFinal(); final toString = - await inspector.invoke(remoteObject.objectId, 'toString', []); + await inspector.invoke(remoteObject.objectId!, 'toString', []); expect(toString.value, 'A test class with message world'); }); @@ -97,9 +95,9 @@ void main() { test('for class with generic', () async { final remoteObject = await libraryPublicFinal(); final instance = - await inspector.getObject(remoteObject.objectId) as Instance; - final classRef = instance.classRef; - final clazz = await inspector.getObject(classRef.id) as Class; + await inspector.getObject(remoteObject.objectId!) as Instance; + final classRef = instance.classRef!; + final clazz = await inspector.getObject(classRef.id!) as Class; expect(clazz.name, 'MyTestClass'); }); }); @@ -120,7 +118,7 @@ void main() { test('properties', () async { final remoteObject = await libraryPublicFinal(); - final properties = await debugger.getProperties(remoteObject.objectId); + final properties = await debugger.getProperties(remoteObject.objectId!); final names = properties.map((p) => p.name).where((x) => x != '__proto__').toList(); final expected = [ @@ -141,8 +139,8 @@ void main() { // We test these here because the test fixture has more complicated members // to exercise. - LibraryRef bootstrapLibrary; - RemoteObject instance; + LibraryRef? bootstrapLibrary; + late RemoteObject instance; setUp(() async { bootstrapLibrary = inspector.isolate.rootLib; @@ -150,7 +148,7 @@ void main() { }); test('invoke top-level private', () async { - final remote = await inspector.invoke(bootstrapLibrary.id, + final remote = await inspector.invoke(bootstrapLibrary!.id!, '_libraryPrivateFunction', [dartIdFor(2), dartIdFor(3)]); expect( remote, @@ -160,7 +158,7 @@ void main() { test('invoke instance private', () async { final remote = await inspector.invoke( - instance.objectId, 'privateMethod', [dartIdFor('some string')]); + instance.objectId!, 'privateMethod', [dartIdFor('some string')]); expect( remote, const TypeMatcher().having((instance) => instance.value, @@ -169,7 +167,7 @@ void main() { test('invoke instance method with object parameter', () async { final remote = await inspector - .invoke(instance.objectId, 'equals', [instance.objectId]); + .invoke(instance.objectId!, 'equals', [instance.objectId]); expect( remote, const TypeMatcher() @@ -179,7 +177,7 @@ void main() { test('invoke instance method with object parameter 2', () async { final libraryPrivateList = await libraryPrivate(); final remote = await inspector - .invoke(instance.objectId, 'equals', [libraryPrivateList.objectId]); + .invoke(instance.objectId!, 'equals', [libraryPrivateList.objectId]); expect( remote, const TypeMatcher() @@ -187,7 +185,7 @@ void main() { }); test('invoke closure stored in an instance field', () async { - final remote = await inspector.invoke(instance.objectId, 'closure', []); + final remote = await inspector.invoke(instance.objectId!, 'closure', []); expect( remote, const TypeMatcher() @@ -196,7 +194,7 @@ void main() { test('invoke a torn-off method', () async { final toString = await inspector.loadField(instance, 'tornOff'); - final result = await inspector.invoke(toString.objectId, 'call', []); + final result = await inspector.invoke(toString.objectId!, 'call', []); expect( result, const TypeMatcher().having((instance) => instance.value, From 9645832d3f997c428d0ebca497826f2664827933 Mon Sep 17 00:00:00 2001 From: Elliott Brooks <21270878+elliette@users.noreply.github.com> Date: Mon, 8 Aug 2022 15:09:15 -0700 Subject: [PATCH 2/2] Respond to PR comments --- dwds/test/inspector_test.dart | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/dwds/test/inspector_test.dart b/dwds/test/inspector_test.dart index 45c57ffb0..f4fdea39a 100644 --- a/dwds/test/inspector_test.dart +++ b/dwds/test/inspector_test.dart @@ -141,10 +141,12 @@ void main() { LibraryRef? bootstrapLibrary; late RemoteObject instance; + late String objectId; setUp(() async { bootstrapLibrary = inspector.isolate.rootLib; instance = await libraryPublicFinal(); + objectId = instance.objectId!; }); test('invoke top-level private', () async { @@ -157,8 +159,8 @@ void main() { }); test('invoke instance private', () async { - final remote = await inspector.invoke( - instance.objectId!, 'privateMethod', [dartIdFor('some string')]); + final remote = await inspector + .invoke(objectId, 'privateMethod', [dartIdFor('some string')]); expect( remote, const TypeMatcher().having((instance) => instance.value, @@ -166,8 +168,7 @@ void main() { }); test('invoke instance method with object parameter', () async { - final remote = await inspector - .invoke(instance.objectId!, 'equals', [instance.objectId]); + final remote = await inspector.invoke(objectId, 'equals', [objectId]); expect( remote, const TypeMatcher() @@ -177,7 +178,7 @@ void main() { test('invoke instance method with object parameter 2', () async { final libraryPrivateList = await libraryPrivate(); final remote = await inspector - .invoke(instance.objectId!, 'equals', [libraryPrivateList.objectId]); + .invoke(objectId, 'equals', [libraryPrivateList.objectId]); expect( remote, const TypeMatcher() @@ -185,7 +186,7 @@ void main() { }); test('invoke closure stored in an instance field', () async { - final remote = await inspector.invoke(instance.objectId!, 'closure', []); + final remote = await inspector.invoke(objectId, 'closure', []); expect( remote, const TypeMatcher()