CCCC
C bytecode compiler + VM interpreter
Loading...
Searching...
No Matches
Macros | Functions
testing.h File Reference

CCCC Test Framework — assertion API injected in –testing mode. More...

Go to the source code of this file.

Macros

#define Assert(cond)   __builtin_assert(!!(cond), #cond, __FILE__, __LINE__)
 Assert that a condition is true.
 
#define AssertTrue(cond)   Assert(cond)
 Assert that a condition is true (alias for Assert).
 
#define AssertFalse(cond)    __builtin_assert_false(!!(cond), #cond, __FILE__, __LINE__)
 Assert that a condition is false.
 
#define AssertFail()   __builtin_assert_fail(__FILE__, __LINE__)
 Unconditionally fail the current test.
 
#define AssertFailMsg(msg)   __builtin_assert_fail_msg(msg, __FILE__, __LINE__)
 Unconditionally fail the current test with a custom message.
 
#define AssertEq(a, b)
 Assert two integers are equal.
 
#define AssertNeq(a, b)
 Assert two integers are not equal.
 
#define AssertGt(a, b)
 Assert one integer is greater than another.
 
#define AssertLt(a, b)
 Assert one integer is less than another.
 
#define AssertGe(a, b)
 Assert one integer is greater than or equal to another.
 
#define AssertLe(a, b)
 Assert one integer is less than or equal to another.
 
#define AssertWithin(delta, expected, actual)
 Assert an integer is within a delta of an expected value.
 
#define AssertBits(mask, expected, actual)
 Assert that specific bits match between expected and actual values.
 
#define AssertBitHigh(bit, actual)
 Assert that a specific bit is set (high/1).
 
#define AssertBitLow(bit, actual)
 Assert that a specific bit is clear (low/0).
 
#define AssertFloatWithin(delta, expected, actual)
 Assert a float is within a delta of an expected value.
 
#define AssertDoubleWithin(delta, expected, actual)
 Assert a double is within a delta of an expected value.
 
#define AssertFloatEq(expected, actual)
 Assert two floats are approximately equal (default epsilon 1e-6).
 
#define AssertDoubleEq(expected, actual)
 Assert two doubles are approximately equal (default epsilon 1e-15).
 
#define AssertNull(p)    __builtin_assert_null((const void *)(p), #p, __FILE__, __LINE__)
 Assert a pointer is NULL.
 
#define AssertNotNull(p)    __builtin_assert_not_null((const void *)(p), #p, __FILE__, __LINE__)
 Assert a pointer is not NULL.
 
#define AssertStrEq(a, b)    __builtin_assert_streq((a), (b), #a, #b, __FILE__, __LINE__)
 Assert two C strings are equal.
 
#define AssertStrEqLen(a, b, len)
 Assert two C strings are equal up to a given length.
 
#define AssertMemEq(expected, actual, len)
 Assert two memory regions are byte-identical.
 
#define AssertArrayEq(expected, actual, count)
 Assert two arrays are element-by-element equal.
 
#define AssertEachEq(expected, actual, count)
 Assert each element of an array equals a scalar expected value.
 
#define AssertMsg(cond, msg)    __builtin_assert_msg(!!(cond), #cond, msg, __FILE__, __LINE__)
 Assert a condition is true with a custom message.
 
#define AssertTrueMsg(cond, msg)   AssertMsg(cond, msg)
 Assert a condition is true with a custom message (alias for AssertMsg).
 
#define AssertFalseMsg(cond, msg)    __builtin_assert_msg(!(cond), #cond, msg, __FILE__, __LINE__)
 Assert a condition is false with a custom message.
 
#define AssertEqMsg(a, b, msg)
 Assert two integers are equal with a custom message.
 
#define AssertStrEqMsg(a, b, msg)    __builtin_assert_streq_msg((a), (b), #a, #b, msg, __FILE__, __LINE__)
 Assert two C strings are equal with a custom message.
 
#define AssertNullMsg(p, msg)    __builtin_assert_null_msg((const void *)(p), #p, msg, __FILE__, __LINE__)
 Assert a pointer is NULL with a custom message.
 
#define AssertNotNullMsg(p, msg)
 Assert a pointer is not NULL with a custom message.
 
#define AssertBitsMsg(mask, expected, actual, msg)
 Assert specific bits match with a custom message.
 

Functions

void __builtin_assert (int cond, const char *expr, const char *file, int line)
 Assert that a condition is true.
 
void __builtin_assert_false (int cond, const char *expr, const char *file, int line)
 Assert that a condition is false.
 
void __builtin_assert_fail (const char *file, int line)
 Unconditionally fail a test.
 
void __builtin_assert_fail_msg (const char *msg, const char *file, int line)
 Unconditionally fail a test with a custom message.
 
void __builtin_assert_eq (long long a, long long b, const char *as, const char *bs, const char *file, int line)
 Assert that two integers are equal.
 
