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
Notes: sideshowbarker 2024-07-19 01:43:46 +09:00
9 changed files with 42 additions and 53 deletions

View file

@ -135,13 +135,13 @@ void actual_extremes_8byte();
template<>
void actual_extremes_8byte<4>()
{
warn() << "(Skipping 8-byte-size_t test)";
warnln("(Skipping 8-byte-size_t test)");
}
template<>
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.
// This is because your editor thinks the world is 32-bit, but it isn't.
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)
{
if (getuid() == 0) {
warn() << "Refusing to run as root";
warnln("Refusing to run as root");
return 1;
}

View file

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

View file

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

View file

@ -80,7 +80,7 @@ int main(int argc, char** argv)
InputStream& gzip_input_stream = gzip_stream;
Tar::TarStream tar_stream((gzip) ? gzip_input_stream : file_input_stream);
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;
}
for (; !tar_stream.finished(); tar_stream.advance()) {

View file

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

View file

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

View file

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