mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:39:49 +00:00
[dart2js] Adding class and classtype dump info tests
Change-Id: Iba41106c2b75a8247123e36b505e0be42ad51fad Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242181 Reviewed-by: Joshua Litt <joshualitt@google.com> Commit-Queue: Mark Zhou <markzipan@google.com>
This commit is contained in:
parent
ee5a62ff4e
commit
dfd5109b64
|
@ -15,6 +15,20 @@
|
|||
|
||||
// @dart = 2.7
|
||||
|
||||
/*class: A:class=[{
|
||||
"id": "class/memory:sdk/tests/web/native/lib2.dart::A",
|
||||
"kind": "class",
|
||||
"name": "A",
|
||||
"size": 68,
|
||||
"outputUnit": "outputUnit/1",
|
||||
"parent": "library/memory:sdk/tests/web/native/lib2.dart::",
|
||||
"modifiers": {
|
||||
"abstract": false
|
||||
},
|
||||
"children": [
|
||||
"function/memory:sdk/tests/web/native/lib2.dart::A.method"
|
||||
]
|
||||
}]*/
|
||||
class A {
|
||||
const A();
|
||||
|
||||
|
|
|
@ -20,6 +20,22 @@ import 'package:expect/expect.dart';
|
|||
external void eval(String code);
|
||||
|
||||
@JS()
|
||||
/*class: Foo:class=[{
|
||||
"id": "class/memory:sdk/tests/web/native/main.dart::Foo",
|
||||
"kind": "class",
|
||||
"name": "Foo",
|
||||
"size": 54,
|
||||
"outputUnit": "outputUnit/main",
|
||||
"parent": "library/memory:sdk/tests/web/native/main.dart::",
|
||||
"modifiers": {
|
||||
"abstract": false
|
||||
},
|
||||
"children": [
|
||||
"function/memory:sdk/tests/web/native/main.dart::Foo.mixedPositionalArgs",
|
||||
"function/memory:sdk/tests/web/native/main.dart::Foo.singleArg",
|
||||
"function/memory:sdk/tests/web/native/main.dart::Foo.singlePositionalArg"
|
||||
]
|
||||
}]*/
|
||||
class Foo {
|
||||
external factory Foo();
|
||||
/*member: Foo.singleArg:function=[{
|
||||
|
@ -117,6 +133,18 @@ class Foo {
|
|||
}
|
||||
|
||||
@JS()
|
||||
/*class: Bar:class=[{
|
||||
"id": "class/memory:sdk/tests/web/native/main.dart::Bar",
|
||||
"kind": "class",
|
||||
"name": "Bar",
|
||||
"size": 54,
|
||||
"outputUnit": "outputUnit/main",
|
||||
"parent": "library/memory:sdk/tests/web/native/main.dart::",
|
||||
"modifiers": {
|
||||
"abstract": false
|
||||
},
|
||||
"children": []
|
||||
}]*/
|
||||
class Bar {
|
||||
external static singleArg(a);
|
||||
external static singlePositionalArg([dynamic? a]);
|
||||
|
|
|
@ -13,6 +13,25 @@
|
|||
],
|
||||
"canonicalUri": "memory:sdk/tests/web/native/main.dart"
|
||||
}]*/
|
||||
/*class: C:class=[{
|
||||
"id": "class/memory:sdk/tests/web/native/main.dart::C",
|
||||
"kind": "class",
|
||||
"name": "C",
|
||||
"size": 46,
|
||||
"outputUnit": "outputUnit/main",
|
||||
"parent": "library/memory:sdk/tests/web/native/main.dart::",
|
||||
"modifiers": {
|
||||
"abstract": false
|
||||
},
|
||||
"children": [
|
||||
"field/memory:sdk/tests/web/native/main.dart::C.counter",
|
||||
"field/memory:sdk/tests/web/native/main.dart::C.value",
|
||||
"field/memory:sdk/tests/web/native/main.dart::C.y",
|
||||
"function/memory:sdk/tests/web/native/main.dart::C.C._default",
|
||||
"function/memory:sdk/tests/web/native/main.dart::C.C.create",
|
||||
"function/memory:sdk/tests/web/native/main.dart::C.compute"
|
||||
]
|
||||
}]*/
|
||||
class C {
|
||||
/*member: C.value:
|
||||
function=[{
|
||||
|
@ -186,6 +205,31 @@ class C {
|
|||
}]*/
|
||||
void F() {}
|
||||
|
||||
/*class: A:
|
||||
class=[{
|
||||
"id": "class/memory:sdk/tests/web/native/main.dart::A",
|
||||
"kind": "class",
|
||||
"name": "A",
|
||||
"size": 46,
|
||||
"outputUnit": "outputUnit/main",
|
||||
"parent": "library/memory:sdk/tests/web/native/main.dart::",
|
||||
"modifiers": {
|
||||
"abstract": false
|
||||
},
|
||||
"children": [
|
||||
"field/memory:sdk/tests/web/native/main.dart::A.a",
|
||||
"function/memory:sdk/tests/web/native/main.dart::A.A"
|
||||
]
|
||||
}],
|
||||
classType=[{
|
||||
"id": "classType/memory:sdk/tests/web/native/main.dart::A",
|
||||
"kind": "classType",
|
||||
"name": "A",
|
||||
"size": 0,
|
||||
"outputUnit": "outputUnit/main",
|
||||
"parent": "library/memory:sdk/tests/web/native/main.dart::"
|
||||
}]
|
||||
*/
|
||||
class A {
|
||||
/*member: A.a:function=[{
|
||||
"id": "field/memory:sdk/tests/web/native/main.dart::A.a",
|
||||
|
|
|
@ -21,7 +21,7 @@ import '../equivalence/id_equivalence_helper.dart';
|
|||
|
||||
main(List<String> args) {
|
||||
asyncTest(() async {
|
||||
Directory dataDir = new Directory.fromUri(Platform.script.resolve('data'));
|
||||
Directory dataDir = Directory.fromUri(Platform.script.resolve('data'));
|
||||
print('Testing output of dump-info');
|
||||
print('==================================================================');
|
||||
await checkTests(dataDir, const DumpInfoDataComputer(),
|
||||
|
@ -59,7 +59,7 @@ class DumpInfoDataComputer extends DataComputer<Features> {
|
|||
isBackwardCompatible: true, filterTreeshaken: false);
|
||||
DumpInfoStateData dumpInfoState = compiler.dumpInfoStateForTesting;
|
||||
|
||||
Features features = new Features();
|
||||
final features = Features();
|
||||
final libraryInfo = dumpInfoState.entityToInfo[library];
|
||||
if (libraryInfo == null) return;
|
||||
|
||||
|
@ -67,8 +67,42 @@ class DumpInfoDataComputer extends DataComputer<Features> {
|
|||
Tags.library, indentedEncoder.convert(libraryInfo.accept(converter)));
|
||||
|
||||
final id = LibraryId(library.canonicalUri);
|
||||
actualMap[id] = new ActualData<Features>(
|
||||
id, features, library.canonicalUri, -1, library);
|
||||
actualMap[id] =
|
||||
ActualData<Features>(id, features, library.canonicalUri, -1, library);
|
||||
}
|
||||
|
||||
@override
|
||||
void computeClassData(Compiler compiler, ClassEntity cls,
|
||||
Map<Id, ActualData<Features>> actualMap,
|
||||
{bool verbose: false}) {
|
||||
final converter = info.AllInfoToJsonConverter(
|
||||
isBackwardCompatible: true, filterTreeshaken: false);
|
||||
DumpInfoStateData dumpInfoState = compiler.dumpInfoStateForTesting;
|
||||
|
||||
final features = Features();
|
||||
final classInfo = dumpInfoState.entityToInfo[cls];
|
||||
if (classInfo == null) return;
|
||||
|
||||
features.addElement(
|
||||
Tags.clazz, indentedEncoder.convert(classInfo.accept(converter)));
|
||||
final classTypeInfos =
|
||||
dumpInfoState.info.classTypes.where((i) => i.name == classInfo.name);
|
||||
assert(
|
||||
classTypeInfos.length < 2,
|
||||
'Ambiguous class type info resolution. '
|
||||
'Expected 0 or 1 elements, found: $classTypeInfos');
|
||||
if (classTypeInfos.length == 1) {
|
||||
features.addElement(Tags.classType,
|
||||
indentedEncoder.convert(classTypeInfos.first.accept(converter)));
|
||||
}
|
||||
|
||||
JsClosedWorld closedWorld = compiler.backendClosedWorldForTesting;
|
||||
JsToElementMap elementMap = closedWorld.elementMap;
|
||||
ir.Class node = elementMap.getClassDefinition(cls).node;
|
||||
ClassId id = ClassId(node.name);
|
||||
ir.TreeNode nodeWithOffset = computeTreeNodeWithOffset(node);
|
||||
actualMap[id] = ActualData<Features>(id, features,
|
||||
nodeWithOffset?.location?.file, nodeWithOffset?.fileOffset, cls);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -79,7 +113,7 @@ class DumpInfoDataComputer extends DataComputer<Features> {
|
|||
isBackwardCompatible: true, filterTreeshaken: false);
|
||||
DumpInfoStateData dumpInfoState = compiler.dumpInfoStateForTesting;
|
||||
|
||||
Features features = new Features();
|
||||
final features = Features();
|
||||
final functionInfo = dumpInfoState.entityToInfo[member];
|
||||
if (functionInfo == null) return;
|
||||
|
||||
|
@ -106,7 +140,7 @@ class DumpInfoDataComputer extends DataComputer<Features> {
|
|||
ir.Member node = elementMap.getMemberDefinition(member).node;
|
||||
Id id = computeMemberId(node);
|
||||
ir.TreeNode nodeWithOffset = computeTreeNodeWithOffset(node);
|
||||
actualMap[id] = new ActualData<Features>(id, features,
|
||||
actualMap[id] = ActualData<Features>(id, features,
|
||||
nodeWithOffset?.location?.file, nodeWithOffset?.fileOffset, member);
|
||||
}
|
||||
|
||||
|
@ -134,7 +168,7 @@ class JsonFeaturesDataInterpreter implements DataInterpreter<Features> {
|
|||
} else {
|
||||
List<String> errorsFound = [];
|
||||
Features expectedFeatures = Features.fromText(expectedData);
|
||||
Set<String> validatedFeatures = new Set<String>();
|
||||
Set<String> validatedFeatures = Set<String>();
|
||||
expectedFeatures.forEach((String key, Object expectedValue) {
|
||||
validatedFeatures.add(key);
|
||||
Object actualValue = actualFeatures[key];
|
||||
|
|
Loading…
Reference in a new issue