+#ifndef CCAN_TAP_H
+#define CCAN_TAP_H
/*-
* Copyright (c) 2004 Nik Clayton
* All rights reserved.
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+#include <ccan/compiler/compiler.h>
/**
* plan_tests - announce the number of tests you plan to run
*/
void plan_tests(unsigned int tests);
-#if (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) && !defined(__GNUC__)
-# error "Needs gcc or C99 compiler for variadic macros."
-#else
-
/**
* ok1 - Simple conditional test
* @e: the expression which we expect to be true.
* file name, line number, and the expression itself.
*
* Example:
- * ok1(init_subsystem() == 1);
+ * ok1(somefunc() == 1);
*/
# define ok1(e) ((e) ? \
_gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) : \
* than simply the expression itself.
*
* Example:
- * ok1(init_subsystem() == 1);
- * ok(init_subsystem() == 0, "Second initialization should fail");
+ * ok1(somefunc() == 1);
+ * ok(somefunc() == 0, "Second somefunc() should fail");
*/
# define ok(e, ...) ((e) ? \
_gen_result(1, __func__, __FILE__, __LINE__, \
* branch and fail() in another.
*
* Example:
- * x = do_something();
- * if (!checkable(x) || check_value(x))
- * pass("do_something() returned a valid value");
- * else
- * fail("do_something() returned an invalid value");
+ * int x = somefunc();
+ * if (x > 0)
+ * pass("somefunc() returned a valid value");
+ * else
+ * fail("somefunc() returned an invalid value");
*/
# define pass(...) ok(1, __VA_ARGS__)
# define skip_end } while(0)
-#ifndef PRINTF_ATTRIBUTE
-#ifdef __GNUC__
-#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
-#else
-#define PRINTF_ATTRIBUTE(a1, a2)
-#endif
-#endif
-
-unsigned int _gen_result(int, const char *, char *, unsigned int, char *, ...)
- PRINTF_ATTRIBUTE(5, 6);
+unsigned int _gen_result(int, const char *, const char *, unsigned int,
+ const char *, ...) PRINTF_FMT(5, 6);
/**
* diag - print a diagnostic message (use instead of printf/fprintf)
* Example:
* diag("Now running complex tests");
*/
-void diag(char *fmt, ...) PRINTF_ATTRIBUTE(1, 2);
+void diag(const char *fmt, ...) PRINTF_FMT(1, 2);
/**
* skip - print a diagnostic message (use instead of printf/fprintf)
*
* Example:
* #ifdef HAVE_SOME_FEATURE
- * ok1(test_some_feature());
+ * ok1(somefunc());
* #else
* skip(1, "Don't have SOME_FEATURE");
* #endif
*/
-void skip(unsigned int n, char *fmt, ...) PRINTF_ATTRIBUTE(2, 3);
+void skip(unsigned int n, const char *fmt, ...) PRINTF_FMT(2, 3);
/**
* todo_start - mark tests that you expect to fail.
* This way, should a test start to succeed unexpectedly, tools like prove(1)
* will indicate this and you can move the test out of the todo block. This
* is much more useful than simply commenting out (or '#if 0') the tests.
- *
+ *
* From the Test::More documentation:
* If it's something the programmer hasn't done yet, use TODO. This is for
* any code you haven't written yet, or bugs you have yet to fix, but want to
* put tests in your testing script (always a good idea).
*
* Example:
+ * static bool dwim(void)
+ * {
+ * return false; // NYI
+ * }
+ * ...
* todo_start("dwim() not returning true yet");
* ok(dwim(), "Did what the user wanted");
* todo_end();
*/
-void todo_start(char *fmt, ...) PRINTF_ATTRIBUTE(1, 2);
+void todo_start(const char *fmt, ...) PRINTF_FMT(1, 2);
/**
* todo_end - end of tests you expect to fail.
/**
* exit_status - the value that main should return.
*
- * For maximum compatability your test program should return a particular exit
+ * For maximum compatibility your test program should return a particular exit
* code (ie. 0 if all tests were run, and every test which was expected to
* succeed succeeded).
*
* Example:
* plan_no_plan();
* while (random() % 2)
- * ok1(some_test());
+ * ok1(somefunc());
* exit(exit_status());
*/
void plan_no_plan(void);
* in the running kernel) use plan_skip_all() instead of plan_tests().
*
* Example:
- * if (!have_some_feature) {
- * plan_skip_all("Need some_feature support");
- * exit(exit_status());
- * }
+ * #ifndef HAVE_SOME_FEATURE
+ * plan_skip_all("Need SOME_FEATURE support");
+ * exit(exit_status());
+ * #else
* plan_tests(13);
+ * ...
+ * #endif
+ */
+void plan_skip_all(const char *reason);
+
+/**
+ * tap_fail_callback - function to call when we fail
+ *
+ * This can be used to ease debugging, or exit on the first failure.
*/
-void plan_skip_all(char *reason);
+extern void (*tap_fail_callback)(void);
-#endif /* C99 or gcc */
+#endif /* CCAN_TAP_H */