1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#pragma once
#include <stdio.h>
#include <AK/AKString.h>
#define LOG_FAIL(cond) \
fprintf(stderr, "\033[31;1mFAIL\033[0m: " #cond "\n")
#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)) { \
LOG_FAIL(cond); \
} else { \
LOG_PASS(cond); \
} \
} 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());
}
|