1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:47:46 +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

@ -58,10 +58,8 @@ TEST_CASE(test_interp_header_tiny_p_filesz)
int nwritten = write(fd, buffer, sizeof(buffer));
EXPECT(nwritten);
auto elf_path_or_error = FileSystem::read_link(DeprecatedString::formatted("/proc/{}/fd/{}", getpid(), fd));
EXPECT(!elf_path_or_error.is_error());
auto elf_path = elf_path_or_error.release_value().to_deprecated_string();
auto elf_path_string = TRY_OR_FAIL(FileSystem::read_link(DeprecatedString::formatted("/proc/{}/fd/{}", getpid(), fd)));
auto elf_path = elf_path_string.to_deprecated_string();
EXPECT(elf_path.characters());
int rc = execl(elf_path.characters(), "test-elf", nullptr);
@ -115,10 +113,8 @@ TEST_CASE(test_interp_header_p_filesz_larger_than_p_memsz)
int nwritten = write(fd, buffer, sizeof(buffer));
EXPECT(nwritten);
auto elf_path_or_error = FileSystem::read_link(DeprecatedString::formatted("/proc/{}/fd/{}", getpid(), fd));
EXPECT(!elf_path_or_error.is_error());
auto elf_path = elf_path_or_error.release_value().to_deprecated_string();
auto elf_path_string = TRY_OR_FAIL(FileSystem::read_link(DeprecatedString::formatted("/proc/{}/fd/{}", getpid(), fd)));
auto elf_path = elf_path_string.to_deprecated_string();
EXPECT(elf_path.characters());
int rc = execl(elf_path.characters(), "test-elf", nullptr);
@ -176,10 +172,8 @@ TEST_CASE(test_interp_header_p_filesz_plus_p_offset_overflow_p_memsz)
int nwritten = write(fd, buffer, sizeof(buffer));
EXPECT(nwritten);
auto elf_path_or_error = FileSystem::read_link(DeprecatedString::formatted("/proc/{}/fd/{}", getpid(), fd));
EXPECT(!elf_path_or_error.is_error());
auto elf_path = elf_path_or_error.release_value().to_deprecated_string();
auto elf_path_string = TRY_OR_FAIL(FileSystem::read_link(DeprecatedString::formatted("/proc/{}/fd/{}", getpid(), fd)));
auto elf_path = elf_path_string.to_deprecated_string();
EXPECT(elf_path.characters());
int rc = execl(elf_path.characters(), "test-elf", nullptr);
@ -234,10 +228,8 @@ TEST_CASE(test_load_header_p_memsz_zero)
int nwritten = write(fd, buffer, sizeof(buffer));
EXPECT(nwritten);
auto elf_path_or_error = FileSystem::read_link(DeprecatedString::formatted("/proc/{}/fd/{}", getpid(), fd));
EXPECT(!elf_path_or_error.is_error());
auto elf_path = elf_path_or_error.release_value().to_deprecated_string();
auto elf_path_string = TRY_OR_FAIL(FileSystem::read_link(DeprecatedString::formatted("/proc/{}/fd/{}", getpid(), fd)));
auto elf_path = elf_path_string.to_deprecated_string();
EXPECT(elf_path.characters());
int rc = execl(elf_path.characters(), "test-elf", nullptr);
@ -292,10 +284,8 @@ TEST_CASE(test_load_header_p_memsz_not_equal_to_p_align)
int nwritten = write(fd, buffer, sizeof(buffer));
EXPECT(nwritten);
auto elf_path_or_error = FileSystem::read_link(DeprecatedString::formatted("/proc/{}/fd/{}", getpid(), fd));
EXPECT(!elf_path_or_error.is_error());
auto elf_path = elf_path_or_error.release_value().to_deprecated_string();
auto elf_path_string = TRY_OR_FAIL(FileSystem::read_link(DeprecatedString::formatted("/proc/{}/fd/{}", getpid(), fd)));
auto elf_path = elf_path_string.to_deprecated_string();
EXPECT(elf_path.characters());
int rc = execl(elf_path.characters(), "test-elf", nullptr);