Unverified Commit c708e5e5 by Edward Thomson Committed by GitHub

Merge pull request #5541 from libgit2/ethomson/clar_tap

clar: add tap output option
parents b4290518 cad7a1ba
...@@ -108,7 +108,7 @@ done: ...@@ -108,7 +108,7 @@ done:
git_buf details = GIT_BUF_INIT; git_buf details = GIT_BUF_INIT;
git_buf_printf(&details, "filename=%s, system=%s, autocrlf=%s, attrs={%s}", git_buf_printf(&details, "filename=%s, system=%s, autocrlf=%s, attrs={%s}",
git_path_basename(actual_path->ptr), systype, cd->autocrlf, cd->attrs); git_path_basename(actual_path->ptr), systype, cd->autocrlf, cd->attrs);
clar__fail(__FILE__, __LINE__, clar__fail(__FILE__, __func__, __LINE__,
"checked out contents did not match expected", details.ptr, 0); "checked out contents did not match expected", details.ptr, 0);
git_buf_dispose(&details); git_buf_dispose(&details);
} }
......
...@@ -96,6 +96,7 @@ fixture_path(const char *base, const char *fixture_name); ...@@ -96,6 +96,7 @@ fixture_path(const char *base, const char *fixture_name);
struct clar_error { struct clar_error {
const char *file; const char *file;
const char *function;
size_t line_number; size_t line_number;
const char *error_msg; const char *error_msg;
char *description; char *description;
...@@ -140,6 +141,8 @@ static struct { ...@@ -140,6 +141,8 @@ static struct {
int tests_ran; int tests_ran;
int suites_ran; int suites_ran;
enum cl_output_format output_format;
int report_errors_only; int report_errors_only;
int exit_on_error; int exit_on_error;
int report_suite_names; int report_suite_names;
...@@ -370,6 +373,7 @@ clar_usage(const char *arg) ...@@ -370,6 +373,7 @@ clar_usage(const char *arg)
printf(" -v Increase verbosity (show suite names)\n"); printf(" -v Increase verbosity (show suite names)\n");
printf(" -q Only report tests that had an error\n"); printf(" -q Only report tests that had an error\n");
printf(" -Q Quit as soon as a test fails\n"); printf(" -Q Quit as soon as a test fails\n");
printf(" -t Display results in tap format\n");
printf(" -l Print suite names\n"); printf(" -l Print suite names\n");
printf(" -r[filename] Write summary file (to the optional filename)\n"); printf(" -r[filename] Write summary file (to the optional filename)\n");
exit(-1); exit(-1);
...@@ -385,7 +389,7 @@ clar_parse_args(int argc, char **argv) ...@@ -385,7 +389,7 @@ clar_parse_args(int argc, char **argv)
char *argument = argv[i]; char *argument = argv[i];
if (argument[0] != '-' || argument[1] == '\0' if (argument[0] != '-' || argument[1] == '\0'
|| strchr("sixvqQlr", argument[1]) == NULL) { || strchr("sixvqQtlr", argument[1]) == NULL) {
clar_usage(argv[0]); clar_usage(argv[0]);
} }
} }
...@@ -468,6 +472,10 @@ clar_parse_args(int argc, char **argv) ...@@ -468,6 +472,10 @@ clar_parse_args(int argc, char **argv)
_clar.exit_on_error = 1; _clar.exit_on_error = 1;
break; break;
case 't':
_clar.output_format = CL_OUTPUT_TAP;
break;
case 'l': { case 'l': {
size_t j; size_t j;
printf("Test suites (use -s<name> to run just one):\n"); printf("Test suites (use -s<name> to run just one):\n");
...@@ -496,6 +504,9 @@ clar_parse_args(int argc, char **argv) ...@@ -496,6 +504,9 @@ clar_parse_args(int argc, char **argv)
void void
clar_test_init(int argc, char **argv) clar_test_init(int argc, char **argv)
{ {
if (argc > 1)
clar_parse_args(argc, argv);
clar_print_init( clar_print_init(
(int)_clar_callback_count, (int)_clar_callback_count,
(int)_clar_suite_count, (int)_clar_suite_count,
...@@ -507,9 +518,6 @@ clar_test_init(int argc, char **argv) ...@@ -507,9 +518,6 @@ clar_test_init(int argc, char **argv)
_clar.summary_filename = strdup(_clar.summary_filename); _clar.summary_filename = strdup(_clar.summary_filename);
} }
if (argc > 1)
clar_parse_args(argc, argv);
if (_clar.write_summary && if (_clar.write_summary &&
!(_clar.summary = clar_summary_init(_clar.summary_filename))) { !(_clar.summary = clar_summary_init(_clar.summary_filename))) {
clar_print_onabort("Failed to open the summary file\n"); clar_print_onabort("Failed to open the summary file\n");
...@@ -605,6 +613,7 @@ void clar__skip(void) ...@@ -605,6 +613,7 @@ void clar__skip(void)
void clar__fail( void clar__fail(
const char *file, const char *file,
const char *function,
size_t line, size_t line,
const char *error_msg, const char *error_msg,
const char *description, const char *description,
...@@ -621,6 +630,7 @@ void clar__fail( ...@@ -621,6 +630,7 @@ void clar__fail(
_clar.last_report->last_error = error; _clar.last_report->last_error = error;
error->file = file; error->file = file;
error->function = function;
error->line_number = line; error->line_number = line;
error->error_msg = error_msg; error->error_msg = error_msg;
...@@ -637,6 +647,7 @@ void clar__fail( ...@@ -637,6 +647,7 @@ void clar__fail(
void clar__assert( void clar__assert(
int condition, int condition,
const char *file, const char *file,
const char *function,
size_t line, size_t line,
const char *error_msg, const char *error_msg,
const char *description, const char *description,
...@@ -645,11 +656,12 @@ void clar__assert( ...@@ -645,11 +656,12 @@ void clar__assert(
if (condition) if (condition)
return; return;
clar__fail(file, line, error_msg, description, should_abort); clar__fail(file, function, line, error_msg, description, should_abort);
} }
void clar__assert_equal( void clar__assert_equal(
const char *file, const char *file,
const char *function,
size_t line, size_t line,
const char *err, const char *err,
int should_abort, int should_abort,
...@@ -760,7 +772,7 @@ void clar__assert_equal( ...@@ -760,7 +772,7 @@ void clar__assert_equal(
va_end(args); va_end(args);
if (!is_equal) if (!is_equal)
clar__fail(file, line, err, buf, should_abort); clar__fail(file, function, line, err, buf, should_abort);
} }
void cl_set_cleanup(void (*cleanup)(void *), void *opaque) void cl_set_cleanup(void (*cleanup)(void *), void *opaque)
......
...@@ -16,6 +16,11 @@ enum cl_test_status { ...@@ -16,6 +16,11 @@ enum cl_test_status {
CL_TEST_NOTRUN, CL_TEST_NOTRUN,
}; };
enum cl_output_format {
CL_OUTPUT_CLAP,
CL_OUTPUT_TAP,
};
/** Setup clar environment */ /** Setup clar environment */
void clar_test_init(int argc, char *argv[]); void clar_test_init(int argc, char *argv[]);
int clar_test_run(void); int clar_test_run(void);
...@@ -81,16 +86,16 @@ const char *cl_fixture_basename(const char *fixture_name); ...@@ -81,16 +86,16 @@ const char *cl_fixture_basename(const char *fixture_name);
/** /**
* Assertion macros with explicit error message * Assertion macros with explicit error message
*/ */
#define cl_must_pass_(expr, desc) clar__assert((expr) >= 0, __FILE__, __LINE__, "Function call failed: " #expr, desc, 1) #define cl_must_pass_(expr, desc) clar__assert((expr) >= 0, __FILE__, __func__, __LINE__, "Function call failed: " #expr, desc, 1)
#define cl_must_fail_(expr, desc) clar__assert((expr) < 0, __FILE__, __LINE__, "Expected function call to fail: " #expr, desc, 1) #define cl_must_fail_(expr, desc) clar__assert((expr) < 0, __FILE__, __func__, __LINE__, "Expected function call to fail: " #expr, desc, 1)
#define cl_assert_(expr, desc) clar__assert((expr) != 0, __FILE__, __LINE__, "Expression is not true: " #expr, desc, 1) #define cl_assert_(expr, desc) clar__assert((expr) != 0, __FILE__, __func__, __LINE__, "Expression is not true: " #expr, desc, 1)
/** /**
* Check macros with explicit error message * Check macros with explicit error message
*/ */
#define cl_check_pass_(expr, desc) clar__assert((expr) >= 0, __FILE__, __LINE__, "Function call failed: " #expr, desc, 0) #define cl_check_pass_(expr, desc) clar__assert((expr) >= 0, __FILE__, __func__, __LINE__, "Function call failed: " #expr, desc, 0)
#define cl_check_fail_(expr, desc) clar__assert((expr) < 0, __FILE__, __LINE__, "Expected function call to fail: " #expr, desc, 0) #define cl_check_fail_(expr, desc) clar__assert((expr) < 0, __FILE__, __func__, __LINE__, "Expected function call to fail: " #expr, desc, 0)
#define cl_check_(expr, desc) clar__assert((expr) != 0, __FILE__, __LINE__, "Expression is not true: " #expr, desc, 0) #define cl_check_(expr, desc) clar__assert((expr) != 0, __FILE__, __func__, __LINE__, "Expression is not true: " #expr, desc, 0)
/** /**
* Assertion macros with no error message * Assertion macros with no error message
...@@ -109,38 +114,39 @@ const char *cl_fixture_basename(const char *fixture_name); ...@@ -109,38 +114,39 @@ const char *cl_fixture_basename(const char *fixture_name);
/** /**
* Forced failure/warning * Forced failure/warning
*/ */
#define cl_fail(desc) clar__fail(__FILE__, __LINE__, "Test failed.", desc, 1) #define cl_fail(desc) clar__fail(__FILE__, __func__, __LINE__, "Test failed.", desc, 1)
#define cl_warning(desc) clar__fail(__FILE__, __LINE__, "Warning during test execution:", desc, 0) #define cl_warning(desc) clar__fail(__FILE__, __func__, __LINE__, "Warning during test execution:", desc, 0)
#define cl_skip() clar__skip() #define cl_skip() clar__skip()
/** /**
* Typed assertion macros * Typed assertion macros
*/ */
#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) clar__assert_equal(__FILE__,__func__,__LINE__,"String mismatch: " #s1 " != " #s2, 1, "%s", (s1), (s2))
#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_s_(s1,s2,note) clar__assert_equal(__FILE__,__func__,__LINE__,"String mismatch: " #s1 " != " #s2 " (" #note ")", 1, "%s", (s1), (s2))
#define cl_assert_equal_wcs(wcs1,wcs2) clar__assert_equal(__FILE__,__LINE__,"String mismatch: " #wcs1 " != " #wcs2, 1, "%ls", (wcs1), (wcs2)) #define cl_assert_equal_wcs(wcs1,wcs2) clar__assert_equal(__FILE__,__func__,__LINE__,"String mismatch: " #wcs1 " != " #wcs2, 1, "%ls", (wcs1), (wcs2))
#define cl_assert_equal_wcs_(wcs1,wcs2,note) clar__assert_equal(__FILE__,__LINE__,"String mismatch: " #wcs1 " != " #wcs2 " (" #note ")", 1, "%ls", (wcs1), (wcs2)) #define cl_assert_equal_wcs_(wcs1,wcs2,note) clar__assert_equal(__FILE__,__func__,__LINE__,"String mismatch: " #wcs1 " != " #wcs2 " (" #note ")", 1, "%ls", (wcs1), (wcs2))
#define cl_assert_equal_strn(s1,s2,len) clar__assert_equal(__FILE__,__LINE__,"String mismatch: " #s1 " != " #s2, 1, "%.*s", (s1), (s2), (int)(len)) #define cl_assert_equal_strn(s1,s2,len) clar__assert_equal(__FILE__,__func__,__LINE__,"String mismatch: " #s1 " != " #s2, 1, "%.*s", (s1), (s2), (int)(len))
#define cl_assert_equal_strn_(s1,s2,len,note) clar__assert_equal(__FILE__,__LINE__,"String mismatch: " #s1 " != " #s2 " (" #note ")", 1, "%.*s", (s1), (s2), (int)(len)) #define cl_assert_equal_strn_(s1,s2,len,note) clar__assert_equal(__FILE__,__func__,__LINE__,"String mismatch: " #s1 " != " #s2 " (" #note ")", 1, "%.*s", (s1), (s2), (int)(len))
#define cl_assert_equal_wcsn(wcs1,wcs2,len) clar__assert_equal(__FILE__,__LINE__,"String mismatch: " #wcs1 " != " #wcs2, 1, "%.*ls", (wcs1), (wcs2), (int)(len)) #define cl_assert_equal_wcsn(wcs1,wcs2,len) clar__assert_equal(__FILE__,__func__,__LINE__,"String mismatch: " #wcs1 " != " #wcs2, 1, "%.*ls", (wcs1), (wcs2), (int)(len))
#define cl_assert_equal_wcsn_(wcs1,wcs2,len,note) clar__assert_equal(__FILE__,__LINE__,"String mismatch: " #wcs1 " != " #wcs2 " (" #note ")", 1, "%.*ls", (wcs1), (wcs2), (int)(len)) #define cl_assert_equal_wcsn_(wcs1,wcs2,len,note) clar__assert_equal(__FILE__,__func__,__LINE__,"String mismatch: " #wcs1 " != " #wcs2 " (" #note ")", 1, "%.*ls", (wcs1), (wcs2), (int)(len))
#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) clar__assert_equal(__FILE__,__func__,__LINE__,#i1 " != " #i2, 1, "%d", (int)(i1), (int)(i2))
#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_(i1,i2,note) clar__assert_equal(__FILE__,__func__,__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_i_fmt(i1,i2,fmt) clar__assert_equal(__FILE__,__func__,__LINE__,#i1 " != " #i2, 1, (fmt), (int)(i1), (int)(i2))
#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_b(b1,b2) clar__assert_equal(__FILE__,__func__,__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) clar__assert_equal(__FILE__,__func__,__LINE__,"Pointer mismatch: " #p1 " != " #p2, 1, "%p", (p1), (p2))
void clar__skip(void); void clar__skip(void);
void clar__fail( void clar__fail(
const char *file, const char *file,
const char *func,
size_t line, size_t line,
const char *error, const char *error,
const char *description, const char *description,
...@@ -149,6 +155,7 @@ void clar__fail( ...@@ -149,6 +155,7 @@ void clar__fail(
void clar__assert( void clar__assert(
int condition, int condition,
const char *file, const char *file,
const char *func,
size_t line, size_t line,
const char *error, const char *error,
const char *description, const char *description,
...@@ -156,6 +163,7 @@ void clar__assert( ...@@ -156,6 +163,7 @@ void clar__assert(
void clar__assert_equal( void clar__assert_equal(
const char *file, const char *file,
const char *func,
size_t line, size_t line,
const char *err, const char *err,
int should_abort, int should_abort,
......
/* clap: clar protocol, the traditional clar output format */
static void clar_print_init(int test_count, int suite_count, const char *suite_names) static void clar_print_clap_init(int test_count, int suite_count, const char *suite_names)
{ {
(void)test_count; (void)test_count;
printf("Loaded %d suites: %s\n", (int)suite_count, suite_names); printf("Loaded %d suites: %s\n", (int)suite_count, suite_names);
printf("Started (test status codes: OK='.' FAILURE='F' SKIPPED='S')\n"); printf("Started (test status codes: OK='.' FAILURE='F' SKIPPED='S')\n");
} }
static void clar_print_shutdown(int test_count, int suite_count, int error_count) static void clar_print_clap_shutdown(int test_count, int suite_count, int error_count)
{ {
(void)test_count; (void)test_count;
(void)suite_count; (void)suite_count;
...@@ -16,7 +17,7 @@ static void clar_print_shutdown(int test_count, int suite_count, int error_count ...@@ -16,7 +17,7 @@ static void clar_print_shutdown(int test_count, int suite_count, int error_count
clar_report_all(); clar_report_all();
} }
static void clar_print_error(int num, const struct clar_report *report, const struct clar_error *error) static void clar_print_clap_error(int num, const struct clar_report *report, const struct clar_error *error)
{ {
printf(" %d) Failure:\n", num); printf(" %d) Failure:\n", num);
...@@ -35,7 +36,7 @@ static void clar_print_error(int num, const struct clar_report *report, const st ...@@ -35,7 +36,7 @@ static void clar_print_error(int num, const struct clar_report *report, const st
fflush(stdout); fflush(stdout);
} }
static void clar_print_ontest(const char *test_name, int test_number, enum cl_test_status status) static void clar_print_clap_ontest(const char *test_name, int test_number, enum cl_test_status status)
{ {
(void)test_name; (void)test_name;
(void)test_number; (void)test_number;
...@@ -50,7 +51,7 @@ static void clar_print_ontest(const char *test_name, int test_number, enum cl_te ...@@ -50,7 +51,7 @@ static void clar_print_ontest(const char *test_name, int test_number, enum cl_te
fflush(stdout); fflush(stdout);
} }
static void clar_print_onsuite(const char *suite_name, int suite_index) static void clar_print_clap_onsuite(const char *suite_name, int suite_index)
{ {
if (_clar.report_suite_names) if (_clar.report_suite_names)
printf("\n%s", suite_name); printf("\n%s", suite_name);
...@@ -58,10 +59,142 @@ static void clar_print_onsuite(const char *suite_name, int suite_index) ...@@ -58,10 +59,142 @@ static void clar_print_onsuite(const char *suite_name, int suite_index)
(void)suite_index; (void)suite_index;
} }
static void clar_print_clap_onabort(const char *fmt, va_list arg)
{
vfprintf(stderr, fmt, arg);
}
/* tap: test anywhere protocol format */
static void clar_print_tap_init(int test_count, int suite_count, const char *suite_names)
{
(void)test_count;
(void)suite_count;
(void)suite_names;
printf("TAP version 13\n");
}
static void clar_print_tap_shutdown(int test_count, int suite_count, int error_count)
{
(void)suite_count;
(void)error_count;
printf("1..%d\n", test_count);
}
static void clar_print_tap_error(int num, const struct clar_report *report, const struct clar_error *error)
{
(void)num;
(void)report;
(void)error;
}
static void print_escaped(const char *str)
{
char *c;
while ((c = strchr(str, '\'')) != NULL) {
printf("%.*s", (int)(c - str), str);
printf("''");
str = c + 1;
}
printf("%s", str);
}
static void clar_print_tap_ontest(const char *test_name, int test_number, enum cl_test_status status)
{
const struct clar_error *error = _clar.last_report->errors;
(void)test_name;
(void)test_number;
switch(status) {
case CL_TEST_OK:
printf("ok %d - %s::%s\n", test_number, _clar.active_suite, test_name);
break;
case CL_TEST_FAILURE:
printf("not ok %d - %s::%s\n", test_number, _clar.active_suite, test_name);
printf(" ---\n");
printf(" reason: |\n");
printf(" %s\n", error->error_msg);
if (error->description)
printf(" %s\n", error->description);
printf(" at:\n");
printf(" file: '"); print_escaped(error->file); printf("'\n");
printf(" line: %" PRIuZ "\n", error->line_number);
printf(" function: '%s'\n", error->function);
printf(" ---\n");
break;
case CL_TEST_SKIP:
case CL_TEST_NOTRUN:
printf("ok %d - # SKIP %s::%s\n", test_number, _clar.active_suite, test_name);
break;
}
fflush(stdout);
}
static void clar_print_tap_onsuite(const char *suite_name, int suite_index)
{
printf("# start of suite %d: %s\n", suite_index, suite_name);
}
static void clar_print_tap_onabort(const char *fmt, va_list arg)
{
printf("Bail out! ");
vprintf(fmt, arg);
fflush(stdout);
}
/* indirection between protocol output selection */
#define PRINT(FN, ...) do { \
switch (_clar.output_format) { \
case CL_OUTPUT_CLAP: \
clar_print_clap_##FN (__VA_ARGS__); \
break; \
case CL_OUTPUT_TAP: \
clar_print_tap_##FN (__VA_ARGS__); \
break; \
default: \
abort(); \
} \
} while (0)
static void clar_print_init(int test_count, int suite_count, const char *suite_names)
{
PRINT(init, test_count, suite_count, suite_names);
}
static void clar_print_shutdown(int test_count, int suite_count, int error_count)
{
PRINT(shutdown, test_count, suite_count, error_count);
}
static void clar_print_error(int num, const struct clar_report *report, const struct clar_error *error)
{
PRINT(error, num, report, error);
}
static void clar_print_ontest(const char *test_name, int test_number, enum cl_test_status status)
{
PRINT(ontest, test_name, test_number, status);
}
static void clar_print_onsuite(const char *suite_name, int suite_index)
{
PRINT(onsuite, suite_name, suite_index);
}
static void clar_print_onabort(const char *msg, ...) static void clar_print_onabort(const char *msg, ...)
{ {
va_list argp; va_list argp;
va_start(argp, msg); va_start(argp, msg);
vfprintf(stderr, msg, argp); PRINT(onabort, msg, argp);
va_end(argp); va_end(argp);
} }
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "git2/sys/repository.h" #include "git2/sys/repository.h"
void cl_git_report_failure( void cl_git_report_failure(
int error, int expected, const char *file, int line, const char *fncall) int error, int expected, const char *file, const char *func, int line, const char *fncall)
{ {
char msg[4096]; char msg[4096];
const git_error *last = git_error_last(); const git_error *last = git_error_last();
...@@ -18,7 +18,7 @@ void cl_git_report_failure( ...@@ -18,7 +18,7 @@ void cl_git_report_failure(
else else
p_snprintf(msg, 4096, "no error, expected non-zero return"); p_snprintf(msg, 4096, "no error, expected non-zero return");
clar__assert(0, file, line, fncall, msg, 1); clar__assert(0, file, func, line, fncall, msg, 1);
} }
void cl_git_mkfile(const char *filename, const char *content) void cl_git_mkfile(const char *filename, const char *content)
...@@ -507,6 +507,7 @@ void clar__assert_equal_file( ...@@ -507,6 +507,7 @@ void clar__assert_equal_file(
int ignore_cr, int ignore_cr,
const char *path, const char *path,
const char *file, const char *file,
const char *func,
int line) int line)
{ {
char buf[4000]; char buf[4000];
...@@ -519,7 +520,7 @@ void clar__assert_equal_file( ...@@ -519,7 +520,7 @@ void clar__assert_equal_file(
while ((bytes = p_read(fd, buf, sizeof(buf))) != 0) { while ((bytes = p_read(fd, buf, sizeof(buf))) != 0) {
clar__assert( clar__assert(
bytes > 0, file, line, "error reading from file", path, 1); bytes > 0, file, func, line, "error reading from file", path, 1);
if (ignore_cr) if (ignore_cr)
bytes = strip_cr_from_buf(buf, bytes); bytes = strip_cr_from_buf(buf, bytes);
...@@ -532,7 +533,7 @@ void clar__assert_equal_file( ...@@ -532,7 +533,7 @@ void clar__assert_equal_file(
buf, sizeof(buf), "file content mismatch at byte %"PRIdZ, buf, sizeof(buf), "file content mismatch at byte %"PRIdZ,
(ssize_t)(total_bytes + pos)); (ssize_t)(total_bytes + pos));
p_close(fd); p_close(fd);
clar__fail(file, line, path, buf, 1); clar__fail(file, func, line, path, buf, 1);
} }
expected_data += bytes; expected_data += bytes;
...@@ -541,8 +542,8 @@ void clar__assert_equal_file( ...@@ -541,8 +542,8 @@ void clar__assert_equal_file(
p_close(fd); p_close(fd);
clar__assert(!bytes, file, line, "error reading from file", path, 1); clar__assert(!bytes, file, func, line, "error reading from file", path, 1);
clar__assert_equal(file, line, "mismatched file length", 1, "%"PRIuZ, clar__assert_equal(file, func, line, "mismatched file length", 1, "%"PRIuZ,
(size_t)expected_bytes, (size_t)total_bytes); (size_t)expected_bytes, (size_t)total_bytes);
} }
......
...@@ -12,15 +12,15 @@ ...@@ -12,15 +12,15 @@
* *
* Use this wrapper around all `git_` library calls that return error codes! * Use this wrapper around all `git_` library calls that return error codes!
*/ */
#define cl_git_pass(expr) cl_git_expect((expr), 0, __FILE__, __LINE__) #define cl_git_pass(expr) cl_git_expect((expr), 0, __FILE__, __func__, __LINE__)
#define cl_git_fail_with(error, expr) cl_git_expect((expr), error, __FILE__, __LINE__) #define cl_git_fail_with(error, expr) cl_git_expect((expr), error, __FILE__, __func__, __LINE__)
#define cl_git_expect(expr, expected, file, line) do { \ #define cl_git_expect(expr, expected, file, func, line) do { \
int _lg2_error; \ int _lg2_error; \
git_error_clear(); \ git_error_clear(); \
if ((_lg2_error = (expr)) != expected) \ if ((_lg2_error = (expr)) != expected) \
cl_git_report_failure(_lg2_error, expected, file, line, "Function call failed: " #expr); \ cl_git_report_failure(_lg2_error, expected, file, func, line, "Function call failed: " #expr); \
} while (0) } while (0)
/** /**
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#define cl_git_fail(expr) do { \ #define cl_git_fail(expr) do { \
if ((expr) == 0) \ if ((expr) == 0) \
git_error_clear(), \ git_error_clear(), \
cl_git_report_failure(0, 0, __FILE__, __LINE__, "Function call succeeded: " #expr); \ cl_git_report_failure(0, 0, __FILE__, __func__, __LINE__, "Function call succeeded: " #expr); \
} while (0) } while (0)
/** /**
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
int _win32_res; \ int _win32_res; \
if ((_win32_res = (expr)) == 0) { \ if ((_win32_res = (expr)) == 0) { \
git_error_set(GIT_ERROR_OS, "Returned: %d, system error code: %lu", _win32_res, GetLastError()); \ git_error_set(GIT_ERROR_OS, "Returned: %d, system error code: %lu", _win32_res, GetLastError()); \
cl_git_report_failure(_win32_res, 0, __FILE__, __LINE__, "System call failed: " #expr); \ cl_git_report_failure(_win32_res, 0, __FILE__, __func__, __LINE__, "System call failed: " #expr); \
} \ } \
} while(0) } while(0)
...@@ -58,22 +58,24 @@ ...@@ -58,22 +58,24 @@
typedef struct { typedef struct {
int error; int error;
const char *file; const char *file;
const char *func;
int line; int line;
const char *expr; const char *expr;
char error_msg[4096]; char error_msg[4096];
} cl_git_thread_err; } cl_git_thread_err;
#ifdef GIT_THREADS #ifdef GIT_THREADS
# define cl_git_thread_pass(threaderr, expr) cl_git_thread_pass_(threaderr, (expr), __FILE__, __LINE__) # define cl_git_thread_pass(threaderr, expr) cl_git_thread_pass_(threaderr, (expr), __FILE__, __func__, __LINE__)
#else #else
# define cl_git_thread_pass(threaderr, expr) cl_git_pass(expr) # define cl_git_thread_pass(threaderr, expr) cl_git_pass(expr)
#endif #endif
#define cl_git_thread_pass_(__threaderr, __expr, __file, __line) do { \ #define cl_git_thread_pass_(__threaderr, __expr, __file, __func, __line) do { \
git_error_clear(); \ git_error_clear(); \
if ((((cl_git_thread_err *)__threaderr)->error = (__expr)) != 0) { \ if ((((cl_git_thread_err *)__threaderr)->error = (__expr)) != 0) { \
const git_error *_last = git_error_last(); \ const git_error *_last = git_error_last(); \
((cl_git_thread_err *)__threaderr)->file = __file; \ ((cl_git_thread_err *)__threaderr)->file = __file; \
((cl_git_thread_err *)__threaderr)->func = __func; \
((cl_git_thread_err *)__threaderr)->line = __line; \ ((cl_git_thread_err *)__threaderr)->line = __line; \
((cl_git_thread_err *)__threaderr)->expr = "Function call failed: " #__expr; \ ((cl_git_thread_err *)__threaderr)->expr = "Function call failed: " #__expr; \
p_snprintf(((cl_git_thread_err *)__threaderr)->error_msg, 4096, "thread 0x%" PRIxZ " - error %d - %s", \ p_snprintf(((cl_git_thread_err *)__threaderr)->error_msg, 4096, "thread 0x%" PRIxZ " - error %d - %s", \
...@@ -87,38 +89,39 @@ GIT_INLINE(void) cl_git_thread_check(void *data) ...@@ -87,38 +89,39 @@ GIT_INLINE(void) cl_git_thread_check(void *data)
{ {
cl_git_thread_err *threaderr = (cl_git_thread_err *)data; cl_git_thread_err *threaderr = (cl_git_thread_err *)data;
if (threaderr->error != 0) if (threaderr->error != 0)
clar__assert(0, threaderr->file, threaderr->line, threaderr->expr, threaderr->error_msg, 1); clar__assert(0, threaderr->file, threaderr->func, threaderr->line, threaderr->expr, threaderr->error_msg, 1);
} }
void cl_git_report_failure(int, int, const char *, int, const char *); void cl_git_report_failure(int, int, const char *, const char *, int, const char *);
#define cl_assert_at_line(expr,file,line) \ #define cl_assert_at_line(expr,file,func,line) \
clar__assert((expr) != 0, file, line, "Expression is not true: " #expr, NULL, 1) clar__assert((expr) != 0, file, func, line, "Expression is not true: " #expr, NULL, 1)
GIT_INLINE(void) clar__assert_in_range( GIT_INLINE(void) clar__assert_in_range(
int lo, int val, int hi, int lo, int val, int hi,
const char *file, int line, const char *err, int should_abort) const char *file, const char *func, int line,
const char *err, int should_abort)
{ {
if (lo > val || hi < val) { if (lo > val || hi < val) {
char buf[128]; char buf[128];
p_snprintf(buf, sizeof(buf), "%d not in [%d,%d]", val, lo, hi); p_snprintf(buf, sizeof(buf), "%d not in [%d,%d]", val, lo, hi);
clar__fail(file, line, err, buf, should_abort); clar__fail(file, func, line, err, buf, should_abort);
} }
} }
#define cl_assert_equal_sz(sz1,sz2) do { \ #define cl_assert_equal_sz(sz1,sz2) do { \
size_t __sz1 = (size_t)(sz1), __sz2 = (size_t)(sz2); \ size_t __sz1 = (size_t)(sz1), __sz2 = (size_t)(sz2); \
clar__assert_equal(__FILE__,__LINE__,#sz1 " != " #sz2, 1, "%"PRIuZ, __sz1, __sz2); \ clar__assert_equal(__FILE__,__func__,__LINE__,#sz1 " != " #sz2, 1, "%"PRIuZ, __sz1, __sz2); \
} while (0) } while (0)
#define cl_assert_in_range(L,V,H) \ #define cl_assert_in_range(L,V,H) \
clar__assert_in_range((L),(V),(H),__FILE__,__LINE__,"Range check: " #V " in [" #L "," #H "]", 1) clar__assert_in_range((L),(V),(H),__FILE__,__func__,__LINE__,"Range check: " #V " in [" #L "," #H "]", 1)
#define cl_assert_equal_file(DATA,SIZE,PATH) \ #define cl_assert_equal_file(DATA,SIZE,PATH) \
clar__assert_equal_file(DATA,SIZE,0,PATH,__FILE__,(int)__LINE__) clar__assert_equal_file(DATA,SIZE,0,PATH,__FILE__,__func__,(int)__LINE__)
#define cl_assert_equal_file_ignore_cr(DATA,SIZE,PATH) \ #define cl_assert_equal_file_ignore_cr(DATA,SIZE,PATH) \
clar__assert_equal_file(DATA,SIZE,1,PATH,__FILE__,(int)__LINE__) clar__assert_equal_file(DATA,SIZE,1,PATH,__FILE__,__func__,(int)__LINE__)
void clar__assert_equal_file( void clar__assert_equal_file(
const char *expected_data, const char *expected_data,
...@@ -126,10 +129,11 @@ void clar__assert_equal_file( ...@@ -126,10 +129,11 @@ void clar__assert_equal_file(
int ignore_cr, int ignore_cr,
const char *path, const char *path,
const char *file, const char *file,
const char *func,
int line); int line);
GIT_INLINE(void) clar__assert_equal_oid( GIT_INLINE(void) clar__assert_equal_oid(
const char *file, int line, const char *desc, const char *file, const char *func, int line, const char *desc,
const git_oid *one, const git_oid *two) const git_oid *one, const git_oid *two)
{ {
if (git_oid_cmp(one, two)) { if (git_oid_cmp(one, two)) {
...@@ -138,12 +142,12 @@ GIT_INLINE(void) clar__assert_equal_oid( ...@@ -138,12 +142,12 @@ GIT_INLINE(void) clar__assert_equal_oid(
git_oid_fmt(&err[1], one); git_oid_fmt(&err[1], one);
git_oid_fmt(&err[47], two); git_oid_fmt(&err[47], two);
clar__fail(file, line, desc, err, 1); clar__fail(file, func, line, desc, err, 1);
} }
} }
#define cl_assert_equal_oid(one, two) \ #define cl_assert_equal_oid(one, two) \
clar__assert_equal_oid(__FILE__, __LINE__, \ clar__assert_equal_oid(__FILE__, __func__, __LINE__, \
"OID mismatch: " #one " != " #two, (one), (two)) "OID mismatch: " #one " != " #two, (one), (two))
/* /*
......
...@@ -150,10 +150,11 @@ static void cleanup_chmod_root(void *ref) ...@@ -150,10 +150,11 @@ static void cleanup_chmod_root(void *ref)
git_futils_rmdir_r("r", NULL, GIT_RMDIR_EMPTY_HIERARCHY); git_futils_rmdir_r("r", NULL, GIT_RMDIR_EMPTY_HIERARCHY);
} }
#define check_mode(X,A) check_mode_at_line((X), (A), __FILE__, __LINE__) #define check_mode(X,A) check_mode_at_line((X), (A), __FILE__, __func__, __LINE__)
static void check_mode_at_line( static void check_mode_at_line(
mode_t expected, mode_t actual, const char *file, int line) mode_t expected, mode_t actual,
const char *file, const char *func, int line)
{ {
/* FAT filesystems don't support exec bit, nor group/world bits */ /* FAT filesystems don't support exec bit, nor group/world bits */
if (!cl_is_chmod_supported()) { if (!cl_is_chmod_supported()) {
...@@ -162,7 +163,7 @@ static void check_mode_at_line( ...@@ -162,7 +163,7 @@ static void check_mode_at_line(
} }
clar__assert_equal( clar__assert_equal(
file, line, "expected_mode != actual_mode", 1, file, func, line, "expected_mode != actual_mode", 1,
"%07o", (int)expected, (int)(actual & 0777)); "%07o", (int)expected, (int)(actual & 0777));
} }
......
...@@ -48,7 +48,7 @@ static void options_cmp(void *one, void *two, size_t size, const char *name) ...@@ -48,7 +48,7 @@ static void options_cmp(void *one, void *two, size_t size, const char *name)
p_snprintf(desc, 1024, "Difference in %s at byte %" PRIuZ ": macro=%u / func=%u", p_snprintf(desc, 1024, "Difference in %s at byte %" PRIuZ ": macro=%u / func=%u",
name, i, ((char *)one)[i], ((char *)two)[i]); name, i, ((char *)one)[i], ((char *)two)[i]);
clar__fail(__FILE__, __LINE__, clar__fail(__FILE__, __func__, __LINE__,
"Difference between macro and function options initializer", "Difference between macro and function options initializer",
desc, 0); desc, 0);
return; return;
......
...@@ -3,21 +3,21 @@ ...@@ -3,21 +3,21 @@
#include "wildmatch.h" #include "wildmatch.h"
#define assert_matches(string, pattern, wildmatch, iwildmatch, pathmatch, ipathmatch) \ #define assert_matches(string, pattern, wildmatch, iwildmatch, pathmatch, ipathmatch) \
assert_matches_(string, pattern, wildmatch, iwildmatch, pathmatch, ipathmatch, __FILE__, __LINE__) assert_matches_(string, pattern, wildmatch, iwildmatch, pathmatch, ipathmatch, __FILE__, __func__, __LINE__)
static void assert_matches_(const char *string, const char *pattern, static void assert_matches_(const char *string, const char *pattern,
char expected_wildmatch, char expected_iwildmatch, char expected_wildmatch, char expected_iwildmatch,
char expected_pathmatch, char expected_ipathmatch, char expected_pathmatch, char expected_ipathmatch,
const char *file, size_t line) const char *file, const char *func, size_t line)
{ {
if (wildmatch(pattern, string, WM_PATHNAME) == expected_wildmatch) if (wildmatch(pattern, string, WM_PATHNAME) == expected_wildmatch)
clar__fail(file, line, "Test failed (wildmatch).", string, 1); clar__fail(file, func, line, "Test failed (wildmatch).", string, 1);
if (wildmatch(pattern, string, WM_PATHNAME|WM_CASEFOLD) == expected_iwildmatch) if (wildmatch(pattern, string, WM_PATHNAME|WM_CASEFOLD) == expected_iwildmatch)
clar__fail(file, line, "Test failed (iwildmatch).", string, 1); clar__fail(file, func, line, "Test failed (iwildmatch).", string, 1);
if (wildmatch(pattern, string, 0) == expected_pathmatch) if (wildmatch(pattern, string, 0) == expected_pathmatch)
clar__fail(file, line, "Test failed (pathmatch).", string, 1); clar__fail(file, func, line, "Test failed (pathmatch).", string, 1);
if (wildmatch(pattern, string, WM_CASEFOLD) == expected_ipathmatch) if (wildmatch(pattern, string, WM_CASEFOLD) == expected_ipathmatch)
clar__fail(file, line, "Test failed (ipathmatch).", string, 1); clar__fail(file, func, line, "Test failed (ipathmatch).", string, 1);
} }
/* /*
......
...@@ -9,7 +9,7 @@ static const char *data = "This is a test test test of This is a test"; ...@@ -9,7 +9,7 @@ static const char *data = "This is a test test test of This is a test";
static void assert_zlib_equal_( static void assert_zlib_equal_(
const void *expected, size_t e_len, const void *expected, size_t e_len,
const void *compressed, size_t c_len, const void *compressed, size_t c_len,
const char *msg, const char *file, int line) const char *msg, const char *file, const char *func, int line)
{ {
z_stream stream; z_stream stream;
char *expanded = git__calloc(1, e_len + INFLATE_EXTRA); char *expanded = git__calloc(1, e_len + INFLATE_EXTRA);
...@@ -26,21 +26,21 @@ static void assert_zlib_equal_( ...@@ -26,21 +26,21 @@ static void assert_zlib_equal_(
inflateEnd(&stream); inflateEnd(&stream);
clar__assert_equal( clar__assert_equal(
file, line, msg, 1, file, func, line, msg, 1,
"%d", (int)stream.total_out, (int)e_len); "%d", (int)stream.total_out, (int)e_len);
clar__assert_equal( clar__assert_equal(
file, line, "Buffer len was not exact match", 1, file, func, line, "Buffer len was not exact match", 1,
"%d", (int)stream.avail_out, (int)INFLATE_EXTRA); "%d", (int)stream.avail_out, (int)INFLATE_EXTRA);
clar__assert( clar__assert(
memcmp(expanded, expected, e_len) == 0, memcmp(expanded, expected, e_len) == 0,
file, line, "uncompressed data did not match", NULL, 1); file, func, line, "uncompressed data did not match", NULL, 1);
git__free(expanded); git__free(expanded);
} }
#define assert_zlib_equal(E,EL,C,CL) \ #define assert_zlib_equal(E,EL,C,CL) \
assert_zlib_equal_(E, EL, C, CL, #EL " != " #CL, __FILE__, (int)__LINE__) assert_zlib_equal_(E, EL, C, CL, #EL " != " #CL, __FILE__, __func__, (int)__LINE__)
void test_core_zstream__basic(void) void test_core_zstream__basic(void)
{ {
......
...@@ -318,20 +318,20 @@ void test_diff_parse__patch_roundtrip_succeeds(void) ...@@ -318,20 +318,20 @@ void test_diff_parse__patch_roundtrip_succeeds(void)
git_buf_dispose(&diffbuf); git_buf_dispose(&diffbuf);
} }
#define cl_assert_equal_i_src(i1,i2,file,line) clar__assert_equal(file,line,#i1 " != " #i2, 1, "%d", (int)(i1), (int)(i2)) #define cl_assert_equal_i_src(i1,i2,file,func,line) clar__assert_equal(file,func,line,#i1 " != " #i2, 1, "%d", (int)(i1), (int)(i2))
static void cl_git_assert_lineinfo_(int old_lineno, int new_lineno, int num_lines, git_patch *patch, size_t hunk_idx, size_t line_idx, const char *file, int lineno) static void cl_git_assert_lineinfo_(int old_lineno, int new_lineno, int num_lines, git_patch *patch, size_t hunk_idx, size_t line_idx, const char *file, const char *func, int lineno)
{ {
const git_diff_line *line; const git_diff_line *line;
cl_git_expect(git_patch_get_line_in_hunk(&line, patch, hunk_idx, line_idx), 0, file, lineno); cl_git_expect(git_patch_get_line_in_hunk(&line, patch, hunk_idx, line_idx), 0, file, func, lineno);
cl_assert_equal_i_src(old_lineno, line->old_lineno, file, lineno); cl_assert_equal_i_src(old_lineno, line->old_lineno, file, func, lineno);
cl_assert_equal_i_src(new_lineno, line->new_lineno, file, lineno); cl_assert_equal_i_src(new_lineno, line->new_lineno, file, func, lineno);
cl_assert_equal_i_src(num_lines, line->num_lines, file, lineno); cl_assert_equal_i_src(num_lines, line->num_lines, file, func, lineno);
} }
#define cl_git_assert_lineinfo(old, new, num, p, h, l) \ #define cl_git_assert_lineinfo(old, new, num, p, h, l) \
cl_git_assert_lineinfo_(old,new,num,p,h,l,__FILE__,__LINE__) cl_git_assert_lineinfo_(old,new,num,p,h,l,__FILE__,__func__,__LINE__)
void test_diff_parse__issue4672(void) void test_diff_parse__issue4672(void)
......
...@@ -18,7 +18,8 @@ void test_diff_submodules__cleanup(void) ...@@ -18,7 +18,8 @@ void test_diff_submodules__cleanup(void)
#define get_buf_ptr(buf) ((buf)->asize ? (buf)->ptr : NULL) #define get_buf_ptr(buf) ((buf)->asize ? (buf)->ptr : NULL)
static void check_diff_patches_at_line( static void check_diff_patches_at_line(
git_diff *diff, const char **expected, const char *file, int line) git_diff *diff, const char **expected,
const char *file, const char *func, int line)
{ {
const git_diff_delta *delta; const git_diff_delta *delta;
git_patch *patch = NULL; git_patch *patch = NULL;
...@@ -30,34 +31,34 @@ static void check_diff_patches_at_line( ...@@ -30,34 +31,34 @@ static void check_diff_patches_at_line(
cl_assert((delta = git_patch_get_delta(patch)) != NULL); cl_assert((delta = git_patch_get_delta(patch)) != NULL);
if (delta->status == GIT_DELTA_UNMODIFIED) { if (delta->status == GIT_DELTA_UNMODIFIED) {
cl_assert_at_line(expected[d] == NULL, file, line); cl_assert_at_line(expected[d] == NULL, file, func, line);
continue; continue;
} }
if (expected[d] && !strcmp(expected[d], "<SKIP>")) if (expected[d] && !strcmp(expected[d], "<SKIP>"))
continue; continue;
if (expected[d] && !strcmp(expected[d], "<UNTRACKED>")) { if (expected[d] && !strcmp(expected[d], "<UNTRACKED>")) {
cl_assert_at_line(delta->status == GIT_DELTA_UNTRACKED, file, line); cl_assert_at_line(delta->status == GIT_DELTA_UNTRACKED, file, func, line);
continue; continue;
} }
if (expected[d] && !strcmp(expected[d], "<END>")) { if (expected[d] && !strcmp(expected[d], "<END>")) {
cl_git_pass(git_patch_to_buf(&buf, patch)); cl_git_pass(git_patch_to_buf(&buf, patch));
cl_assert_at_line(!strcmp(expected[d], "<END>"), file, line); cl_assert_at_line(!strcmp(expected[d], "<END>"), file, func, line);
} }
cl_git_pass(git_patch_to_buf(&buf, patch)); cl_git_pass(git_patch_to_buf(&buf, patch));
clar__assert_equal( clar__assert_equal(
file, line, "expected diff did not match actual diff", 1, file, func, line, "expected diff did not match actual diff", 1,
"%s", expected[d], get_buf_ptr(&buf)); "%s", expected[d], get_buf_ptr(&buf));
git_buf_dispose(&buf); git_buf_dispose(&buf);
} }
cl_assert_at_line(expected[d] && !strcmp(expected[d], "<END>"), file, line); cl_assert_at_line(expected[d] && !strcmp(expected[d], "<END>"), file, func, line);
} }
#define check_diff_patches(diff, exp) \ #define check_diff_patches(diff, exp) \
check_diff_patches_at_line(diff, exp, __FILE__, __LINE__) check_diff_patches_at_line(diff, exp, __FILE__, __func__, __LINE__)
void test_diff_submodules__unmodified_submodule(void) void test_diff_submodules__unmodified_submodule(void)
{ {
......
...@@ -17,19 +17,20 @@ void test_ignore_path__cleanup(void) ...@@ -17,19 +17,20 @@ void test_ignore_path__cleanup(void)
} }
static void assert_is_ignored_( static void assert_is_ignored_(
bool expected, const char *filepath, const char *file, int line) bool expected, const char *filepath,
const char *file, const char *func, int line)
{ {
int is_ignored = 0; int is_ignored = 0;
cl_git_expect( cl_git_expect(
git_ignore_path_is_ignored(&is_ignored, g_repo, filepath), 0, file, line); git_ignore_path_is_ignored(&is_ignored, g_repo, filepath), 0, file, func, line);
clar__assert_equal( clar__assert_equal(
file, line, "expected != is_ignored", 1, "%d", file, func, line, "expected != is_ignored", 1, "%d",
(int)(expected != 0), (int)(is_ignored != 0)); (int)(expected != 0), (int)(is_ignored != 0));
} }
#define assert_is_ignored(expected, filepath) \ #define assert_is_ignored(expected, filepath) \
assert_is_ignored_(expected, filepath, __FILE__, __LINE__) assert_is_ignored_(expected, filepath, __FILE__, __func__, __LINE__)
void test_ignore_path__honor_temporary_rules(void) void test_ignore_path__honor_temporary_rules(void)
{ {
......
...@@ -17,21 +17,22 @@ void test_ignore_status__cleanup(void) ...@@ -17,21 +17,22 @@ void test_ignore_status__cleanup(void)
} }
static void assert_ignored_( static void assert_ignored_(
bool expected, const char *filepath, const char *file, int line) bool expected, const char *filepath,
const char *file, const char *func, int line)
{ {
int is_ignored = 0; int is_ignored = 0;
cl_git_expect( cl_git_expect(
git_status_should_ignore(&is_ignored, g_repo, filepath), 0, file, line); git_status_should_ignore(&is_ignored, g_repo, filepath), 0, file, func, line);
clar__assert( clar__assert(
(expected != 0) == (is_ignored != 0), (expected != 0) == (is_ignored != 0),
file, line, "expected != is_ignored", filepath, 1); file, func, line, "expected != is_ignored", filepath, 1);
} }
#define assert_ignored(expected, filepath) \ #define assert_ignored(expected, filepath) \
assert_ignored_(expected, filepath, __FILE__, __LINE__) assert_ignored_(expected, filepath, __FILE__, __func__, __LINE__)
#define assert_is_ignored(filepath) \ #define assert_is_ignored(filepath) \
assert_ignored_(true, filepath, __FILE__, __LINE__) assert_ignored_(true, filepath, __FILE__, __func__, __LINE__)
#define refute_is_ignored(filepath) \ #define refute_is_ignored(filepath) \
assert_ignored_(false, filepath, __FILE__, __LINE__) assert_ignored_(false, filepath, __FILE__, __func__, __LINE__)
void test_ignore_status__0(void) void test_ignore_status__0(void)
{ {
......
...@@ -75,7 +75,7 @@ static void check_status_at_line( ...@@ -75,7 +75,7 @@ static void check_status_at_line(
git_repository *repo, git_repository *repo,
size_t index_adds, size_t index_dels, size_t index_mods, size_t index_adds, size_t index_dels, size_t index_mods,
size_t wt_adds, size_t wt_dels, size_t wt_mods, size_t ignores, size_t wt_adds, size_t wt_dels, size_t wt_mods, size_t ignores,
size_t conflicts, const char *file, int line) size_t conflicts, const char *file, const char *func, int line)
{ {
index_status_counts vals; index_status_counts vals;
...@@ -84,25 +84,25 @@ static void check_status_at_line( ...@@ -84,25 +84,25 @@ static void check_status_at_line(
cl_git_pass(git_status_foreach(repo, index_status_cb, &vals)); cl_git_pass(git_status_foreach(repo, index_status_cb, &vals));
clar__assert_equal( clar__assert_equal(
file,line,"wrong index adds", 1, "%"PRIuZ, index_adds, vals.index_adds); file,func,line,"wrong index adds", 1, "%"PRIuZ, index_adds, vals.index_adds);
clar__assert_equal( clar__assert_equal(
file,line,"wrong index dels", 1, "%"PRIuZ, index_dels, vals.index_dels); file,func,line,"wrong index dels", 1, "%"PRIuZ, index_dels, vals.index_dels);
clar__assert_equal( clar__assert_equal(
file,line,"wrong index mods", 1, "%"PRIuZ, index_mods, vals.index_mods); file,func,line,"wrong index mods", 1, "%"PRIuZ, index_mods, vals.index_mods);
clar__assert_equal( clar__assert_equal(
file,line,"wrong workdir adds", 1, "%"PRIuZ, wt_adds, vals.wt_adds); file,func,line,"wrong workdir adds", 1, "%"PRIuZ, wt_adds, vals.wt_adds);
clar__assert_equal( clar__assert_equal(
file,line,"wrong workdir dels", 1, "%"PRIuZ, wt_dels, vals.wt_dels); file,func,line,"wrong workdir dels", 1, "%"PRIuZ, wt_dels, vals.wt_dels);
clar__assert_equal( clar__assert_equal(
file,line,"wrong workdir mods", 1, "%"PRIuZ, wt_mods, vals.wt_mods); file,func,line,"wrong workdir mods", 1, "%"PRIuZ, wt_mods, vals.wt_mods);
clar__assert_equal( clar__assert_equal(
file,line,"wrong ignores", 1, "%"PRIuZ, ignores, vals.ignores); file,func,line,"wrong ignores", 1, "%"PRIuZ, ignores, vals.ignores);
clar__assert_equal( clar__assert_equal(
file,line,"wrong conflicts", 1, "%"PRIuZ, conflicts, vals.conflicts); file,func,line,"wrong conflicts", 1, "%"PRIuZ, conflicts, vals.conflicts);
} }
#define check_status(R,IA,ID,IM,WA,WD,WM,IG,C) \ #define check_status(R,IA,ID,IM,WA,WD,WM,IG,C) \
check_status_at_line(R,IA,ID,IM,WA,WD,WM,IG,C,__FILE__,__LINE__) check_status_at_line(R,IA,ID,IM,WA,WD,WM,IG,C,__FILE__,__func__,__LINE__)
static void check_stat_data(git_index *index, const char *path, bool match) static void check_stat_data(git_index *index, const char *path, bool match)
{ {
......
...@@ -96,7 +96,7 @@ done: ...@@ -96,7 +96,7 @@ done:
git_buf details = GIT_BUF_INIT; git_buf details = GIT_BUF_INIT;
git_buf_printf(&details, "filename=%s, system=%s, autocrlf=%s, safecrlf=%s, attrs={%s}", git_buf_printf(&details, "filename=%s, system=%s, autocrlf=%s, safecrlf=%s, attrs={%s}",
basename, cd->systype, cd->autocrlf, cd->safecrlf, cd->attrs); basename, cd->systype, cd->autocrlf, cd->safecrlf, cd->attrs);
clar__fail(__FILE__, __LINE__, clar__fail(__FILE__, __func__, __LINE__,
"index contents did not match expected", details.ptr, 0); "index contents did not match expected", details.ptr, 0);
git_buf_dispose(&details); git_buf_dispose(&details);
} }
......
...@@ -51,11 +51,11 @@ static void replace_file_with_mode( ...@@ -51,11 +51,11 @@ static void replace_file_with_mode(
git_buf_dispose(&content); git_buf_dispose(&content);
} }
#define add_and_check_mode(I,F,X) add_and_check_mode_(I,F,X,__FILE__,__LINE__) #define add_and_check_mode(I,F,X) add_and_check_mode_(I,F,X,__FILE__,__func__,__LINE__)
static void add_and_check_mode_( static void add_and_check_mode_(
git_index *index, const char *filename, unsigned int expect_mode, git_index *index, const char *filename, unsigned int expect_mode,
const char *file, int line) const char *file, const char *func, int line)
{ {
size_t pos; size_t pos;
const git_index_entry *entry; const git_index_entry *entry;
...@@ -63,11 +63,11 @@ static void add_and_check_mode_( ...@@ -63,11 +63,11 @@ static void add_and_check_mode_(
cl_git_pass(git_index_add_bypath(index, filename)); cl_git_pass(git_index_add_bypath(index, filename));
clar__assert(!git_index_find(&pos, index, filename), clar__assert(!git_index_find(&pos, index, filename),
file, line, "Cannot find index entry", NULL, 1); file, func, line, "Cannot find index entry", NULL, 1);
entry = git_index_get_byindex(index, pos); entry = git_index_get_byindex(index, pos);
clar__assert_equal(file, line, "Expected mode does not match index", clar__assert_equal(file, func, line, "Expected mode does not match index",
1, "%07o", (unsigned int)entry->mode, (unsigned int)expect_mode); 1, "%07o", (unsigned int)entry->mode, (unsigned int)expect_mode);
} }
...@@ -153,11 +153,11 @@ void test_index_filemodes__trusted(void) ...@@ -153,11 +153,11 @@ void test_index_filemodes__trusted(void)
git_index_free(index); git_index_free(index);
} }
#define add_entry_and_check_mode(I,FF,X) add_entry_and_check_mode_(I,FF,X,__FILE__,__LINE__) #define add_entry_and_check_mode(I,FF,X) add_entry_and_check_mode_(I,FF,X,__FILE__,__func__,__LINE__)
static void add_entry_and_check_mode_( static void add_entry_and_check_mode_(
git_index *index, bool from_file, git_filemode_t mode, git_index *index, bool from_file, git_filemode_t mode,
const char *file, int line) const char *file, const char *func, int line)
{ {
size_t pos; size_t pos;
const git_index_entry* entry; const git_index_entry* entry;
...@@ -169,7 +169,7 @@ static void add_entry_and_check_mode_( ...@@ -169,7 +169,7 @@ static void add_entry_and_check_mode_(
if (from_file) if (from_file)
{ {
clar__assert(!git_index_find(&pos, index, "exec_off"), clar__assert(!git_index_find(&pos, index, "exec_off"),
file, line, "Cannot find original index entry", NULL, 1); file, func, line, "Cannot find original index entry", NULL, 1);
entry = git_index_get_byindex(index, pos); entry = git_index_get_byindex(index, pos);
...@@ -184,21 +184,21 @@ static void add_entry_and_check_mode_( ...@@ -184,21 +184,21 @@ static void add_entry_and_check_mode_(
if (from_file) if (from_file)
{ {
clar__assert(!git_index_add(index, &new_entry), clar__assert(!git_index_add(index, &new_entry),
file, line, "Cannot add index entry", NULL, 1); file, func, line, "Cannot add index entry", NULL, 1);
} }
else else
{ {
const char *content = "hey there\n"; const char *content = "hey there\n";
clar__assert(!git_index_add_from_buffer(index, &new_entry, content, strlen(content)), clar__assert(!git_index_add_from_buffer(index, &new_entry, content, strlen(content)),
file, line, "Cannot add index entry from buffer", NULL, 1); file, func, line, "Cannot add index entry from buffer", NULL, 1);
} }
clar__assert(!git_index_find(&pos, index, "filemodes/explicit_test"), clar__assert(!git_index_find(&pos, index, "filemodes/explicit_test"),
file, line, "Cannot find new index entry", NULL, 1); file, func, line, "Cannot find new index entry", NULL, 1);
entry = git_index_get_byindex(index, pos); entry = git_index_get_byindex(index, pos);
clar__assert_equal(file, line, "Expected mode does not match index", clar__assert_equal(file, func, line, "Expected mode does not match index",
1, "%07o", (unsigned int)entry->mode, (unsigned int)mode); 1, "%07o", (unsigned int)entry->mode, (unsigned int)mode);
} }
......
...@@ -49,9 +49,9 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void) ...@@ -49,9 +49,9 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
* tree 2b297e643c551e76cfa1f93810c50811382f9117 * tree 2b297e643c551e76cfa1f93810c50811382f9117
* author nulltoken <emeric.fermas@gmail.com> 1323847743 +0100 * author nulltoken <emeric.fermas@gmail.com> 1323847743 +0100
* committer nulltoken <emeric.fermas@gmail.com> 1323847743 +0100 * committer nulltoken <emeric.fermas@gmail.com> 1323847743 +0100
* *
* Initial commit * Initial commit
* *
* diff --git a/test.txt b/test.txt * diff --git a/test.txt b/test.txt
* new file mode 100644 * new file mode 100644
* index 0000000..9daeafb * index 0000000..9daeafb
...@@ -141,14 +141,14 @@ static void assert_commit_tree_has_n_entries(git_commit *c, int count) ...@@ -141,14 +141,14 @@ static void assert_commit_tree_has_n_entries(git_commit *c, int count)
git_tree_free(tree); git_tree_free(tree);
} }
static void assert_commit_is_head_(git_commit *c, const char *file, int line) static void assert_commit_is_head_(git_commit *c, const char *file, const char *func, int line)
{ {
git_commit *head; git_commit *head;
cl_git_pass(git_revparse_single((git_object **)&head, repo, "HEAD")); cl_git_pass(git_revparse_single((git_object **)&head, repo, "HEAD"));
clar__assert(git_oid_equal(git_commit_id(c), git_commit_id(head)), file, line, "Commit is not the HEAD", NULL, 1); clar__assert(git_oid_equal(git_commit_id(c), git_commit_id(head)), file, func, line, "Commit is not the HEAD", NULL, 1);
git_commit_free(head); git_commit_free(head);
} }
#define assert_commit_is_head(C) assert_commit_is_head_((C),__FILE__,__LINE__) #define assert_commit_is_head(C) assert_commit_is_head_((C),__FILE__,__func__,__LINE__)
void test_object_commit_commitstagedfile__amend_commit(void) void test_object_commit_commitstagedfile__amend_commit(void)
{ {
......
...@@ -453,7 +453,8 @@ static void test_invalid_objects(bool should_allow_invalid) ...@@ -453,7 +453,8 @@ static void test_invalid_objects(bool should_allow_invalid)
git_oid valid_blob_id, invalid_blob_id, valid_tree_id, invalid_tree_id; git_oid valid_blob_id, invalid_blob_id, valid_tree_id, invalid_tree_id;
#define assert_allowed(expr) \ #define assert_allowed(expr) \
clar__assert(!(expr) == should_allow_invalid, __FILE__, __LINE__, \ clar__assert(!(expr) == should_allow_invalid, \
__FILE__, __func__, __LINE__, \
(should_allow_invalid ? \ (should_allow_invalid ? \
"Expected function call to succeed: " #expr : \ "Expected function call to succeed: " #expr : \
"Expected function call to fail: " #expr), \ "Expected function call to fail: " #expr), \
......
...@@ -29,7 +29,8 @@ size_t reflog_entrycount(git_repository *repo, const char *name) ...@@ -29,7 +29,8 @@ size_t reflog_entrycount(git_repository *repo, const char *name)
void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx, void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx,
const char *old_spec, const char *new_spec, const char *old_spec, const char *new_spec,
const char *email, const char *message, const char *file, int line) const char *email, const char *message,
const char *file, const char *func, int line)
{ {
git_reflog *log; git_reflog *log;
const git_reflog_entry *entry; const git_reflog_entry *entry;
...@@ -38,7 +39,7 @@ void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx ...@@ -38,7 +39,7 @@ void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx
cl_git_pass(git_reflog_read(&log, repo, reflog)); cl_git_pass(git_reflog_read(&log, repo, reflog));
entry = git_reflog_entry_byindex(log, idx); entry = git_reflog_entry_byindex(log, idx);
if (entry == NULL) if (entry == NULL)
clar__fail(file, line, "Reflog has no such entry", NULL, 1); clar__fail(file, func, line, "Reflog has no such entry", NULL, 1);
if (old_spec) { if (old_spec) {
git_object *obj = NULL; git_object *obj = NULL;
...@@ -92,7 +93,7 @@ void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx ...@@ -92,7 +93,7 @@ void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx
git_buf_printf(&result, "\tMessage: \"%s\" != \"%s\"\n", message, entry_msg); git_buf_printf(&result, "\tMessage: \"%s\" != \"%s\"\n", message, entry_msg);
} }
if (git_buf_len(&result) != 0) if (git_buf_len(&result) != 0)
clar__fail(file, line, "Reflog entry mismatch", git_buf_cstr(&result), 1); clar__fail(file, func, line, "Reflog entry mismatch", git_buf_cstr(&result), 1);
git_buf_dispose(&result); git_buf_dispose(&result);
git_reflog_free(log); git_reflog_free(log);
......
...@@ -53,44 +53,44 @@ static int GIT_FORMAT_PRINTF(2, 3) cl_setenv_printf(const char *name, const char ...@@ -53,44 +53,44 @@ static int GIT_FORMAT_PRINTF(2, 3) cl_setenv_printf(const char *name, const char
* from the caller rather than those of the helper. The expression strings * from the caller rather than those of the helper. The expression strings
* distinguish between the possible failures within the helper. */ * distinguish between the possible failures within the helper. */
static void env_pass_(const char *path, const char *file, int line) static void env_pass_(const char *path, const char *file, const char *func, int line)
{ {
git_repository *repo; git_repository *repo;
cl_git_expect(git_repository_open_ext(NULL, path, GIT_REPOSITORY_OPEN_FROM_ENV, NULL), 0, file, line); cl_git_expect(git_repository_open_ext(NULL, path, GIT_REPOSITORY_OPEN_FROM_ENV, NULL), 0, file, func, line);
cl_git_expect(git_repository_open_ext(&repo, path, GIT_REPOSITORY_OPEN_FROM_ENV, NULL), 0, file, line); cl_git_expect(git_repository_open_ext(&repo, path, GIT_REPOSITORY_OPEN_FROM_ENV, NULL), 0, file, func, line);
cl_assert_at_line(git__suffixcmp(git_repository_path(repo), "attr/.git/") == 0, file, line); cl_assert_at_line(git__suffixcmp(git_repository_path(repo), "attr/.git/") == 0, file, func, line);
cl_assert_at_line(git__suffixcmp(git_repository_workdir(repo), "attr/") == 0, file, line); cl_assert_at_line(git__suffixcmp(git_repository_workdir(repo), "attr/") == 0, file, func, line);
cl_assert_at_line(!git_repository_is_bare(repo), file, line); cl_assert_at_line(!git_repository_is_bare(repo), file, func, line);
git_repository_free(repo); git_repository_free(repo);
} }
#define env_pass(path) env_pass_((path), __FILE__, __LINE__) #define env_pass(path) env_pass_((path), __FILE__, __func__, __LINE__)
#define cl_git_fail_at_line(expr, file, line) clar__assert((expr) < 0, file, line, "Expected function call to fail: " #expr, NULL, 1) #define cl_git_fail_at_line(expr, file, func, line) clar__assert((expr) < 0, file, func, line, "Expected function call to fail: " #expr, NULL, 1)
static void env_fail_(const char *path, const char *file, int line) static void env_fail_(const char *path, const char *file, const char *func, int line)
{ {
git_repository *repo; git_repository *repo;
cl_git_fail_at_line(git_repository_open_ext(NULL, path, GIT_REPOSITORY_OPEN_FROM_ENV, NULL), file, line); cl_git_fail_at_line(git_repository_open_ext(NULL, path, GIT_REPOSITORY_OPEN_FROM_ENV, NULL), file, func, line);
cl_git_fail_at_line(git_repository_open_ext(&repo, path, GIT_REPOSITORY_OPEN_FROM_ENV, NULL), file, line); cl_git_fail_at_line(git_repository_open_ext(&repo, path, GIT_REPOSITORY_OPEN_FROM_ENV, NULL), file, func, line);
} }
#define env_fail(path) env_fail_((path), __FILE__, __LINE__) #define env_fail(path) env_fail_((path), __FILE__, __func__, __LINE__)
static void env_cd_( static void env_cd_(
const char *path, const char *path,
void (*passfail_)(const char *, const char *, int), void (*passfail_)(const char *, const char *, const char *, int),
const char *file, int line) const char *file, const char *func, int line)
{ {
git_buf cwd_buf = GIT_BUF_INIT; git_buf cwd_buf = GIT_BUF_INIT;
cl_git_pass(git_path_prettify_dir(&cwd_buf, ".", NULL)); cl_git_pass(git_path_prettify_dir(&cwd_buf, ".", NULL));
cl_must_pass(p_chdir(path)); cl_must_pass(p_chdir(path));
passfail_(NULL, file, line); passfail_(NULL, file, func, line);
cl_must_pass(p_chdir(git_buf_cstr(&cwd_buf))); cl_must_pass(p_chdir(git_buf_cstr(&cwd_buf)));
git_buf_dispose(&cwd_buf); git_buf_dispose(&cwd_buf);
} }
#define env_cd_pass(path) env_cd_((path), env_pass_, __FILE__, __LINE__) #define env_cd_pass(path) env_cd_((path), env_pass_, __FILE__, __func__, __LINE__)
#define env_cd_fail(path) env_cd_((path), env_fail_, __FILE__, __LINE__) #define env_cd_fail(path) env_cd_((path), env_fail_, __FILE__, __func__, __LINE__)
static void env_check_objects_(bool a, bool t, bool p, const char *file, int line) static void env_check_objects_(bool a, bool t, bool p, const char *file, const char *func, int line)
{ {
git_repository *repo; git_repository *repo;
git_oid oid_a, oid_t, oid_p; git_oid oid_a, oid_t, oid_p;
...@@ -98,32 +98,32 @@ static void env_check_objects_(bool a, bool t, bool p, const char *file, int lin ...@@ -98,32 +98,32 @@ static void env_check_objects_(bool a, bool t, bool p, const char *file, int lin
cl_git_pass(git_oid_fromstr(&oid_a, "45141a79a77842c59a63229403220a4e4be74e3d")); cl_git_pass(git_oid_fromstr(&oid_a, "45141a79a77842c59a63229403220a4e4be74e3d"));
cl_git_pass(git_oid_fromstr(&oid_t, "1385f264afb75a56a5bec74243be9b367ba4ca08")); cl_git_pass(git_oid_fromstr(&oid_t, "1385f264afb75a56a5bec74243be9b367ba4ca08"));
cl_git_pass(git_oid_fromstr(&oid_p, "0df1a5865c8abfc09f1f2182e6a31be550e99f07")); cl_git_pass(git_oid_fromstr(&oid_p, "0df1a5865c8abfc09f1f2182e6a31be550e99f07"));
cl_git_expect(git_repository_open_ext(&repo, "attr", GIT_REPOSITORY_OPEN_FROM_ENV, NULL), 0, file, line); cl_git_expect(git_repository_open_ext(&repo, "attr", GIT_REPOSITORY_OPEN_FROM_ENV, NULL), 0, file, func, line);
if (a) { if (a) {
cl_git_expect(git_object_lookup(&object, repo, &oid_a, GIT_OBJECT_BLOB), 0, file, line); cl_git_expect(git_object_lookup(&object, repo, &oid_a, GIT_OBJECT_BLOB), 0, file, func, line);
git_object_free(object); git_object_free(object);
} else { } else {
cl_git_fail_at_line(git_object_lookup(&object, repo, &oid_a, GIT_OBJECT_BLOB), file, line); cl_git_fail_at_line(git_object_lookup(&object, repo, &oid_a, GIT_OBJECT_BLOB), file, func, line);
} }
if (t) { if (t) {
cl_git_expect(git_object_lookup(&object, repo, &oid_t, GIT_OBJECT_BLOB), 0, file, line); cl_git_expect(git_object_lookup(&object, repo, &oid_t, GIT_OBJECT_BLOB), 0, file, func, line);
git_object_free(object); git_object_free(object);
} else { } else {
cl_git_fail_at_line(git_object_lookup(&object, repo, &oid_t, GIT_OBJECT_BLOB), file, line); cl_git_fail_at_line(git_object_lookup(&object, repo, &oid_t, GIT_OBJECT_BLOB), file, func, line);
} }
if (p) { if (p) {
cl_git_expect(git_object_lookup(&object, repo, &oid_p, GIT_OBJECT_COMMIT), 0, file, line); cl_git_expect(git_object_lookup(&object, repo, &oid_p, GIT_OBJECT_COMMIT), 0, file, func, line);
git_object_free(object); git_object_free(object);
} else { } else {
cl_git_fail_at_line(git_object_lookup(&object, repo, &oid_p, GIT_OBJECT_COMMIT), file, line); cl_git_fail_at_line(git_object_lookup(&object, repo, &oid_p, GIT_OBJECT_COMMIT), file, func, line);
} }
git_repository_free(repo); git_repository_free(repo);
} }
#define env_check_objects(a, t, t2) env_check_objects_((a), (t), (t2), __FILE__, __LINE__) #define env_check_objects(a, t, t2) env_check_objects_((a), (t), (t2), __FILE__, __func__, __LINE__)
void test_repo_env__open(void) void test_repo_env__open(void)
{ {
......
...@@ -9,6 +9,7 @@ typedef struct { ...@@ -9,6 +9,7 @@ typedef struct {
const char** expected_paths; const char** expected_paths;
int expected_entry_count; int expected_entry_count;
const char *file; const char *file;
const char *func;
int line; int line;
bool debug; bool debug;
} status_entry_counts; } status_entry_counts;
...@@ -18,6 +19,7 @@ typedef struct { ...@@ -18,6 +19,7 @@ typedef struct {
(counts).expected_statuses = (statuses); \ (counts).expected_statuses = (statuses); \
(counts).expected_paths = (paths); \ (counts).expected_paths = (paths); \
(counts).file = __FILE__; \ (counts).file = __FILE__; \
(counts).func = __func__; \
(counts).line = __LINE__; \ (counts).line = __LINE__; \
} while (0) } while (0)
......
...@@ -71,12 +71,12 @@ static int cb_status__match(const char *p, unsigned int s, void *payload) ...@@ -71,12 +71,12 @@ static int cb_status__match(const char *p, unsigned int s, void *payload)
int idx = counts->entry_count++; int idx = counts->entry_count++;
clar__assert_equal( clar__assert_equal(
counts->file, counts->line, counts->file, counts->func, counts->line,
"Status path mismatch", 1, "Status path mismatch", 1,
"%s", counts->expected_paths[idx], p); "%s", counts->expected_paths[idx], p);
clar__assert_equal( clar__assert_equal(
counts->file, counts->line, counts->file, counts->func, counts->line,
"Status code mismatch", 1, "Status code mismatch", 1,
"%o", counts->expected_statuses[idx], s); "%o", counts->expected_statuses[idx], s);
......
...@@ -199,22 +199,22 @@ git_repository *setup_fixture_submodule_with_path(void) ...@@ -199,22 +199,22 @@ git_repository *setup_fixture_submodule_with_path(void)
void assert__submodule_exists( void assert__submodule_exists(
git_repository *repo, const char *name, git_repository *repo, const char *name,
const char *msg, const char *file, int line) const char *msg, const char *file, const char *func, int line)
{ {
git_submodule *sm; git_submodule *sm;
int error = git_submodule_lookup(&sm, repo, name); int error = git_submodule_lookup(&sm, repo, name);
if (error) if (error)
cl_git_report_failure(error, 0, file, line, msg); cl_git_report_failure(error, 0, file, func, line, msg);
cl_assert_at_line(sm != NULL, file, line); cl_assert_at_line(sm != NULL, file, func, line);
git_submodule_free(sm); git_submodule_free(sm);
} }
void refute__submodule_exists( void refute__submodule_exists(
git_repository *repo, const char *name, int expected_error, git_repository *repo, const char *name, int expected_error,
const char *msg, const char *file, int line) const char *msg, const char *file, const char *func, int line)
{ {
clar__assert_equal( clar__assert_equal(
file, line, msg, 1, "%i", file, func, line, msg, 1, "%i",
expected_error, (int)(git_submodule_lookup(NULL, repo, name))); expected_error, (int)(git_submodule_lookup(NULL, repo, name)));
} }
......
...@@ -10,16 +10,16 @@ extern git_repository *setup_fixture_submodule_with_path(void); ...@@ -10,16 +10,16 @@ extern git_repository *setup_fixture_submodule_with_path(void);
extern unsigned int get_submodule_status(git_repository *, const char *); extern unsigned int get_submodule_status(git_repository *, const char *);
extern void assert__submodule_exists( extern void assert__submodule_exists(git_repository *, const char *,
git_repository *, const char *, const char *, const char *, int); const char *, const char *, const char *, int);
#define assert_submodule_exists(repo,name) \ #define assert_submodule_exists(repo,name) \
assert__submodule_exists(repo, name, "git_submodule_lookup(" #name ") failed", __FILE__, __LINE__) assert__submodule_exists(repo, name, "git_submodule_lookup(" #name ") failed", __FILE__, __func__, __LINE__)
extern void refute__submodule_exists( extern void refute__submodule_exists(git_repository *, const char *,
git_repository *, const char *, int err, const char *, const char *, int); int err, const char *, const char *, const char *, int);
#define refute_submodule_exists(repo,name,code) \ #define refute_submodule_exists(repo,name,code) \
refute__submodule_exists(repo, name, code, "expected git_submodule_lookup(" #name ") to fail with error " #code, __FILE__, __LINE__) refute__submodule_exists(repo, name, code, "expected git_submodule_lookup(" #name ") to fail with error " #code, __FILE__, __func__, __LINE__)
extern void dump_submodules(git_repository *repo); extern void dump_submodules(git_repository *repo);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment