Skip to content

Commit

Permalink
[test] Update copied mirrors tests for Dart 3.
Browse files Browse the repository at this point in the history
Bug: #40045
Change-Id: Ic0f62843d61b613e61f434b72b9553dd1e6897af
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132441
Reviewed-by: Ben Konyi <[email protected]>
Commit-Queue: Ryan Macnak <[email protected]>
  • Loading branch information
rmacnak-google authored and [email protected] committed Jan 23, 2020
1 parent 3aabdc8 commit 081e2ac
Show file tree
Hide file tree
Showing 62 changed files with 338 additions and 314 deletions.
13 changes: 7 additions & 6 deletions pkg/expect/lib/expect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class Expect {
/**
* Checks whether the expected and actual values are equal (using `==`).
*/
static void equals(var expected, var actual, [String reason = ""]) {
static void equals(dynamic expected, dynamic actual, [String reason = ""]) {
if (expected == actual) return;
String msg = _getMessage(reason);
if (expected is String && actual is String) {
Expand All @@ -129,7 +129,7 @@ class Expect {
/**
* Checks whether the actual value is a bool and its value is true.
*/
static void isTrue(var actual, [String reason = ""]) {
static void isTrue(dynamic actual, [String reason = ""]) {
if (_identical(actual, true)) return;
String msg = _getMessage(reason);
_fail("Expect.isTrue($actual$msg) fails.");
Expand All @@ -138,7 +138,7 @@ class Expect {
/**
* Checks whether the actual value is a bool and its value is false.
*/
static void isFalse(var actual, [String reason = ""]) {
static void isFalse(dynamic actual, [String reason = ""]) {
if (_identical(actual, false)) return;
String msg = _getMessage(reason);
_fail("Expect.isFalse($actual$msg) fails.");
Expand All @@ -147,7 +147,7 @@ class Expect {
/**
* Checks whether [actual] is null.
*/
static void isNull(actual, [String reason = ""]) {
static void isNull(dynamic actual, [String reason = ""]) {
if (null == actual) return;
String msg = _getMessage(reason);
_fail("Expect.isNull(actual: <$actual>$msg) fails.");
Expand All @@ -156,7 +156,7 @@ class Expect {
/**
* Checks whether [actual] is not null.
*/
static void isNotNull(actual, [String reason = ""]) {
static void isNotNull(dynamic actual, [String reason = ""]) {
if (null != actual) return;
String msg = _getMessage(reason);
_fail("Expect.isNotNull(actual: <$actual>$msg) fails.");
Expand All @@ -166,7 +166,8 @@ class Expect {
* Checks whether the expected and actual values are identical
* (using `identical`).
*/
static void identical(var expected, var actual, [String reason = ""]) {
static void identical(dynamic expected, dynamic actual,
[String reason = ""]) {
if (_identical(expected, actual)) return;
String msg = _getMessage(reason);
if (expected is String && actual is String) {
Expand Down
42 changes: 22 additions & 20 deletions tests/lib/mirrors/abstract_class_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Bar extends Foo {
testSimple() {
Expect.isTrue(reflectClass(Foo).isAbstract);
Expect.isFalse(reflectClass(Bar).isAbstract);
Expect.isTrue(reflect(new Bar()).type.superclass.isAbstract);
Expect.isTrue(reflect(new Bar()).type.superclass!.isAbstract);
Expect.isFalse(reflect(new Bar()).type.isAbstract);
}

Expand All @@ -48,7 +48,7 @@ class FunctionBar extends FunctionFoo {
testFakeFunction() {
Expect.isTrue(reflectClass(FunctionFoo).isAbstract);
Expect.isFalse(reflectClass(FunctionBar).isAbstract);
Expect.isTrue(reflect(new FunctionBar()).type.superclass.isAbstract);
Expect.isTrue(reflect(new FunctionBar()).type.superclass!.isAbstract);
Expect.isFalse(reflect(new FunctionBar()).type.isAbstract);
}

Expand All @@ -65,7 +65,7 @@ testGeneric() {
Expect.isTrue(reflectClass(GenericFoo).isAbstract);
Expect.isFalse(reflectClass(GenericBar).isAbstract);
// Bound.
Expect.isTrue(reflect(new GenericBar<int>()).type.superclass.isAbstract);
Expect.isTrue(reflect(new GenericBar<int>()).type.superclass!.isAbstract);
Expect.isFalse(reflect(new GenericBar<int>()).type.isAbstract);
}

Expand Down Expand Up @@ -106,30 +106,31 @@ testAnonMixinApplication() {
{
// Mixin is abstract.
Expect.isFalse(reflectClass(SubMA).isAbstract);
Expect.isTrue(reflectClass(SubMA).superclass.isAbstract);
Expect.isTrue(reflectClass(SubMA).superclass.superclass.isAbstract);
Expect.isTrue(reflectClass(SubMA).superclass!.isAbstract);
Expect.isTrue(reflectClass(SubMA).superclass!.superclass!.isAbstract);
Expect.isTrue(reflectClass(MA).isAbstract);
Expect.isTrue(reflectClass(MA).superclass.isAbstract);
Expect.isTrue(reflectClass(MA).superclass!.isAbstract);

// Mixin is concrete.
Expect.isFalse(reflectClass(SubMA2).isAbstract);
Expect.isTrue(reflectClass(SubMA2).superclass.isAbstract);
Expect.isTrue(reflectClass(SubMA2).superclass.superclass.isAbstract);
Expect.isTrue(reflectClass(SubMA2).superclass!.isAbstract);
Expect.isTrue(reflectClass(SubMA2).superclass!.superclass!.isAbstract);
Expect.isTrue(reflectClass(MA2).isAbstract);
Expect.isTrue(reflectClass(MA2).superclass.isAbstract);
Expect.isTrue(reflectClass(MA2).superclass!.isAbstract);
}

// Application is concrete.
{
// Mixin is abstract.
Expect.isFalse(reflectClass(ConcreteMA).isAbstract);
Expect.isTrue(reflectClass(ConcreteMA).superclass.isAbstract);
Expect.isFalse(reflectClass(ConcreteMA).superclass.superclass.isAbstract);
Expect.isTrue(reflectClass(ConcreteMA).superclass!.isAbstract);
Expect.isFalse(reflectClass(ConcreteMA).superclass!.superclass!.isAbstract);

// Mixin is concrete.
Expect.isFalse(reflectClass(ConcreteMA2).isAbstract);
Expect.isTrue(reflectClass(ConcreteMA2).superclass.isAbstract);
Expect.isFalse(reflectClass(ConcreteMA2).superclass.superclass.isAbstract);
Expect.isTrue(reflectClass(ConcreteMA2).superclass!.isAbstract);
Expect.isFalse(
reflectClass(ConcreteMA2).superclass!.superclass!.isAbstract);
}
}

Expand All @@ -152,23 +153,24 @@ testNamedMixinApplication() {
{
// Mixin is abstract.
Expect.isFalse(reflectClass(SubNamedMA).isAbstract);
Expect.isTrue(reflectClass(SubNamedMA).superclass.isAbstract);
Expect.isFalse(reflectClass(SubNamedMA).superclass.superclass.isAbstract);
Expect.isTrue(reflectClass(SubNamedMA).superclass!.isAbstract);
Expect.isFalse(reflectClass(SubNamedMA).superclass!.superclass!.isAbstract);
Expect.isTrue(reflectClass(NamedMA).isAbstract);
Expect.isFalse(reflectClass(NamedMA).superclass.isAbstract);
Expect.isFalse(reflectClass(NamedMA).superclass!.isAbstract);

// Mixin is concrete.
Expect.isFalse(reflectClass(SubNamedMA2).isAbstract);
Expect.isTrue(reflectClass(SubNamedMA2).superclass.isAbstract);
Expect.isFalse(reflectClass(SubNamedMA2).superclass.superclass.isAbstract);
Expect.isTrue(reflectClass(SubNamedMA2).superclass!.isAbstract);
Expect.isFalse(
reflectClass(SubNamedMA2).superclass!.superclass!.isAbstract);
Expect.isTrue(reflectClass(NamedMA2).isAbstract);
Expect.isFalse(reflectClass(NamedMA2).superclass.isAbstract);
Expect.isFalse(reflectClass(NamedMA2).superclass!.isAbstract);
}

// Application is concrete.
{
// Mixin is concrete.
Expect.isFalse(reflectClass(ConcreteNamedMA2).isAbstract);
Expect.isFalse(reflectClass(ConcreteNamedMA2).superclass.isAbstract);
Expect.isFalse(reflectClass(ConcreteNamedMA2).superclass!.isAbstract);
}
}
6 changes: 3 additions & 3 deletions tests/lib/mirrors/bad_argument_types_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ void bar<T extends num>(T a) {
}

class Foo {
Map<String, String> bork;
static Map<String, String> bark;
Map<String, String>? bork;
static Map<String, String>? bark;
static set woof(Map<String, String> x) {
bark = x;
}
Expand All @@ -35,7 +35,7 @@ class Foo {

Foo.a();

static void baz(Map<String, String> m, {String bar}) {
static void baz(Map<String, String> m, {String? bar}) {
print('baz');
print(m['bar']);
print(bar);
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/mirrors/class_declarations_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:expect/expect.dart';
import 'stringify.dart';
import 'declarations_model.dart' as declarations_model;

Set<DeclarationMirror> inheritedDeclarations(ClassMirror cm) {
Set<DeclarationMirror> inheritedDeclarations(ClassMirror? cm) {
var decls = new Set<DeclarationMirror>();
while (cm != null) {
decls.addAll(cm.declarations.values);
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/mirrors/class_mirror_location_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ enum AnnotatedEnum { SALT, PEPPER }
// any number of absolute paths.
expectLocation(
DeclarationMirror mirror, String uriSuffix, int line, int column) {
final location = mirror.location;
final location = mirror.location!;
final uri = location.sourceUri;
Expect.isTrue(
uri.toString().endsWith(uriSuffix), "Expected suffix $uriSuffix in $uri");
Expand Down Expand Up @@ -64,6 +64,6 @@ main() {
expectLocation(reflectClass(TabIndentedInOtherFile), otherSuffix, 11, 2);

// Synthetic classes.
Expect.isNull(reflectClass(MA).superclass.location);
Expect.isNull(reflectClass(MA).superclass!.location);
Expect.isNull((reflect(main) as ClosureMirror).type.location);
}
2 changes: 1 addition & 1 deletion tests/lib/mirrors/deferred_mirrors_metadata_lib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class E {
String foo() {
String c = reflectClass(E).metadata[0].invoke(#toString, []).reflectee;
String d = reflectClass(E)
.declarations[#f]
.declarations[#f]!
.metadata[0]
.invoke(#toString, []).reflectee;
InstanceMirror i = currentMirrorSystem().findLibrary(#main).metadata[0];
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/mirrors/equality_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BadEqualityHash {
typedef bool Predicate(Object o);
Predicate somePredicate = (Object o) => false;

checkEquality(List<Map<String, Object>> equivalenceClasses) {
checkEquality(List<Map<String, Object?>> equivalenceClasses) {
for (var equivalenceClass in equivalenceClasses) {
equivalenceClass.forEach((name, member) {
equivalenceClass.forEach((otherName, otherMember) {
Expand Down Expand Up @@ -61,7 +61,7 @@ main() {
var badEqualityHash1 = new BadEqualityHash();
var badEqualityHash2 = new BadEqualityHash();

checkEquality(<Map<String, Object>>[
checkEquality(<Map<String, Object?>>[
{'reflect(o1)': reflect(o1), 'reflect(o1), again': reflect(o1)},
{'reflect(o2)': reflect(o2), 'reflect(o2), again': reflect(o2)},
{
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/mirrors/field_type_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class A<T> {
@C(44)
String field = "";
var dynamicTypeField;
T typeVariableField;
H<int> parameterizedTypeField;
late T typeVariableField;
late H<int> parameterizedTypeField;
}

class H<T> {}
Expand Down
8 changes: 4 additions & 4 deletions tests/lib/mirrors/generic_bounded_by_type_parameter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ class Generic<X, Y> extends Super<X, Y> {} //# 02: compile-time error

main() {
ClassMirror superDecl = reflectClass(Super);
ClassMirror superOfNumAndInt = reflectClass(Fixed).superclass;
ClassMirror superOfNumAndInt = reflectClass(Fixed).superclass!;
ClassMirror genericDecl = reflectClass(Generic); // //# 02: continued
ClassMirror superOfXAndY = genericDecl.superclass; // //# 02: continued
ClassMirror superOfXAndY = genericDecl.superclass!; // //# 02: continued
ClassMirror genericOfNumAndDouble = reflect(new Generic<num, double>()).type; // //# 02: continued
ClassMirror superOfNumAndDouble = genericOfNumAndDouble.superclass; // //# 02: continued
ClassMirror superOfNumAndDouble = genericOfNumAndDouble.superclass!; // //# 02: continued

ClassMirror genericOfNumAndBool = reflect(new Generic<num, bool>()).type; // //# 02: compile-time error
ClassMirror superOfNumAndBool = genericOfNumAndBool.superclass; // //# 02: continued
ClassMirror superOfNumAndBool = genericOfNumAndBool.superclass!; // //# 02: continued
Expect.isFalse(genericOfNumAndBool.isOriginalDeclaration); // //# 02: continued
Expect.isFalse(superOfNumAndBool.isOriginalDeclaration); // //# 02: continued
typeParameters(genericOfNumAndBool, [#X, #Y]); // //# 02: continued
Expand Down
10 changes: 5 additions & 5 deletions tests/lib/mirrors/generic_bounded_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ class Malbounded extends Super<String> {} //# 01: compile-time error

main() {
ClassMirror superDecl = reflectClass(Super);
ClassMirror superOfInt = reflectClass(Fixed).superclass;
ClassMirror superOfInt = reflectClass(Fixed).superclass!;
ClassMirror genericDecl = reflectClass(Generic); // //# 02: continued
ClassMirror superOfR = genericDecl.superclass; // //# 02: continued
ClassMirror superOfR = genericDecl.superclass!; // //# 02: continued
ClassMirror genericOfDouble = reflect(new Generic<double>()).type; // //# 02: continued
ClassMirror superOfDouble = genericOfDouble.superclass; // //# 02: continued
ClassMirror superOfDouble = genericOfDouble.superclass!; // //# 02: continued
ClassMirror genericOfBool = reflect(new Generic<bool>()).type; // //# 02: compile-time error
ClassMirror superOfBool = genericOfBool.superclass; // //# 02: continued
ClassMirror superOfBool = genericOfBool.superclass!; // //# 02: continued
Expect.isFalse(genericOfBool.isOriginalDeclaration); // //# 02: continued
Expect.isFalse(superOfBool.isOriginalDeclaration); // //# 02: continued
typeParameters(genericOfBool, [#R]); // //# 02: continued
typeParameters(superOfBool, [#T]); // //# 02: continued
typeArguments(genericOfBool, [reflectClass(bool)]); // //# 02: continued
typeArguments(superOfBool, [reflectClass(bool)]); // //# 02: continued

ClassMirror superOfString = reflectClass(Malbounded).superclass; // //# 01: continued
ClassMirror superOfString = reflectClass(Malbounded).superclass!; // //# 01: continued

Expect.isTrue(superDecl.isOriginalDeclaration);
Expect.isFalse(superOfInt.isOriginalDeclaration);
Expand Down
10 changes: 5 additions & 5 deletions tests/lib/mirrors/generic_f_bounded_mixin_application_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ main() {
ClassMirror orderedCollectionSerializerDecl =
reflectClass(OrderedCollectionSerializer);

ClassMirror orderedCollectionOfInt = orderedIntegerCollection.superclass;
ClassMirror orderedCollectionOfInt = orderedIntegerCollection.superclass!;
ClassMirror customOrderedCollectionOfInt =
customOrderedIntegerCollection.superclass;
ClassMirror serializerOfCollection = collectionSerializerDecl.superclass;
customOrderedIntegerCollection.superclass!;
ClassMirror serializerOfCollection = collectionSerializerDecl.superclass!;
ClassMirror serializerOfOrderedCollection =
orderedCollectionSerializerDecl.superclass;
orderedCollectionSerializerDecl.superclass!;
ClassMirror collectionOfDynamic = reflect(new Collection()).type;
ClassMirror orderedCollectionOfDynamic =
reflect(new OrderedCollection()).type;
ClassMirror collectionWithSerializableOfOrderedCollection =
orderedCollectionDecl.superclass;
orderedCollectionDecl.superclass!;

Expect.isTrue(collectionDecl.isOriginalDeclaration);
Expect.isTrue(serializableDecl.isOriginalDeclaration);
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/mirrors/generic_f_bounded_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ main() {
ClassMirror realDecl = reflectClass(Real);
ClassMirror sorterDecl = reflectClass(Sorter);
ClassMirror realSorterDecl = reflectClass(RealSorter);
ClassMirror magnitudeOfReal = realDecl.superclass;
ClassMirror sorterOfReal = realSorterDecl.superclass;
ClassMirror magnitudeOfReal = realDecl.superclass!;
ClassMirror sorterOfReal = realSorterDecl.superclass!;

Expect.isTrue(magnitudeDecl.isOriginalDeclaration);
Expect.isTrue(realDecl.isOriginalDeclaration);
Expand All @@ -38,7 +38,7 @@ main() {

Expect.equals(reflectClass(Object), tFromMagnitude.upperBound);

ClassMirror magnitudeOfR = rFromSorter.upperBound;
ClassMirror magnitudeOfR = rFromSorter.upperBound as ClassMirror;
Expect.isFalse(magnitudeOfR.isOriginalDeclaration);
Expect.equals(magnitudeDecl, magnitudeOfR.originalDeclaration);
Expect.equals(rFromSorter, magnitudeOfR.typeArguments.single);
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/mirrors/generic_function_typedef_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ typedef bool GenericPredicate<T>(T t);
typedef S GenericTransform<S>(S s);

class C<R> {
GenericPredicate<num> predicateOfNum;
GenericTransform<String> transformOfString;
GenericTransform<R> transformOfR;
GenericPredicate<num> predicateOfNum = (num n) => false;
GenericTransform<String> transformOfString = (String s) => s;
GenericTransform<R> transformOfR = (R r) => r;
}

reflectTypeDeclaration(t) => reflectType(t).originalDeclaration;
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/mirrors/generic_method_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'dart:mirrors';
import 'package:expect/expect.dart';

class Foo {
T bar<T>() => null;
T bar<T>() => throw "does-not-return";
}

void main() {
Expand Down
26 changes: 14 additions & 12 deletions tests/lib/mirrors/generic_mixin_applications_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ main() {
typeArguments(reflectClass(GenericMultipleMixins), []);
// Anonymous mixin applications have no type parameters or type arguments.
typeArguments(
reflectClass(NonGenericClass1).superclass.originalDeclaration, []);
reflectClass(NonGenericClass1).superclass!.originalDeclaration, []);
typeArguments(
reflectClass(NonGenericClass2).superclass.originalDeclaration, []);
typeArguments(reflectClass(GenericClass1).superclass.originalDeclaration, []);
typeArguments(reflectClass(GenericClass2).superclass.originalDeclaration, []);
reflectClass(NonGenericClass2).superclass!.originalDeclaration, []);
typeArguments(
reflectClass(GenericClass1).superclass!.originalDeclaration, []);
typeArguments(
reflectClass(GenericClass2).superclass!.originalDeclaration, []);

// Instantiations.
typeParameters(reflect(new NonGenericMixinApplication1()).type, []);
Expand All @@ -80,10 +82,10 @@ main() {
typeParameters(reflect(new GenericMultipleMixins<bool, String, int>()).type,
[#A, #B, #C]);
// Anonymous mixin applications have no type parameters or type arguments.
typeParameters(reflect(new NonGenericClass1()).type.superclass, []);
typeParameters(reflect(new NonGenericClass2()).type.superclass, []);
typeParameters(reflect(new GenericClass1<bool>()).type.superclass, []);
typeParameters(reflect(new GenericClass2<bool>()).type.superclass, []);
typeParameters(reflect(new NonGenericClass1()).type.superclass!, []);
typeParameters(reflect(new NonGenericClass2()).type.superclass!, []);
typeParameters(reflect(new GenericClass1<bool>()).type.superclass!, []);
typeParameters(reflect(new GenericClass2<bool>()).type.superclass!, []);

typeArguments(reflect(new NonGenericMixinApplication1()).type, []);
typeArguments(reflect(new NonGenericMixinApplication2()).type, []);
Expand All @@ -98,8 +100,8 @@ main() {
typeArguments(reflect(new GenericMultipleMixins<bool, String, int>()).type,
[reflectClass(bool), reflectClass(String), reflectClass(int)]);
// Anonymous mixin applications have no type parameters or type arguments.
typeArguments(reflect(new NonGenericClass1()).type.superclass, []);
typeArguments(reflect(new NonGenericClass2()).type.superclass, []);
typeArguments(reflect(new GenericClass1<bool>()).type.superclass, []);
typeArguments(reflect(new GenericClass2<bool>()).type.superclass, []);
typeArguments(reflect(new NonGenericClass1()).type.superclass!, []);
typeArguments(reflect(new NonGenericClass2()).type.superclass!, []);
typeArguments(reflect(new GenericClass1<bool>()).type.superclass!, []);
typeArguments(reflect(new GenericClass2<bool>()).type.superclass!, []);
}
Loading

0 comments on commit 081e2ac

Please sign in to comment.