2 * This file is part of DisOrder.
3 * Copyright (C) 2005, 2007, 2008 Richard Kettlewell
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 /** @file lib/test.c @brief Library tests */
26 long long tests, errors;
30 void count_error(void) {
36 const char *format(const char *s) {
42 while((c = (unsigned char)*s++)) {
43 if(c >= ' ' && c <= '~')
46 sprintf(buf, "\\x%02X", (unsigned)c);
47 dynstr_append_string(&d, buf);
54 const char *format_utf32(const uint32_t *s) {
61 sprintf(buf, " %04lX", (long)c);
62 dynstr_append_string(&d, buf);
68 uint32_t *ucs4parse(const char *s) {
75 dynstr_ucs4_append(&d, strtoul(s, &e, 0));
76 if(errno) fatal(errno, "strtoul (%s)", s);
79 dynstr_ucs4_terminate(&d);
83 const char *do_printf(const char *fmt, ...) {
89 rc = byte_vasprintf(&s, fmt, ap);
98 void test_exitfn(int rc) {
100 longjmp(fatal_env, rc);
103 static const struct option options[] = {
104 { "verbose", no_argument, 0, 'v' },
105 { "fail-first", no_argument, 0, 'F' },
106 { "help", no_argument, 0, 'h' },
107 { "version", no_argument, 0, 'V' },
110 /* display usage message and terminate */
111 static void help(void) {
115 " --help, -h Display usage message\n"
116 " --version, -V Display version number\n"
117 " --verbose, -v Verbose output\n"
118 " --fail-first, -F Stop on first failure\n",
124 void test_init(int argc, char **argv) {
129 while((n = getopt_long(argc, argv, "vFhV", options, 0)) >= 0) {
131 case 'v': verbose = 1; break;
132 case 'F': fail_first = 1; break;
134 case 'V': version(progname);
138 if(getenv("FAIL_FIRST"))