Skip to content

Commit 439caba

Browse files
rmacnak-googlecommit-bot@chromium.org
authored andcommitted
[test] Changes to mirrors tests to make them more Dart 3 compatible.
These changes are not sufficient by themselves, but the subset that can still run in Dart 2. Bug: #40045 Change-Id: Ie8f61fc9ee94b85329a701f97b5d3f91dbc1f889 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132422 Commit-Queue: Ryan Macnak <[email protected]> Reviewed-by: Siva Annamalai <[email protected]> Reviewed-by: Ben Konyi <[email protected]>
1 parent ec28afc commit 439caba

File tree

93 files changed

+366
-327
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+366
-327
lines changed

tests/lib_2/mirrors/bad_argument_types_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void badClassStaticInvoke() {
8080
}
8181

8282
void badStaticInvoke() {
83-
final ClosureMirror im = reflect(foo);
83+
final im = reflect(foo) as ClosureMirror;
8484
Expect.throwsTypeError(() => im.apply(['Hello world!']));
8585
}
8686

@@ -124,7 +124,7 @@ void badGenericFactoryInvoke() {
124124
}
125125

126126
void badGenericStaticInvoke() {
127-
final ClosureMirror im = reflect(bar);
127+
final im = reflect(bar) as ClosureMirror;
128128
Expect.throwsTypeError(() => im.apply(['Hello world!']));
129129
}
130130

