Skip to content

Commit a930738

Browse files
srujzsCommit Queue
authored andcommitted
Handle new module format in debugger_test
- Since libraries can't be exposed anymore with the new module format, relies on "this" and the JS foreign function to get the current library so we can only test the formatting of libraries. Patches in a link function to match the behavior of the new module system. - Cleans up some unnecessary code to support old type system. - Adds a status file to skip this test in d8 (it's currently failing). Change-Id: Ib8c503c5971a96e459d952602ff0ce2004d72878 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389589 Reviewed-by: Nicholas Shahan <[email protected]> Commit-Queue: Srujan Gaddam <[email protected]>
1 parent 97e59ba commit a930738

File tree

3 files changed

+89
-51
lines changed

3 files changed

+89
-51
lines changed

tests/dartdevc/dartdevc.status

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (c) 2024, 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+
[ $runtime == d8 ]
6+
debugger/debugger_test: SkipByDesign # Uses the DOM

tests/dartdevc/debugger/debugger_test.dart

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import 'package:expect/legacy/minitest.dart'; // ignore: deprecated_member_use_f
1616
import 'package:js/js.dart' as pkgJs;
1717

1818
import 'dart:_debugger' as _debugger;
19+
import 'dart:_foreign_helper' as _foreign_helper;
1920

2021
class TestClass {
2122
String name = 'test class';
@@ -55,6 +56,9 @@ class FormattedObject {
5556
JSAny? config;
5657
}
5758

59+
@JS()
60+
external JSAny? get dartDevEmbedder;
61+
5862
@JS('JSON.stringify')
5963
external String? stringify(JSAny? value, [JSFunction replacer, int space]);
6064

@@ -106,10 +110,6 @@ JSAny? replacer(String key, JSAny? externalValue) {
106110
if (new RegExp(r'[.](js|dart|html)').hasMatch(value)) {
107111
return '<FILE>'.toJS;
108112
}
109-
// Normalize the name of the `Event` type as it appears in this test.
110-
// The new type system preserves the original name from the Dart source.
111-
// TODO(48585): Remove when no longer running with the old type system.
112-
return value.replaceAll(r'Event$', 'Event').toJS;
113113
}
114114
return externalValue;
115115
}
@@ -149,6 +149,14 @@ List<FormattedObject> extractNestedFormattedObjects(JSAny json) {
149149
return ret;
150150
}
151151

