1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 03:08:13 +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

@ -14,28 +14,25 @@
TEST_CASE(linearized_pdf)
{
auto file = Core::MappedFile::map("linearized.pdf"sv).release_value();
auto document = PDF::Document::create(file->bytes());
EXPECT(!document.is_error());
EXPECT(!document.value()->initialize().is_error());
EXPECT_EQ(document.value()->get_page_count(), 1U);
auto document = MUST(PDF::Document::create(file->bytes()));
MUST(document->initialize());
EXPECT_EQ(document->get_page_count(), 1U);
}
TEST_CASE(non_linearized_pdf)
{
auto file = Core::MappedFile::map("non-linearized.pdf"sv).release_value();
auto document = PDF::Document::create(file->bytes());
EXPECT(!document.is_error());
EXPECT(!document.value()->initialize().is_error());
EXPECT_EQ(document.value()->get_page_count(), 1U);
auto document = MUST(PDF::Document::create(file->bytes()));
MUST(document->initialize());
EXPECT_EQ(document->get_page_count(), 1U);
}
TEST_CASE(complex_pdf)
{
auto file = Core::MappedFile::map("complex.pdf"sv).release_value();
auto document = PDF::Document::create(file->bytes());
EXPECT(!document.is_error());
EXPECT(!document.value()->initialize().is_error());
EXPECT_EQ(document.value()->get_page_count(), 3U);
auto document = MUST(PDF::Document::create(file->bytes()));
MUST(document->initialize());
EXPECT_EQ(document->get_page_count(), 3U);
}
TEST_CASE(empty_file_issue_10702)