diff --git a/pubspec.lock b/pubspec.lock index db33b90bf4..3b32681ee2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -157,10 +157,10 @@ packages: dependency: "direct dev" description: name: checks - sha256: "03c1a2e4a4d3341ce0512f1401204ecdcdca8cc035e373820a73929cc0bf4fd3" + sha256: aad431b45a8ae2fa26db8c22e385b9cdec73f72986a1d9d9f2017f4c39ecf5c9 url: "https://pub.dev" source: hosted - version: "0.2.2" + version: "0.3.0" cli_util: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 0feaec8b27..938dc3a84b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -86,7 +86,7 @@ dev_dependencies: json_serializable: ^6.5.4 build_runner: ^2.3.3 test: ^1.23.1 - checks: ^0.2.2 + checks: ^0.3.0 drift_dev: ^2.5.2 fake_async: ^1.3.1 diff --git a/test/api/core_test.dart b/test/api/core_test.dart index 1c7831e7c3..bfffe3c475 100644 --- a/test/api/core_test.dart +++ b/test/api/core_test.dart @@ -2,7 +2,6 @@ import 'dart:convert'; import 'dart:io'; import 'package:checks/checks.dart'; -import 'package:checks/context.dart'; import 'package:flutter_gen/gen_l10n/zulip_localizations.dart'; import 'package:http/http.dart' as http; import 'package:test/scaffolding.dart'; @@ -85,12 +84,12 @@ void main() { ..url.asString.equals('${eg.realmUrl.origin}/api/v1/example/route') ..headers.deepEquals(authHeader(email: eg.selfAccount.email, apiKey: eg.selfAccount.apiKey)) ..fields.deepEquals({}) - ..files.single.which(it() + ..files.single.which((it) => it ..field.equals('file') ..length.equals(length) ..filename.equals(filename) ..has>>((f) => f.finalize().toBytes(), 'contents') - .completes(it()..deepEquals(content.expand((l) => l))) + .completes((it) => it.deepEquals(content.expand((l) => l))) ); }); } @@ -148,16 +147,16 @@ void main() { Future checkRequest( T exception, Condition condition) { return check(tryRequest(exception: exception)) - .throws(it() + .throws((it) => it ..routeName.equals(kExampleRouteName) ..cause.equals(exception) ..which(condition)); } final zulipLocalizations = lookupZulipLocalizations(ZulipLocalizations.supportedLocales.first); - checkRequest(http.ClientException('Oops'), it()..message.equals('Oops')); - checkRequest(const TlsException('Oops'), it()..message.equals('Oops')); - checkRequest((foo: 'bar'), it() + checkRequest(http.ClientException('Oops'), (it) => it.message.equals('Oops')); + checkRequest(const TlsException('Oops'), (it) => it.message.equals('Oops')); + checkRequest((foo: 'bar'), (it) => it ..message.equals(zulipLocalizations.errorNetworkRequestFailed)); }); @@ -176,7 +175,7 @@ void main() { ...data, }; await check(tryRequest(httpStatus: httpStatus, json: json)) - .throws(it() + .throws((it) => it ..routeName.equals(kExampleRouteName) ..httpStatus.equals(httpStatus) ..code.equals(expectedCode ?? code!) @@ -197,7 +196,7 @@ void main() { int httpStatus = 400, Map? json, String? body}) async { assert((json == null) != (body == null)); await check(tryRequest(httpStatus: httpStatus, json: json, body: body)) - .throws(it() + .throws((it) => it ..routeName.equals(kExampleRouteName) ..httpStatus.equals(httpStatus) ..data.deepEquals(json)); @@ -224,7 +223,7 @@ void main() { Future check5xx({ required int httpStatus, Map? json, String? body}) { return check(tryRequest(httpStatus: httpStatus, json: json, body: body)) - .throws(it() + .throws((it) => it ..routeName.equals(kExampleRouteName) ..httpStatus.equals(httpStatus) ..data.deepEquals(json)); @@ -241,7 +240,7 @@ void main() { Future checkMalformed({ required int httpStatus, Map? json, String? body}) { return check(tryRequest(httpStatus: httpStatus, json: json, body: body)) - .throws(it() + .throws((it) => it ..routeName.equals(kExampleRouteName) ..httpStatus.equals(httpStatus) ..data.deepEquals(json)); @@ -260,13 +259,13 @@ void main() { Object? Function(Map)? fromJson, }) { return check(tryRequest(json: json, body: body, fromJson: fromJson)) - .throws(it() + .throws((it) => it ..routeName.equals(kExampleRouteName) ..httpStatus.equals(200) ..data.deepEquals(json)); } - await check(tryRequest(json: {})).completes(it()..deepEquals({})); + await check(tryRequest(json: {})).completes((it) => it.deepEquals({})); await checkMalformed(body: jsonEncode([])); await checkMalformed(body: jsonEncode(null)); @@ -275,7 +274,7 @@ void main() { await checkMalformed(body: 'not JSON'); await check(tryRequest(json: {'x': 'y'}, fromJson: (json) => json['x'] as String)) - .completes(it()..equals('y')); + .completes((it) => it.equals('y')); await checkMalformed( json: {}, fromJson: (json) => json['x'] as String); await checkMalformed( json: {'x': 3}, fromJson: (json) => json['x'] as String); }); diff --git a/test/api/model/model_checks.dart b/test/api/model/model_checks.dart index ef8d583484..cc33f9bbbd 100644 --- a/test/api/model/model_checks.dart +++ b/test/api/model/model_checks.dart @@ -50,7 +50,7 @@ extension ReactionWithVotesChecks on Subject { // No double-votes from one person (we don't expect this from servers) assert(userIds.length == reactions.length); - return which(it() + return which((it) => it ..reactionType.equals(first.reactionType) ..emojiCode.equals(first.emojiCode) ..userIds.deepEquals(userIds) diff --git a/test/api/model/model_test.dart b/test/api/model/model_test.dart index 11a9f95d2f..ca854743ff 100644 --- a/test/api/model/model_test.dart +++ b/test/api/model/model_test.dart @@ -56,7 +56,7 @@ void main() { check(mkUser({'profile_data': {}}).profileData).isNull(); check(mkUser({'profile_data': null}).profileData).isNull(); check(mkUser({'profile_data': {'1': {'value': 'foo'}}}).profileData) - .isNotNull().deepEquals({1: it()}); + .isNotNull().deepEquals({1: (it) => it}); }); test('is_system_bot', () { diff --git a/test/api/model/reaction_test.dart b/test/api/model/reaction_test.dart index c933c146e2..e0e737c01e 100644 --- a/test/api/model/reaction_test.dart +++ b/test/api/model/reaction_test.dart @@ -1,5 +1,4 @@ import 'package:checks/checks.dart'; -import 'package:checks/context.dart'; import 'package:test/scaffolding.dart'; import 'package:zulip/api/model/reaction.dart'; @@ -8,8 +7,8 @@ import 'model_checks.dart'; void main() { group('Reactions', () { // helper to cut out "it()..isA()" goo for callers - ConditionSubject matchesReactions(List reactions) { - return it()..isA().matchesReactions(reactions); + matchesReactions(List reactions) { + return (Subject it) => it.isA().matchesReactions(reactions); } test('fromJson', () { diff --git a/test/api/notifications_test.dart b/test/api/notifications_test.dart index d9c9d9c55c..f43340e7de 100644 --- a/test/api/notifications_test.dart +++ b/test/api/notifications_test.dart @@ -76,7 +76,7 @@ void main() { ..senderAvatarUrl.equals(Uri.parse(streamJson['sender_avatar_url']!)) ..senderFullName.equals(streamJson['sender_full_name']!) ..zulipMessageId.equals(12345) - ..recipient.isA().which(it() + ..recipient.isA().which((it) => it ..streamId.equals(42) ..streamName.equals(streamJson['stream']!) ..topic.equals(streamJson['topic']!)) @@ -94,7 +94,7 @@ void main() { test('optional fields missing cause no error', () { check(parse({ ...streamJson }..remove('stream'))) - .recipient.isA().which(it() + .recipient.isA().which((it) => it ..streamId.equals(42) ..streamName.isNull()); }); diff --git a/test/model/database_test.dart b/test/model/database_test.dart index ecd9b66859..b1587c02ac 100644 --- a/test/model/database_test.dart +++ b/test/model/database_test.dart @@ -37,7 +37,7 @@ void main() { .first; check(account.toCompanion(false).toJson()).deepEquals({ ...accountData.toJson(), - 'id': it(), + 'id': (it) => it, 'acked_push_token': null, }); }); diff --git a/test/model/message_list_test.dart b/test/model/message_list_test.dart index 294218702d..9ed3e7a17f 100644 --- a/test/model/message_list_test.dart +++ b/test/model/message_list_test.dart @@ -281,10 +281,10 @@ void main() async { final message = model.messages.single; check(message) - ..content.not(it()..equals(updateEvent.renderedContent!)) + ..content.not((it) => it.equals(updateEvent.renderedContent!)) ..lastEditTimestamp.isNull() - ..flags.not(it()..deepEquals(updateEvent.flags)) - ..isMeMessage.not(it()..equals(updateEvent.isMeMessage!)); + ..flags.not((it) => it.deepEquals(updateEvent.flags)) + ..isMeMessage.not((it) => it.equals(updateEvent.isMeMessage!)); model.maybeUpdateMessage(updateEvent); checkNotifiedOnce(); @@ -310,7 +310,7 @@ void main() async { checkNotNotified(); check(model).messages.single ..content.equals(originalMessage.content) - ..content.not(it()..equals(updateEvent.renderedContent!)); + ..content.not((it) => it.equals(updateEvent.renderedContent!)); }); // TODO(server-5): Cut legacy case for rendering-only message update @@ -336,7 +336,7 @@ void main() async { ..content.equals(updateEvent.renderedContent!) // ... edit timestamp is not. ..lastEditTimestamp.equals(originalMessage.lastEditTimestamp) - ..lastEditTimestamp.not(it()..equals(updateEvent.editTimestamp)); + ..lastEditTimestamp.not((it) => it.equals(updateEvent.editTimestamp)); } test('rendering-only update does not change timestamp', () async { @@ -545,7 +545,7 @@ void main() async { model.contents[0] = const ZulipContent(nodes: [ ParagraphNode(links: null, nodes: [TextNode('something outdated')]) ]); - check(model.contents[0]).not(it()..equalsNode(correctContent)); + check(model.contents[0]).not((it) => it.equalsNode(correctContent)); model.reassemble(); checkNotifiedOnce(); @@ -802,16 +802,16 @@ void main() async { // We check showSender has the right values in [checkInvariants], // but to make this test explicit: - check(model.items).deepEquals([ - it()..isA(), - it()..isA(), - it()..isA().showSender.isTrue(), - it()..isA().showSender.isFalse(), - it()..isA().showSender.isTrue(), - it()..isA(), - it()..isA().showSender.isTrue(), - it()..isA(), - it()..isA().showSender.isTrue(), + check(model.items).deepEquals()>[ + (it) => it.isA(), + (it) => it.isA(), + (it) => it.isA().showSender.isTrue(), + (it) => it.isA().showSender.isFalse(), + (it) => it.isA().showSender.isTrue(), + (it) => it.isA(), + (it) => it.isA().showSender.isTrue(), + (it) => it.isA(), + (it) => it.isA().showSender.isTrue(), ]); }); diff --git a/test/model/store_test.dart b/test/model/store_test.dart index cde30b2c56..6a5a73a54d 100644 --- a/test/model/store_test.dart +++ b/test/model/store_test.dart @@ -232,7 +232,7 @@ void main() { await Future.delayed(Duration.zero); // The global store has a new store. - check(globalStore.perAccountSync(store.account.id)).not(it()..identicalTo(store)); + check(globalStore.perAccountSync(store.account.id)).not((it) => it.identicalTo(store)); updateFromGlobalStore(); // The new UpdateMachine updates the new store. diff --git a/test/notifications_test.dart b/test/notifications_test.dart index ef90be1198..50940943ea 100644 --- a/test/notifications_test.dart +++ b/test/notifications_test.dart @@ -123,7 +123,7 @@ void main() { ..title.equals(expectedTitle) ..body.equals(data.content) ..payload.equals(jsonEncode(data.toJson())) - ..notificationDetails.isNotNull().android.isNotNull().which(it() + ..notificationDetails.isNotNull().android.isNotNull().which((it) => it ..channelId.equals(NotificationChannelManager.kChannelId) ..tag.equals(expectedTag) ..color.equals(kZulipBrandColor) diff --git a/test/widgets/action_sheet_test.dart b/test/widgets/action_sheet_test.dart index 91bca5b091..069e3810cf 100644 --- a/test/widgets/action_sheet_test.dart +++ b/test/widgets/action_sheet_test.dart @@ -352,7 +352,7 @@ void main() { builder.selection = TextSelection.collapsed(offset: builder.text.length); } check(contentController).value.equals(builder.value); - check(contentController).not(it()..validationErrors.contains(ContentValidationError.quoteAndReplyInProgress)); + check(contentController).not((it) => it.validationErrors.contains(ContentValidationError.quoteAndReplyInProgress)); } testWidgets('in stream narrow', (WidgetTester tester) async { diff --git a/test/widgets/store_test.dart b/test/widgets/store_test.dart index 71da83403a..580ab9fd8e 100644 --- a/test/widgets/store_test.dart +++ b/test/widgets/store_test.dart @@ -142,7 +142,7 @@ void main() { // (... even one that really is separate, with its own fresh state node ...) check(tester.state(find.byType(PerAccountStoreWidget))) - .not(it()..identicalTo(oldState)); + .not((it) => it.identicalTo(oldState)); // ... then its child appears immediately, without waiting to load. check(tester.any(find.textContaining('found store'))).isTrue();