Update to the latest version of tinytest

This brings us up to tinytest 709a36ba63ff16d8
This commit is contained in:
Nick Mathewson 2014-03-06 18:09:00 -05:00
parent 239d8345be
commit 7a80476768
4 changed files with 55 additions and 2 deletions

View File

@ -31,6 +31,8 @@
#include <string.h>
#include <assert.h>
#ifndef NO_FORKING
#ifdef _WIN32
#include <windows.h>
#else
@ -48,6 +50,8 @@
#endif
#endif
#endif /* !NO_FORKING */
#ifndef __GNUC__
#define __attribute__(x)
#endif
@ -111,6 +115,8 @@ testcase_run_bare_(const struct testcase_t *testcase)
#define MAGIC_EXITCODE 42
#ifndef NO_FORKING
static enum outcome
testcase_run_forked_(const struct testgroup_t *group,
const struct testcase_t *testcase)
@ -211,6 +217,8 @@ testcase_run_forked_(const struct testgroup_t *group,
#endif
}
#endif /* !NO_FORKING */
int
testcase_run_one(const struct testgroup_t *group,
const struct testcase_t *testcase)
@ -234,9 +242,13 @@ testcase_run_one(const struct testgroup_t *group,
cur_test_name = testcase->name;
}
#ifndef NO_FORKING
if ((testcase->flags & TT_FORK) && !(opt_forked||opt_nofork)) {
outcome = testcase_run_forked_(group, testcase);
} else {
#else
{
#endif
outcome = testcase_run_bare_(testcase);
}
@ -411,7 +423,9 @@ tinytest_main(int c, const char **v, struct testgroup_t *groups)
if (!n)
tinytest_set_flag_(groups, "..", 1, TT_ENABLED_);
#ifdef _IONBF
setvbuf(stdout, NULL, _IONBF, 0);
#endif
++in_tinytest_main;
for (i=0; groups[i].prefix; ++i)
@ -458,3 +472,22 @@ tinytest_set_test_skipped_(void)
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;
}

View File

@ -81,6 +81,8 @@ int tinytest_get_verbosity_(void);
/** Implementation: Set a flag on tests matching a name; returns number
* of tests that matched. */
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. */
#define tinytest_skip(groups, named) \

View File

@ -152,6 +152,9 @@ test_memcpy(void *ptr)
memcpy(db->buffer2, db->buffer1, sizeof(db->buffer1));
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.
The end block of the function will clean it up. */
mem = strdup("Hello world.");

View File

@ -144,6 +144,10 @@
tt_assert_test_fmt_type(a,b,str_test,type,test,type,fmt, \
{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
* printf format fmt on failure. */
#define tt_assert_op_type(a,op,b,type,fmt) \
@ -163,8 +167,19 @@
(val1_ op val2_),"%p",TT_EXIT_TEST_FUNCTION)
#define tt_str_op(a,op,b) \
tt_assert_test_type(a,b,#a" "#op" "#b,const char *, \
(strcmp(val1_,val2_) op 0),"<%s>",TT_EXIT_TEST_FUNCTION)
tt_assert_test_type_opt(a,b,#a" "#op" "#b,const char *, \
(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) \
tt_assert_test_type(a,b,#a" "#op" "#b,long,(val1_ op val2_),"%ld",(void)0)