Hash :
7784bcbb
Author :
Date :
2012-04-11T11:52:59
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
#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, err, buf, 1);
}
}
#define cl_assert_intequal(a,b) \
do { if ((a) != (b)) { char buf[128]; snprintf(buf,128,"%d != %d",(a),(b)); clar__assert(0,__FILE__,__LINE__,#a " != " #b,buf,1); } } while (0)
/*
* 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);
void cl_git_append2file(const char *filename, const char *new_content);
void cl_git_rewritefile(const char *filename, const char *new_content);
void cl_git_write2file(const char *filename, const char *new_content, int mode);
/* Git sandbox setup helpers */
git_repository *cl_git_sandbox_init(const char *sandbox);
void cl_git_sandbox_cleanup(void);
#endif