152+
JSObject getCurrentLibrary() =>
153+
// With the new module format, we can't get the current library, so this is
154+
// a workaround to fetch it. Note that this is run in the top-level scope.
155+
// We can't use interop for this, as the lowering would be emitted as
156+
// `dart.global.eval('this')`, which does not evaluate to the same value as
157+
// `eval('this')`.
158+
_foreign_helper.JS('', 'this');
159+
152160
main() async {
153161
asyncStart();
154162
if (devtoolsFormatters == null) {
@@ -315,13 +323,22 @@ window.PackageJSClass = function PackageJSClass(x) {
315323
expect(_devtoolsFormatter.header(object, null), isNull);
316324
});
317325

318-
group('Module formatting', () {
319-
var moduleNames = _debugger.getModuleNames();
320-
var testModuleName = "debugger_test";
321-
expect(moduleNames.contains(testModuleName), isTrue);
322-
323-
addAllNestedFormatterGoldens(
324-
'Test library Module', _debugger.getModuleLibraries(testModuleName));
326+
group('Library formatting', () {
327+
final lib = getCurrentLibrary();
328+
if (dartDevEmbedder == null) {
329+
// The new module format adds a `link` function to every library. Patch
330+
// something like that in so we can have a consistent golden file for all
331+
// module formats.
332+
lib['link'] = () {}.toJS;
333+
}
334+
addFormatterGoldens(
335+
'Test library',
336+
// TODO(srujzs): We have to construct a `Library` manually here,
337+
// whereas the `LibraryModuleFormatter` does that for us automatically
338+
// when we format the module. We should add properties to libraries so
339+
// that we can detect them as a library. Once we have support for that,
340+
// revisit this and the formatter code.
341+
_debugger.Library('debugger_test', lib));
325342
});
326343

327344
group('StackTrace formatting', () {
@@ -355,13 +372,14 @@ window.PackageJSClass = function PackageJSClass(x) {
355372
});
356373

357374
test('verify golden match', () {
358-
// Warning: all other test groups must have run for this test to be meaningful
375+
// Warning: all other test groups must have run for this test to be
376+
// meaningful
359377
var actualStr = actual.toString().trim();
360378

361379
if (actualStr != golden) {
362380
var helpMessage =
363381
'Debugger output does not match the golden data found in:\n'
364-
'tests/dartdevc/debugger/debugger_test_golden.txt\n'
382+
'tests/dartdevc/debugger/debugger_test_golden.txt.\n'
365383
'The new golden data is copied to the clipboard when you click on '
366384
'this window.\n'
367385
'Please update the golden file with the following output and review '

tests/dartdevc/debugger/debugger_test_golden.txt

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5136,17 +5136,17 @@ Value:
51365136
}
51375137
]
51385138
-----------------------------------
5139-
Test: Test library Module header
5139+
Test: Test library formatting header
51405140
Value:
51415141
[
51425142
"span",
51435143
{
51445144
"style": "background-color: #d9edf7;color: black"
51455145
},
5146-
"Library Module: debugger_test"
5146+
"debugger_test"
51475147
]
51485148
-----------------------------------
5149-
Test: Test library Module body
5149+
Test: Test library formatting body
51505150
Value:
51515151
[
51525152
"ol",
@@ -5161,7 +5161,14 @@ Value:
51615161
[
51625162
"span",
51635163
{
5164-
"style": ""
5164+
"style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px"
5165+
},
5166+
"TestClass: "
5167+
],
5168+
[
5169+
"span",
5170+
{
5171+
"style": "margin-left: 13px"
51655172
},
51665173
[
51675174
"object",
@@ -5171,26 +5178,7 @@ Value:
51715178
}
51725179
]
51735180
]
5174-
]
5175-
]
5176-
-----------------------------------
5177-
Test: Test library Module child 0 formatting header
5178-
Value:
5179-
[
5180-
"span",
5181-
{
5182-
"style": "background-color: #d9edf7;color: black"
5183-
},
5184-
"<FILE>"
5185-
]
5186-
-----------------------------------
5187-
Test: Test library Module child 0 formatting body
5188-
Value:
5189-
[
5190-
"ol",
5191-
{
5192-
"style": "list-style-type: none;padding-left: 0px;margin-top: 0px;margin-bottom: 0px;margin-left: 12px;"
5193-
},
5181+
],
51945182
[
51955183
"li",
51965184
{
@@ -5201,7 +5189,7 @@ Value:
52015189
{
52025190
"style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px"
52035191
},
5204-
"TestClass: "
5192+
"TestGenericClass: "
52055193
],
52065194
[
52075195
"span",
@@ -5227,7 +5215,7 @@ Value:
52275215
{
52285216
"style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px"
52295217
},
5230-
"TestGenericClass: "
5218+
"FormattedObject: "
52315219
],
52325220
[
52335221
"span",
@@ -5253,7 +5241,7 @@ Value:
52535241
{
52545242
"style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px"
52555243
},
5256-
"FormattedObject: "
5244+
"PackageJSClass: "
52575245
],
52585246
[
52595247
"span",
@@ -5279,7 +5267,7 @@ Value:
52795267
{
52805268
"style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px"
52815269
},
5282-
"PackageJSClass: "
5270+
"FormattedJSObject|constructor#_: "
52835271
],
52845272
[
52855273
"span",
@@ -5305,7 +5293,7 @@ Value:
53055293
{
53065294
"style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px"
53075295
},
5308-
"FormattedJSObject|constructor#_: "
5296+
"FormattedJSObject|constructor#_#_#tearOff: "
53095297
],
53105298
[
53115299
"span",
@@ -5331,7 +5319,7 @@ Value:
53315319
{
53325320
"style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px"
53335321
},
5334-
"FormattedJSObject|constructor#_#_#tearOff: "
5322+
"Prototype|constructor#_: "
53355323
],
53365324
[
53375325
"span",
@@ -5357,7 +5345,7 @@ Value:
53575345
{
53585346
"style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px"
53595347
},
5360-
"Prototype|constructor#_: "
5348+
"Prototype|constructor#_#_#tearOff: "
53615349
],
53625350
[
53635351
"span",
@@ -5383,7 +5371,7 @@ Value:
53835371
{
53845372
"style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px"
53855373
},
5386-
"Prototype|constructor#_#_#tearOff: "
5374+
"FooBar|constructor#_: "
53875375
],
53885376
[
53895377
"span",
@@ -5409,7 +5397,7 @@ Value:
54095397
{
54105398
"style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px"
54115399
},
5412-
"FooBar|constructor#_: "
5400+
"FooBar|constructor#_#_#tearOff: "
54135401
],
54145402
[
54155403
"span",
@@ -5435,7 +5423,7 @@ Value:
54355423
{
54365424
"style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px"
54375425
},
5438-
"FooBar|constructor#_#_#tearOff: "
5426+
"unsafeCast: "
54395427
],
54405428
[
54415429
"span",
@@ -5461,7 +5449,7 @@ Value:
54615449
{
54625450
"style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px"
54635451
},
5464-
"unsafeCast: "
5452+
"replacer: "
54655453
],
54665454
[
54675455
"span",
@@ -5487,7 +5475,7 @@ Value:
54875475
{
54885476
"style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px"
54895477
},
5490-
"replacer: "
5478+
"format: "
54915479
],
54925480
[
54935481
"span",
@@ -5513,7 +5501,7 @@ Value:
55135501
{
55145502
"style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px"
55155503
},
5516-
"format: "
5504+
"extractNestedFormattedObjects: "
55175505
],
55185506
[
55195507
"span",
@@ -5539,7 +5527,7 @@ Value:
55395527
{
55405528
"style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px"
55415529
},
5542-
"extractNestedFormattedObjects: "
5530+
"getCurrentLibrary: "
55435531
],
55445532
[
55455533
"span",
@@ -5580,6 +5568,32 @@ Value:
55805568
}
55815569
]
55825570
]
5571+
],
5572+
[
5573+
"li",
5574+
{
5575+
"style": "padding-left: 13px;"
5576+
},
5577+
[
5578+
"span",
5579+
{
5580+
"style": "background-color: thistle; color: rgb(136, 19, 145); margin-right: -13px"
5581+
},
5582+
"link: "
5583+
],
5584+
[
5585+
"span",
5586+
{
5587+
"style": "margin-left: 13px"
5588+
},
5589+
[
5590+
"object",
5591+
{
5592+
"object": "<OBJECT>",
5593+
"config": {}
5594+
}
5595+
]
5596+
]
55835597
]
55845598
]
55855599
-----------------------------------

0 commit comments

Comments
 (0)