2010-09-23 16:05:17 +02:00
|
|
|
/* This is a really minimal testing framework for C.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
*
|
|
|
|
* test_cond("Check if 1 == 1", 1==1)
|
|
|
|
* test_cond("Check if 5 > 10", 5 > 10)
|
|
|
|
* test_report()
|
|
|
|
*
|
2012-11-08 18:25:23 +01:00
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
*
|
2024-03-20 23:38:24 +01:00
|
|
|
* Copyright (c) 2009-Present, Redis Ltd.
|
2010-09-23 16:05:17 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2024-03-20 23:38:24 +01:00
|
|
|
* Licensed under your choice of the Redis Source Available License 2.0
|
|
|
|
* (RSALv2) or the Server Side Public License v1 (SSPLv1).
|
2010-09-23 16:05:17 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __TESTHELP_H
|
|
|
|
#define __TESTHELP_H
|
|
|
|
|
2021-11-16 07:55:10 +01:00
|
|
|
#define REDIS_TEST_ACCURATE (1<<0)
|
|
|
|
#define REDIS_TEST_LARGE_MEMORY (1<<1)
|
2023-02-16 09:50:58 +01:00
|
|
|
#define REDIS_TEST_VALGRIND (1<<2)
|
2021-11-16 07:55:10 +01:00
|
|
|
|
|
|
|
extern int __failed_tests;
|
|
|
|
extern int __test_num;
|
|
|
|
|
2010-09-23 16:05:17 +02:00
|
|
|
#define test_cond(descr,_c) do { \
|
|
|
|
__test_num++; printf("%d - %s: ", __test_num, descr); \
|
|
|
|
if(_c) printf("PASSED\n"); else {printf("FAILED\n"); __failed_tests++;} \
|
2020-12-22 07:57:45 +01:00
|
|
|
} while(0)
|
2010-09-23 16:05:17 +02:00
|
|
|
#define test_report() do { \
|
|
|
|
printf("%d tests, %d passed, %d failed\n", __test_num, \
|
|
|
|
__test_num-__failed_tests, __failed_tests); \
|
|
|
|
if (__failed_tests) { \
|
|
|
|
printf("=== WARNING === We have failed tests here...\n"); \
|
2011-11-02 16:52:10 +01:00
|
|
|
exit(1); \
|
2010-09-23 16:05:17 +02:00
|
|
|
} \
|
2020-12-22 07:57:45 +01:00
|
|
|
} while(0)
|
2010-09-23 16:05:17 +02:00
|
|
|
|
|
|
|
#endif
|