summaryrefslogtreecommitdiff
path: root/tests-clar/clar_libgit2.h
diff options
context:
space:
mode:
authorVicent Martí <tanoku@gmail.com>2012-01-24 20:35:15 -0800
committerVicent Martí <tanoku@gmail.com>2012-01-24 20:35:15 -0800
commit3fd1520cd4d8b4d6b6493a7d3dc393ffd9abf1db (patch)
tree51b29f5d8ffeb31ba751ab2a099e4f2a32d4be07 /tests-clar/clar_libgit2.h
parenta9fe8ae0ee1ddcc289fad53f1a671f02a3e9a88f (diff)
downloadlibgit2-3fd1520cd4d8b4d6b6493a7d3dc393ffd9abf1db.tar.gz
Rename the Clay test suite to Clar
Clay is the name of a programming language on the makings, and we want to avoid confusions. Sorry for the huge diff!
Diffstat (limited to 'tests-clar/clar_libgit2.h')
-rw-r--r--tests-clar/clar_libgit2.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests-clar/clar_libgit2.h b/tests-clar/clar_libgit2.h
new file mode 100644
index 000000000..73ef66844
--- /dev/null
+++ b/tests-clar/clar_libgit2.h
@@ -0,0 +1,57 @@
+#ifndef __CLAR_LIBGIT2__
+#define __CLAR_LIBGIT2__
+
+#include "clar.h"
+#include <git2.h>
+#include "common.h"
+
+/**
+ * Special wrapper 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!
+ */
+#define cl_git_pass(expr) do { \
+ git_clearerror(); \
+ if ((expr) != GIT_SUCCESS) \
+ clar__assert(0, __FILE__, __LINE__, "Function call failed: " #expr, git_lasterror(), 1); \
+ } while(0)
+
+/**
+ * Wrapper for `clar_must_fail` -- this one is
+ * just for consistency. Use with `git_` library
+ * calls that are supposed to fail!
+ */
+#define cl_git_fail(expr) cl_must_fail(expr)
+
+/**
+ * Wrapper for string comparison that knows about nulls.
+ */
+#define cl_assert_strequal(a,b) \
+ cl_assert_strequal_internal(a,b,__FILE__,__LINE__,"string mismatch: " #a " != " #b)
+
+GIT_INLINE(void) cl_assert_strequal_internal(
+ const char *a, const char *b, const char *file, int line, const char *err)
+{
+ int match = (a == NULL || b == NULL) ? (a == b) : (strcmp(a, b) == 0);
+ if (!match) {
+ char buf[4096];
+ snprintf(buf, 4096, "'%s' != '%s'", a, b);
+ clar__assert(0, file, line, buf, err, 1);
+ }
+}
+
+/*
+ * Some utility macros for building long strings
+ */
+#define REP4(STR) STR STR STR STR
+#define REP15(STR) REP4(STR) REP4(STR) REP4(STR) STR STR STR
+#define REP16(STR) REP4(REP4(STR))
+#define REP256(STR) REP16(REP16(STR))
+#define REP1024(STR) REP4(REP256(STR))
+
+/* Write the contents of a buffer to disk */
+void cl_git_mkfile(const char *filename, const char *content);
+
+#endif