Write testing framework
This commit is contained in:
parent
1a607488ce
commit
63facb3954
8
tests/testing.c
Normal file
8
tests/testing.c
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Camden Dixie O'Brien
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "testing.h"
|
||||||
|
|
||||||
|
int fail_count;
|
38
tests/testing.h
Normal file
38
tests/testing.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Camden Dixie O'Brien
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TESTING_H
|
||||||
|
#define TESTING_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define TESTING_BEGIN() fail_count = 0
|
||||||
|
#define TESTING_END() fail_count == 0 ? EXIT_SUCCESS : EXIT_FAILURE
|
||||||
|
|
||||||
|
#define FAIL \
|
||||||
|
do { \
|
||||||
|
++fail_count; \
|
||||||
|
printf("%s: FAIL @ %s:%d\n", __func__, __FILE__, __LINE__); \
|
||||||
|
return; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ASSERT_FALSE(p) \
|
||||||
|
do { \
|
||||||
|
if (p) \
|
||||||
|
FAIL; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define ASSERT_TRUE(p) ASSERT_FALSE(!(p))
|
||||||
|
#define ASSERT_EQ(x, y) ASSERT_FALSE((x) != (y))
|
||||||
|
#define ASSERT_NE(x, y) ASSERT_FALSE((x) == (y))
|
||||||
|
#define ASSERT_NULL(p) ASSERT_FALSE(NULL != (p))
|
||||||
|
#define ASSERT_NOT_NULL(p) ASSERT_FALSE(NULL == (p))
|
||||||
|
#define ASSERT_MEM_EQ(p, q, n) ASSERT_FALSE(memcmp(p, q, n) != 0)
|
||||||
|
|
||||||
|
extern int fail_count;
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user