void __builtin_assert_neq (long long a, long long b, const char *as, const char *bs, const char *file, int line)
 Assert that two integers are not equal.
 
void __builtin_assert_gt (long long a, long long b, const char *as, const char *bs, const char *file, int line)
 Assert that one integer is greater than another.
 
void __builtin_assert_lt (long long a, long long b, const char *as, const char *bs, const char *file, int line)
 Assert that one integer is less than another.
 
void __builtin_assert_ge (long long a, long long b, const char *as, const char *bs, const char *file, int line)
 Assert that one integer is greater than or equal to another.
 
void __builtin_assert_le (long long a, long long b, const char *as, const char *bs, const char *file, int line)
 Assert that one integer is less than or equal to another.
 
void __builtin_assert_within (long long delta, long long expected, long long actual, const char *ds, const char *es, const char *as, const char *file, int line)
 Assert that an integer is within a delta of an expected value.
 
void __builtin_assert_null (const void *p, const char *ps, const char *file, int line)
 Assert that a pointer is NULL.
 
void __builtin_assert_not_null (const void *p, const char *ps, const char *file, int line)
 Assert that a pointer is not NULL.
 
void __builtin_assert_streq (const char *a, const char *b, const char *as, const char *bs, const char *file, int line)
 Assert that two C strings are equal (full strcmp).
 
void __builtin_assert_streq_len (const char *a, const char *b, long long len, const char *as, const char *bs, const char *file, int line)
 Assert that two C strings are equal up to a given length.
 
void __builtin_assert_mem_eq (const void *expected, const void *actual, long long len, const char *es, const char *as, const char *file, int line)
 Assert that two memory regions are byte-identical.
 
void __builtin_assert_float_within (double delta, double expected, double actual, const char *ds, const char *es, const char *as, const char *file, int line)
 Assert that a float is within a delta of an expected value.
 
void __builtin_assert_double_within (double delta, double expected, double actual, const char *ds, const char *es, const char *as, const char *file, int line)
 Assert that a double is within a delta of an expected value.
 
void __builtin_assert_bits (long long mask, long long expected, long long actual, const char *ms, const char *es, const char *as, const char *file, int line)
 Assert that specific bits match between expected and actual values.
 
void __builtin_assert_bit_high (int bit, long long actual, const char *bs, const char *as, const char *file, int line)
 Assert that a specific bit is set (high/1).
 
void __builtin_assert_bit_low (int bit, long long actual, const char *bs, const char *as, const char *file, int line)
 Assert that a specific bit is clear (low/0).
 
void __builtin_assert_eq_array (const void *expected, const void *actual, long long elem_size, long long count, const char *es, const char *as, const char *file, int line)
 Assert that two arrays are element-by-element equal.
 
void __builtin_assert_msg (int cond, const char *expr, const char *msg, const char *file, int line)
 Assert a condition is true with a custom message.
 
void __builtin_assert_eq_msg (long long a, long long b, const char *as, const char *bs, const char *msg, const char *file, int line)
 Assert two integers are equal with a custom message.
 
void __builtin_assert_streq_msg (const char *a, const char *b, const char *as, const char *bs, const char *msg, const char *file, int line)
 Assert two C strings are equal with a custom message.
 
void __builtin_assert_null_msg (const void *p, const char *ps, const char *msg, const char *file, int line)
 Assert a pointer is NULL with a custom message.
 
void __builtin_assert_not_null_msg (const void *p, const char *ps, const char *msg, const char *file, int line)
 Assert a pointer is not NULL with a custom message.
 
void __builtin_assert_bits_msg (long long mask, long long expected, long long actual, const char *ms, const char *es, const char *as, const char *msg, const char *file, int line)
 Assert specific bits match with a custom message.
 

Detailed Description

CCCC Test Framework — assertion API injected in –testing mode.

This header provides macros and underlying FFI-callable builtins for writing self-verifying test programs. It is automatically injected when CCCC is invoked with the --testing flag and should not be included directly.

A test passes if it exits with code 42.

Usage

int main(void) {
AssertEq(1 + 1, 2);
AssertStrEq("hello", "hello");
AssertNull(NULL);
return 42;
}
#define AssertEq(a, b)
Assert two integers are equal.
Definition testing.h:497
#define AssertNull(p)
Assert a pointer is NULL.
Definition testing.h:664
#define AssertStrEq(a, b)
Assert two C strings are equal.
Definition testing.h:685

Each assertion macro expands to a call to an FFI-callable __builtin_assert_* function. On failure, the builtin prints the source location and expression, then terminates with a failure exit code.

Macro Definition Documentation

◆ Assert

#define Assert (   cond)    __builtin_assert(!!(cond), #cond, __FILE__, __LINE__)

Assert that a condition is true.

Parameters
condThe condition to test.

