cbase 1.46.11
C/C++ Static Template
Loading...
Searching...
No Matches
test_harness.h File Reference

A lightweight, dependency-free unit testing harness. More...

#include <stdio.h>
#include <stdlib.h>
Include dependency graph for test_harness.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define EXPECT(cond)
 Evaluates a condition. If it fails, prints the file/line and increments the fail count.
#define EXPECT_STR8_EQ(a, b)
 Helper to test if two String8 objects match exactly.
#define TEST_CASE(name)
 Defines a test case function.
#define RUN_TEST(name)
 Runs a test case and prints its execution status.

Variables

static int tests_run = 0
 Global counter tracking the total number of tests executed.
static int tests_failed = 0
 Global counter tracking the total number of tests that failed.

Detailed Description

A lightweight, dependency-free unit testing harness.

Definition in file test_harness.h.

Macro Definition Documentation

◆ EXPECT

#define EXPECT ( cond)
Value:
do { \
if (!(cond)) { \
printf(" [FAIL] %s:%d: %s\n", __FILE__, __LINE__, #cond); \
} \
} while (0)
static int tests_failed
Global counter tracking the total number of tests that failed.

Evaluates a condition. If it fails, prints the file/line and increments the fail count.

Definition at line 18 of file test_harness.h.

◆ EXPECT_STR8_EQ

#define EXPECT_STR8_EQ ( a,
b )
Value:
EXPECT(str8_match((a), (b)))
static b32 str8_match(String8 a, String8 b)
Checks if two String8s are exactly equal (case-sensitive).
#define EXPECT(cond)
Evaluates a condition. If it fails, prints the file/line and increments the fail count.

Helper to test if two String8 objects match exactly.

Definition at line 27 of file test_harness.h.

◆ RUN_TEST

#define RUN_TEST ( name)
Value:
do { \
printf("Running " #name "...\n"); \
test_##name(); \
tests_run++; \
} while (0)
static int tests_run
Global counter tracking the total number of tests executed.

Runs a test case and prints its execution status.

Definition at line 33 of file test_harness.h.

◆ TEST_CASE

#define TEST_CASE ( name)
Value:
static void test_##name(void)

Defines a test case function.

Definition at line 30 of file test_harness.h.

Variable Documentation

◆ tests_failed

int tests_failed = 0
static

Global counter tracking the total number of tests that failed.

Definition at line 14 of file test_harness.h.

◆ tests_run

int tests_run = 0
static

Global counter tracking the total number of tests executed.

Definition at line 12 of file test_harness.h.