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