chiark
/
gitweb
/
~mdw
/
disorder
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge tag 'branchpoint-5.1' into release
[disorder]
/
libtests
/
test.c
diff --git
a/libtests/test.c
b/libtests/test.c
index f5dd036d443eff8581549c539b8b6ab4e38e592a..3270d470ab47e9d0393bf0925140136e5ff5bc7f 100644
(file)
--- a/
libtests/test.c
+++ b/
libtests/test.c
@@
-1,38
+1,57
@@
/*
* This file is part of DisOrder.
/*
* This file is part of DisOrder.
- * Copyright (C) 2005, 2007
, 2008
Richard Kettlewell
+ * Copyright (C) 2005, 2007
-2009
Richard Kettlewell
*
*
- * This program is free software
;
you can redistribute it and/or modify
+ * This program is free software
:
you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation
; either version 2
of the License, or
+ * the Free Software Foundation
, either version 3
of the License, or
* (at your option) any later version.
* (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU
- * General Public License for more details.
- *
+ *
+ * This program is distributed in the hope that it will be useful,
+ *
but
WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * G
NU G
eneral Public License for more details.
+ *
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
-/** @file lib/test.c @brief Library tests */
+/** @file lib
tests
/test.c @brief Library tests */
#include "test.h"
#include "version.h"
#include <getopt.h>
#include "test.h"
#include "version.h"
#include <getopt.h>
-long long tests, errors;
+/** @brief Count of tests */
+long long tests;
+
+/** @brief Count of errors */
+long long errors;
+
+/** @brief If set, first error will fail whole test */
int fail_first;
int fail_first;
+
+/** @brief Verbose mode */
int verbose;
int verbose;
+/** @brief If set, test will return 'skipped' indicator */
+int skipped;
+
+/** @brief Count up an error
+ *
+ * If @ref fail_first is set then the test run is aborted.
+ */
void count_error(void) {
++errors;
if(fail_first)
abort();
}
void count_error(void) {
++errors;
if(fail_first)
abort();
}
+/** @brief Render a string into printable ASCII
+ * @param s String to format
+ * @return Allocated copy of formatted string
+ *
+ * Replaces any non-ASCII characters with a hex escape.
+ */
const char *format(const char *s) {
struct dynstr d;
int c;
const char *format(const char *s) {
struct dynstr d;
int c;
@@
-51,6
+70,12
@@
const char *format(const char *s) {
return d.vec;
}
return d.vec;
}
+/** @brief Format a UTF-32 string into hex
+ * @param s String to format
+ * @return Allocated copy of formatted string
+ *
+ * Returns the hex codes of @p s separated by spaces.
+ */
const char *format_utf32(const uint32_t *s) {
struct dynstr d;
uint32_t c;
const char *format_utf32(const uint32_t *s) {
struct dynstr d;
uint32_t c;
@@
-65,6
+90,10
@@
const char *format_utf32(const uint32_t *s) {
return d.vec;
}
return d.vec;
}
+/** @brief Convert a string of hex codes to a UTF-32 string
+ * @param s String of hex codes, separated by spaces
+ * @return Allocated string, 0-terminated
+ */
uint32_t *ucs4parse(const char *s) {
struct dynstr_ucs4 d;
char *e;
uint32_t *ucs4parse(const char *s) {
struct dynstr_ucs4 d;
char *e;
@@
-73,13
+102,19
@@
uint32_t *ucs4parse(const char *s) {
while(*s) {
errno = 0;
dynstr_ucs4_append(&d, strtoul(s, &e, 0));
while(*s) {
errno = 0;
dynstr_ucs4_append(&d, strtoul(s, &e, 0));
- if(errno) fatal(errno, "strtoul (%s)", s);
+ if(errno)
+ disorder_fatal(errno, "strtoul (%s)", s);
s = e;
}
dynstr_ucs4_terminate(&d);
return d.vec;
}
s = e;
}
dynstr_ucs4_terminate(&d);
return d.vec;
}
+/** @brief Format a string like asprintf()
+ * @param fmt Format string, per printf(3)
+ * @param ... Arguments
+ * @return Formatted string or null pointer on error
+ */
const char *do_printf(const char *fmt, ...) {
va_list ap;
char *s;
const char *do_printf(const char *fmt, ...) {
va_list ap;
char *s;
@@
-93,6
+128,18
@@
const char *do_printf(const char *fmt, ...) {
return s;
}
return s;
}
+/** @brief Jump buffer for exitfn() testing */
+jmp_buf fatal_env;
+
+/** @brief exitfn() callback for testing
+ * @param rc Value to return from setjmp()
+ * Jumps to @ref fatal_env
+ */
+void test_exitfn(int rc) {
+ assert(rc != 0);
+ longjmp(fatal_env, rc);
+}
+
static const struct option options[] = {
{ "verbose", no_argument, 0, 'v' },
{ "fail-first", no_argument, 0, 'F' },
static const struct option options[] = {
{ "verbose", no_argument, 0, 'v' },
{ "fail-first", no_argument, 0, 'F' },
@@
-114,6
+161,10
@@
static void help(void) {
exit(0);
}
exit(0);
}
+/** @brief Standard test program initialization
+ * @param argc Argument count
+ * @param argv Arguments
+ */
void test_init(int argc, char **argv) {
int n;
void test_init(int argc, char **argv) {
int n;