2 * Copyright (c) 2012 Dag-Erling Smørgrav
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote
14 * products derived from this software without specific prior written
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * $Id: t_main.c 651 2013-03-05 18:11:59Z des $
46 const char *t_progname;
51 t_verbose(const char *fmt, ...)
57 vfprintf(stderr, fmt, ap);
66 fprintf(stderr, "usage: %s [-v]\n", t_progname);
71 main(int argc, char *argv[])
73 const struct t_test **t_plan;
78 #ifdef HAVE_SETLOGMASK
79 /* suppress openpam_log() */
80 setlogmask(LOG_UPTO(0));
83 /* clean up temp files in case of premature exit */
86 if ((t_progname = strrchr(argv[0], '/')) != NULL)
87 t_progname++; /* one past the slash */
91 while ((opt = getopt(argc, argv, "v")) != -1)
103 /* prepare the test plan */
104 if ((t_plan = t_prepare(argc, argv)) == NULL)
105 errx(1, "no plan\n");
107 /* count the tests */
108 for (n = 0; t_plan[n] != NULL; ++n)
110 printf("1..%d\n", n);
113 for (n = pass = fail = 0; t_plan[n] != NULL; ++n) {
114 desc = t_plan[n]->desc ? t_plan[n]->desc : "no description";
115 if ((*t_plan[n]->func)(t_plan[n]->arg)) {
116 printf("ok %d - %s\n", n + 1, desc);
119 printf("not ok %d - %s\n", n + 1, desc);
124 /* clean up and exit */
126 exit(fail > 0 ? 1 : 0);