Expands to __builtin_assert with stringified expression, source file, and line. Equivalent to AssertTrue.

◆ AssertArrayEq

#define AssertArrayEq (   expected,
  actual,
  count 
)
Value:
(const void *)(expected), (const void *)(actual), \
(long long)sizeof((expected)[0]), (long long)(count), #expected, \
#actual, __FILE__, __LINE__)
void __builtin_assert_eq_array(const void *expected, const void *actual, long long elem_size, long long count, const char *es, const char *as, const char *file, int line)
Assert that two arrays are element-by-element equal.

Assert two arrays are element-by-element equal.

Parameters
expectedPointer to expected array.
actualPointer to actual array.
countNumber of elements (element size is inferred).

Uses sizeof((expected)[0]) to infer element size.

◆ AssertBitHigh

#define AssertBitHigh (   bit,
  actual 
)
Value:
__builtin_assert_bit_high((int)(bit), (long long)(actual), #bit, #actual, \
__FILE__, __LINE__)
void __builtin_assert_bit_high(int bit, long long actual, const char *bs, const char *as, const char *file, int line)
Assert that a specific bit is set (high/1).

Assert that a specific bit is set (high/1).

Parameters
bitZero-based bit index.
actualValue to inspect.

Passes if (actual >> bit) & 1.

◆ AssertBitLow

#define AssertBitLow (   bit,
  actual 
)
Value:
__builtin_assert_bit_low((int)(bit), (long long)(actual), #bit, #actual, \
__FILE__, __LINE__)
void __builtin_assert_bit_low(int bit, long long actual, const char *bs, const char *as, const char *file, int line)
Assert that a specific bit is clear (low/0).

Assert that a specific bit is clear (low/0).

Parameters
bitZero-based bit index.
actualValue to inspect.

Passes if !((actual >> bit) & 1).

◆ AssertBits

#define AssertBits (   mask,
  expected,
  actual 
)
Value:
__builtin_assert_bits((long long)(mask), (long long)(expected), \
(long long)(actual), #mask, #expected, #actual, \
__FILE__, __LINE__)
void __builtin_assert_bits(long long mask, long long expected, long long actual, const char *ms, const char *es, const char *as, const char *file, int line)
Assert that specific bits match between expected and actual values.

Assert that specific bits match between expected and actual values.

Parameters
maskBit mask to apply.
expectedExpected masked value.
actualActual value to mask and compare.

Passes if (actual & mask) == (expected & mask).

◆ AssertBitsMsg

#define AssertBitsMsg (   mask,
  expected,
  actual,
  msg 
)
Value:
__builtin_assert_bits_msg((long long)(mask), (long long)(expected), \
(long long)(actual), #mask, #expected, #actual, \
msg, __FILE__, __LINE__)
void __builtin_assert_bits_msg(long long mask, long long expected, long long actual, const char *ms, const char *es, const char *as, const char *msg, const char *file, int line)
Assert specific bits match with a custom message.

Assert specific bits match with a custom message.

Parameters
maskBit mask to apply.
expectedExpected masked value.
actualActual value to mask and compare.
msgCustom failure message.

◆ AssertDoubleEq

#define AssertDoubleEq (   expected,
  actual 
)
Value:
__builtin_assert_double_within(1e-15, (double)(expected), \
(double)(actual), #expected, #expected, \
#actual, __FILE__, __LINE__)
void __builtin_assert_double_within(double delta, double expected, double actual, const char *ds, const char *es, const char *as, const char *file, int line)
Assert that a double is within a delta of an expected value.

Assert two doubles are approximately equal (default epsilon 1e-15).

Parameters
expectedExpected value.
actualActual value.

Uses a default delta of 1e-15.

◆ AssertDoubleWithin

#define AssertDoubleWithin (   delta,
  expected,
  actual 
)
Value:
__builtin_assert_double_within((double)(delta), (double)(expected), \
(double)(actual), #delta, #expected, \
#actual, __FILE__, __LINE__)

Assert a double is within a delta of an expected value.

Parameters
deltaMaximum allowed absolute difference.
expectedExpected value.
actualActual value.

◆ AssertEachEq

#define AssertEachEq (   expected,
  actual,
  count 
)
Value:
do { \
long long _cccc_i_; \
for (_cccc_i_ = 0; _cccc_i_ < (long long)(count); _cccc_i_++) \
__builtin_assert_eq((long long)((expected)), \
(long long)(((const typeof(( \
actual)[0]) *)(actual))[_cccc_i_]), \
#expected, #actual "[i]", __FILE__, __LINE__); \
} while (0)
void __builtin_assert_eq(long long a, long long b, const char *as, const char *bs, const char *file, int line)
Assert that two integers are equal.

Assert each element of an array equals a scalar expected value.

Parameters
expectedScalar expected value.
actualArray expression.
countNumber of elements.

Iterates over the array and compares each element individually. On failure, reports the failing index as "[i]".

◆ AssertEq

#define AssertEq (   a,
  b 
)
Value:
__builtin_assert_eq((long long)(a), (long long)(b), #a, #b, __FILE__, \
__LINE__)

