1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:27:35 +00:00

AK/Tests: Add a simple EXPECT_EQ macro and use it for the String test.

This commit is contained in:
Andreas Kling 2019-06-14 17:52:51 +02:00
parent 3557f277f6
commit a12751695e
3 changed files with 60 additions and 11 deletions

View file

@ -1,6 +1,7 @@
#pragma once
#include <stdio.h>
#include <AK/AKString.h>
#define LOG_FAIL(cond) \
fprintf(stderr, "\033[31;1mFAIL\033[0m: " #cond "\n")
@ -8,6 +9,24 @@
#define LOG_PASS(cond) \
fprintf(stderr, "\033[32;1mPASS\033[0m: " #cond "\n")
#define LOG_FAIL_EQ(cond, expected_value, actual_value) \
fprintf(stderr, "\033[31;1mFAIL\033[0m: " #cond " should be " #expected_value ", got "); \
stringify_for_test(actual_value); \
fprintf(stderr, "\n")
#define LOG_PASS_EQ(cond, expected_value) \
fprintf(stderr, "\033[32;1mPASS\033[0m: " #cond " should be " #expected_value " and it is\n")
#define EXPECT_EQ(expr, expected_value) \
do { \
auto result = (expr); \
if (!(result == expected_value)) { \
LOG_FAIL_EQ(expr, expected_value, result); \
} else { \
LOG_PASS_EQ(expr, expected_value); \
} \
} while(0)
#define EXPECT(cond) \
do { \
if (!(cond)) { \
@ -17,3 +36,33 @@
} \
} while(0)
inline void stringify_for_test(int value)
{
fprintf(stderr, "%d", value);
}
inline void stringify_for_test(unsigned value)
{
fprintf(stderr, "%u", value);
}
inline void stringify_for_test(const char* value)
{
fprintf(stderr, "%s", value);
}
inline void stringify_for_test(char value)
{
fprintf(stderr, "%c", value);
}
inline void stringify_for_test(const AK::String& string)
{
stringify_for_test(string.characters());
}
inline void stringify_for_test(const AK::StringImpl& string)
{
stringify_for_test(string.characters());
}