diff --git a/CHANGELOG.md b/CHANGELOG.md index 6120a6cf6..c2cd206d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,30 @@ and groups marked as solo will be run. It is still recommended that users instead filter their tests by using the runner argument `-n`. +* Updated exported `package:matcher` to `0.12.3` which includes these updates: + + - Many improvements to `TypeMatcher` + - Can now be used directly as `const TypeMatcher()`. + - Added a type parameter to specify the target `Type`. + - Made the `name` constructor parameter optional and marked it deprecated. + It's redundant to the type parameter. + - Migrated all `isType` matchers to `TypeMatcher`. + - Added a `having` function that allows chained validations of specific + features of the target type. + + ```dart + /// Validates that the object is a [RangeError] with a message containing + /// the string 'details' and `start` and `end` properties that are `null`. + final _rangeMatcher = isRangeError + .having((e) => e.message, 'message', contains('details')) + .having((e) => e.start, 'start', isNull) + .having((e) => e.end, 'end', isNull); + ``` + + - Deprecated the `isInstanceOf` class. Use `TypeMatcher` instead. + + - Improved the output of `Matcher` instances that fail due to type errors. + ## 0.12.41 * Add support for debugging VM tests. diff --git a/lib/src/frontend/async_matcher.dart b/lib/src/frontend/async_matcher.dart index 2a4ceabf6..959b99e1c 100644 --- a/lib/src/frontend/async_matcher.dart +++ b/lib/src/frontend/async_matcher.dart @@ -35,8 +35,8 @@ abstract class AsyncMatcher extends Matcher { result, anyOf([ equals(null), - new isInstanceOf(), - new isInstanceOf() + new TypeMatcher(), + new TypeMatcher() ]), reason: "matchAsync() may only return a String, a Future, or null."); diff --git a/lib/src/frontend/expect.dart b/lib/src/frontend/expect.dart index 0f7f0ab17..612d4f9bc 100644 --- a/lib/src/frontend/expect.dart +++ b/lib/src/frontend/expect.dart @@ -124,8 +124,8 @@ Future _expect(actual, matcher, result, anyOf([ equals(null), - new isInstanceOf(), - new isInstanceOf() + new TypeMatcher(), + new TypeMatcher() ]), reason: "matchAsync() may only return a String, a Future, or null."); diff --git a/pubspec.yaml b/pubspec.yaml index 514d3b0da..ea3bcbeec 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -40,7 +40,7 @@ dependencies: # Use a tight version constraint to ensure that a constraint on matcher # properly constrains all features it provides. - matcher: '>=0.12.2 <0.12.3' + matcher: '>=0.12.3 <0.12.4' dev_dependencies: fake_async: '>=0.1.2 <2.0.0' shelf_test_handler: '^1.0.0' diff --git a/test/backend/declarer_test.dart b/test/backend/declarer_test.dart index 6d854b937..e2872f620 100644 --- a/test/backend/declarer_test.dart +++ b/test/backend/declarer_test.dart @@ -313,7 +313,7 @@ void main() { var testGroup = entries.single as Group; expect(testGroup.name, equals("group")); expect(testGroup.entries, hasLength(1)); - expect(testGroup.entries.single, new isInstanceOf()); + expect(testGroup.entries.single, new TypeMatcher()); expect(testGroup.entries.single.name, "group description"); }); @@ -328,7 +328,7 @@ void main() { var testGroup = entries.single as Group; expect(testGroup.name, equals("Object")); expect(testGroup.entries, hasLength(1)); - expect(testGroup.entries.single, new isInstanceOf()); + expect(testGroup.entries.single, new TypeMatcher()); expect(testGroup.entries.single.name, "Object description"); }); @@ -343,7 +343,7 @@ void main() { var testGroup = entries.single as Group; expect(testGroup.metadata.timeout.scaleFactor, equals(2)); expect(testGroup.entries, hasLength(1)); - expect(testGroup.entries.single, new isInstanceOf()); + expect(testGroup.entries.single, new TypeMatcher()); expect(testGroup.entries.single.metadata.timeout.scaleFactor, equals(6)); }); @@ -359,7 +359,7 @@ void main() { expect(testGroup.metadata.timeout.duration, equals(new Duration(seconds: 10))); expect(testGroup.entries, hasLength(1)); - expect(testGroup.entries.single, new isInstanceOf()); + expect(testGroup.entries.single, new TypeMatcher()); expect(testGroup.entries.single.metadata.timeout.duration, equals(new Duration(seconds: 20))); }); @@ -376,7 +376,7 @@ void main() { expect(testGroup.metadata.timeout.duration, equals(new Duration(seconds: 10))); expect(testGroup.entries, hasLength(1)); - expect(testGroup.entries.single, new isInstanceOf()); + expect(testGroup.entries.single, new TypeMatcher()); expect(testGroup.entries.single.metadata.timeout.duration, equals(new Duration(seconds: 15))); }); diff --git a/test/backend/invoker_test.dart b/test/backend/invoker_test.dart index 6e0ef9d85..a3d015110 100644 --- a/test/backend/invoker_test.dart +++ b/test/backend/invoker_test.dart @@ -438,7 +438,7 @@ void main() { expectErrors(liveTest, [ (error) { expect(lastState.status, equals(Status.complete)); - expect(error, new isInstanceOf()); + expect(error, new TypeMatcher()); } ]); @@ -464,7 +464,7 @@ void main() { expectErrors(liveTest, [ (error) { expect(lastState.status, equals(Status.complete)); - expect(error, new isInstanceOf()); + expect(error, new TypeMatcher()); } ]); @@ -488,7 +488,7 @@ void main() { expectErrors(liveTest, [ (error) { expect(lastState.status, equals(Status.complete)); - expect(error, new isInstanceOf()); + expect(error, new TypeMatcher()); } ]); diff --git a/test/frontend/matcher/throws_type_test.dart b/test/frontend/matcher/throws_type_test.dart index 979e9da33..57eb0fcad 100644 --- a/test/frontend/matcher/throws_type_test.dart +++ b/test/frontend/matcher/throws_type_test.dart @@ -17,7 +17,8 @@ void main() { expect(() => throw new Exception(), throwsArgumentError); }); - expectTestFailed(liveTest, startsWith("Expected: throws ArgumentError")); + expectTestFailed(liveTest, + startsWith("Expected: throws ")); }); }); @@ -33,7 +34,9 @@ void main() { }); expectTestFailed( - liveTest, startsWith("Expected: throws ConcurrentModificationError")); + liveTest, + startsWith( + "Expected: throws ")); }); }); @@ -49,7 +52,9 @@ void main() { }); expectTestFailed( - liveTest, startsWith("Expected: throws CyclicInitializationError")); + liveTest, + startsWith( + "Expected: throws ")); }); }); @@ -63,7 +68,8 @@ void main() { expect(() => throw 'oh no', throwsException); }); - expectTestFailed(liveTest, startsWith("Expected: throws Exception")); + expectTestFailed( + liveTest, startsWith("Expected: throws ")); }); }); @@ -77,8 +83,8 @@ void main() { expect(() => throw new Exception(), throwsFormatException); }); - expectTestFailed( - liveTest, startsWith("Expected: throws FormatException")); + expectTestFailed(liveTest, + startsWith("Expected: throws ")); }); }); @@ -94,8 +100,8 @@ void main() { expect(() => throw new Exception(), throwsNoSuchMethodError); }); - expectTestFailed( - liveTest, startsWith("Expected: throws NoSuchMethodError")); + expectTestFailed(liveTest, + startsWith("Expected: throws ")); }); }); @@ -109,8 +115,8 @@ void main() { expect(() => throw new Exception(), throwsNullThrownError); }); - expectTestFailed( - liveTest, startsWith("Expected: throws NullThrownError")); + expectTestFailed(liveTest, + startsWith("Expected: throws ")); }); }); @@ -124,7 +130,8 @@ void main() { expect(() => throw new Exception(), throwsRangeError); }); - expectTestFailed(liveTest, startsWith("Expected: throws RangeError")); + expectTestFailed( + liveTest, startsWith("Expected: throws ")); }); }); @@ -138,7 +145,8 @@ void main() { expect(() => throw new Exception(), throwsStateError); }); - expectTestFailed(liveTest, startsWith("Expected: throws StateError")); + expectTestFailed( + liveTest, startsWith("Expected: throws ")); }); }); @@ -152,8 +160,8 @@ void main() { expect(() => throw new Exception(), throwsUnimplementedError); }); - expectTestFailed( - liveTest, startsWith("Expected: throws UnimplementedError")); + expectTestFailed(liveTest, + startsWith("Expected: throws ")); }); }); @@ -167,8 +175,8 @@ void main() { expect(() => throw new Exception(), throwsUnsupportedError); }); - expectTestFailed( - liveTest, startsWith("Expected: throws UnsupportedError")); + expectTestFailed(liveTest, + startsWith("Expected: throws ")); }); }); } diff --git a/test/runner/hybrid_test.dart b/test/runner/hybrid_test.dart index 2e0c647da..f9a6d2c43 100644 --- a/test/runner/hybrid_test.dart +++ b/test/runner/hybrid_test.dart @@ -168,7 +168,7 @@ void main() { } """); - expect(channel.stream.first, throwsA(new isInstanceOf())); + expect(channel.stream.first, throwsA(new TypeMatcher())); }); test("gracefully handles an unserializable message in the VM", () { @@ -582,6 +582,6 @@ void _spawnHybridUriTests([Iterable arguments]) { test("emits an error from the stream channel if the isolate fails to load", () { expect(spawnHybridUri("non existent file").stream.first, - throwsA(new isInstanceOf())); + throwsA(new TypeMatcher())); }); }