cmocka: 🔧 Configuration and Output

cmocka 2.0.0 Unit testing library with mock support

Loading...
Searching...
No Matches
Data Structures | Enumerations | Functions
🔧 Configuration and Output
📚 The CMocka API

Control test output formats and execution behavior. More...

## Data Structures
struct | CMCallbacks

## Enumerations
enum | cm_message_output { CM_OUTPUT_STANDARD = 0x00000001 , CM_OUTPUT_STDOUT = 0x00000001 , CM_OUTPUT_SUBUNIT = 0x00000002 , CM_OUTPUT_TAP = 0x00000004 , CM_OUTPUT_XML = 0x00000008 }
| Output format options for test results. More...

## Functions
void | print_message (const char *const format,...) CMOCKA_PRINTF_ATTRIBUTE(1
void void | print_error (const char *const format,...) CMOCKA_PRINTF_ATTRIBUTE(1
void void void | vprint_message (const char *const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1
void void void void | vprint_error (const char *const format, va_list args) CMOCKA_PRINTF_ATTRIBUTE(1
void | cmocka_set_callbacks (const struct CMCallbacks *f_callbacks)
| Set callback functions for CMocka.
void | cm_print_error (const char *const format,...)
void | cmocka_print_error (const char *const format,...) CMOCKA_PRINTF_ATTRIBUTE(1
| Print error message using the cmocka output format.
void void | cmocka_set_message_output (uint32_t output)
| Function to set the output format for a test.
void | cmocka_set_test_filter (const char *pattern)
| Set a pattern to only run the test matching the pattern.
void | cmocka_set_skip_filter (const char *pattern)
| Set a pattern to skip tests matching the pattern.

## Detailed Description

Control test output formats and execution behavior.

Configure test execution behavior and output formatting.

This module provides functions to customize CMocka's behavior, including setting custom output callbacks, controlling output format (STANDARD, SUBUNIT, TAP, XML), and filtering which tests to run or skip.

## Enumeration Type Documentation

## ◆ cm_message_output

enum cm_message_output

Output format options for test results.

These are bitfield flags that can be combined using bitwise OR to enable multiple output formats simultaneously.

Enumerator
CM_OUTPUT_STANDARD | Standard CMocka output format (bit 0)
CM_OUTPUT_STDOUT | Alias for CM_OUTPUT_STANDARD (for API compatibility)
CM_OUTPUT_SUBUNIT | Subunit output format for test result aggregation (bit 1)
CM_OUTPUT_TAP | Test Anything Protocol (TAP) output format (bit 2)
CM_OUTPUT_XML | JUnit-compatible XML output format (bit 3)

## Function Documentation

## ◆ cm_print_error()

void cm_print_error | ( | const char *const | format,
|  |  | ... )

Deprecated
  Use cmocka_print_error()

## ◆ cmocka_print_error()

void cmocka_print_error | ( | const char *const | format,
|  |  | ... )

Print error message using the cmocka output format.

This prints an error message using the message output defined by the environment variable CMOCKA_MESSAGE_OUTPUT or cmocka_set_message_output().

Parameters

  format | The format string fprintf(3) uses.
  ... | The parameters used to fill format.

## ◆ cmocka_set_callbacks()

void cmocka_set_callbacks | ( | const struct CMCallbacks * | f_callbacks | ) |

Set callback functions for CMocka.

Input is a structure containing function pointers to one or more user-supplied callback functions. A NULL pointer for a particular callback will set that callback to the default implementation.

See the CMCallbacks documentation for details of each callback.

Parameters

  [in] | f_callbacks | A structure containing the user callbacks to use.

See also
  CMCallbacks

## ◆ cmocka_set_message_output()

void void cmocka_set_message_output | ( | uint32_t | output | ) |

Function to set the output format for a test.

The output format(s) for the test can either be set globally using this function or overwritten with environment variable CMOCKA_MESSAGE_OUTPUT.

The environment variable can be set to STANDARD, SUBUNIT, TAP or XML. Multiple outputs separated with comma are permitted. (e.g. export CMOCKA_MESSAGE_OUTPUT=STANDARD,XML)

Parameters

  [in] | output | The output format from cm_message_output to use for the test. For multiple outputs OR options together.

## ◆ cmocka_set_skip_filter()

void cmocka_set_skip_filter | ( | const char * | pattern | ) |

Set a pattern to skip tests matching the pattern.

This allows to filter tests and skip the ones matching the pattern. The pattern can include two wildcards. The first is '*', a wildcard that matches zero or more characters, or '?', a wildcard that matches exactly one character.

The same can also be achieved by setting the environment variable CMOCKA_SKIP_FILTER, without needing to recompile the application.

Parameters

  [in] | pattern | The pattern to match, e.g. "test_wurst*"

## ◆ cmocka_set_test_filter()

void cmocka_set_test_filter | ( | const char * | pattern | ) |

Set a pattern to only run the test matching the pattern.

This allows to filter tests and only run the ones matching the pattern. The pattern can include two wildcards. The first is '*', a wildcard that matches zero or more characters, or '?', a wildcard that matches exactly one character.

The same can also be achieved by setting the environment variable CMOCKA_TEST_FILTER, without needing to recompile the application.

Parameters

  [in] | pattern | The pattern to match, e.g. "test_wurst*"