Tchatator413
TripEnArvor instant messaging protocol - JSON-based
Loading...
Searching...
No Matches
Data Structures | Macros | Functions
stb_test.h File Reference

Quick unit testing library. More...

#include <stdbool.h>
#include <stdio.h>

Go to the source code of this file.

Data Structures

struct  test
 Represents a test suite with a name and a collection of test cases. More...
 
struct  _stbtest_case
 

Macros

#define STB_TEST_DEFINITION
 Defines modifier keywords for the definitions. Example value: static inline.
 
#define _STBTEST_ATTR_FORMAT(archetype, string_index, first_to_check)
 
#define test_fail(test, name, ...)   _stbtest_test_case(__LINE__, __FILE_NAME__, (test), false, "(fail)", (name)__VA_OPT__(, ) __VA_ARGS__)
 Add a test case that is always a failure.
 
#define test_case(test, expr, name, ...)   _stbtest_test_case(__LINE__, __FILE_NAME__, (test), (expr), #expr, (name)__VA_OPT__(, ) __VA_ARGS__)
 Add a test case.
 
#define test_case_wide(test, expr, name, ...)   _stbtest_test_case(__LINE__, __FILE_NAME__, (test), (expr), NULL, (name)__VA_OPT__(, ) __VA_ARGS__)
 Add a test case with the expr and name columns merged.
 

Functions

STB_TEST_DEFINITION struct test test_start (char const *name)
 Start a new test suite with the given name.
 
STB_TEST_DEFINITION bool _stbtest_test_case (unsigned line, char const *file, struct test *test, bool ok, char const *expr, char const *fmt_name,...) _STBTEST_ATTR_FORMAT(printf
 
STB_TEST_DEFINITION bool STB_TEST_DEFINITION bool test_end (struct test *test, FILE *output)
 Finish a test suite and prints the results to the provided output stream.
 

Detailed Description

Quick unit testing library.

Author
5cover (Scover)
Date
30/01/2024

See README.md for details and usage.

Definition in file stb_test.h.

Macro Definition Documentation

◆ _STBTEST_ATTR_FORMAT

#define _STBTEST_ATTR_FORMAT (   archetype,
  string_index,
  first_to_check 
)

Definition at line 23 of file stb_test.h.

◆ STB_TEST_DEFINITION

#define STB_TEST_DEFINITION

Defines modifier keywords for the definitions. Example value: static inline.

Definition at line 14 of file stb_test.h.

◆ test_case

#define test_case (   test,
  expr,
  name,
  ... 
)    _stbtest_test_case(__LINE__, __FILE_NAME__, (test), (expr), #expr, (name)__VA_OPT__(, ) __VA_ARGS__)

Add a test case.

Definition at line 51 of file stb_test.h.

◆ test_case_wide

#define test_case_wide (   test,
  expr,
  name,
  ... 
)    _stbtest_test_case(__LINE__, __FILE_NAME__, (test), (expr), NULL, (name)__VA_OPT__(, ) __VA_ARGS__)

Add a test case with the expr and name columns merged.

Definition at line 53 of file stb_test.h.

◆ test_fail

#define test_fail (   test,
  name,
  ... 
)    _stbtest_test_case(__LINE__, __FILE_NAME__, (test), false, "(fail)", (name)__VA_OPT__(, ) __VA_ARGS__)

Add a test case that is always a failure.

Definition at line 49 of file stb_test.h.

Function Documentation

◆ test_end()

STB_TEST_DEFINITION bool STB_TEST_DEFINITION bool test_end ( struct test test,
FILE *  output 
)

Finish a test suite and prints the results to the provided output stream.

This function takes a struct test instance and an output stream, and prints the results of the test suite to the output stream. It includes information about the number of successful and failed test cases, as well as the names and file locations of the failed test cases.

Remarks
This function destroys test Dereferencing test after calling this function is undefined behavior.
Parameters
testThe test suite to be finished.
outputThe output stream to print the results to.
Returns
true if all test cases passed
false otherwise.

◆ test_start()

STB_TEST_DEFINITION struct test test_start ( char const *  name)

Start a new test suite with the given name.

This function creates a new struct test instance with the provided name and an empty list of test cases.

Parameters
nameThe name of the test suite.
Returns
The newly created struct test instance.