summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2012-12-19 14:52:12 -0800
committerRussell Belfer <rb@github.com>2013-01-04 15:23:47 -0800
commite9e20c8474b4f7ecdb1076c2f2d9c06f21e6be5b (patch)
tree33fbfba821ba0469e079da7c91f4075c2a0349b2
parent6040616214c69a53d2155c2378b31a0d65e37567 (diff)
downloadlibgit2-e9e20c8474b4f7ecdb1076c2f2d9c06f21e6be5b.tar.gz
Update cl_git_pass to return more info
This adds a failure reporting function that is called by cl_git_pass which captures the actual error return code and the error message if available in the failure report.
-rw-r--r--tests-clar/clar_libgit2.c10
-rw-r--r--tests-clar/clar_libgit2.h18
2 files changed, 21 insertions, 7 deletions
diff --git a/tests-clar/clar_libgit2.c b/tests-clar/clar_libgit2.c
index ce3ec4af4..88ffb2bca 100644
--- a/tests-clar/clar_libgit2.c
+++ b/tests-clar/clar_libgit2.c
@@ -2,6 +2,16 @@
#include "posix.h"
#include "path.h"
+void cl_git_report_failure(
+ int error, const char *file, int line, const char *fncall)
+{
+ char msg[4096];
+ const git_error *last = giterr_last();
+ p_snprintf(msg, 4096, "error %d - %s",
+ error, last ? last->message : "<no message>");
+ clar__assert(0, file, line, fncall, msg, 1);
+}
+
void cl_git_mkfile(const char *filename, const char *content)
{
int fd;
diff --git a/tests-clar/clar_libgit2.h b/tests-clar/clar_libgit2.h
index 91a542654..321ec5f2f 100644
--- a/tests-clar/clar_libgit2.h
+++ b/tests-clar/clar_libgit2.h
@@ -6,17 +6,17 @@
#include "common.h"
/**
- * Special wrapper for `clar_must_pass` that passes
- * the last library error as the test failure message.
+ * Replace for `clar_must_pass` that passes the last library error as the
+ * test failure message.
*
- * Use this wrapper around all `git_` library calls that
- * return error codes!
+ * Use this wrapper around all `git_` library calls that return error codes!
*/
#define cl_git_pass(expr) do { \
+ int _lg2_error; \
giterr_clear(); \
- if ((expr) != 0) \
- clar__assert(0, __FILE__, __LINE__, "Function call failed: " #expr, giterr_last() ? giterr_last()->message : NULL, 1); \
- } while(0)
+ if ((_lg2_error = (expr)) != 0) \
+ cl_git_report_failure(_lg2_error, __FILE__, __LINE__, "Function call failed: " #expr); \
+ } while (0)
/**
* Wrapper for `clar_must_fail` -- this one is
@@ -25,6 +25,10 @@
*/
#define cl_git_fail(expr) cl_must_fail(expr)
+#define cl_git_fail_with(expr, error) cl_assert_equal_i(error,expr)
+
+void cl_git_report_failure(int, const char *, int, const char *);
+
#define cl_assert_equal_sz(sz1,sz2) cl_assert((sz1) == (sz2))
/*