1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:28:12 +00:00

Tests: Prefer TRY_OR_FAIL() and MUST() over EXPECT(!.is_error())

Note that in some cases (in particular SQL::Result and PDFErrorOr),
there is no Formatter defined for the error type, hence TRY_OR_FAIL
cannot work as-is. Furthermore, this commit leaves untouched the places
where MUST could be replaced by TRY_OR_FAIL.

Inspired by:
https://github.com/SerenityOS/serenity/pull/18710#discussion_r1186892445
This commit is contained in:
Ben Wiederhake 2023-05-07 20:14:06 +02:00 committed by Andrew Kaster
parent 87a7299078
commit f890b70eae
23 changed files with 415 additions and 742 deletions

View file

@ -20,7 +20,7 @@ TEST_CASE(simple_enqueue)
{
auto queue = MUST(TestQueue::create());
for (size_t i = 0; i < queue.size() - 1; ++i)
EXPECT(!queue.enqueue((int)i).is_error());
MUST(queue.enqueue((int)i));
auto result = queue.enqueue(0);
EXPECT(result.is_error());
@ -34,9 +34,9 @@ TEST_CASE(simple_dequeue)
for (int i = 0; i < test_count; ++i)
(void)queue.enqueue(i);
for (int i = 0; i < test_count; ++i) {
auto const element = queue.dequeue();
EXPECT(!element.is_error());
EXPECT_EQ(element.value(), i);
// TODO: This could be TRY_OR_FAIL(), if someone implements Formatter<SharedSingleProducerCircularQueue::QueueStatus>.
auto const element = MUST(queue.dequeue());
EXPECT_EQ(element, i);
}
}