Lumiera  0.pre.03
»edit your freedom«
test.h
Go to the documentation of this file.
1 /*
2  TEST.h - support macros for plain-C tests
3 
4  Copyright (C) Lumiera.org
5  2008, 2010 Christian Thaeter <ct@pipapo.org>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
33 #ifndef LIB_TEST_TEST_H
34 #define LIB_TEST_TEST_H
35 
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <nobug.h>
40 
41 
42 
43 #define TESTS_BEGIN \
44 int \
45 main (int argc, const char** argv) \
46 { \
47  NOBUG_INIT; \
48  unsigned testcnt=0; \
49  int ret = 0; \
50  \
51  if (argc == 1) \
52  fprintf (stderr, "supported tests:\n");
53 
54 #define TEST(name) \
55  if (argc == 1) \
56  fprintf (stderr, " "#name"\n"); \
57  else if (!strcmp(argv[1], #name) && ++testcnt)
58 
59 #define PLANNED_TEST(name) \
60  if (argc == 1) \
61  fprintf (stderr, " "#name" (planned)\n"); \
62  else if (!++testcnt)
63 
64 #define TESTS_END \
65  if (!testcnt && argc !=1) \
66  fprintf (stderr,"no such test: %s\n", argv[1]); \
67  return ret; \
68 }
69 
70 
71 #endif
72 
73 /*
74 // Local Variables:
75 // mode: C
76 // c-file-style: "gnu"
77 // indent-tabs-mode: nil
78 // End:
79 */