Assert two integers are equal.

Parameters
aLeft-hand operand.
bRight-hand operand.

◆ AssertEqMsg

#define AssertEqMsg (   a,
  b,
  msg 
)
Value:
__builtin_assert_eq_msg((long long)(a), (long long)(b), #a, #b, msg, \
__FILE__, __LINE__)
void __builtin_assert_eq_msg(long long a, long long b, const char *as, const char *bs, const char *msg, const char *file, int line)
Assert two integers are equal with a custom message.

Assert two integers are equal with a custom message.

Parameters
aLeft-hand operand.
bRight-hand operand.
msgCustom failure message.

◆ AssertFail

#define AssertFail ( )    __builtin_assert_fail(__FILE__, __LINE__)

Unconditionally fail the current test.

◆ AssertFailMsg

#define AssertFailMsg (   msg)    __builtin_assert_fail_msg(msg, __FILE__, __LINE__)

Unconditionally fail the current test with a custom message.

Parameters
msgCustom failure message.

◆ AssertFalse

#define AssertFalse (   cond)     __builtin_assert_false(!!(cond), #cond, __FILE__, __LINE__)

Assert that a condition is false.

Parameters
condThe condition to test (must evaluate to zero).

◆ AssertFalseMsg

#define AssertFalseMsg (   cond,
  msg 
)     __builtin_assert_msg(!(cond), #cond, msg, __FILE__, __LINE__)

Assert a condition is false with a custom message.

Parameters
condThe condition to test.
msgCustom failure message.

◆ AssertFloatEq

#define AssertFloatEq (   expected,
  actual 
)
Value:
__builtin_assert_float_within(1e-6, (double)(expected), (double)(actual), \
#expected, #expected, #actual, __FILE__, \
__LINE__)
void __builtin_assert_float_within(double delta, double expected, double actual, const char *ds, const char *es, const char *as, const char *file, int line)
Assert that a float is within a delta of an expected value.

Assert two floats are approximately equal (default epsilon 1e-6).

Parameters
expectedExpected value.
actualActual value.

Uses a default delta of 1e-6.

◆ AssertFloatWithin

#define AssertFloatWithin (   delta,
  expected,
  actual 
)
Value:
__builtin_assert_float_within((double)(delta), (double)(expected), \
(double)(actual), #delta, #expected, \
#actual, __FILE__, __LINE__)

Assert a float is within a delta of an expected value.

Parameters
deltaMaximum allowed absolute difference.
expectedExpected value.
actualActual value.

◆ AssertGe

#define AssertGe (   a,
  b 
)
Value:
__builtin_assert_ge((long long)(a), (long long)(b), #a, #b, __FILE__, \
__LINE__)
void __builtin_assert_ge(long long a, long long b, const char *as, const char *bs, const char *file, int line)
Assert that one integer is greater than or equal to another.

Assert one integer is greater than or equal to another.

Parameters
aLeft-hand operand.
bRight-hand operand.

◆ AssertGt

#define AssertGt (   a,
  b 
)
Value:
__builtin_assert_gt((long long)(a), (long long)(b), #a, #b, __FILE__, \
__LINE__)
void __builtin_assert_gt(long long a, long long b, const char *as, const char *bs, const char *file, int line)
Assert that one integer is greater than another.

Assert one integer is greater than another.

Parameters
aLeft-hand operand.
bRight-hand operand.

◆ AssertLe

#define AssertLe (   a,
  b 
)
Value:
__builtin_assert_le((long long)(a), (long long)(b), #a, #b, __FILE__, \
__LINE__)
void __builtin_assert_le(long long a, long long b, const char *as, const char *bs, const char *file, int line)
Assert that one integer is less than or equal to another.

Assert one integer is less than or equal to another.

Parameters
aLeft-hand operand.
bRight-hand operand.

◆ AssertLt

#define AssertLt (   a,
  b 
)
Value:
__builtin_assert_lt((long long)(a), (long long)(b), #a, #b, __FILE__, \
__LINE__)
void __builtin_assert_lt(long long a, long long b, const char *as, const char *bs, const char *file, int line)
Assert that one integer is less than another.

Assert one integer is less than another.

Parameters
aLeft-hand operand.
bRight-hand operand.

◆ AssertMemEq

#define AssertMemEq (   expected,
  actual,
  len 
)
Value:
__builtin_assert_mem_eq((const void *)(expected), (const void *)(actual), \
(long long)(len), #expected, #actual, __FILE__, \
__LINE__)
void __builtin_assert_mem_eq(const void *expected, const void *actual, long long len, const char *es, const char *as, const char *file, int line)
Assert that two memory regions are byte-identical.

Assert two memory regions are byte-identical.

Parameters
expectedPointer to expected data.
actualPointer to actual data.
lenNumber of bytes to compare.

◆ AssertMsg

#define AssertMsg (   cond,
  msg 
)     __builtin_assert_msg(!!(cond), #cond, msg, __FILE__, __LINE__)

Assert a condition is true with a custom message.

Parameters
condThe condition to test.
msgCustom failure message.

◆ AssertNeq

#define AssertNeq (   a,
  b 
)
Value:
__builtin_assert_neq((long long)(a), (long long)(b), #a, #b, __FILE__, \
__LINE__)
void __builtin_assert_neq(long long a, long long b, const char *as, const char *bs, const char *file, int line)
Assert that two integers are not equal.

Assert two integers are not equal.

Parameters
aLeft-hand operand.
bRight-hand operand.

◆ AssertNotNull

#define AssertNotNull (   p)     __builtin_assert_not_null((const void *)(p), #p, __FILE__, __LINE__)

Assert a pointer is not NULL.

Parameters
pThe pointer to check.

◆ AssertNotNullMsg

#define AssertNotNullMsg (   p,
  msg 
)
Value:
__builtin_assert_not_null_msg((const void *)(p), #p, msg, __FILE__, \
__LINE__)
void __builtin_assert_not_null_msg(const void *p, const char *ps, const char *msg, const char *file, int line)
Assert a pointer is not NULL with a custom message.

Assert a pointer is not NULL with a custom message.

Parameters
pThe pointer to check.
msgCustom failure message.

◆ AssertNull

#define AssertNull (   p)     __builtin_assert_null((const void *)(p), #p, __FILE__, __LINE__)

Assert a pointer is NULL.

Parameters
pThe pointer to check.

◆ AssertNullMsg

#define AssertNullMsg (   p,
  msg 
)     __builtin_assert_null_msg((const void *)(p), #p, msg, __FILE__, __LINE__)

Assert a pointer is NULL with a custom message.

Parameters
pThe pointer to check.
msgCustom failure message.

◆ AssertStrEq

#define AssertStrEq (   a,
  b 
)     __builtin_assert_streq((a), (b), #a, #b, __FILE__, __LINE__)

Assert two C strings are equal.

Parameters
aExpected string.
bActual string.

◆ AssertStrEqLen

#define AssertStrEqLen (   a,
  b,
  len 
)
Value:
__builtin_assert_streq_len((a), (b), (long long)(len), #a, #b, __FILE__, \
__LINE__)
void __builtin_assert_streq_len(const char *a, const char *b, long long len, const char *as, const char *bs, const char *file, int line)
Assert that two C strings are equal up to a given length.

Assert two C strings are equal up to a given length.

Parameters
aExpected string.
bActual string.
lenMaximum number of characters to compare.

◆ AssertStrEqMsg

#define AssertStrEqMsg (   a,
  b,
  msg 
)     __builtin_assert_streq_msg((a), (b), #a, #b, msg, __FILE__, __LINE__)

Assert two C strings are equal with a custom message.

Parameters
aExpected string.
bActual string.
msgCustom failure message.

◆ AssertTrue

#define AssertTrue (   cond)    Assert(cond)

Assert that a condition is true (alias for Assert).

Parameters
condThe condition to test.

◆ AssertTrueMsg

#define AssertTrueMsg (   cond,
  msg 
)    AssertMsg(cond, msg)

Assert a condition is true with a custom message (alias for AssertMsg).

Parameters
condThe condition to test.
msgCustom failure message.

◆ AssertWithin

#define AssertWithin (   delta,
  expected,
  actual 
)
Value:
__builtin_assert_within((long long)(delta), (long long)(expected), \
(long long)(actual), #delta, #expected, #actual, \
__FILE__, __LINE__)
void __builtin_assert_within(long long delta, long long expected, long long actual, const char *ds, const char *es, const char *as, const char *file, int line)
Assert that an integer is within a delta of an expected value.

Assert an integer is within a delta of an expected value.

Parameters
deltaMaximum allowed absolute difference.
expectedExpected value.
actualActual value.

Passes if |actual - expected| <= delta.

Function Documentation

◆ __builtin_assert()

void __builtin_assert ( int  cond,
const char *  expr,
const char *  file,
int  line 
)

Assert that a condition is true.

Parameters
condThe boolean condition (must be non-zero to pass).
exprStringified expression for diagnostic output.
fileSource file name.
lineSource line number.
Note
Passes silently if cond is non-zero; otherwise prints the failure location/expression and terminates the test with a non-zero exit code.

Backend for Assert and AssertTrue.

◆ __builtin_assert_bit_high()

void __builtin_assert_bit_high ( int  bit,
long long  actual,
const char *  bs,
const char *  as,
const char *  file,
int  line 
)

Assert that a specific bit is set (high/1).

Parameters
bitZero-based bit index.
actualValue to inspect.
bsStringified bit index expression.
asStringified actual expression.
fileSource file name.
lineSource line number.
Note
Passes silently if bit bit of actual is set; otherwise terminates the test with a non-zero exit code.

Backend for AssertBitHigh. Passes if (actual >> bit) & 1.

◆ __builtin_assert_bit_low()

void __builtin_assert_bit_low ( int  bit,
long long  actual,
const char *  bs,
const char *  as,
const char *  file,
int  line 
)

Assert that a specific bit is clear (low/0).

Parameters
bitZero-based bit index.
actualValue to inspect.
bsStringified bit index expression.
asStringified actual expression.
fileSource file name.
lineSource line number.
Note
Passes silently if bit bit of actual is clear; otherwise terminates the test with a non-zero exit code.

Backend for AssertBitLow. Passes if !((actual >> bit) & 1).

◆ __builtin_assert_bits()

void __builtin_assert_bits ( long long  mask,
long long  expected,
long long  actual,
const char *  ms,
const char *  es,
const char *  as,
const char *  file,
int  line 
)

Assert that specific bits match between expected and actual values.

Parameters
maskBit mask to apply.
expectedExpected masked value.
actualActual value to mask and compare.
msStringified mask expression.
esStringified expected expression.
asStringified actual expression.
fileSource file name.
lineSource line number.
Note
Passes silently if (actual & mask) == (expected & mask); otherwise prints all three values and terminates the test with a non-zero exit code.

Backend for AssertBits. Passes if (actual & mask) == (expected & mask).

◆ __builtin_assert_bits_msg()

void __builtin_assert_bits_msg ( long long  mask,
long long  expected,
long long  actual,
const char *  ms,
const char *  es,
const char *  as,
const char *  msg,
const char *  file,
int  line 
)

Assert specific bits match with a custom message.

Parameters
maskBit mask to apply.
expectedExpected masked value.
actualActual value to mask and compare.
msStringified mask expression.
esStringified expected expression.
asStringified actual expression.
msgCustom failure message.
fileSource file name.
lineSource line number.
Note
Passes silently if (actual & mask) == (expected & mask); otherwise prints all three values, msg, and terminates the test with a non-zero exit code.

Backend for AssertBitsMsg. Passes if (actual & mask) == (expected & mask).

◆ __builtin_assert_double_within()

void __builtin_assert_double_within ( double  delta,
double  expected,
double  actual,
const char *  ds,
const char *  es,
const char *  as,
const char *  file,
int  line 
)

Assert that a double is within a delta of an expected value.

Parameters
deltaMaximum allowed absolute difference.
expectedExpected value.
actualActual value.
dsStringified delta expression.
esStringified expected expression.
asStringified actual expression.
fileSource file name.
lineSource line number.
Note
Passes silently if |actual - expected| <= delta; otherwise prints all three values and terminates the test with a non-zero exit code.

Backend for AssertDoubleWithin and AssertDoubleEq. Passes if |actual - expected| <= delta.

◆ __builtin_assert_eq()

void __builtin_assert_eq ( long long  a,
long long  b,
const char *  as,
const char *  bs,
const char *  file,
int  line 
)

Assert that two integers are equal.

Parameters
aLeft-hand operand.
bRight-hand operand.
asStringified left expression.
bsStringified right expression.
fileSource file name.
lineSource line number.
Note
Passes silently if a equals b; otherwise prints both values and terminates the test with a non-zero exit code.

Backend for AssertEq.

◆ __builtin_assert_eq_array()

void __builtin_assert_eq_array ( const void *  expected,
const void *  actual,
long long  elem_size,
long long  count,
const char *  es,
const char *  as,
const char *  file,
int  line 
)

Assert that two arrays are element-by-element equal.

Parameters
expectedPointer to expected array.
actualPointer to actual array.
elem_sizeSize of each element in bytes.
countNumber of elements to compare.
esStringified expected expression.
asStringified actual expression.
fileSource file name.
lineSource line number.
Note
Passes silently if the two arrays compare equal via memcmp; otherwise terminates the test with a non-zero exit code.

Backend for AssertArrayEq. Uses memcmp internally.

◆ __builtin_assert_eq_msg()

void __builtin_assert_eq_msg ( long long  a,
long long  b,
const char *  as,
const char *  bs,
const char *  msg,
const char *  file,
int  line 
)

Assert two integers are equal with a custom message.

Parameters
aLeft-hand operand.
bRight-hand operand.
asStringified left expression.
bsStringified right expression.
msgCustom failure message.
fileSource file name.
lineSource line number.
Note
Passes silently if a equals b; otherwise prints both values, msg, and terminates the test with a non-zero exit code.

Backend for AssertEqMsg.

◆ __builtin_assert_fail()

