aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_utils.h')
-rw-r--r--tests/test_utils.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/test_utils.h b/tests/test_utils.h
new file mode 100644
index 00000000..815d55fd
--- /dev/null
+++ b/tests/test_utils.h
@@ -0,0 +1,42 @@
+/*
+ Copyright 2011-2017 David Robillard <http://drobilla.net>
+
+ Permission to use, copy, modify, and/or distribute this software for any
+ purpose with or without fee is hereby granted, provided that the above
+ copyright notice and this permission notice appear in all copies.
+
+ THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#ifndef SERD_TEST_UTILS_H
+#define SERD_TEST_UTILS_H
+
+#include <stdarg.h>
+#include <stdio.h>
+
+static inline int
+serd_test_failure(const char* fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ fprintf(stderr, "error: ");
+ vfprintf(stderr, fmt, args);
+ va_end(args);
+ return 1;
+}
+
+#define FAIL(fmt) \
+ fprintf(stderr, "%s:%d: ", __FILE__, __LINE__); \
+ return serd_test_failure(fmt);
+
+#define FAILF(fmt, ...) \
+ fprintf(stderr, "%s:%d: ", __FILE__, __LINE__); \
+ return serd_test_failure(fmt, __VA_ARGS__);
+
+#endif /* SERD_TEST_UTILS_H */