tests/lib_2/mirrors/basic_types_in_dart_core_test.dart

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,43 @@ import 'package:expect/expect.dart';
1010
main() {
1111
LibraryMirror dartcore = currentMirrorSystem().findLibrary(#dart.core);
1212
ClassMirror cm;
13+
TypeMirror tm;
1314

14-
cm = dartcore.declarations[#int];
15+
cm = dartcore.declarations[#int] as ClassMirror;
1516
Expect.equals(reflectClass(int), cm);
1617
Expect.equals(#int, cm.simpleName);
1718

18-
cm = dartcore.declarations[#double];
19+
cm = dartcore.declarations[#double] as ClassMirror;
1920
Expect.equals(reflectClass(double), cm);
2021
Expect.equals(#double, cm.simpleName);
2122

22-
cm = dartcore.declarations[#num];
23+
cm = dartcore.declarations[#num] as ClassMirror;
2324
Expect.equals(reflectClass(num), cm);
2425
Expect.equals(#num, cm.simpleName);
2526

26-
cm = dartcore.declarations[#bool];
27+
cm = dartcore.declarations[#bool] as ClassMirror;
2728
Expect.equals(reflectClass(bool), cm);
2829
Expect.equals(#bool, cm.simpleName);
2930

30-
cm = dartcore.declarations[#String];
31+
cm = dartcore.declarations[#String] as ClassMirror;
3132
Expect.equals(reflectClass(String), cm);
3233
Expect.equals(#String, cm.simpleName);
3334

34-
cm = dartcore.declarations[#List];
35+
cm = dartcore.declarations[#List] as ClassMirror;
3536
Expect.equals(reflectClass(List), cm);
3637
Expect.equals(#List, cm.simpleName);
3738

38-
cm = dartcore.declarations[#Null];
39+
cm = dartcore.declarations[#Null] as ClassMirror;
3940
Expect.equals(reflectClass(Null), cm);
4041
Expect.equals(#Null, cm.simpleName);
4142

42-
cm = dartcore.declarations[#Object];
43+
cm = dartcore.declarations[#Object] as ClassMirror;
4344
Expect.equals(reflectClass(Object), cm);
4445
Expect.equals(#Object, cm.simpleName);
4546

46-
cm = dartcore.declarations[#dynamic];
47-
Expect.isNull(cm);
47+
tm = dartcore.declarations[#dynamic] as TypeMirror;
48+
Expect.isNull(tm);
4849

49-
cm = dartcore.declarations[const Symbol('void')];
50-
Expect.isNull(cm);
50+
tm = dartcore.declarations[const Symbol('void')] as TypeMirror;
51+
Expect.isNull(tm);
5152
}

tests/lib_2/mirrors/class_mirror_location_test.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ enum AnnotatedEnum { SALT, PEPPER }
3434
// any number of absolute paths.
3535
expectLocation(
3636
DeclarationMirror mirror, String uriSuffix, int line, int column) {
37-
Uri uri = mirror.location.sourceUri;
37+
final location = mirror.location;
38+
final uri = location.sourceUri;
3839
Expect.isTrue(
3940
uri.toString().endsWith(uriSuffix), "Expected suffix $uriSuffix in $uri");
40-
Expect.equals(line, mirror.location.line, "line");
41-
Expect.equals(column, mirror.location.column, "column");
41+
Expect.equals(line, location.line, "line");
42+
Expect.equals(column, location.column, "column");
4243
}
4344

4445
main() {

tests/lib_2/mirrors/class_mirror_type_variables_expect.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ void testA(Env env) {
4545

4646
TypeVariableMirror aT = a.typeVariables[0];
4747
TypeVariableMirror aS = a.typeVariables[1];
48-
ClassMirror aTBound = aT.upperBound;
49-
ClassMirror aSBound = aS.upperBound;
48+
ClassMirror aTBound = aT.upperBound as ClassMirror;
49+
ClassMirror aSBound = aS.upperBound as ClassMirror;
5050

5151
Expect.isTrue(aTBound.isOriginalDeclaration);
5252
Expect.isTrue(aSBound.isOriginalDeclaration);
@@ -64,8 +64,8 @@ void testBAndC(Env env) {
6464

6565
TypeVariableMirror bZ = b.typeVariables[0];
6666
TypeVariableMirror cZ = c.typeVariables[0];
67-
ClassMirror bZBound = bZ.upperBound;
68-
ClassMirror cZBound = cZ.upperBound;
67+
ClassMirror bZBound = bZ.upperBound as ClassMirror;
68+
ClassMirror cZBound = cZ.upperBound as ClassMirror;
6969

7070
Expect.isFalse(bZBound.isOriginalDeclaration);
7171
Expect.isFalse(cZBound.isOriginalDeclaration);
@@ -108,7 +108,7 @@ testD(Env env) {
108108
void testE(Env env) {
109109
ClassMirror e = env.getE();
110110
TypeVariableMirror eR = e.typeVariables.single;
111-
ClassMirror mapRAndHelperOfString = eR.upperBound;
111+
ClassMirror mapRAndHelperOfString = eR.upperBound as ClassMirror;
112112

113113
Expect.isFalse(mapRAndHelperOfString.isOriginalDeclaration);
114114
Expect.equals(eR, mapRAndHelperOfString.typeArguments.first);
@@ -119,8 +119,8 @@ void testE(Env env) {
119119
void testF(Env env) {
120120
ClassMirror f = env.getF();
121121
TypeVariableMirror fZ = f.typeVariables[0];
122-
ClassMirror fZBound = fZ.upperBound;
123-
ClassMirror fZBoundTypeArgument = fZBound.typeArguments.single;
122+
ClassMirror fZBound = fZ.upperBound as ClassMirror;
123+
ClassMirror fZBoundTypeArgument = fZBound.typeArguments.single as ClassMirror;
124124

125125
Expect.equals(1, f.typeVariables.length);
126126
Expect.isFalse(fZBound.isOriginalDeclaration);

tests/lib_2/mirrors/closurization_equivalence_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class C {
1313
}
1414

1515
main() {
16-
LibraryMirror thisLibrary = reflectClass(C).owner;
16+
LibraryMirror thisLibrary = reflectClass(C).owner as LibraryMirror;
1717
Expect.equals(thisLibrary.declarations[#topLevelMethod],
1818
(reflect(topLevelMethod) as ClosureMirror).function, "topLevel");
1919

tests/lib_2/mirrors/constructor_kinds_test.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ main() {
4444
cm = reflectClass(ClassWithDefaultConstructor);
4545
mm = cm.declarations.values
4646
.where((d) => d is MethodMirror && d.isConstructor)
47-
.single;
47+
.single as MethodMirror;
4848
Expect.isTrue(mm.isConstructor);
4949
Expect.isTrue(mm.isGenerativeConstructor);
5050
Expect.isFalse(mm.isFactoryConstructor);
@@ -53,57 +53,57 @@ main() {
5353

5454
cm = reflectClass(Class);
5555

56-
mm = cm.declarations[#Class.generativeConstructor];
56+
mm = cm.declarations[#Class.generativeConstructor] as MethodMirror;
5757
Expect.isTrue(mm.isConstructor);
5858
Expect.isTrue(mm.isGenerativeConstructor);
5959
Expect.isFalse(mm.isFactoryConstructor);
6060
Expect.isFalse(mm.isRedirectingConstructor);
6161
Expect.isFalse(mm.isConstConstructor);
6262

63-
mm = cm.declarations[#Class.redirectingGenerativeConstructor];
63+
mm = cm.declarations[#Class.redirectingGenerativeConstructor] as MethodMirror;
6464
Expect.isTrue(mm.isConstructor);
6565
Expect.isTrue(mm.isGenerativeConstructor);
6666
Expect.isFalse(mm.isFactoryConstructor);
6767
Expect.isTrue(mm.isRedirectingConstructor);
6868
Expect.isFalse(mm.isConstConstructor);
6969

70-
mm = cm.declarations[#Class.factoryConstructor];
70+
mm = cm.declarations[#Class.factoryConstructor] as MethodMirror;
7171
Expect.isTrue(mm.isConstructor);
7272
Expect.isFalse(mm.isGenerativeConstructor);
7373
Expect.isTrue(mm.isFactoryConstructor);
7474
Expect.isFalse(mm.isRedirectingConstructor);
7575
Expect.isFalse(mm.isConstConstructor);
7676

77-
mm = cm.declarations[#Class.redirectingFactoryConstructor];
77+
mm = cm.declarations[#Class.redirectingFactoryConstructor] as MethodMirror;
7878
Expect.isTrue(mm.isConstructor);
7979
Expect.isFalse(mm.isGenerativeConstructor);
8080
Expect.isTrue(mm.isFactoryConstructor);
8181
Expect.isTrue(mm.isRedirectingConstructor);
8282
Expect.isFalse(mm.isConstConstructor);
8383

84-
mm = cm.declarations[#Class.constGenerativeConstructor];
84+
mm = cm.declarations[#Class.constGenerativeConstructor] as MethodMirror;
8585
Expect.isTrue(mm.isConstructor);
8686
Expect.isTrue(mm.isGenerativeConstructor);
8787
Expect.isFalse(mm.isFactoryConstructor);
8888
Expect.isFalse(mm.isRedirectingConstructor);
8989
Expect.isTrue(mm.isConstConstructor);
9090

91-
mm = cm.declarations[#Class.constRedirectingGenerativeConstructor];
91+
mm = cm.declarations[#Class.constRedirectingGenerativeConstructor] as MethodMirror;
9292
Expect.isTrue(mm.isConstructor);
9393
Expect.isTrue(mm.isGenerativeConstructor);
9494
Expect.isFalse(mm.isFactoryConstructor);
9595
Expect.isTrue(mm.isRedirectingConstructor);
9696
Expect.isTrue(mm.isConstConstructor);
9797

9898
// Not legal.
99-
// mm = cm.declarations[#Class.constFactoryConstructor];
99+
// mm = cm.declarations[#Class.constFactoryConstructor] as MethodMirror;
100100
// Expect.isTrue(mm.isConstructor);
101101
// Expect.isFalse(mm.isGenerativeConstructor);
102102
// Expect.isTrue(mm.isFactoryConstructor);
103103
// Expect.isFalse(mm.isRedirectingConstructor);
104104
// Expect.isTrue(mm.isConstConstructor);
105105

106-
mm = cm.declarations[#Class.constRedirectingFactoryConstructor];
106+
mm = cm.declarations[#Class.constRedirectingFactoryConstructor] as MethodMirror;
107107
Expect.isTrue(mm.isConstructor);
108108
Expect.isFalse(mm.isGenerativeConstructor);
109109
Expect.isTrue(mm.isFactoryConstructor);

tests/lib_2/mirrors/deferred_mirrors_metadata_lib.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ class H {
99

1010
class F {
1111
@H()
12-
int f;
12+
int f = 0;
1313
}
1414

1515
@C()
1616
class E {
1717
@D()
18-
var f;
18+
dynamic f;
1919
}
2020

2121
String foo() {

tests/lib_2/mirrors/deferred_mirrors_metatarget_lib.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class A {
1616
}
1717

1818
String foo() {
19-
ClassMirror a = currentMirrorSystem().findLibrary(#lib).declarations[#A];
19+
final a =
20+
currentMirrorSystem().findLibrary(#lib).declarations[#A] as ClassMirror;
2021
return a.newInstance(Symbol.empty, []).invoke(#toString, []).reflectee;
2122
}

tests/lib_2/mirrors/equality_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ class BadEqualityHash {
2626
}
2727

2828
typedef bool Predicate(Object o);
29-
Predicate somePredicate;
29+
Predicate somePredicate = (Object o) => false;
3030

31-
checkEquality(List<Map> equivalenceClasses) {
31+
checkEquality(List<Map<String, Object>> equivalenceClasses) {
3232
for (var equivalenceClass in equivalenceClasses) {
3333
equivalenceClass.forEach((name, member) {
3434
equivalenceClass.forEach((otherName, otherMember) {
@@ -61,7 +61,7 @@ main() {
6161
var badEqualityHash1 = new BadEqualityHash();
6262
var badEqualityHash2 = new BadEqualityHash();
6363

64-
checkEquality([
64+
checkEquality(<Map<String, Object>>[
6565
{'reflect(o1)': reflect(o1), 'reflect(o1), again': reflect(o1)},
6666
{'reflect(o2)': reflect(o2), 'reflect(o2), again': reflect(o2)},
6767
{

tests/lib_2/mirrors/fake_function_with_call_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class WannabeFunction {
2323
main() {
2424
Expect.isTrue(new WannabeFunction() is Function);
2525

26-
ClosureMirror cm = reflect(new WannabeFunction());
26+
ClosureMirror cm = reflect(new WannabeFunction()) as ClosureMirror;
2727
Expect.equals(7, cm.invoke(#call, [3, 4]).reflectee);
2828
Expect.throwsNoSuchMethodError(() => cm.invoke(#call, [3]), "Wrong arity");
2929
Expect.equals(49, cm.invoke(#method, [7]).reflectee);

tests/lib_2/mirrors/fake_function_without_call_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ main() {
2525
Expect.equals('a,b,c', Function.apply(f, ['a', 'b', 'c']));
2626
Expect.throwsNoSuchMethodError(() => f.foo('a', 'b', 'c'));
2727

28-
ClosureMirror cm = reflect(f);
28+
ClosureMirror cm = reflect(f) as ClosureMirror;
2929
Expect.isTrue(cm is ClosureMirror);
3030
Expect.equals('a', cm.apply(['a']).reflectee);
3131
Expect.equals('a,b', cm.apply(['a', 'b']).reflectee);

tests/lib_2/mirrors/field_metadata2_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ void main() {
1818
// Check that we can now reflect on the annotations.
1919
dynamic f = new Foo();
2020
var members = reflect(f).type.declarations;
21-
var bar = members[#x].metadata.first.reflectee as Bar;
21+
var x = members[#x] as VariableMirror;
22+
var bar = x.metadata.first.reflectee as Bar;
2223
Expect.equals(bar.name, 'bar');
2324

24-
var baz = members[#y].metadata.first.reflectee as Bar;
25+
var y = members[#y] as VariableMirror;
26+
var baz = y.metadata.first.reflectee as Bar;
2527
Expect.equals(baz.name, 'baz');
2628
}

tests/lib_2/mirrors/field_type_test.dart

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ library field_test;
77
import 'dart:mirrors';
88
import "package:expect/expect.dart";
99

10-
String toplevelVariable;
10+
String toplevelVariable = "";
1111

1212
class C {
1313
final int i;
1414
const C(this.i);
1515
}
1616

1717
class A<T> {
18-
static int staticField;
18+
static int staticField = 0;
1919
@C(42)
2020
@C(44)
21-
String field;
21+
String field = "";
2222
var dynamicTypeField;
2323
T typeVariableField;
2424
H<int> parameterizedTypeField;
@@ -28,12 +28,14 @@ class H<T> {}
2828

2929
testOriginalDeclaration() {
3030
ClassMirror a = reflectClass(A);
31-
VariableMirror staticField = a.declarations[#staticField];
32-
VariableMirror field = a.declarations[#field];
33-
VariableMirror dynamicTypeField = a.declarations[#dynamicTypeField];
34-
VariableMirror typeVariableField = a.declarations[#typeVariableField];
31+
VariableMirror staticField = a.declarations[#staticField] as VariableMirror;
32+
VariableMirror field = a.declarations[#field] as VariableMirror;
33+
VariableMirror dynamicTypeField =
34+
a.declarations[#dynamicTypeField] as VariableMirror;
35+
VariableMirror typeVariableField =
36+
a.declarations[#typeVariableField] as VariableMirror;
3537
VariableMirror parameterizedTypeField =
36-
a.declarations[#parameterizedTypeField];
38+
a.declarations[#parameterizedTypeField] as VariableMirror;
3739

3840
Expect.equals(reflectType(int), staticField.type);
3941
Expect.equals(reflectClass(String), field.type);
@@ -48,12 +50,15 @@ testOriginalDeclaration() {
4850

4951
testInstance() {
5052
ClassMirror aOfString = reflect(new A<String>()).type;
51-
VariableMirror staticField = aOfString.declarations[#staticField];
52-
VariableMirror field = aOfString.declarations[#field];
53-
VariableMirror dynamicTypeField = aOfString.declarations[#dynamicTypeField];
54-
VariableMirror typeVariableField = aOfString.declarations[#typeVariableField];
53+
VariableMirror staticField =
54+
aOfString.declarations[#staticField] as VariableMirror;
55+
VariableMirror field = aOfString.declarations[#field] as VariableMirror;
56+
VariableMirror dynamicTypeField =
57+
aOfString.declarations[#dynamicTypeField] as VariableMirror;
58+
VariableMirror typeVariableField =
59+
aOfString.declarations[#typeVariableField] as VariableMirror;
5560
VariableMirror parameterizedTypeField =
56-
aOfString.declarations[#parameterizedTypeField];
61+
aOfString.declarations[#parameterizedTypeField] as VariableMirror;
5762

5863
Expect.equals(reflectType(int), staticField.type);
5964
Expect.equals(reflectClass(String), field.type);
@@ -68,7 +73,8 @@ testInstance() {
6873

6974
testTopLevel() {
7075
LibraryMirror currentLibrary = currentMirrorSystem().findLibrary(#field_test);
71-
VariableMirror topLevel = currentLibrary.declarations[#toplevelVariable];
76+
VariableMirror topLevel =
77+
currentLibrary.declarations[#toplevelVariable] as VariableMirror;
7278
Expect.equals(reflectClass(String), topLevel.type);
7379
}
7480

tests/lib_2/mirrors/function_apply_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ foo(int y) => 456 + y;
1717

1818
main() {
1919
// Static function.
20-
ClosureMirror f1 = reflect(foo);
20+
ClosureMirror f1 = reflect(foo) as ClosureMirror;
2121
Expect.equals(1456, f1.apply([1000]).reflectee);
2222

2323
// Local declaration.
2424
chomp(int z) => z + 42;
25-
ClosureMirror f2 = reflect(chomp);
25+
ClosureMirror f2 = reflect(chomp) as ClosureMirror;
2626
Expect.equals(1042, f2.apply([1000]).reflectee);
2727

2828
// Local expression.
29-
ClosureMirror f3 = reflect((u) => u + 987);
29+
ClosureMirror f3 = reflect((u) => u + 987) as ClosureMirror;
3030
Expect.equals(1987, f3.apply([1000]).reflectee);
3131

3232
// Instance property extraction.
33-
ClosureMirror f4 = reflect(new A().bar);
33+
ClosureMirror f4 = reflect(new A().bar) as ClosureMirror;
3434
Expect.equals(1321, f4.apply([1000]).reflectee);
3535

3636
// Instance implementing Function via call method.
37-
ClosureMirror f5 = reflect(new A());
37+
ClosureMirror f5 = reflect(new A()) as ClosureMirror;
3838
Expect.equals(1123, f5.apply([1000]).reflectee);
3939
}

0 commit comments

Comments
 (0)