]>
Commit | Line | Data |
---|---|---|
3fd1520c VM |
1 | #ifndef __CLAR_LIBGIT2__ |
2 | #define __CLAR_LIBGIT2__ | |
f1558d9b | 3 | |
3fd1520c | 4 | #include "clar.h" |
f1558d9b VM |
5 | #include <git2.h> |
6 | #include "common.h" | |
7 | ||
8 | /** | |
3fd1520c | 9 | * Special wrapper for `clar_must_pass` that passes |
f1558d9b VM |
10 | * the last library error as the test failure message. |
11 | * | |
12 | * Use this wrapper around all `git_` library calls that | |
13 | * return error codes! | |
14 | */ | |
15 | #define cl_git_pass(expr) do { \ | |
3fbcac89 VM |
16 | giterr_clear(); \ |
17 | if ((expr) != 0) \ | |
9b62e40e | 18 | clar__assert(0, __FILE__, __LINE__, "Function call failed: " #expr, giterr_last() ? giterr_last()->message : NULL, 1); \ |
b026b00d | 19 | } while(0) |
f1558d9b VM |
20 | |
21 | /** | |
3fd1520c | 22 | * Wrapper for `clar_must_fail` -- this one is |
f1558d9b VM |
23 | * just for consistency. Use with `git_` library |
24 | * calls that are supposed to fail! | |
25 | */ | |
d1a721c5 | 26 | #define cl_git_fail(expr) cl_must_fail(expr) |
f1558d9b | 27 | |
e9ca852e RB |
28 | #define cl_assert_equal_sz(sz1,sz2) cl_assert((sz1) == (sz2)) |
29 | ||
97769280 RB |
30 | /* |
31 | * Some utility macros for building long strings | |
32 | */ | |
33 | #define REP4(STR) STR STR STR STR | |
34 | #define REP15(STR) REP4(STR) REP4(STR) REP4(STR) STR STR STR | |
35 | #define REP16(STR) REP4(REP4(STR)) | |
36 | #define REP256(STR) REP16(REP16(STR)) | |
37 | #define REP1024(STR) REP4(REP256(STR)) | |
38 | ||
1d415455 VM |
39 | /* Write the contents of a buffer to disk */ |
40 | void cl_git_mkfile(const char *filename, const char *content); | |
ce49c7a8 | 41 | void cl_git_append2file(const char *filename, const char *new_content); |
7784bcbb | 42 | void cl_git_rewritefile(const char *filename, const char *new_content); |
da825c92 | 43 | void cl_git_write2file(const char *filename, const char *new_content, int flags, unsigned int mode); |
1d415455 | 44 | |
0abd7244 RB |
45 | bool cl_toggle_filemode(const char *filename); |
46 | bool cl_is_chmod_supported(void); | |
47 | ||
e272efcb BS |
48 | /* Environment wrappers */ |
49 | char *cl_getenv(const char *name); | |
50 | int cl_setenv(const char *name, const char *value); | |
51 | ||
854eccbb RB |
52 | /* Git sandbox setup helpers */ |
53 | ||
54 | git_repository *cl_git_sandbox_init(const char *sandbox); | |
55 | void cl_git_sandbox_cleanup(void); | |
56 | ||
f1558d9b | 57 | #endif |