PicoTest
A minimalist unit testing framework for C programs
Loading...
Searching...
No Matches
logger.c File Reference

Example of PicoTest error logging, prints location and info of failed assertions to stdout. More...

Detailed Description

Example of PicoTest error logging, prints location and info of failed assertions to stdout.

#include <stdio.h>
#include <picotest.h>
/* Test failure logger declaration. */
#undef PICOTEST_FAILURE_LOGGER
#define PICOTEST_FAILURE_LOGGER logFailure
/* Test failure logger function. */
void logFailure(const char *file, int line, const char *type, const char *test, const char *msg, va_list args) {
/* Error type. */
printf("[%s] ", type);
/* Location in source code. */
printf("%s(%d) : ", file, line);
/* Failed expression. */
printf("%s", test);
/* Optional message. */
if (msg) {
printf(" | ");
vprintf(msg, args);
}
printf("\n");
}
/* Hooks */
#undef PICOTEST_CASE_ENTER
#undef PICOTEST_CASE_LEAVE
#define PICOTEST_CASE_ENTER logEnter
#define PICOTEST_CASE_LEAVE logLeave
int level = 0;
void indent(int level) {
while (level--) printf(" ");
}
void logEnter(const char *name) {
indent(level++);
printf("begin %s\n", name);
}
void logLeave(const char *name, int fail) {
level--;
if (!fail) {
indent(level);
printf("end %s\n", name);
}
}
/* Main test suite */
#include "mainSuite.inc"
void main() {
mainSuite(NULL);
}
void PicoTestFailureLoggerProc(const char *file, int line, const char *type, const char *test, const char *msg, va_list args)
Function signature of test failure log handlers.
Definition picotest.h:438
void PicoTestCaseEnterProc(const char *testName)
Function signature of test case enter hooks.
Definition picotest.h:633
void PicoTestCaseLeaveProc(const char *testName, int fail)
Function signature of test case leave hooks.
Definition picotest.h:681
Example of a simple PicoTest suite.
This file defines a minimalist unit testing framework for C programs.