]> git.saurik.com Git - redis.git/blame_incremental - src/testhelp.h
Make sure an automatic rewrite only gets triggered when no other child is in execution.
[redis.git] / src / testhelp.h
... / ...
CommitLineData
1/* This is a really minimal testing framework for C.
2 *
3 * Example:
4 *
5 * test_cond("Check if 1 == 1", 1==1)
6 * test_cond("Check if 5 > 10", 5 > 10)
7 * test_report()
8 *
9 * Copyright (c) 2010, Salvatore Sanfilippo <antirez at gmail dot com>
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions are met:
14 *
15 * * Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * * Neither the name of Redis nor the names of its contributors may be used
21 * to endorse or promote products derived from this software without
22 * specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#ifndef __TESTHELP_H
38#define __TESTHELP_H
39
40int __failed_tests = 0;
41int __test_num = 0;
42#define test_cond(descr,_c) do { \
43 __test_num++; printf("%d - %s: ", __test_num, descr); \
44 if(_c) printf("PASSED\n"); else {printf("FAILED\n"); __failed_tests++;} \
45} while(0);
46#define test_report() do { \
47 printf("%d tests, %d passed, %d failed\n", __test_num, \
48 __test_num-__failed_tests, __failed_tests); \
49 if (__failed_tests) { \
50 printf("=== WARNING === We have failed tests here...\n"); \
51 } \
52} while(0);
53
54#endif