Skip to content

Commit

Permalink
feature: update exported pkg:matcher to 0.12.3 (#882)
Browse files Browse the repository at this point in the history
Updated test to make new output of Type mismatch errors
Update usage of isInstanceOf to TypeMatcher
  • Loading branch information
kevmoo authored Jun 15, 2018
1 parent 38b5696 commit 72336b0
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 31 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyType>()`.
- 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.
Expand Down
4 changes: 2 additions & 2 deletions lib/src/frontend/async_matcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ abstract class AsyncMatcher extends Matcher {
result,
anyOf([
equals(null),
new isInstanceOf<Future>(),
new isInstanceOf<String>()
new TypeMatcher<Future>(),
new TypeMatcher<String>()
]),
reason: "matchAsync() may only return a String, a Future, or null.");

Expand Down
4 changes: 2 additions & 2 deletions lib/src/frontend/expect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ Future _expect(actual, matcher,
result,
anyOf([
equals(null),
new isInstanceOf<Future>(),
new isInstanceOf<String>()
new TypeMatcher<Future>(),
new TypeMatcher<String>()
]),
reason: "matchAsync() may only return a String, a Future, or null.");

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
10 changes: 5 additions & 5 deletions test/backend/declarer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Test>());
expect(testGroup.entries.single, new TypeMatcher<Test>());
expect(testGroup.entries.single.name, "group description");
});

Expand All @@ -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<Test>());
expect(testGroup.entries.single, new TypeMatcher<Test>());
expect(testGroup.entries.single.name, "Object description");
});

Expand All @@ -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<Test>());
expect(testGroup.entries.single, new TypeMatcher<Test>());
expect(testGroup.entries.single.metadata.timeout.scaleFactor, equals(6));
});

Expand All @@ -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<Test>());
expect(testGroup.entries.single, new TypeMatcher<Test>());
expect(testGroup.entries.single.metadata.timeout.duration,
equals(new Duration(seconds: 20)));
});
Expand All @@ -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<Test>());
expect(testGroup.entries.single, new TypeMatcher<Test>());
expect(testGroup.entries.single.metadata.timeout.duration,
equals(new Duration(seconds: 15)));
});
Expand Down
6 changes: 3 additions & 3 deletions test/backend/invoker_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ void main() {
expectErrors(liveTest, [
(error) {
expect(lastState.status, equals(Status.complete));
expect(error, new isInstanceOf<TimeoutException>());
expect(error, new TypeMatcher<TimeoutException>());
}
]);

Expand All @@ -464,7 +464,7 @@ void main() {
expectErrors(liveTest, [
(error) {
expect(lastState.status, equals(Status.complete));
expect(error, new isInstanceOf<TimeoutException>());
expect(error, new TypeMatcher<TimeoutException>());
}
]);

Expand All @@ -488,7 +488,7 @@ void main() {
expectErrors(liveTest, [
(error) {
expect(lastState.status, equals(Status.complete));
expect(error, new isInstanceOf<TimeoutException>());
expect(error, new TypeMatcher<TimeoutException>());
}
]);

Expand Down
40 changes: 24 additions & 16 deletions test/frontend/matcher/throws_type_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ void main() {
expect(() => throw new Exception(), throwsArgumentError);
});

expectTestFailed(liveTest, startsWith("Expected: throws ArgumentError"));
expectTestFailed(liveTest,
startsWith("Expected: throws <Instance of 'ArgumentError'>"));
});
});

Expand All @@ -33,7 +34,9 @@ void main() {
});

expectTestFailed(
liveTest, startsWith("Expected: throws ConcurrentModificationError"));
liveTest,
startsWith(
"Expected: throws <Instance of 'ConcurrentModificationError'>"));
});
});

Expand All @@ -49,7 +52,9 @@ void main() {
});

expectTestFailed(
liveTest, startsWith("Expected: throws CyclicInitializationError"));
liveTest,
startsWith(
"Expected: throws <Instance of 'CyclicInitializationError'>"));
});
});

Expand All @@ -63,7 +68,8 @@ void main() {
expect(() => throw 'oh no', throwsException);
});

expectTestFailed(liveTest, startsWith("Expected: throws Exception"));
expectTestFailed(
liveTest, startsWith("Expected: throws <Instance of 'Exception'>"));
});
});

Expand All @@ -77,8 +83,8 @@ void main() {
expect(() => throw new Exception(), throwsFormatException);
});

expectTestFailed(
liveTest, startsWith("Expected: throws FormatException"));
expectTestFailed(liveTest,
startsWith("Expected: throws <Instance of 'FormatException'>"));
});
});

Expand All @@ -94,8 +100,8 @@ void main() {
expect(() => throw new Exception(), throwsNoSuchMethodError);
});

expectTestFailed(
liveTest, startsWith("Expected: throws NoSuchMethodError"));
expectTestFailed(liveTest,
startsWith("Expected: throws <Instance of 'NoSuchMethodError'>"));
});
});

Expand All @@ -109,8 +115,8 @@ void main() {
expect(() => throw new Exception(), throwsNullThrownError);
});

expectTestFailed(
liveTest, startsWith("Expected: throws NullThrownError"));
expectTestFailed(liveTest,
startsWith("Expected: throws <Instance of 'NullThrownError'>"));
});
});

Expand All @@ -124,7 +130,8 @@ void main() {
expect(() => throw new Exception(), throwsRangeError);
});

expectTestFailed(liveTest, startsWith("Expected: throws RangeError"));
expectTestFailed(
liveTest, startsWith("Expected: throws <Instance of 'RangeError'>"));
});
});

Expand All @@ -138,7 +145,8 @@ void main() {
expect(() => throw new Exception(), throwsStateError);
});

expectTestFailed(liveTest, startsWith("Expected: throws StateError"));
expectTestFailed(
liveTest, startsWith("Expected: throws <Instance of 'StateError'>"));
});
});

Expand All @@ -152,8 +160,8 @@ void main() {
expect(() => throw new Exception(), throwsUnimplementedError);
});

expectTestFailed(
liveTest, startsWith("Expected: throws UnimplementedError"));
expectTestFailed(liveTest,
startsWith("Expected: throws <Instance of 'UnimplementedError'>"));
});
});

Expand All @@ -167,8 +175,8 @@ void main() {
expect(() => throw new Exception(), throwsUnsupportedError);
});

expectTestFailed(
liveTest, startsWith("Expected: throws UnsupportedError"));
expectTestFailed(liveTest,
startsWith("Expected: throws <Instance of 'UnsupportedError'>"));
});
});
}
4 changes: 2 additions & 2 deletions test/runner/hybrid_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void main() {
}
""");

expect(channel.stream.first, throwsA(new isInstanceOf<TestFailure>()));
expect(channel.stream.first, throwsA(new TypeMatcher<TestFailure>()));
});

test("gracefully handles an unserializable message in the VM", () {
Expand Down Expand Up @@ -582,6 +582,6 @@ void _spawnHybridUriTests([Iterable<String> 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<IsolateSpawnException>()));
throwsA(new TypeMatcher<IsolateSpawnException>()));
});
}

0 comments on commit 72336b0

Please sign in to comment.