]>
git.proxmox.com Git - libgit2.git/blob - tests/clar_libgit2.h
1 #ifndef __CLAR_LIBGIT2__
2 #define __CLAR_LIBGIT2__
9 * Replace for `clar_must_pass` that passes the last library error as the
10 * test failure message.
12 * Use this wrapper around all `git_` library calls that return error codes!
14 #define cl_git_pass(expr) cl_git_pass_((expr), __FILE__, __LINE__)
16 #define cl_git_pass_(expr, file, line) do { \
19 if ((_lg2_error = (expr)) != 0) \
20 cl_git_report_failure(_lg2_error, file, line, "Function call failed: " #expr); \
24 * Wrapper for `clar_must_fail` -- this one is
25 * just for consistency. Use with `git_` library
26 * calls that are supposed to fail!
28 #define cl_git_fail(expr) cl_must_fail(expr)
30 #define cl_git_fail_with(expr, error) cl_assert_equal_i(error,expr)
32 void cl_git_report_failure(int, const char *, int, const char *);
34 #define cl_assert_at_line(expr,file,line) \
35 clar__assert((expr) != 0, file, line, "Expression is not true: " #expr, NULL, 1)
37 GIT_INLINE(void) clar__assert_in_range(
38 int lo
, int val
, int hi
,
39 const char *file
, int line
, const char *err
, int should_abort
)
41 if (lo
> val
|| hi
< val
) {
43 snprintf(buf
, sizeof(buf
), "%d not in [%d,%d]", val
, lo
, hi
);
44 clar__fail(file
, line
, err
, buf
, should_abort
);
48 #define cl_assert_equal_sz(sz1,sz2) do { \
49 size_t __sz1 = (size_t)(sz1), __sz2 = (size_t)(sz2); \
50 clar__assert_equal(__FILE__,__LINE__,#sz1 " != " #sz2, 1, "%"PRIuZ, __sz1, __sz2); \
53 #define cl_assert_in_range(L,V,H) \
54 clar__assert_in_range((L),(V),(H),__FILE__,__LINE__,"Range check: " #V " in [" #L "," #H "]", 1)
56 #define cl_assert_equal_file(DATA,SIZE,PATH) \
57 clar__assert_equal_file(DATA,SIZE,0,PATH,__FILE__,(int)__LINE__)
59 #define cl_assert_equal_file_ignore_cr(DATA,SIZE,PATH) \
60 clar__assert_equal_file(DATA,SIZE,1,PATH,__FILE__,(int)__LINE__)
62 void clar__assert_equal_file(
63 const char *expected_data
,
71 * Some utility macros for building long strings
73 #define REP4(STR) STR STR STR STR
74 #define REP15(STR) REP4(STR) REP4(STR) REP4(STR) STR STR STR
75 #define REP16(STR) REP4(REP4(STR))
76 #define REP256(STR) REP16(REP16(STR))
77 #define REP1024(STR) REP4(REP256(STR))
79 /* Write the contents of a buffer to disk */
80 void cl_git_mkfile(const char *filename
, const char *content
);
81 void cl_git_append2file(const char *filename
, const char *new_content
);
82 void cl_git_rewritefile(const char *filename
, const char *new_content
);
83 void cl_git_write2file(const char *path
, const char *data
,
84 size_t datalen
, int flags
, unsigned int mode
);
86 bool cl_toggle_filemode(const char *filename
);
87 bool cl_is_chmod_supported(void);
89 /* Environment wrappers */
90 char *cl_getenv(const char *name
);
91 int cl_setenv(const char *name
, const char *value
);
94 int cl_rename(const char *source
, const char *dest
);
96 /* Git sandbox setup helpers */
98 git_repository
*cl_git_sandbox_init(const char *sandbox
);
99 void cl_git_sandbox_cleanup(void);
100 git_repository
*cl_git_sandbox_reopen(void);
102 /* Local-repo url helpers */
103 const char* cl_git_fixture_url(const char *fixturename
);
104 const char* cl_git_path_url(const char *path
);
106 /* Test repository cleaner */
107 int cl_git_remove_placeholders(const char *directory_path
, const char *filename
);
109 /* commit creation helpers */
110 void cl_repo_commit_from_index(
112 git_repository
*repo
,
117 /* config setting helpers */
118 void cl_repo_set_bool(git_repository
*repo
, const char *cfg
, int value
);
119 int cl_repo_get_bool(git_repository
*repo
, const char *cfg
);
121 void cl_repo_set_string(git_repository
*repo
, const char *cfg
, const char *value
);
123 void cl_fake_home(git_buf
*restore
);
124 void cl_fake_home_cleanup(git_buf
*restore
);