1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:47:44 +00:00

AK: Eradicate calls to warn().

This commit is contained in:
asynts 2020-10-25 17:46:16 +01:00 committed by Andreas Kling
parent a5f5c3fd33
commit 1254cbbd0b
9 changed files with 42 additions and 53 deletions

View file

@ -135,13 +135,13 @@ void actual_extremes_8byte();
template<> template<>
void actual_extremes_8byte<4>() void actual_extremes_8byte<4>()
{ {
warn() << "(Skipping 8-byte-size_t test)"; warnln("(Skipping 8-byte-size_t test)");
} }
template<> template<>
void actual_extremes_8byte<8>() void actual_extremes_8byte<8>()
{ {
warn() << "(Running true 8-byte-size_t test)"; warnln("(Running true 8-byte-size_t test)");
// Your editor might show "implicit conversion" warnings here. // Your editor might show "implicit conversion" warnings here.
// This is because your editor thinks the world is 32-bit, but it isn't. // This is because your editor thinks the world is 32-bit, but it isn't.
EXPECT_EQ(human_readable_size(0x100000000ULL), "4.0 GiB"); EXPECT_EQ(human_readable_size(0x100000000ULL), "4.0 GiB");

View file

@ -63,7 +63,7 @@ static String bookmarks_file_path()
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
if (getuid() == 0) { if (getuid() == 0) {
warn() << "Refusing to run as root"; warnln("Refusing to run as root");
return 1; return 1;
} }

View file

@ -46,7 +46,7 @@ static String show(const ByteBuffer& buf)
{ {
StringBuilder builder; StringBuilder builder;
for (size_t i = 0; i < buf.size(); ++i) { for (size_t i = 0; i < buf.size(); ++i) {
builder.appendf("%02x", buf[i]); builder.appendff("{:02x}", buf[i]);
} }
builder.append(' '); builder.append(' ');
builder.append('('); builder.append('(');
@ -66,8 +66,7 @@ static bool test_single(const Testcase& testcase)
{ {
// Preconditions: // Preconditions:
if (testcase.dest_n != testcase.dest_expected_n) { if (testcase.dest_n != testcase.dest_expected_n) {
fprintf(stderr, "dest length %zu != expected dest length %zu? Check testcase! (Probably miscounted.)\n", warnln("dest length {} != expected dest length {}? Check testcase! (Probably miscounted.)", testcase.dest_n, testcase.dest_expected_n);
testcase.dest_n, testcase.dest_expected_n);
return false; return false;
} }
@ -93,33 +92,29 @@ static bool test_single(const Testcase& testcase)
// Evaluate gravity: // Evaluate gravity:
if (buf_ok && (!canary_1_ok || !main_ok || !canary_2_ok)) { if (buf_ok && (!canary_1_ok || !main_ok || !canary_2_ok)) {
fprintf(stderr, "Internal error! (%d != %d | %d | %d)\n", warnln("Internal error! ({} != {} | {} | {})", buf_ok, canary_1_ok, main_ok, canary_2_ok);
buf_ok, canary_1_ok, main_ok, canary_2_ok);
buf_ok = false; buf_ok = false;
} }
if (!canary_1_ok) { if (!canary_1_ok) {
warn() << "Canary 1 overwritten: Expected canary " warnln("Canary 1 overwritten: Expected {}\n"
<< show(expected.slice_view(0, SANDBOX_CANARY_SIZE)) " instead got {}",
<< ", got " show(expected.slice_view(0, SANDBOX_CANARY_SIZE)),
<< show(actual.slice_view(0, SANDBOX_CANARY_SIZE)) show(actual.slice_view(0, SANDBOX_CANARY_SIZE)));
<< " instead!";
} }
if (!main_ok) { if (!main_ok) {
warn() << "Wrong output: Expected " warnln("Wrong output: Expected {}\n"
<< show(expected.slice_view(SANDBOX_CANARY_SIZE, testcase.dest_n)) " instead, got {}",
<< "\n instead, got " // visually align show(expected.slice_view(SANDBOX_CANARY_SIZE, testcase.dest_n)),
<< show(actual.slice_view(SANDBOX_CANARY_SIZE, testcase.dest_n)); show(actual.slice_view(SANDBOX_CANARY_SIZE, testcase.dest_n)));
} }
if (!canary_2_ok) { if (!canary_2_ok) {
warn() << "Canary 2 overwritten: Expected " warnln("Canary 2 overwritten: Expected {}\n"
<< show(expected.slice_view(SANDBOX_CANARY_SIZE + testcase.dest_n, SANDBOX_CANARY_SIZE)) " instead, got {}",
<< ", got " show(expected.slice_view(SANDBOX_CANARY_SIZE + testcase.dest_n, SANDBOX_CANARY_SIZE)),
<< show(actual.slice_view(SANDBOX_CANARY_SIZE + testcase.dest_n, SANDBOX_CANARY_SIZE)) show(actual.slice_view(SANDBOX_CANARY_SIZE + testcase.dest_n, SANDBOX_CANARY_SIZE)));
<< " instead!";
} }
if (!return_ok) { if (!return_ok) {
fprintf(stderr, "Wrong return value: Expected %d, got %d instead!\n", warnln("Wrong return value: Expected {}, got {} instead!", testcase.expected_return, actual_return);
testcase.expected_return, actual_return);
} }
return buf_ok && return_ok; return buf_ok && return_ok;

View file

@ -46,7 +46,7 @@ static String show(const ByteBuffer& buf)
{ {
StringBuilder builder; StringBuilder builder;
for (size_t i = 0; i < buf.size(); ++i) { for (size_t i = 0; i < buf.size(); ++i) {
builder.appendf("%02x", buf[i]); builder.appendff("{:02x}", buf[i]);
} }
builder.append(' '); builder.append(' ');
builder.append('('); builder.append('(');
@ -66,13 +66,11 @@ static bool test_single(const Testcase& testcase)
{ {
// Preconditions: // Preconditions:
if (testcase.dest_n != testcase.dest_expected_n) { if (testcase.dest_n != testcase.dest_expected_n) {
fprintf(stderr, "dest length %zu != expected dest length %zu? Check testcase! (Probably miscounted.)\n", warnln("dest length {} != expected dest length {}? Check testcase! (Probably miscounted.)", testcase.dest_n, testcase.dest_expected_n);
testcase.dest_n, testcase.dest_expected_n);
return false; return false;
} }
if (testcase.src_n != strlen(testcase.src)) { if (testcase.src_n != strlen(testcase.src)) {
fprintf(stderr, "src length %zu != actual src length %zu? src can't contain NUL bytes!\n", warnln("src length {} != actual src length {}? src can't contain NUL bytes!", testcase.src_n, strlen(testcase.src));
testcase.src_n, strlen(testcase.src));
return false; return false;
} }
@ -98,33 +96,29 @@ static bool test_single(const Testcase& testcase)
// Evaluate gravity: // Evaluate gravity:
if (buf_ok && (!canary_1_ok || !main_ok || !canary_2_ok)) { if (buf_ok && (!canary_1_ok || !main_ok || !canary_2_ok)) {
fprintf(stderr, "Internal error! (%d != %d | %d | %d)\n", warnln("Internal error! ({} != {} | {} | {})", buf_ok, canary_1_ok, main_ok, canary_2_ok);
buf_ok, canary_1_ok, main_ok, canary_2_ok);
buf_ok = false; buf_ok = false;
} }
if (!canary_1_ok) { if (!canary_1_ok) {
warn() << "Canary 1 overwritten: Expected canary " warnln("Canary 1 overwritten: Expected canary {}\n"
<< show(expected.slice_view(0, SANDBOX_CANARY_SIZE)) " instead got {}",
<< ", got " show(expected.slice_view(0, SANDBOX_CANARY_SIZE)),
<< show(actual.slice_view(0, SANDBOX_CANARY_SIZE)) show(actual.slice_view(0, SANDBOX_CANARY_SIZE)));
<< " instead!";
} }
if (!main_ok) { if (!main_ok) {
warn() << "Wrong output: Expected " warnln("Wrong output: Expected {}\n"
<< show(expected.slice_view(SANDBOX_CANARY_SIZE, testcase.dest_n)) " instead got {}",
<< "\n instead, got " // visually align show(expected.slice_view(SANDBOX_CANARY_SIZE, testcase.dest_n)),
<< show(actual.slice_view(SANDBOX_CANARY_SIZE, testcase.dest_n)); show(actual.slice_view(SANDBOX_CANARY_SIZE, testcase.dest_n)));
} }
if (!canary_2_ok) { if (!canary_2_ok) {
warn() << "Canary 2 overwritten: Expected " warnln("Canary 2 overwritten: Expected {}\n"
<< show(expected.slice_view(SANDBOX_CANARY_SIZE + testcase.dest_n, SANDBOX_CANARY_SIZE)) " instead got {}",
<< ", got " show(expected.slice_view(SANDBOX_CANARY_SIZE + testcase.dest_n, SANDBOX_CANARY_SIZE)),
<< show(actual.slice_view(SANDBOX_CANARY_SIZE + testcase.dest_n, SANDBOX_CANARY_SIZE)) show(actual.slice_view(SANDBOX_CANARY_SIZE + testcase.dest_n, SANDBOX_CANARY_SIZE)));
<< " instead!";
} }
if (!return_ok) { if (!return_ok) {
fprintf(stderr, "Wrong return value: Expected %zu, got %zu instead!\n", warnln("Wrong return value: Expected {}, got {} instead!", testcase.src_n, actual_return);
testcase.src_n, actual_return);
} }
return buf_ok && return_ok; return buf_ok && return_ok;

View file

@ -58,7 +58,7 @@ int main(int argc, char** argv)
String filepath = Core::find_executable_in_path(filename); String filepath = Core::find_executable_in_path(filename);
if (filepath.is_null()) { if (filepath.is_null()) {
warn() << "no " << filename << " in path"; warnln("no {} in path", filename);
return 1; return 1;
} }

View file

@ -80,7 +80,7 @@ int main(int argc, char** argv)
InputStream& gzip_input_stream = gzip_stream; InputStream& gzip_input_stream = gzip_stream;
Tar::TarStream tar_stream((gzip) ? gzip_input_stream : file_input_stream); Tar::TarStream tar_stream((gzip) ? gzip_input_stream : file_input_stream);
if (!tar_stream.valid()) { if (!tar_stream.valid()) {
warn() << "the provided file is not a well-formatted ustar file"; warnln("the provided file is not a well-formatted ustar file");
return 1; return 1;
} }
for (; !tar_stream.finished(); tar_stream.advance()) { for (; !tar_stream.finished(); tar_stream.advance()) {

View file

@ -298,7 +298,7 @@ static void test_rmdir_root()
{ {
int rc = rmdir("/"); int rc = rmdir("/");
if (rc != -1 || errno != EBUSY) { if (rc != -1 || errno != EBUSY) {
warn() << "rmdir(/) didn't fail with EBUSY"; warnln("rmdir(/) didn't fail with EBUSY");
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
} }
} }

View file

@ -60,7 +60,7 @@ int main(int argc, char** argv)
args_parser.parse(argc, argv); args_parser.parse(argc, argv);
if (flag_create && flag_delete) { if (flag_create && flag_delete) {
warn() << "-c and -d are mutually exclusive"; warnln("-c and -d are mutually exclusive");
return 1; return 1;
} }

View file

@ -65,13 +65,13 @@ int main()
auto file_or_error = Core::File::open("/var/run/utmp", Core::IODevice::ReadOnly); auto file_or_error = Core::File::open("/var/run/utmp", Core::IODevice::ReadOnly);
if (file_or_error.is_error()) { if (file_or_error.is_error()) {
warn() << "Error: " << file_or_error.error(); warnln("Error: {}", file_or_error.error());
return 1; return 1;
} }
auto& file = *file_or_error.value(); auto& file = *file_or_error.value();
auto json = JsonValue::from_string(file.read_all()); auto json = JsonValue::from_string(file.read_all());
if (!json.has_value() || !json.value().is_object()) { if (!json.has_value() || !json.value().is_object()) {
warn() << "Error: Could not parse /var/run/utmp"; warnln("Error: Could not parse /var/run/utmp");
return 1; return 1;
} }