mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-11 05:14:46 -04:00
Update to the latest version of tinytest
This brings us up to tinytest 709a36ba63ff16d8
This commit is contained in:
parent
239d8345be
commit
7a80476768
@ -31,6 +31,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
#ifndef NO_FORKING
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#else
|
#else
|
||||||
@ -48,6 +50,8 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif /* !NO_FORKING */
|
||||||
|
|
||||||
#ifndef __GNUC__
|
#ifndef __GNUC__
|
||||||
#define __attribute__(x)
|
#define __attribute__(x)
|
||||||
#endif
|
#endif
|
||||||
@ -111,6 +115,8 @@ testcase_run_bare_(const struct testcase_t *testcase)
|
|||||||
|
|
||||||
#define MAGIC_EXITCODE 42
|
#define MAGIC_EXITCODE 42
|
||||||
|
|
||||||
|
#ifndef NO_FORKING
|
||||||
|
|
||||||
static enum outcome
|
static enum outcome
|
||||||
testcase_run_forked_(const struct testgroup_t *group,
|
testcase_run_forked_(const struct testgroup_t *group,
|
||||||
const struct testcase_t *testcase)
|
const struct testcase_t *testcase)
|
||||||
@ -211,6 +217,8 @@ testcase_run_forked_(const struct testgroup_t *group,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* !NO_FORKING */
|
||||||
|
|
||||||
int
|
int
|
||||||
testcase_run_one(const struct testgroup_t *group,
|
testcase_run_one(const struct testgroup_t *group,
|
||||||
const struct testcase_t *testcase)
|
const struct testcase_t *testcase)
|
||||||
@ -234,9 +242,13 @@ testcase_run_one(const struct testgroup_t *group,
|
|||||||
cur_test_name = testcase->name;
|
cur_test_name = testcase->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef NO_FORKING
|
||||||
if ((testcase->flags & TT_FORK) && !(opt_forked||opt_nofork)) {
|
if ((testcase->flags & TT_FORK) && !(opt_forked||opt_nofork)) {
|
||||||
outcome = testcase_run_forked_(group, testcase);
|
outcome = testcase_run_forked_(group, testcase);
|
||||||
} else {
|
} else {
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
#endif
|
||||||
outcome = testcase_run_bare_(testcase);
|
outcome = testcase_run_bare_(testcase);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -411,7 +423,9 @@ tinytest_main(int c, const char **v, struct testgroup_t *groups)
|
|||||||
if (!n)
|
if (!n)
|
||||||
tinytest_set_flag_(groups, "..", 1, TT_ENABLED_);
|
tinytest_set_flag_(groups, "..", 1, TT_ENABLED_);
|
||||||
|
|
||||||
|
#ifdef _IONBF
|
||||||
setvbuf(stdout, NULL, _IONBF, 0);
|
setvbuf(stdout, NULL, _IONBF, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
++in_tinytest_main;
|
++in_tinytest_main;
|
||||||
for (i=0; groups[i].prefix; ++i)
|
for (i=0; groups[i].prefix; ++i)
|
||||||
@ -458,3 +472,22 @@ tinytest_set_test_skipped_(void)
|
|||||||
cur_test_outcome = SKIP;
|
cur_test_outcome = SKIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
tinytest_format_hex_(const void *val_, unsigned long len)
|
||||||
|
{
|
||||||
|
const unsigned char *val = val_;
|
||||||
|
char *result, *cp;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (!val)
|
||||||
|
return strdup("null");
|
||||||
|
if (!(result = malloc(len*2+1)))
|
||||||
|
return strdup("<allocation failure>");
|
||||||
|
cp = result;
|
||||||
|
for (i=0;i<len;++i) {
|
||||||
|
*cp++ = "0123456789ABCDEF"[val[i] >> 4];
|
||||||
|
*cp++ = "0123456789ABCDEF"[val[i] & 0x0f];
|
||||||
|
}
|
||||||
|
*cp = 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
@ -81,6 +81,8 @@ int tinytest_get_verbosity_(void);
|
|||||||
/** Implementation: Set a flag on tests matching a name; returns number
|
/** Implementation: Set a flag on tests matching a name; returns number
|
||||||
* of tests that matched. */
|
* of tests that matched. */
|
||||||
int tinytest_set_flag_(struct testgroup_t *, const char *, int set, unsigned long);
|
int tinytest_set_flag_(struct testgroup_t *, const char *, int set, unsigned long);
|
||||||
|
/** Implementation: Put a chunk of memory into hex. */
|
||||||
|
char *tinytest_format_hex_(const void *, unsigned long);
|
||||||
|
|
||||||
/** Set all tests in 'groups' matching the name 'named' to be skipped. */
|
/** Set all tests in 'groups' matching the name 'named' to be skipped. */
|
||||||
#define tinytest_skip(groups, named) \
|
#define tinytest_skip(groups, named) \
|
||||||
|
@ -152,6 +152,9 @@ test_memcpy(void *ptr)
|
|||||||
memcpy(db->buffer2, db->buffer1, sizeof(db->buffer1));
|
memcpy(db->buffer2, db->buffer1, sizeof(db->buffer1));
|
||||||
tt_str_op(db->buffer1, ==, db->buffer2);
|
tt_str_op(db->buffer1, ==, db->buffer2);
|
||||||
|
|
||||||
|
/* This one works if there's an internal NUL. */
|
||||||
|
tt_mem_op(db->buffer1, <, db->buffer2, sizeof(db->buffer1));
|
||||||
|
|
||||||
/* Now we've allocated memory that's referenced by a local variable.
|
/* Now we've allocated memory that's referenced by a local variable.
|
||||||
The end block of the function will clean it up. */
|
The end block of the function will clean it up. */
|
||||||
mem = strdup("Hello world.");
|
mem = strdup("Hello world.");
|
||||||
|
@ -144,6 +144,10 @@
|
|||||||
tt_assert_test_fmt_type(a,b,str_test,type,test,type,fmt, \
|
tt_assert_test_fmt_type(a,b,str_test,type,test,type,fmt, \
|
||||||
{print_=value_;},{},die_on_fail)
|
{print_=value_;},{},die_on_fail)
|
||||||
|
|
||||||
|
#define tt_assert_test_type_opt(a,b,str_test,type,test,fmt,die_on_fail) \
|
||||||
|
tt_assert_test_fmt_type(a,b,str_test,type,test,type,fmt, \
|
||||||
|
{print_=value_?value_:"<NULL>";},{},die_on_fail)
|
||||||
|
|
||||||
/* Helper: assert that a op b, when cast to type. Format the values with
|
/* Helper: assert that a op b, when cast to type. Format the values with
|
||||||
* printf format fmt on failure. */
|
* printf format fmt on failure. */
|
||||||
#define tt_assert_op_type(a,op,b,type,fmt) \
|
#define tt_assert_op_type(a,op,b,type,fmt) \
|
||||||
@ -163,8 +167,19 @@
|
|||||||
(val1_ op val2_),"%p",TT_EXIT_TEST_FUNCTION)
|
(val1_ op val2_),"%p",TT_EXIT_TEST_FUNCTION)
|
||||||
|
|
||||||
#define tt_str_op(a,op,b) \
|
#define tt_str_op(a,op,b) \
|
||||||
tt_assert_test_type(a,b,#a" "#op" "#b,const char *, \
|
tt_assert_test_type_opt(a,b,#a" "#op" "#b,const char *, \
|
||||||
(strcmp(val1_,val2_) op 0),"<%s>",TT_EXIT_TEST_FUNCTION)
|
(val1_ && val2_ && strcmp(val1_,val2_) op 0),"<%s>", \
|
||||||
|
TT_EXIT_TEST_FUNCTION)
|
||||||
|
|
||||||
|
#define tt_mem_op(expr1, op, expr2, len) \
|
||||||
|
tt_assert_test_fmt_type(expr1,expr2,#expr1" "#op" "#expr2, \
|
||||||
|
const char *, \
|
||||||
|
(val1_ && val2_ && memcmp(val1_, val2_, len) op 0), \
|
||||||
|
char *, "%s", \
|
||||||
|
{ print_ = tinytest_format_hex_(value_, (len)); }, \
|
||||||
|
{ if (print_) free(print_); }, \
|
||||||
|
TT_EXIT_TEST_FUNCTION \
|
||||||
|
);
|
||||||
|
|
||||||
#define tt_want_int_op(a,op,b) \
|
#define tt_want_int_op(a,op,b) \
|
||||||
tt_assert_test_type(a,b,#a" "#op" "#b,long,(val1_ op val2_),"%ld",(void)0)
|
tt_assert_test_type(a,b,#a" "#op" "#b,long,(val1_ op val2_),"%ld",(void)0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user