mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 05:17:34 +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:
parent
87a7299078
commit
f890b70eae
23 changed files with 415 additions and 742 deletions
|
@ -217,10 +217,7 @@ TEST_CASE(unlink_symlink)
|
|||
perror("symlink");
|
||||
}
|
||||
|
||||
auto target_or_error = FileSystem::read_link("/tmp/linky"sv);
|
||||
EXPECT(!target_or_error.is_error());
|
||||
|
||||
auto target = target_or_error.release_value();
|
||||
auto target = TRY_OR_FAIL(FileSystem::read_link("/tmp/linky"sv));
|
||||
EXPECT_EQ(target.bytes_as_string_view(), "/proc/2/foo"sv);
|
||||
|
||||
rc = unlink("/tmp/linky");
|
||||
|
|
|
@ -86,10 +86,8 @@ TEST_CASE(test_mkstemp_unique_filename)
|
|||
auto fd = mkstemp(path);
|
||||
EXPECT_NE(fd, -1);
|
||||
|
||||
auto temp_path_or_error = FileSystem::read_link(DeprecatedString::formatted("/proc/{}/fd/{}", getpid(), fd));
|
||||
EXPECT(!temp_path_or_error.is_error());
|
||||
|
||||
auto temp_path = temp_path_or_error.release_value().to_deprecated_string();
|
||||
auto temp_path_string = TRY_OR_FAIL(FileSystem::read_link(DeprecatedString::formatted("/proc/{}/fd/{}", getpid(), fd)));
|
||||
auto temp_path = temp_path_string.to_deprecated_string();
|
||||
EXPECT(temp_path.characters());
|
||||
|
||||
close(fd);
|
||||
|
@ -107,10 +105,8 @@ TEST_CASE(test_mkstemp_unique_filename)
|
|||
auto fd = mkstemp(path);
|
||||
EXPECT(fd != -1);
|
||||
|
||||
auto path2_or_error = FileSystem::read_link(DeprecatedString::formatted("/proc/{}/fd/{}", getpid(), fd));
|
||||
EXPECT(!path2_or_error.is_error());
|
||||
|
||||
auto path2 = path2_or_error.release_value().to_deprecated_string();
|
||||
auto path2_string = TRY_OR_FAIL(FileSystem::read_link(DeprecatedString::formatted("/proc/{}/fd/{}", getpid(), fd)));
|
||||
auto path2 = path2_string.to_deprecated_string();
|
||||
EXPECT(path2.characters());
|
||||
|
||||
close(fd);
|
||||
|
@ -132,10 +128,8 @@ TEST_CASE(test_mkstemps_unique_filename)
|
|||
auto fd = mkstemps(path, 6);
|
||||
EXPECT_NE(fd, -1);
|
||||
|
||||
auto temp_path_or_error = FileSystem::read_link(DeprecatedString::formatted("/proc/{}/fd/{}", getpid(), fd));
|
||||
EXPECT(!temp_path_or_error.is_error());
|
||||
|
||||
auto temp_path = temp_path_or_error.release_value().to_deprecated_string();
|
||||
auto temp_path_string = TRY_OR_FAIL(FileSystem::read_link(DeprecatedString::formatted("/proc/{}/fd/{}", getpid(), fd)));
|
||||
auto temp_path = temp_path_string.to_deprecated_string();
|
||||
EXPECT(temp_path.characters());
|
||||
|
||||
close(fd);
|
||||
|
@ -157,10 +151,8 @@ TEST_CASE(test_mkstemps_unique_filename)
|
|||
auto fd = mkstemps(path, 6);
|
||||
EXPECT(fd != -1);
|
||||
|
||||
auto path2_or_error = FileSystem::read_link(DeprecatedString::formatted("/proc/{}/fd/{}", getpid(), fd));
|
||||
EXPECT(!path2_or_error.is_error());
|
||||
|
||||
auto path2 = path2_or_error.release_value().to_deprecated_string();
|
||||
auto path2_string = TRY_OR_FAIL(FileSystem::read_link(DeprecatedString::formatted("/proc/{}/fd/{}", getpid(), fd)));
|
||||
auto path2 = path2_string.to_deprecated_string();
|
||||
EXPECT(path2.characters());
|
||||
|
||||
close(fd);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue