libpulsar
A modular compiler for the pulsar programming language
Loading...
Searching...
No Matches
Macros | Functions
unit_testing.h File Reference

Provides assertion macros for unit tests. More...

#include "def.h"

Go to the source code of this file.

Macros

#define PS_BEGIN_UNIT_TESTS()   _PS_BEGIN_UNIT_TESTS(__FILE__)
 Begin unit tests.
 
#define PS_UNIT_ASSERT(result, ...)    _PS_UNIT_ASSERT(result, #result, __func__, __LINE__, "" __VA_ARGS__)
 Assert that the result is true.
 
#define PS_UNIT_ASSERT_EQ(exp, act, fmt, msg, ...)
 Assert that the two values are equal.
 
#define PS_UNIT_SUPPRESS(msg)   _PS_UNIT_SUPPRESS(msg, __func__, __LINE__)
 Suppress unit test output.
 

Functions

void _PS_BEGIN_UNIT_TESTS (STR file)
 
void PS_END_UNIT_TESTS (void)
 End unit tests.
 
void _PS_UNIT_ASSERT (int result, STR expr, STR func, u64 line, STR msg,...)
 
void _PS_UNIT_SUPPRESS (STR msg, STR func, u64 line)
 
void PS_UNIT_UNSUPPRESS (void)
 Unsuppress unit test output.
 

Detailed Description

Provides assertion macros for unit tests.

Author
Ethan Uppal

Definition in file unit_testing.h.

Macro Definition Documentation

◆ PS_BEGIN_UNIT_TESTS

#define PS_BEGIN_UNIT_TESTS ( )    _PS_BEGIN_UNIT_TESTS(__FILE__)

Begin unit tests.

Definition at line 34 of file unit_testing.h.

◆ PS_UNIT_ASSERT

#define PS_UNIT_ASSERT (   result,
  ... 
)     _PS_UNIT_ASSERT(result, #result, __func__, __LINE__, "" __VA_ARGS__)

Assert that the result is true.

Parameters
resultThe result to assert.
...The message to print (with optional args) if the assertion fails.

Definition at line 41 of file unit_testing.h.

◆ PS_UNIT_ASSERT_EQ

#define PS_UNIT_ASSERT_EQ (   exp,
  act,
  fmt,
  msg,
  ... 
)
Value:
do { \
auto_t exp_ = exp; \
auto_t act_ = act; \
_PS_UNIT_ASSERT(((exp_) == (act_)), #exp " == " #act, __func__, \
__LINE__, "Expected: " fmt "\n\tActual: " fmt "\n\t%s", exp_, \
act_, msg, ##__VA_ARGS__); \
} while (0)
#define auto_t
Definition def.h:53

Assert that the two values are equal.

Parameters
expThe expected value.
actThe actual value.
fmtThe format string for the expected and actual values.
msgThe message to print (with optional args) if the assertion fails.

Definition at line 51 of file unit_testing.h.

◆ PS_UNIT_SUPPRESS

#define PS_UNIT_SUPPRESS (   msg)    _PS_UNIT_SUPPRESS(msg, __func__, __LINE__)

Suppress unit test output.

Must call PS_UNIT_UNSURPRESS before calling again.

Parameters
msgThe message to print when suppressing.
See also
PS_UNIT_UNSUPPRESS

Definition at line 66 of file unit_testing.h.

Function Documentation

◆ _PS_BEGIN_UNIT_TESTS()

void _PS_BEGIN_UNIT_TESTS ( STR  file)

Definition at line 32 of file unit_testing.c.

◆ _PS_UNIT_ASSERT()

void _PS_UNIT_ASSERT ( int  result,
STR  expr,
STR  func,
u64  line,
STR  msg,
  ... 
)

Definition at line 70 of file unit_testing.c.

◆ _PS_UNIT_SUPPRESS()

void _PS_UNIT_SUPPRESS ( STR  msg,
STR  func,
u64  line 
)

Definition at line 109 of file unit_testing.c.

◆ PS_END_UNIT_TESTS()

void PS_END_UNIT_TESTS ( void  )

End unit tests.

Do not call this function directly. Instead, PS_BEGIN_UNIT_TESTS will call this function for you.

Definition at line 56 of file unit_testing.c.

◆ PS_UNIT_UNSUPPRESS()

void PS_UNIT_UNSUPPRESS ( void  )

Unsuppress unit test output.

See also
PS_UNIT_SUPPRESS

Definition at line 119 of file unit_testing.c.