void __builtin_assert_fail ( const char *  file,
int  line 
)

Unconditionally fail a test.

Parameters
fileSource file name.
lineSource line number.
Note
Always prints the failure location and terminates the test with a non-zero exit code.

Backend for AssertFail.

◆ __builtin_assert_fail_msg()

void __builtin_assert_fail_msg ( const char *  msg,
const char *  file,
int  line 
)

Unconditionally fail a test with a custom message.

Parameters
msgCustom failure message.
fileSource file name.
lineSource line number.
Note
Always prints msg and the failure location, then terminates the test with a non-zero exit code.

Backend for AssertFailMsg.

◆ __builtin_assert_false()

void __builtin_assert_false ( int  cond,
const char *  expr,
const char *  file,
int  line 
)

Assert that a condition is false.

Parameters
condThe boolean condition (must be zero to pass).
exprStringified expression for diagnostic output.
fileSource file name.
lineSource line number.
Note
Passes silently if cond is zero; otherwise prints the failure location/expression and terminates the test with a non-zero exit code.

Backend for AssertFalse.

◆ __builtin_assert_float_within()

void __builtin_assert_float_within ( double  delta,
double  expected,
double  actual,
const char *  ds,
const char *  es,
const char *  as,
const char *  file,
int  line 
)

Assert that a float is within a delta of an expected value.

Parameters
deltaMaximum allowed absolute difference.
expectedExpected value.
actualActual value.
dsStringified delta expression.
esStringified expected expression.
asStringified actual expression.
fileSource file name.
lineSource line number.
Note
Passes silently if |actual - expected| <= delta; otherwise prints all three values and terminates the test with a non-zero exit code.

Backend for AssertFloatWithin and AssertFloatEq. Passes if |actual - expected| <= delta.

◆ __builtin_assert_ge()

void __builtin_assert_ge ( long long  a,
long long  b,
const char *  as,
const char *  bs,
const char *  file,
int  line 
)

Assert that one integer is greater than or equal to another.

Parameters
aLeft-hand operand.
bRight-hand operand.
asStringified left expression.
bsStringified right expression.
fileSource file name.
lineSource line number.
Note
Passes silently if a is greater than or equal to b; otherwise prints both values and terminates the test with a non-zero exit code.

Backend for AssertGe.

◆ __builtin_assert_gt()

void __builtin_assert_gt ( long long  a,
long long  b,
const char *  as,
const char *  bs,
const char *  file,
int  line 
)

Assert that one integer is greater than another.

Parameters
aLeft-hand operand.
bRight-hand operand.
asStringified left expression.
bsStringified right expression.
fileSource file name.
lineSource line number.
Note
Passes silently if a is greater than b; otherwise prints both values and terminates the test with a non-zero exit code.

Backend for AssertGt.

◆ __builtin_assert_le()

void __builtin_assert_le ( long long  a,
long long  b,
const char *  as,
const char *  bs,
const char *  file,
int  line 
)

Assert that one integer is less than or equal to another.

Parameters
aLeft-hand operand.
bRight-hand operand.
asStringified left expression.
bsStringified right expression.
fileSource file name.
lineSource line number.
Note
Passes silently if a is less than or equal to b; otherwise prints both values and terminates the test with a non-zero exit code.

Backend for AssertLe.

◆ __builtin_assert_lt()

void __builtin_assert_lt ( long long  a,
long long  b,
const char *  as,
const char *  bs,
const char *  file,
int  line 
)

Assert that one integer is less than another.

Parameters
aLeft-hand operand.
bRight-hand operand.
asStringified left expression.
bsStringified right expression.
fileSource file name.
lineSource line number.
Note
Passes silently if a is less than b; otherwise prints both values and terminates the test with a non-zero exit code.

Backend for AssertLt.

◆ __builtin_assert_mem_eq()

void __builtin_assert_mem_eq ( const void *  expected,
const void *  actual,
long long  len,
const char *  es,
const char *  as,
const char *  file,
int  line 
)

Assert that two memory regions are byte-identical.

Parameters
expectedPointer to expected data.
actualPointer to actual data.
lenNumber of bytes to compare.
esStringified expected expression.
asStringified actual expression.
fileSource file name.
lineSource line number.
Note
Passes silently if the two regions compare equal via memcmp; otherwise terminates the test with a non-zero exit code.

Backend for AssertMemEq. Uses memcmp for comparison.

◆ __builtin_assert_msg()

void __builtin_assert_msg ( int  cond,
const char *  expr,
const char *  msg,
const char *  file,
int  line 
)

Assert a condition is true with a custom message.

Parameters
condThe boolean condition (must be non-zero to pass).
exprStringified expression for diagnostic output.
msgCustom failure message.
fileSource file name.
lineSource line number.
Note
Passes silently if cond is non-zero; otherwise prints msg and the failure location, then terminates the test with a non-zero exit code.

