style: add clang-format
This commit is contained in:
parent
3a74610390
commit
18fdefe286
|
@ -0,0 +1,68 @@
|
||||||
|
# alignment
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignArrayOfStructures: Left
|
||||||
|
AlignConsecutiveAssignments: None
|
||||||
|
AlignConsecutiveBitFields: Consecutive
|
||||||
|
AlignConsecutiveDeclarations: None
|
||||||
|
AlignConsecutiveMacros: Consecutive
|
||||||
|
AlignEscapedNewlines: Right
|
||||||
|
AlignOperands: Align
|
||||||
|
AlignTrailingComments: true
|
||||||
|
# wrapping and line breaks
|
||||||
|
AllowAllArgumentsOnNextLine: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
|
AlwaysBreakAfterReturnType: AllDefinitions
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
BinPackArguments: true
|
||||||
|
BinPackParameters: false
|
||||||
|
BreakBeforeBinaryOperators: NonAssignment
|
||||||
|
BreakBeforeBraces: WebKit
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakStringLiterals: true
|
||||||
|
ColumnLimit: 100
|
||||||
|
IndentWrappedFunctionNames: false
|
||||||
|
ReflowComments: true
|
||||||
|
# braces and blocks
|
||||||
|
AllowShortBlocksOnASingleLine: Empty
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortEnumsOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: Empty
|
||||||
|
AllowShortIfStatementsOnASingleLine: Never
|
||||||
|
InsertBraces: true
|
||||||
|
# spacing
|
||||||
|
BitFieldColonSpacing: Both
|
||||||
|
Cpp11BracedListStyle: false
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
IncludeBlocks: Merge
|
||||||
|
#InsertTrailingCommas: Wrapped
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
PointerAlignment: Right
|
||||||
|
QualifierAlignment: Left
|
||||||
|
SeparateDefinitionBlocks: Always
|
||||||
|
SortIncludes: CaseSensitive
|
||||||
|
SpaceAfterCStyleCast: true
|
||||||
|
SpaceAfterLogicalNot: true
|
||||||
|
SpaceAroundPointerQualifiers: Default
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeCaseColon: false
|
||||||
|
SpaceBeforeParens: Always
|
||||||
|
SpaceBeforeSquareBrackets: false
|
||||||
|
SpaceInEmptyBlock: true
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpacesInConditionalStatement: false
|
||||||
|
SpacesInLineCommentPrefix: { Minimum: 1, Maximum: 1 }
|
||||||
|
SpacesInParentheses: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
# indentation
|
||||||
|
ContinuationIndentWidth: 2
|
||||||
|
IndentCaseBlocks: false
|
||||||
|
IndentCaseLabels: true
|
||||||
|
IndentGotoLabels: false
|
||||||
|
IndentPPDirectives: AfterHash
|
||||||
|
IndentWidth: 2
|
||||||
|
PPIndentWidth: 2
|
||||||
|
TabWidth: 2
|
||||||
|
UseTab: Never
|
52
inc/common.h
52
inc/common.h
|
@ -1,60 +1,56 @@
|
||||||
#ifndef COMMON_H_
|
#ifndef COMMON_H_
|
||||||
#define COMMON_H_
|
#define COMMON_H_
|
||||||
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
/** macros ****************************************************************************************/
|
||||||
/** macros ********************************************************************/
|
|
||||||
|
|
||||||
/// define debug macros
|
/// define debug macros
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
# define DEBUG_ALLOC
|
# define DEBUG_ALLOC
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// c11 / c23 compatibility. many of these can be removed once the project fully
|
/// c11 / c23 compatibility. many of these can be removed once the project fully migrates to c23,
|
||||||
/// migrates to c23, but for now, some of these will have to be used. when
|
/// but for now, some of these will have to be used. when migrating, remember that the usage of
|
||||||
/// migrating, remember that the usage of macros like `_Noreturn` should be
|
/// macros like `_Noreturn` should be replaced by c23-specific syntax, in this case the
|
||||||
/// replaced by c23-specific syntax, in this case the `[[noreturn]]` attribute.
|
/// `[[noreturn]]` attribute.
|
||||||
|
|
||||||
// if the program is compiled with c23 or newer, define `STDC23` as a feature
|
// if the program is compiled with c23 or newer, define `STDC23` as a feature test macro that is
|
||||||
// test macro that is used for enabling features based on if c23 or c11 is used.
|
// used for enabling features based on if c23 or c11 is used.
|
||||||
|
|
||||||
#if __STDC_VERSION__ >= 202000L
|
#if __STDC_VERSION__ >= 202000L
|
||||||
# define STDC23
|
# define STDC23
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// enable C11-specific features
|
// enable C11-specific features
|
||||||
|
|
||||||
#if !defined(STDC23)
|
#if ! defined(STDC23)
|
||||||
# define nullptr NULL /* `nullptr` from C23 */
|
# define nullptr NULL /* `nullptr` from C23 */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// enable C23-specific features
|
// enable C23-specific features
|
||||||
|
|
||||||
#if defined(STDC23)
|
#if defined(STDC23)
|
||||||
# define _Noreturn [[noreturn]]
|
# define _Noreturn [[noreturn]]
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/// function wrappers
|
/// function wrappers
|
||||||
|
|
||||||
#ifdef DEBUG_ALLOC
|
#ifdef DEBUG_ALLOC
|
||||||
# define smalloc(nmemb, size) __smalloc (nmemb, size, __FILE__, __LINE__)
|
# define smalloc(nmemb, size) __smalloc (nmemb, size, __FILE__, __LINE__)
|
||||||
# define scalloc(nmemb, size) __scalloc (nmemb, size, __FILE__, __LINE__)
|
# define scalloc(nmemb, size) __scalloc (nmemb, size, __FILE__, __LINE__)
|
||||||
# define srealloc(ptr, nmemb, size) __srealloc (ptr, nmemb, size, __FILE__, __LINE__)
|
# define srealloc(ptr, nmemb, size) __srealloc (ptr, nmemb, size, __FILE__, __LINE__)
|
||||||
#else
|
#else
|
||||||
# define smalloc(nmemb, size) __smalloc (nmemb, size)
|
# define smalloc(nmemb, size) __smalloc (nmemb, size)
|
||||||
# define scalloc(nmemb, size) __scalloc (nmemb, size)
|
# define scalloc(nmemb, size) __scalloc (nmemb, size)
|
||||||
# define srealloc(ptr, nmemb, size) __srealloc (ptr, nmemb, size)
|
# define srealloc(ptr, nmemb, size) __srealloc (ptr, nmemb, size)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/** typedefs **************************************************************************************/
|
||||||
/** typedefs ******************************************************************/
|
|
||||||
|
|
||||||
/// common type abbreviations
|
/// common type abbreviations
|
||||||
|
|
||||||
|
@ -88,15 +84,14 @@ typedef float f32;
|
||||||
typedef double f64;
|
typedef double f64;
|
||||||
typedef long double f128;
|
typedef long double f128;
|
||||||
|
|
||||||
|
/** functions *************************************************************************************/
|
||||||
/** functions *****************************************************************/
|
|
||||||
|
|
||||||
/// safe memory allocation
|
/// safe memory allocation
|
||||||
|
|
||||||
#ifdef DEBUG_ALLOC
|
#ifdef DEBUG_ALLOC
|
||||||
void *__smalloc (const usize nmemb, const usize size, const char *const file, const usize line);
|
void *__smalloc (const usize nmemb, const usize size, char *file, usize line);
|
||||||
void *__scalloc (const usize nmemb, const usize size, const char *const file, const usize line);
|
void *__scalloc (const usize nmemb, const usize size, char *file, usize line);
|
||||||
void *__srealloc (void *ptr, const usize nmemb, const usize size, const char *const file, const usize line);
|
void *__srealloc (void *ptr, const usize nmemb, const usize size, char *file, usize line);
|
||||||
void sfree (void *ptr);
|
void sfree (void *ptr);
|
||||||
#else
|
#else
|
||||||
void *__smalloc (const usize nmemb, const usize size);
|
void *__smalloc (const usize nmemb, const usize size);
|
||||||
|
@ -105,5 +100,4 @@ void *__srealloc (void *ptr, const usize nmemb, const usize size);
|
||||||
void sfree (void *ptr);
|
void sfree (void *ptr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif // COMMON_H_
|
#endif // COMMON_H_
|
||||||
|
|
38
inc/log.h
38
inc/log.h
|
@ -1,39 +1,35 @@
|
||||||
#ifndef LOG_H_
|
#ifndef LOG_H_
|
||||||
#define LOG_H_
|
#define LOG_H_
|
||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/** macros ****************************************************************************************/
|
||||||
/** macros ********************************************************************/
|
|
||||||
|
|
||||||
#define log_debug(...) __log_print (__Log_Level_Debug, __VA_ARGS__)
|
#define log_debug(...) __log_print (__Log_Level_Debug, __VA_ARGS__)
|
||||||
#define log_info(...) __log_print (__Log_Level_Info, __VA_ARGS__)
|
#define log_info(...) __log_print (__Log_Level_Info, __VA_ARGS__)
|
||||||
#define log_ok(...) __log_print (__Log_Level_Ok, __VA_ARGS__)
|
#define log_ok(...) __log_print (__Log_Level_Ok, __VA_ARGS__)
|
||||||
#define log_warn(...) __log_print (__Log_Level_Warn, __VA_ARGS__)
|
#define log_warn(...) __log_print (__Log_Level_Warn, __VA_ARGS__)
|
||||||
#define log_err(...) __log_print (__Log_Level_Err, __VA_ARGS__)
|
#define log_err(...) __log_print (__Log_Level_Err, __VA_ARGS__)
|
||||||
|
|
||||||
#define log_die(...) \
|
#define log_die(...) \
|
||||||
do { \
|
do { \
|
||||||
__log_print(__Log_Level_Err, __VA_ARGS__); \
|
__log_print (__Log_Level_Err, __VA_ARGS__); \
|
||||||
exit(EXIT_FAILURE); \
|
exit (EXIT_FAILURE); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
/** enums *****************************************************************************************/
|
||||||
/** enums *********************************************************************/
|
|
||||||
|
|
||||||
enum __Log_Level {
|
enum __Log_Level {
|
||||||
__Log_Level_Debug,
|
__Log_Level_Debug,
|
||||||
__Log_Level_Info,
|
__Log_Level_Info,
|
||||||
__Log_Level_Ok,
|
__Log_Level_Ok,
|
||||||
__Log_Level_Warn,
|
__Log_Level_Warn,
|
||||||
__Log_Level_Err,
|
__Log_Level_Err,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** functions *****************************************************************/
|
/** functions *****************************************************************/
|
||||||
|
|
||||||
void __log_print (enum __Log_Level level, const char *const fmt, ...) __attribute__ ((format (printf, 2, 3)));
|
void __log_print (enum __Log_Level level, const char *const fmt, ...)
|
||||||
|
__attribute__ ((format (printf, 2, 3)));
|
||||||
|
|
||||||
#endif // LOG_H_
|
#endif // LOG_H_
|
||||||
|
|
57
src/common.c
57
src/common.c
|
@ -1,24 +1,24 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "log.h"
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "log.h"
|
|
||||||
|
|
||||||
|
/** functions *************************************************************************************/
|
||||||
/** functions *****************************************************************/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* safe `malloc()` wrapper. instead of returning `nullptr` on error, this
|
* safe `malloc()` wrapper. instead of returning `nullptr` on error, this function will crash the
|
||||||
* function will crash the program. returns a pointer to the allocated memory.
|
* program. returns a pointer to the allocated memory.
|
||||||
*/
|
*/
|
||||||
void *
|
void *
|
||||||
__smalloc (const usize nmemb, /* number of elements to allocate */
|
__smalloc (const usize nmemb, /* number of elements to allocate */
|
||||||
const usize size /* size of each element */
|
const usize size /* size of each element */
|
||||||
#ifdef DEBUG_ALLOC
|
#ifdef DEBUG_ALLOC
|
||||||
,
|
,
|
||||||
const char *const file, /* __FILE__ */
|
char *file, /* __FILE__ */
|
||||||
const usize line /* __LINE__ */
|
usize line /* __LINE__ */
|
||||||
#endif
|
#endif
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
void *ptr;
|
void *ptr;
|
||||||
|
|
||||||
ptr = malloc (nmemb * size);
|
ptr = malloc (nmemb * size);
|
||||||
|
@ -36,18 +36,19 @@ __smalloc (const usize nmemb, /* number of elements to allocate */
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* safe `calloc()` wrapper. instead of returning `nullptr` on error, this
|
* safe `calloc()` wrapper. instead of returning `nullptr` on error, this function will crash the
|
||||||
* function will crash the program. returns a pointer to the allocated memory.
|
* program. returns a pointer to the allocated memory.
|
||||||
*/
|
*/
|
||||||
void *
|
void *
|
||||||
__scalloc (const usize nmemb, /* number of elements to allocate */
|
__scalloc (const usize nmemb, /* number of elements to allocate */
|
||||||
const usize size /* size of each element */
|
const usize size /* size of each element */
|
||||||
#ifdef DEBUG_ALLOC
|
#ifdef DEBUG_ALLOC
|
||||||
,
|
,
|
||||||
const char *const file, /* __FILE__ */
|
char *file, /* __FILE__ */
|
||||||
const usize line /* __LINE__ */
|
usize line /* __LINE__ */
|
||||||
#endif
|
#endif
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
void *ptr;
|
void *ptr;
|
||||||
|
|
||||||
ptr = calloc (nmemb, size);
|
ptr = calloc (nmemb, size);
|
||||||
|
@ -65,19 +66,20 @@ __scalloc (const usize nmemb, /* number of elements to allocate */
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* safe `realloc()` wrapper. instead of returning `nullptr` on error, this
|
* safe `realloc()` wrapper. instead of returning `nullptr` on error, this function will crash the
|
||||||
* function will crash the program. returns a pointer to the reallocated memory.
|
* program. returns a pointer to the reallocated memory.
|
||||||
*/
|
*/
|
||||||
void *
|
void *
|
||||||
__srealloc (void *ptr, /* the pointer to reallocate */
|
__srealloc (void *ptr, /* the pointer to reallocate */
|
||||||
const usize nmemb, /* number of elements to allocate */
|
const usize nmemb, /* number of elements to allocate */
|
||||||
const usize size /* size of each element */
|
const usize size /* size of each element */
|
||||||
#ifdef DEBUG_ALLOC
|
#ifdef DEBUG_ALLOC
|
||||||
,
|
,
|
||||||
const char *const file, /* __FILE__ */
|
char *file, /* __FILE__ */
|
||||||
const usize line /* __LINE__ */
|
usize line /* __LINE__ */
|
||||||
#endif
|
#endif
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
ptr = realloc (ptr, nmemb * size);
|
ptr = realloc (ptr, nmemb * size);
|
||||||
if (ptr == nullptr) {
|
if (ptr == nullptr) {
|
||||||
#ifdef DEBUG_ALLOC
|
#ifdef DEBUG_ALLOC
|
||||||
|
@ -93,9 +95,8 @@ __srealloc (void *ptr, /* the pointer to reallocate */
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wrapper for `free()`. will not call `free()` on pointers that are `nullptr`.
|
* wrapper for `free()`. will not call `free()` on pointers that are `nullptr`. this is technically
|
||||||
* this is technically not necessary according to the c standard, but you never
|
* not necessary according to the c standard, but you never know.
|
||||||
* know.
|
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
sfree (void *ptr) /* the pointer to free */
|
sfree (void *ptr) /* the pointer to free */
|
||||||
|
|
23
src/log.c
23
src/log.c
|
@ -3,29 +3,28 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/** functions *************************************************************************************/
|
||||||
/** functions *****************************************************************/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* print a formatted message to stderr using printf formatting and a given log
|
* print a formatted message to stderr using printf formatting and a given log level. this functions
|
||||||
* level. this functions is not intended to be used directly. the `log_*` macros
|
* is not intended to be used directly. the `log_*` macros should be used instead.
|
||||||
* should be used instead.
|
|
||||||
*/
|
*/
|
||||||
__attribute__ ((format (printf, 2, 3)))
|
__attribute__ ((format (printf, 2, 3))) void
|
||||||
void
|
|
||||||
__log_print (enum __Log_Level level, /* log level */
|
__log_print (enum __Log_Level level, /* log level */
|
||||||
const char *const fmt, /* format string */
|
const char *const fmt, /* format string */
|
||||||
...) /* format parameters */
|
...) /* format parameters */
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case __Log_Level_Debug: { fprintf (stderr, "\x1b[90m[\x1b[35mdebug\x1b[90m]\x1b[0m "); break; }
|
case __Log_Level_Debug: { fprintf (stderr, "\x1b[90m[\x1b[35mdebug\x1b[90m]\x1b[0m "); } break;
|
||||||
case __Log_Level_Info: { fprintf (stderr, "\x1b[90m[\x1b[34minfo\x1b[90m]\x1b[0m " ); break; }
|
case __Log_Level_Info: { fprintf (stderr, "\x1b[90m[\x1b[34minfo\x1b[90m]\x1b[0m "); } break;
|
||||||
case __Log_Level_Ok: { fprintf (stderr, "\x1b[90m[\x1b[32mok\x1b[90m]\x1b[0m " ); break; }
|
case __Log_Level_Ok: { fprintf (stderr, "\x1b[90m[\x1b[32mok\x1b[90m]\x1b[0m "); } break;
|
||||||
case __Log_Level_Warn: { fprintf (stderr, "\x1b[90m[\x1b[33mwarn\x1b[90m]\x1b[0m " ); break; }
|
case __Log_Level_Warn: { fprintf (stderr, "\x1b[90m[\x1b[33mwarn\x1b[90m]\x1b[0m "); } break;
|
||||||
case __Log_Level_Err: { fprintf (stderr, "\x1b[90m[\x1b[31merr\x1b[90m]\x1b[0m " ); break; }
|
case __Log_Level_Err: { fprintf (stderr, "\x1b[90m[\x1b[31merr\x1b[90m]\x1b[0m "); } break;
|
||||||
}
|
}
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
va_start (ap, fmt);
|
va_start (ap, fmt);
|
||||||
vfprintf (stderr, fmt, ap);
|
vfprintf (stderr, fmt, ap);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include <stdlib.h>
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
main (const int argc, const char *const argv[])
|
main (const int argc, const char *const argv[])
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
/** declarations **************************************************************/
|
/** declarations **************************************************************/
|
||||||
|
|
||||||
static Test_Result test_add (void);
|
static Test_Result test_add (void);
|
||||||
static u64 add(u64 a, u64 b);
|
static u64 add (u64 a, u64 b);
|
||||||
|
|
||||||
|
|
||||||
/** functions *****************************************************************/
|
/** functions *****************************************************************/
|
||||||
|
|
||||||
|
@ -25,7 +23,6 @@ main (const int argc, const char *const argv[])
|
||||||
t_exit ();
|
t_exit ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** static functions **********************************************************/
|
/** static functions **********************************************************/
|
||||||
|
|
||||||
static Test_Result
|
static Test_Result
|
||||||
|
|
73
test/test.h
73
test/test.h
|
@ -1,62 +1,57 @@
|
||||||
#ifndef TEST_H_
|
#ifndef TEST_H_
|
||||||
#define TEST_H_
|
#define TEST_H_
|
||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/** structs ***************************************************************************************/
|
||||||
/** structs *******************************************************************/
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
usize success;
|
usize success;
|
||||||
usize failure;
|
usize failure;
|
||||||
} Test_Result;
|
} Test_Result;
|
||||||
|
|
||||||
|
/** macros ****************************************************************************************/
|
||||||
|
|
||||||
/** macros ********************************************************************/
|
#define t_start() Test_Result __test_result = { .success = 0u, .failure = 0u }
|
||||||
|
|
||||||
#define t_start() \
|
#define t_assert(check, msg) \
|
||||||
Test_Result __test_result = { .success = 0u, .failure = 0u }
|
do { \
|
||||||
|
if (check) { \
|
||||||
#define t_assert(check, msg) \
|
__test_result.success += 1; \
|
||||||
do { \
|
} else { \
|
||||||
if (check) { \
|
log_err ("\x1b[90m(\x1b[35m" __FILE__ "\x1b[90m:\x1b[34m%d\x1b[90m)" \
|
||||||
__test_result.success += 1; \
|
"\x1b[0m assertion '" msg "' (" #check ") failed\n", \
|
||||||
} else { \
|
__LINE__); \
|
||||||
log_err ("\x1b[90m(\x1b[35m" __FILE__ "\x1b[90m:\x1b[34m%d\x1b[90m)" \
|
__test_result.failure += 1; \
|
||||||
"\x1b[0m assertion '" msg "' (" #check ") failed\n", __LINE__); \
|
} \
|
||||||
__test_result.failure += 1; \
|
|
||||||
} \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define t_end() \
|
#define t_end() return __test_result
|
||||||
return __test_result
|
|
||||||
|
|
||||||
#define t_run(func) \
|
#define t_run(func) \
|
||||||
do { \
|
do { \
|
||||||
Test_Result res = func (); \
|
Test_Result res = func (); \
|
||||||
__test_results.success += res.success; \
|
__test_results.success += res.success; \
|
||||||
__test_results.failure += res.failure; \
|
__test_results.failure += res.failure; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define t_start_tests() \
|
#define t_start_tests() Test_Result __test_results = { .success = 0u, .failure = 0u }
|
||||||
Test_Result __test_results = { .success = 0u, .failure = 0u }
|
|
||||||
|
|
||||||
#define t_end_tests() \
|
#define t_end_tests() \
|
||||||
do { \
|
do { \
|
||||||
if (__test_results.failure == 0u) { \
|
if (__test_results.failure == 0u) { \
|
||||||
log_ok ("successfully executed %zu tests.\n", __test_results.success); \
|
log_ok ("successfully executed %zu tests.\n", __test_results.success); \
|
||||||
} else { \
|
} else { \
|
||||||
log_err ("%zu out of %zu tests failed.\n", __test_results.failure, \
|
log_err ("%zu out of %zu tests failed.\n", __test_results.failure, \
|
||||||
__test_results.success + __test_results.failure); \
|
__test_results.success + __test_results.failure); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define t_exit() \
|
#define t_exit() \
|
||||||
do { \
|
do { \
|
||||||
exit (__test_results.failure == 0u ? EXIT_SUCCESS : EXIT_FAILURE); \
|
exit (__test_results.failure == 0u ? EXIT_SUCCESS : EXIT_FAILURE); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#endif // TEST_H_
|
#endif // TEST_H_
|
||||||
|
|
Loading…
Reference in New Issue