Importing correct header, improved compare printf
This commit is contained in:
+53
-30
@@ -13,9 +13,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "malunal/config.h"
|
||||
#include "malunal/types/bool.h"
|
||||
#include "malunal/types/integer.h"
|
||||
#include "malunal/types/string.h"
|
||||
#include "malunal/type.h"
|
||||
|
||||
#ifndef MALUNAL_MICROTEST_HEADER
|
||||
#define MALUNAL_MICROTEST_HEADER
|
||||
@@ -199,6 +197,31 @@ microtest_should_decompose_macro(
|
||||
#define MICROTEST_FAIL_INSIDE_TEST microtest_fail_inside_test()
|
||||
#define MICROTEST_ABORT_INSIDE_TEST microtest_abort_inside_test()
|
||||
|
||||
#define microtest_printf(...) \
|
||||
printf(__VA_ARGS__)
|
||||
|
||||
// TODO: Add float, double, and long double to type.h
|
||||
#define microtest_overload_printer(value) \
|
||||
microtest_printf(_Generic( \
|
||||
(value), \
|
||||
malunal_bool_t : "%d", \
|
||||
malunal_cstr_t : "%s", \
|
||||
malunal_uint8_t : "%hhu", \
|
||||
malunal_uint16_t : "%hu", \
|
||||
malunal_uint32_t : "%u", \
|
||||
malunal_uintptr_t : "%lu", \
|
||||
malunal_uint64_t : "%llu", \
|
||||
malunal_int8_t : "'%c'", \
|
||||
malunal_int16_t : "%hd", \
|
||||
malunal_int32_t : "%d", \
|
||||
malunal_intptr_t : "%ld", \
|
||||
malunal_int64_t : "%lld", \
|
||||
float : "%f", \
|
||||
double : "%f", \
|
||||
long double : "%Lf", \
|
||||
malunal_mptr_t : "%p" \
|
||||
), (value))
|
||||
|
||||
|
||||
// This is a little hack that allows a form of "polymorphism" to a macro - it allows a user to optionally pass
|
||||
// an extra argument to a macro in {EXPECT|ASSERT}.
|
||||
@@ -248,21 +271,21 @@ microtest_should_decompose_macro(
|
||||
#define MICROTEST_COMPARE(actual, expected, condition, macro, handler, ...) \
|
||||
do { \
|
||||
if(!((actual) condition (expected))) { \
|
||||
printf("%s:%u: ", __FILE__, __LINE__); \
|
||||
printf(__VA_ARGS__); \
|
||||
printf("\n"); \
|
||||
microtest_printf("%s:%u: ", __FILE__, __LINE__); \
|
||||
microtest_printf(__VA_ARGS__); \
|
||||
microtest_printf("\n"); \
|
||||
if(microtest_should_decompose_macro(#actual, #expected, 0)) { \
|
||||
printf(" In macro : "); \
|
||||
printf("%s( %s, %s )\n", #macro, #actual, #expected); \
|
||||
microtest_printf(" In macro : "); \
|
||||
microtest_printf("%s( %s, %s )\n", #macro, #actual, #expected); \
|
||||
} \
|
||||
printf(" Expected : %s", #actual); \
|
||||
printf(" %s ", #condition); \
|
||||
printf(#expected); \
|
||||
printf("\n"); \
|
||||
printf(" Actual : %s", #actual); \
|
||||
printf(" == "); \
|
||||
printf(#actual); \
|
||||
printf("\n"); \
|
||||
microtest_printf(" Expected : %s", #actual); \
|
||||
microtest_printf(" %s ", #condition); \
|
||||
microtest_overload_printf(expected); \
|
||||
microtest_printf("\n"); \
|
||||
microtest_printf(" Actual : %s", #actual); \
|
||||
microtest_printf(" == "); \
|
||||
microtest_overload_printf(#actual); \
|
||||
microtest_printf("\n"); \
|
||||
handler; \
|
||||
if (microtest_should_abort_test) \
|
||||
return; \
|
||||
@@ -287,25 +310,25 @@ microtest_should_decompose_macro(
|
||||
|
||||
#define MICROTEST_EXPECT_(cond, ...) MICROTEST_EXPECT_ASSERT(cond, MICROTEST_FAIL_INSIDE_TEST, MICROTEST_EXPECT, __VA_ARGS__)
|
||||
#define MICROTEST_EXPECT_EQ_(actual, expected, ...) MICROTEST_COMPARE(actual, expected, ==, MICROTEST_EXPECT_EQ, MICROTEST_FAIL_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_EXPECT_NE_(actual, expected, ...) MICROTEST_COMPARE(actual, expected, !=, MICROTEST_EXPECT_EQ, MICROTEST_FAIL_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_EXPECT_LT_(actual, expected, ...) MICROTEST_COMPARE(actual, expected, <, MICROTEST_EXPECT_EQ, MICROTEST_FAIL_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_EXPECT_LE_(actual, expected, ...) MICROTEST_COMPARE(actual, expected, <=, MICROTEST_EXPECT_EQ, MICROTEST_FAIL_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_EXPECT_GT_(actual, expected, ...) MICROTEST_COMPARE(actual, expected, >, MICROTEST_EXPECT_EQ, MICROTEST_FAIL_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_EXPECT_GE_(actual, expected, ...) MICROTEST_COMPARE(actual, expected, >=, MICROTEST_EXPECT_EQ, MICROTEST_FAIL_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_EXPECT_TRUE_(actual, ...) MICROTEST_COMPARE(actual, true, ==, MICROTEST_EXPECT_EQ, MICROTEST_FAIL_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_EXPECT_FALSE_(actual, ...) MICROTEST_COMPARE(actual, false, ==, MICROTEST_EXPECT_EQ, MICROTEST_FAIL_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_EXPECT_NE_(actual, expected, ...) MICROTEST_COMPARE(actual, expected, !=, MICROTEST_EXPECT_NE, MICROTEST_FAIL_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_EXPECT_LT_(actual, expected, ...) MICROTEST_COMPARE(actual, expected, <, MICROTEST_EXPECT_LT, MICROTEST_FAIL_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_EXPECT_LE_(actual, expected, ...) MICROTEST_COMPARE(actual, expected, <=, MICROTEST_EXPECT_LE, MICROTEST_FAIL_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_EXPECT_GT_(actual, expected, ...) MICROTEST_COMPARE(actual, expected, >, MICROTEST_EXPECT_GT, MICROTEST_FAIL_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_EXPECT_GE_(actual, expected, ...) MICROTEST_COMPARE(actual, expected, >=, MICROTEST_EXPECT_GE, MICROTEST_FAIL_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_EXPECT_TRUE_(actual, ...) MICROTEST_COMPARE(actual, true, ==, MICROTEST_EXPECT_TRUE, MICROTEST_FAIL_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_EXPECT_FALSE_(actual, ...) MICROTEST_COMPARE(actual, false, ==, MICROTEST_EXPECT_FALSE, MICROTEST_FAIL_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_EXPECT_NULL_(actual, ...) MICROTEST_EXPECT_(actual == null, __VA_ARGS__)
|
||||
#define MICROTEST_EXPECT_NOT_NULL_(actual, ...) MICROTEST_EXPECT_(actual != null, __VA_ARGS__)
|
||||
|
||||
#define MICROTEST_ASSERT_(cond, ...) MICROTEST_EXPECT_ASSERT(cond, MICROTEST_ABORT_INSIDE_TEST, MICROTEST_ASSERT, __VA_ARGS__)
|
||||
#define MICROTEST_ASSERT_EQ_(actual, expected, ...) MICROTEST_COMPARE(actual, expected, ==, MICROTEST_ASSERT_EQ, MICROTEST_ABORT_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_ASSERT_NE_(actual, expected, ...) MICROTEST_COMPARE(actual, expected, !=, MICROTEST_ASSERT_EQ, MICROTEST_ABORT_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_ASSERT_LT_(actual, expected, ...) MICROTEST_COMPARE(actual, expected, <, MICROTEST_ASSERT_EQ, MICROTEST_ABORT_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_ASSERT_LE_(actual, expected, ...) MICROTEST_COMPARE(actual, expected, <=, MICROTEST_ASSERT_EQ, MICROTEST_ABORT_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_ASSERT_GT_(actual, expected, ...) MICROTEST_COMPARE(actual, expected, >, MICROTEST_ASSERT_EQ, MICROTEST_ABORT_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_ASSERT_GE_(actual, expected, ...) MICROTEST_COMPARE(actual, expected, >=, MICROTEST_ASSERT_EQ, MICROTEST_ABORT_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_ASSERT_TRUE_(actual, ...) MICROTEST_COMPARE(actual, true, ==, MICROTEST_ASSERT_EQ, MICROTEST_ABORT_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_ASSERT_FALSE_(actual, ...) MICROTEST_COMPARE(actual, false, ==, MICROTEST_ASSERT_EQ, MICROTEST_ABORT_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_ASSERT_NE_(actual, expected, ...) MICROTEST_COMPARE(actual, expected, !=, MICROTEST_ASSERT_NE, MICROTEST_ABORT_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_ASSERT_LT_(actual, expected, ...) MICROTEST_COMPARE(actual, expected, <, MICROTEST_ASSERT_LT, MICROTEST_ABORT_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_ASSERT_LE_(actual, expected, ...) MICROTEST_COMPARE(actual, expected, <=, MICROTEST_ASSERT_LE, MICROTEST_ABORT_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_ASSERT_GT_(actual, expected, ...) MICROTEST_COMPARE(actual, expected, >, MICROTEST_ASSERT_GT, MICROTEST_ABORT_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_ASSERT_GE_(actual, expected, ...) MICROTEST_COMPARE(actual, expected, >=, MICROTEST_ASSERT_GE, MICROTEST_ABORT_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_ASSERT_TRUE_(actual, ...) MICROTEST_COMPARE(actual, true, ==, MICROTEST_ASSERT_TRUE, MICROTEST_ABORT_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_ASSERT_FALSE_(actual, ...) MICROTEST_COMPARE(actual, false, ==, MICROTEST_ASSERT_FALSE, MICROTEST_ABORT_INSIDE_TEST, __VA_ARGS__)
|
||||
#define MICROTEST_ASSERT_NULL_(actual, ...) MICROTEST_ASSERT_(actual == null, __VA_ARGS__)
|
||||
#define MICROTEST_ASSERT_NOT_NULL_(actual, ...) MICROTEST_ASSERT_(actual != null, __VA_ARGS__)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user