mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-29 05:44:08 +00:00
Update clar
This commit is contained in:
parent
61d57b7a21
commit
cf94024c58
@ -74,8 +74,8 @@ static void check_file_contents_internal(
|
|||||||
if (strip_cr)
|
if (strip_cr)
|
||||||
strip_cr_from_buf(&buf);
|
strip_cr_from_buf(&buf);
|
||||||
|
|
||||||
clar__assert_equal_i((int)expected_len, (int)buf.size, file, line, "strlen(expected_content) != strlen(actual_content)", 1);
|
clar__assert_equal(file, line, "strlen(expected_content) != strlen(actual_content)", 1, PRIuZ, expected_len, (size_t)buf.size);
|
||||||
clar__assert_equal_s(expected_content, buf.ptr, file, line, msg, 1);
|
clar__assert_equal(file, line, msg, 1, "%s", expected_content, buf.ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void check_file_contents_at_line(
|
void check_file_contents_at_line(
|
||||||
|
@ -24,28 +24,59 @@
|
|||||||
|
|
||||||
# define _MAIN_CC __cdecl
|
# define _MAIN_CC __cdecl
|
||||||
|
|
||||||
# define stat(path, st) _stat(path, st)
|
# ifndef stat
|
||||||
# define mkdir(path, mode) _mkdir(path)
|
# define stat(path, st) _stat(path, st)
|
||||||
# define chdir(path) _chdir(path)
|
# endif
|
||||||
# define access(path, mode) _access(path, mode)
|
# ifndef mkdir
|
||||||
# define strdup(str) _strdup(str)
|
# define mkdir(path, mode) _mkdir(path)
|
||||||
# define strcasecmp(a,b) _stricmp(a,b)
|
# endif
|
||||||
|
# ifndef chdir
|
||||||
|
# define chdir(path) _chdir(path)
|
||||||
|
# endif
|
||||||
|
# ifndef access
|
||||||
|
# define access(path, mode) _access(path, mode)
|
||||||
|
# endif
|
||||||
|
# ifndef strdup
|
||||||
|
# define strdup(str) _strdup(str)
|
||||||
|
# endif
|
||||||
|
# ifndef strcasecmp
|
||||||
|
# define strcasecmp(a,b) _stricmp(a,b)
|
||||||
|
# endif
|
||||||
|
|
||||||
# ifndef __MINGW32__
|
# ifndef __MINGW32__
|
||||||
# pragma comment(lib, "shell32")
|
# pragma comment(lib, "shell32")
|
||||||
# define strncpy(to, from, to_size) strncpy_s(to, to_size, from, _TRUNCATE)
|
# ifndef strncpy
|
||||||
# define W_OK 02
|
# define strncpy(to, from, to_size) strncpy_s(to, to_size, from, _TRUNCATE)
|
||||||
# define S_ISDIR(x) ((x & _S_IFDIR) != 0)
|
# endif
|
||||||
# define snprint_eq(buf,sz,fmt,...) _snprintf_s(buf,sz,_TRUNCATE,fmt,__VA_ARGS__)
|
# ifndef W_OK
|
||||||
|
# define W_OK 02
|
||||||
|
# endif
|
||||||
|
# ifndef S_ISDIR
|
||||||
|
# define S_ISDIR(x) ((x & _S_IFDIR) != 0)
|
||||||
|
# endif
|
||||||
|
# define p_snprintf(buf,sz,fmt,...) _snprintf_s(buf,sz,_TRUNCATE,fmt,__VA_ARGS__)
|
||||||
# else
|
# else
|
||||||
# define snprint_eq snprintf
|
# define p_snprintf snprintf
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# ifndef PRIuZ
|
||||||
|
# define PRIuZ "Iu"
|
||||||
|
# endif
|
||||||
|
# ifndef PRIxZ
|
||||||
|
# define PRIxZ "Ix"
|
||||||
# endif
|
# endif
|
||||||
typedef struct _stat STAT_T;
|
typedef struct _stat STAT_T;
|
||||||
#else
|
#else
|
||||||
# include <sys/wait.h> /* waitpid(2) */
|
# include <sys/wait.h> /* waitpid(2) */
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# define _MAIN_CC
|
# define _MAIN_CC
|
||||||
# define snprint_eq snprintf
|
# define p_snprintf snprintf
|
||||||
|
# ifndef PRIuZ
|
||||||
|
# define PRIuZ "zu"
|
||||||
|
# endif
|
||||||
|
# ifndef PRIxZ
|
||||||
|
# define PRIxZ "zx"
|
||||||
|
# endif
|
||||||
typedef struct stat STAT_T;
|
typedef struct stat STAT_T;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -406,45 +437,66 @@ void clar__assert(
|
|||||||
clar__fail(file, line, error_msg, description, should_abort);
|
clar__fail(file, line, error_msg, description, should_abort);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clar__assert_equal_s(
|
void clar__assert_equal(
|
||||||
const char *s1,
|
|
||||||
const char *s2,
|
|
||||||
const char *file,
|
const char *file,
|
||||||
int line,
|
int line,
|
||||||
const char *err,
|
const char *err,
|
||||||
int should_abort)
|
int should_abort,
|
||||||
|
const char *fmt,
|
||||||
|
...)
|
||||||
{
|
{
|
||||||
int match = (s1 == NULL || s2 == NULL) ? (s1 == s2) : (strcmp(s1, s2) == 0);
|
va_list args;
|
||||||
|
char buf[4096];
|
||||||
|
int is_equal = 1;
|
||||||
|
|
||||||
if (!match) {
|
va_start(args, fmt);
|
||||||
char buf[4096];
|
|
||||||
|
|
||||||
if (s1 && s2) {
|
if (!strcmp("%s", fmt)) {
|
||||||
int pos;
|
const char *s1 = va_arg(args, const char *);
|
||||||
for (pos = 0; s1[pos] == s2[pos] && s1[pos] && s2[pos]; ++pos)
|
const char *s2 = va_arg(args, const char *);
|
||||||
/* find differing byte offset */;
|
is_equal = (!s1 || !s2) ? (s1 == s2) : !strcmp(s1, s2);
|
||||||
snprint_eq(buf, sizeof(buf), "'%s' != '%s' (at byte %d)", s1, s2, pos);
|
|
||||||
} else {
|
if (!is_equal) {
|
||||||
snprint_eq(buf, sizeof(buf), "'%s' != '%s'", s1, s2);
|
if (s1 && s2) {
|
||||||
|
int pos;
|
||||||
|
for (pos = 0; s1[pos] == s2[pos] && s1[pos] && s2[pos]; ++pos)
|
||||||
|
/* find differing byte offset */;
|
||||||
|
p_snprintf(buf, sizeof(buf), "'%s' != '%s' (at byte %d)",
|
||||||
|
s1, s2, pos);
|
||||||
|
} else {
|
||||||
|
p_snprintf(buf, sizeof(buf), "'%s' != '%s'", s1, s2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clar__fail(file, line, err, buf, should_abort);
|
|
||||||
}
|
}
|
||||||
}
|
else if (!strcmp(PRIuZ, fmt) || !strcmp(PRIxZ, fmt)) {
|
||||||
|
size_t sz1 = va_arg(args, size_t), sz2 = va_arg(args, size_t);
|
||||||
void clar__assert_equal_i(
|
is_equal = (sz1 == sz2);
|
||||||
int i1,
|
if (!is_equal) {
|
||||||
int i2,
|
int offset = p_snprintf(buf, sizeof(buf), fmt, sz1);
|
||||||
const char *file,
|
strncat(buf, " != ", sizeof(buf) - offset);
|
||||||
int line,
|
p_snprintf(buf + offset + 4, sizeof(buf) - offset - 4, fmt, sz2);
|
||||||
const char *err,
|
}
|
||||||
int should_abort)
|
|
||||||
{
|
|
||||||
if (i1 != i2) {
|
|
||||||
char buf[128];
|
|
||||||
snprint_eq(buf, sizeof(buf), "%d != %d", i1, i2);
|
|
||||||
clar__fail(file, line, err, buf, should_abort);
|
|
||||||
}
|
}
|
||||||
|
else if (!strcmp("%p", fmt)) {
|
||||||
|
void *p1 = va_arg(args, void *), *p2 = va_arg(args, void *);
|
||||||
|
is_equal = (p1 == p2);
|
||||||
|
if (!is_equal)
|
||||||
|
p_snprintf(buf, sizeof(buf), "%p != %p", p1, p2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int i1 = va_arg(args, int), i2 = va_arg(args, int);
|
||||||
|
is_equal = (i1 == i2);
|
||||||
|
if (!is_equal) {
|
||||||
|
int offset = p_snprintf(buf, sizeof(buf), fmt, i1);
|
||||||
|
strncat(buf, " != ", sizeof(buf) - offset);
|
||||||
|
p_snprintf(buf + offset + 4, sizeof(buf) - offset - 4, fmt, i2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
if (!is_equal)
|
||||||
|
clar__fail(file, line, err, buf, should_abort);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cl_set_cleanup(void (*cleanup)(void *), void *opaque)
|
void cl_set_cleanup(void (*cleanup)(void *), void *opaque)
|
||||||
|
@ -57,15 +57,17 @@ void cl_fixture_cleanup(const char *fixture_name);
|
|||||||
/**
|
/**
|
||||||
* Typed assertion macros
|
* Typed assertion macros
|
||||||
*/
|
*/
|
||||||
#define cl_assert_equal_s(s1,s2) clar__assert_equal_s((s1),(s2),__FILE__,__LINE__,"String mismatch: " #s1 " != " #s2, 1)
|
#define cl_assert_equal_s(s1,s2) clar__assert_equal(__FILE__,__LINE__,"String mismatch: " #s1 " != " #s2, 1, "%s", (s1), (s2))
|
||||||
#define cl_assert_equal_s_(s1,s2,note) clar__assert_equal_s((s1),(s2),__FILE__,__LINE__,"String mismatch: " #s1 " != " #s2 " (" #note ")", 1)
|
#define cl_assert_equal_s_(s1,s2,note) clar__assert_equal(__FILE__,__LINE__,"String mismatch: " #s1 " != " #s2 " (" #note ")", 1, "%s", (s1), (s2))
|
||||||
|
|
||||||
#define cl_assert_equal_i(i1,i2) clar__assert_equal_i((i1),(i2),__FILE__,__LINE__,#i1 " != " #i2, 1)
|
#define cl_assert_equal_i(i1,i2) clar__assert_equal(__FILE__,__LINE__,#i1 " != " #i2, 1, "%d", (int)(i1), (int)(i2))
|
||||||
#define cl_assert_equal_i_(i1,i2,note) clar__assert_equal_i((i1),(i2),__FILE__,__LINE__,#i1 " != " #i2 " (" #note ")", 1)
|
#define cl_assert_equal_i_(i1,i2,note) clar__assert_equal(__FILE__,__LINE__,#i1 " != " #i2 " (" #note ")", 1, "%d", (i1), (i2))
|
||||||
|
#define cl_assert_equal_i_fmt(i1,i2,fmt) clar__assert_equal(__FILE__,__LINE__,#i1 " != " #i2, 1, (fmt), (int)(i1), (int)(i2))
|
||||||
|
|
||||||
#define cl_assert_equal_b(b1,b2) clar__assert_equal_i(!!(b1),!!(b2),__FILE__,__LINE__,#b1 " != " #b2, 1)
|
#define cl_assert_equal_b(b1,b2) clar__assert_equal(__FILE__,__LINE__,#b1 " != " #b2, 1, "%d", (int)((b1) != 0),(int)((b2) != 0))
|
||||||
|
|
||||||
|
#define cl_assert_equal_p(p1,p2) clar__assert_equal(__FILE__,__LINE__,"Pointer mismatch: " #p1 " != " #p2, 1, "%p", (p1), (p2))
|
||||||
|
|
||||||
#define cl_assert_equal_p(p1,p2) cl_assert((p1) == (p2))
|
|
||||||
|
|
||||||
void clar__fail(
|
void clar__fail(
|
||||||
const char *file,
|
const char *file,
|
||||||
@ -82,7 +84,12 @@ void clar__assert(
|
|||||||
const char *description,
|
const char *description,
|
||||||
int should_abort);
|
int should_abort);
|
||||||
|
|
||||||
void clar__assert_equal_s(const char *,const char *,const char *,int,const char *,int);
|
void clar__assert_equal(
|
||||||
void clar__assert_equal_i(int,int,const char *,int,const char *,int);
|
const char *file,
|
||||||
|
int line,
|
||||||
|
const char *err,
|
||||||
|
int should_abort,
|
||||||
|
const char *fmt,
|
||||||
|
...);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -43,10 +43,8 @@ find_tmp_path(char *buffer, size_t length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
DWORD env_len;
|
DWORD env_len = GetEnvironmentVariable("CLAR_TMP", buffer, (DWORD)length);
|
||||||
|
if (env_len > 0 && env_len < (DWORD)length)
|
||||||
if ((env_len = GetEnvironmentVariable("CLAR_TMP", buffer, length)) > 0 &&
|
|
||||||
env_len < length)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (GetTempPath((DWORD)length, buffer))
|
if (GetTempPath((DWORD)length, buffer))
|
||||||
|
@ -39,8 +39,9 @@ static void check_diff_patches_at_line(
|
|||||||
|
|
||||||
cl_git_pass(git_diff_patch_to_str(&patch_text, patch));
|
cl_git_pass(git_diff_patch_to_str(&patch_text, patch));
|
||||||
|
|
||||||
clar__assert_equal_s(expected[d], patch_text, file, line,
|
clar__assert_equal(
|
||||||
"expected diff did not match actual diff", 1);
|
file, line, "expected diff did not match actual diff", 1,
|
||||||
|
"%s", expected[d], patch_text);
|
||||||
git__free(patch_text);
|
git__free(patch_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user