Stop using deprecated errors (#201)
Prepare for the errors to be removed from the SDK and stop referencing
them entirely. Deprecate the matchers for these errors and change the
types to target the more general `Error` and `TypeError` which will
still catch the same situations.
Move the ignore for same package deprecations to cover the entire test
file.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 77c0822..a67f797 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,8 @@
## 0.12.14
* Add `containsOnce` matcher.
+* Deprecate `isCyclicInitializationError` and `NullThrownError`. These errors
+ will be removed from the SDK. Update them to catch more general errors.
## 0.12.13
diff --git a/lib/src/error_matchers.dart b/lib/src/error_matchers.dart
index df93d3e..5b6238d 100644
--- a/lib/src/error_matchers.dart
+++ b/lib/src/error_matchers.dart
@@ -15,8 +15,11 @@
const isConcurrentModificationError =
TypeMatcher<ConcurrentModificationError>();
-/// A matcher for [CyclicInitializationError].
-const isCyclicInitializationError = TypeMatcher<CyclicInitializationError>();
+/// A matcher for [Error].
+@Deprecated(
+ 'CyclicInitializationError is deprecated and will be removed in Dart 3. '
+ 'Use `isA<Error>()` instead.')
+const isCyclicInitializationError = TypeMatcher<Error>();
/// A matcher for [Exception].
const isException = TypeMatcher<Exception>();
@@ -27,8 +30,10 @@
/// A matcher for [NoSuchMethodError].
const isNoSuchMethodError = TypeMatcher<NoSuchMethodError>();
-/// A matcher for [NullThrownError].
-const isNullThrownError = TypeMatcher<NullThrownError>();
+/// A matcher for [TypeError].
+@Deprecated('NullThrownError is deprecated and will be removed in Dart 3. '
+ 'Use `isA<TypeError>()` instead.')
+const isNullThrownError = TypeMatcher<TypeError>();
/// A matcher for [RangeError].
const isRangeError = TypeMatcher<RangeError>();
diff --git a/test/type_matcher_test.dart b/test/type_matcher_test.dart
index 306202c..99d4459 100644
--- a/test/type_matcher_test.dart
+++ b/test/type_matcher_test.dart
@@ -2,6 +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.
+// ignore_for_file: deprecated_member_use_from_same_package
import 'package:matcher/matcher.dart';
import 'package:test/test.dart' show test, group;
@@ -11,7 +12,6 @@
_test(isMap, {}, name: 'Map');
_test(isList, [], name: 'List');
_test(isArgumentError, ArgumentError());
- // ignore: deprecated_member_use, deprecated_member_use_from_same_package
_test(isCastError, TypeError());
_test<Exception>(isException, const FormatException());
_test(isFormatException, const FormatException());
@@ -20,13 +20,12 @@
_test(isUnimplementedError, UnimplementedError('oops'));
_test(isUnsupportedError, UnsupportedError('oops'));
_test(isConcurrentModificationError, ConcurrentModificationError());
- _test(isCyclicInitializationError, CyclicInitializationError());
+ _test(isCyclicInitializationError, Error());
_test<NoSuchMethodError?>(isNoSuchMethodError, null,
name: 'NoSuchMethodError');
- _test(isNullThrownError, NullThrownError());
+ _test(isNullThrownError, TypeError());
group('custom `TypeMatcher`', () {
- // ignore: deprecated_member_use_from_same_package
_test(const isInstanceOf<String>(), 'hello');
_test(const _StringMatcher(), 'hello');
_test(const TypeMatcher<String>(), 'hello');
@@ -56,9 +55,7 @@
// Validate that existing implementations continue to work.
class _StringMatcher extends TypeMatcher {
- const _StringMatcher() : super(
- // ignore: deprecated_member_use_from_same_package
- 'String');
+ const _StringMatcher() : super('String');
@override
bool matches(dynamic item, Map matchState) => item is String;