Backend for AssertMsg and AssertTrueMsg.

◆ __builtin_assert_neq()

void __builtin_assert_neq ( long long  a,
long long  b,
const char *  as,
const char *  bs,
const char *  file,
int  line 
)

Assert that two integers are not equal.

Parameters
aLeft-hand operand.
bRight-hand operand.
asStringified left expression.
bsStringified right expression.
fileSource file name.
lineSource line number.
Note
Passes silently if a differs from b; otherwise prints both values and terminates the test with a non-zero exit code.

Backend for AssertNeq.

◆ __builtin_assert_not_null()

void __builtin_assert_not_null ( const void *  p,
const char *  ps,
const char *  file,
int  line 
)

Assert that a pointer is not NULL.

Parameters
pThe pointer to check.
psStringified pointer expression.
fileSource file name.
lineSource line number.
Note
Passes silently if p is non-NULL; otherwise terminates the test with a non-zero exit code.

Backend for AssertNotNull.

◆ __builtin_assert_not_null_msg()

void __builtin_assert_not_null_msg ( const void *  p,
const char *  ps,
const char *  msg,
const char *  file,
int  line 
)

Assert a pointer is not NULL with a custom message.

Parameters
pThe pointer to check.
psStringified pointer expression.
msgCustom failure message.
fileSource file name.
lineSource line number.
Note
Passes silently if p is non-NULL; otherwise prints msg and terminates the test with a non-zero exit code.

Backend for AssertNotNullMsg.

◆ __builtin_assert_null()

void __builtin_assert_null ( const void *  p,
const char *  ps,
const char *  file,
int  line 
)

Assert that a pointer is NULL.

Parameters
pThe pointer to check.
psStringified pointer expression.
fileSource file name.
lineSource line number.
Note
Passes silently if p is NULL; otherwise prints the pointer value and terminates the test with a non-zero exit code.

Backend for AssertNull.

◆ __builtin_assert_null_msg()

void __builtin_assert_null_msg ( const void *  p,
const char *  ps,
const char *  msg,
const char *  file,
int  line 
)

Assert a pointer is NULL with a custom message.

Parameters
pThe pointer to check.
psStringified pointer expression.
msgCustom failure message.
fileSource file name.
lineSource line number.
Note
Passes silently if p is NULL; otherwise prints msg and terminates the test with a non-zero exit code.

Backend for AssertNullMsg.

◆ __builtin_assert_streq()

void __builtin_assert_streq ( const char *  a,
const char *  b,
const char *  as,
const char *  bs,
const char *  file,
int  line 
)

Assert that two C strings are equal (full strcmp).

Parameters
aExpected string.
bActual string.
asStringified expected expression.
bsStringified actual expression.
fileSource file name.
lineSource line number.
Note
Passes silently if a and b compare equal via strcmp; otherwise prints both strings and terminates the test with a non-zero exit code.

Backend for AssertStrEq. Uses strcmp for comparison.

◆ __builtin_assert_streq_len()

void __builtin_assert_streq_len ( const char *  a,
const char *  b,
long long  len,
const char *  as,
const char *  bs,
const char *  file,
int  line 
)

Assert that two C strings are equal up to a given length.

Parameters
aExpected string.
bActual string.
lenMaximum number of characters to compare.
asStringified expected expression.
bsStringified actual expression.
fileSource file name.
lineSource line number.
Note
Passes silently if a and b compare equal for the first len characters via strncmp; otherwise prints both strings and terminates the test with a non-zero exit code.

Backend for AssertStrEqLen. Uses strncmp for comparison.

◆ __builtin_assert_streq_msg()

void __builtin_assert_streq_msg ( const char *  a,
const char *  b,
const char *  as,
const char *  bs,
const char *  msg,
const char *  file,
int  line 
)

Assert two C strings are equal with a custom message.

Parameters
aExpected string.
bActual string.
asStringified expected expression.
bsStringified actual expression.
msgCustom failure message.
fileSource file name.
lineSource line number.
Note
Passes silently if a and b compare equal via strcmp; otherwise prints both strings, msg, and terminates the test with a non-zero exit code.

Backend for AssertStrEqMsg.

◆ __builtin_assert_within()

void __builtin_assert_within ( long long  delta,
long long  expected,
long long  actual,
const char *  ds,
const char *  es,
const char *  as,
const char *  file,
int  line 
)

Assert that an integer is within a delta of an expected value.

Parameters
deltaMaximum allowed absolute difference.
expectedExpected value.
actualActual value.
dsStringified delta expression.
esStringified expected expression.
asStringified actual expression.
fileSource file name.
lineSource line number.
Note
Passes silently if |actual - expected| <= delta; otherwise prints all three values and terminates the test with a non-zero exit code.

Backend for AssertWithin. Passes if |actual - expected| <= delta.