chiark / gitweb /
Add missing notification when scratch queued, lost a couple of commits back
[disorder] / libtests / test.c
index 6b2435e103afa7db74321fce8e6f263deeb7d3dd..354106b2ffc4366b0bfd70882d456a3bd5b56039 100644 (file)
 #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;
+
+/** @brief Verbose mode */
 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();
 }
 
+/** @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;
@@ -50,6 +70,12 @@ const char *format(const char *s) {
   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;
@@ -64,6 +90,10 @@ const char *format_utf32(const uint32_t *s) {
   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;
@@ -72,13 +102,19 @@ uint32_t *ucs4parse(const char *s) {
   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;
 }
 
+/** @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;
@@ -92,8 +128,13 @@ const char *do_printf(const char *fmt, ...) {
   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);
@@ -120,6 +161,10 @@ static void help(void) {
   exit(0);
 }
 
+/** @brief Standard test program initialization
+ * @param argc Argument count
+ * @param argv Arguments
+ */
 void test_init(int argc, char **argv) {
   int n;