|
| 1 | +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +@Tags(['daily']) |
| 6 | +@TestOn('vm') |
| 7 | +@Timeout(Duration(minutes: 2)) |
| 8 | + |
| 9 | +import 'package:test/test.dart'; |
| 10 | +import 'package:test_common/logging.dart'; |
| 11 | +import 'package:test_common/test_sdk_configuration.dart'; |
| 12 | +import 'package:vm_service/vm_service.dart'; |
| 13 | + |
| 14 | +import '../fixtures/context.dart'; |
| 15 | +import '../fixtures/project.dart'; |
| 16 | +import 'common/test_inspector.dart'; |
| 17 | + |
| 18 | +void main() { |
| 19 | + // Enable verbose logging for debugging. |
| 20 | + final debug = false; |
| 21 | + |
| 22 | + final provider = TestSdkConfigurationProvider( |
| 23 | + verbose: debug, |
| 24 | + ); |
| 25 | + |
| 26 | + final context = |
| 27 | + TestContext(TestProject.testExperimentWithSoundNullSafety, provider); |
| 28 | + final testInspector = TestInspector(context); |
| 29 | + |
| 30 | + late VmService service; |
| 31 | + late Stream<Event> stream; |
| 32 | + late String isolateId; |
| 33 | + late ScriptRef mainScript; |
| 34 | + |
| 35 | + onBreakPoint(breakPointId, body) => testInspector.onBreakPoint( |
| 36 | + stream, |
| 37 | + isolateId, |
| 38 | + mainScript, |
| 39 | + breakPointId, |
| 40 | + body, |
| 41 | + ); |
| 42 | + |
| 43 | + getObject(instanceId) => service.getObject(isolateId, instanceId); |
| 44 | + |
| 45 | + group('Class |', () { |
| 46 | + tearDownAll(provider.dispose); |
| 47 | + |
| 48 | + for (var compilationMode in CompilationMode.values) { |
| 49 | + group('$compilationMode |', () { |
| 50 | + setUpAll(() async { |
| 51 | + setCurrentLogWriter(debug: debug); |
| 52 | + await context.setUp( |
| 53 | + compilationMode: compilationMode, |
| 54 | + enableExpressionEvaluation: true, |
| 55 | + verboseCompiler: debug, |
| 56 | + ); |
| 57 | + service = context.debugConnection.vmService; |
| 58 | + |
| 59 | + final vm = await service.getVM(); |
| 60 | + isolateId = vm.isolates!.first.id!; |
| 61 | + final scripts = await service.getScripts(isolateId); |
| 62 | + |
| 63 | + await service.streamListen('Debug'); |
| 64 | + stream = service.onEvent('Debug'); |
| 65 | + |
| 66 | + mainScript = scripts.scripts! |
| 67 | + .firstWhere((each) => each.uri!.contains('main.dart')); |
| 68 | + }); |
| 69 | + |
| 70 | + tearDownAll(() async { |
| 71 | + await context.tearDown(); |
| 72 | + }); |
| 73 | + |
| 74 | + setUp(() => setCurrentLogWriter(debug: debug)); |
| 75 | + tearDown(() => service.resume(isolateId)); |
| 76 | + |
| 77 | + group('calling getObject for an existent class', () { |
| 78 | + test('returns the correct class representation', () async { |
| 79 | + await onBreakPoint('testClass1Case1', (event) async { |
| 80 | + // classes|dart:core|Object_Diagnosticable |
| 81 | + final result = await getObject( |
| 82 | + 'classes|org-dartlang-app:///web/main.dart|GreeterClass', |
| 83 | + ); |
| 84 | + final clazz = result as Class?; |
| 85 | + expect(clazz!.name, equals('GreeterClass')); |
| 86 | + expect( |
| 87 | + clazz.fields!.map((field) => field.name), |
| 88 | + unorderedEquals([ |
| 89 | + 'greeteeName', |
| 90 | + 'useFrench', |
| 91 | + ]), |
| 92 | + ); |
| 93 | + expect( |
| 94 | + clazz.functions!.map((fn) => fn.name), |
| 95 | + containsAll([ |
| 96 | + 'sayHello', |
| 97 | + 'greetInEnglish', |
| 98 | + 'greetInFrench', |
| 99 | + ]), |
| 100 | + ); |
| 101 | + }); |
| 102 | + }); |
| 103 | + }); |
| 104 | + |
| 105 | + group('calling getObject for a non-existent class', () { |
| 106 | + // TODO(https://github.com/dart-lang/webdev/issues/2297): Ideally we |
| 107 | + // should throw an error in this case for the client to catch instead |
| 108 | + // of returning an empty class. |
| 109 | + test('returns an empty class representation', () async { |
| 110 | + await onBreakPoint('testClass1Case1', (event) async { |
| 111 | + final result = await getObject( |
| 112 | + 'classes|dart:core|Object_Diagnosticable', |
| 113 | + ); |
| 114 | + final clazz = result as Class?; |
| 115 | + expect(clazz!.name, equals('Object_Diagnosticable')); |
| 116 | + expect(clazz.fields, isEmpty); |
| 117 | + expect(clazz.functions, isEmpty); |
| 118 | + }); |
| 119 | + }); |
| 120 | + }); |
| 121 | + }); |
| 122 | + } |
| 123 | + }); |
| 124 | +} |
0 commit comments