Add package:expect/matchers_lite.dart

Change-Id: I671f317ee2c806380584646c75412762e549418e
Reviewed-on: https://dart-review.googlesource.com/c/93023
Reviewed-by: Jens Johansen <jensj@google.com>
diff --git a/pkg/expect/lib/matchers_lite.dart b/pkg/expect/lib/matchers_lite.dart
new file mode 100644
index 0000000..004e37e
--- /dev/null
+++ b/pkg/expect/lib/matchers_lite.dart
@@ -0,0 +1,54 @@
+// Copyright (c) 2019, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+/// This library is supposed help to remove dependencies on package:test from
+/// an existing test.
+///
+/// Feel free to add more matchers, as long as they remain lite. Batteries
+/// aren't included here. This is intended to be used in low-level platform
+/// tests and shouldn't rely on advanced features such as reflection. Using
+/// asynchronous code is acceptable, but only for testing code that is
+/// *already* asynchronous, but try to avoid using "async" and other generators
+/// (it's hard testing the implemention of generators if the test
+/// infrastructure relies on them itself).
+library expect.matchers_lite;
+
+import "expect.dart" show Expect;
+
+typedef Matcher = void Function(Object actual);
+
+void expect(Object actual, Object expected) {
+  if (expected is Matcher) {
+    expected(actual);
+  } else {
+    equals(expected)(actual);
+  }
+}
+
+Matcher unorderedEquals(Iterable<Object> expected) {
+  return (Object actual) => Expect.setEquals(expected, actual);
+}
+
+fail(String message) {
+  Expect.fail(message);
+}
+
+Matcher same(Object expected) {
+  return (Object actual) => Expect.identical(expected, actual);
+}
+
+Matcher equals(Object expected) {
+  if (expected is String) {
+    return (Object actual) => Expect.stringEquals(expected, actual);
+  } else if (expected is Iterable<Object>) {
+    return (dynamic actual) =>
+        Expect.listEquals(expected.toList(), actual.toList());
+  } else {
+    return (Object actual) => Expect.equals(expected, actual);
+  }
+}
+
+final Matcher isEmpty = (dynamic actual) => Expect.isTrue(actual.isEmpty);
+
+final Matcher isNull = (Object actual) => Expect.isNull(actual);
diff --git a/pkg/kernel/test/class_hierarchy_test.dart b/pkg/kernel/test/class_hierarchy_test.dart
index 25b34e1..c98017a 100644
--- a/pkg/kernel/test/class_hierarchy_test.dart
+++ b/pkg/kernel/test/class_hierarchy_test.dart
@@ -2,7 +2,7 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-import "package:expect/expect.dart" show Expect;
+import "package:expect/matchers_lite.dart";
 
 import "package:kernel/ast.dart";
 import "package:kernel/class_hierarchy.dart";
@@ -11,37 +11,6 @@
 import "package:kernel/text/ast_to_text.dart";
 import "package:kernel/type_algebra.dart";
 
-typedef Matcher = void Function(Object actual);
-
-void expect(Object actual, Object expected) {
-  if (expected is Matcher) {
-    expected(actual);
-  } else {
-    same(expected)(actual);
-  }
-}
-
-Matcher unorderedEquals(List<Object> expected) {
-  return (Object actual) => Expect.setEquals(expected, actual);
-}
-
-fail(String message) {
-  Expect.fail(message);
-}
-
-Matcher same(Object expected) {
-  if (expected is Iterable<Object>) {
-    return (dynamic actual) =>
-        Expect.listEquals(expected.toList(), actual.toList());
-  } else {
-    return (Object actual) => Expect.equals(expected, actual);
-  }
-}
-
-final Matcher isEmpty = (dynamic actual) => Expect.isTrue(actual.isEmpty);
-
-final Matcher isNull = (Object actual) => Expect.isNull(actual);
-
 main() {
   new ClosedWorldClassHierarchyTest().test_applyTreeChanges();