htils 1
A small set of utilities for C programming.
Loading...
Searching...
No Matches
test.h File Reference
#include <stdlib.h>
#include <htils/arena.h>
#include <htils/basictypes.h>

Go to the source code of this file.

Macros

#define COLOR_GREEN   "\x1b[32m"
 
#define COLOR_CYAN   "\x1b[36m"
 
#define COLOR_RED   "\x1b[31m"
 
#define COLOR_RESET   "\x1b[0m"
 
#define HTILS_TEST_ASSERT(cond, msg)
 
#define HTILS_TEST(name)   static const cstr *htils_test_##name(arena_t *arena)
 
#define HTILS_TEST_RUN(name)
 
#define HTILS_TEST_RESULT()
 
#define HTILS_TEST_PASS   null
 
#define HTILS_TEST_SKIP   "@"
 

Typedefs

typedef const cstrtest_fn(arena_t *arena)
 

Macro Definition Documentation

◆ COLOR_CYAN

#define COLOR_CYAN   "\x1b[36m"

◆ COLOR_GREEN

#define COLOR_GREEN   "\x1b[32m"

◆ COLOR_RED

#define COLOR_RED   "\x1b[31m"

◆ COLOR_RESET

#define COLOR_RESET   "\x1b[0m"

◆ HTILS_TEST

#define HTILS_TEST (   name)    static const cstr *htils_test_##name(arena_t *arena)

The test macro for test declarations.

◆ HTILS_TEST_ASSERT

#define HTILS_TEST_ASSERT (   cond,
  msg 
)
Value:
do { \
if (!(cond)) { \
fprintf(stderr, " %sFAIL%s: %s:%d: %s\n", COLOR_RED, COLOR_RESET, \
__FILE__, __LINE__, msg); \
return (msg); \
} \
} while (0)
#define COLOR_RESET
Definition test.h:16
#define COLOR_RED
Definition test.h:15

The test assertion, basically signals if condition is false, the test fails.

◆ HTILS_TEST_PASS

#define HTILS_TEST_PASS   null

Lil macro that makes test passes more opaque

◆ HTILS_TEST_RESULT

#define HTILS_TEST_RESULT ( )
Value:
do { \
if (failures > 0) { \
fprintf(stderr, "\n%u Tests %sFAILED%s.\n", failures, COLOR_RED, \
fprintf(stderr, "%sSKIPPED%s %u tests.\n", COLOR_CYAN, COLOR_RESET, \
skips); \
return 1; \
} \
\
fprintf(stderr, "\nAll %u tests %sPASSED%s.\n", test_count, COLOR_GREEN, \
fprintf(stderr, "%sSKIPPED%s %u tests.\n", COLOR_CYAN, COLOR_RESET, \
skips); \
return 0; \
} while (0)
#define COLOR_CYAN
Definition test.h:14
#define COLOR_GREEN
Definition test.h:13

Handle the test results, prints the results and returns 0 if all tests pass, returns 1 if any test fails.

◆ HTILS_TEST_RUN

#define HTILS_TEST_RUN (   name)
Value:
do { \
test_count++; \
if (arena == null) { \
fprintf(stderr, "No arena found, did you forget to initialize one?\n"); \
exit(1); \
} \
\
fprintf(stderr, "Running test: %s...\n", #name); \
const cstr *result = htils_test_##name(temp_arena.arena); \
temp_arena_free(temp_arena); \
\
if (!result) \
fprintf(stderr, " %sPASS%s: %s\n", COLOR_GREEN, COLOR_RESET, #name); \
else if (result[0] == '@') { \
fprintf(stderr, " %sSKIPPED%s: %s\n", COLOR_CYAN, COLOR_RESET, #name); \
skips++; \
} else \
(failures)++; \
} while (0)
temp_arena_t temp_arena_new(arena_t *arena)
Create a new temp_arena.
Definition arena.c:346
#define null
Definition basictypes.h:47
char cstr
Definition basictypes.h:50
An arena.
Definition arena.h:26
A temporary arena.
Definition arena.h:39
struct arena * arena
Definition arena.h:40

The runtime for the tests, uses temporary arenas.

◆ HTILS_TEST_SKIP

#define HTILS_TEST_SKIP   "@"

Lil macro to tell the test suite to skip a test

Typedef Documentation

◆ test_fn

typedef const cstr * test_fn(arena_t *arena)

Test function type.