c-repl/test/include/test.h
2023-12-15 15:10:05 +01:00

42 lines
1.7 KiB
C++

#ifndef DEF_TEST_H
#define DEF_TEST_H
#include "../../src/include/colors.h"
#include "../../src/include/errors.h"
#define _TEST_PRESENTATION(description) { printf("\n" BLUE "#### %s:" BOLD "%s" RESET BLUE " #####" RESET "\n", __FILE__, description); }
#define _TEST_ASSERT(condition, description, show_ok) { \
if (condition) { \
if (show_ok) printf("[" GREEN "OK" RESET "] %s:%d: %s\n", __FILE__, __LINE__, description); \
} else { \
printf("[" RED "ERREUR" RESET "] %s:%d: %s\n", __FILE__, __LINE__, description); \
exit(1); \
} \
}
#define _TEST_NO_EXCEPTION(expr) \
[&]() -> bool { \
try { \
bool result = (expr); \
return result; \
} catch (...) { \
return false; \
} \
}()
#define _TEST_IS_EXCEPTION(expr, error) \
[&]() -> bool { \
try { \
(expr); \
return false; \
} catch (const UserError& e) { \
return e.type == error; \
} \
catch (...) { \
return false; \
} \
}()
#endif