diff options
| author | Garrett D'Amore <garrett@damore.org> | 2016-12-18 19:44:12 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2016-12-18 19:44:12 -0800 |
| commit | 260ce618d98c9ec732362ab82b2efeb2c412ac24 (patch) | |
| tree | b3320f61913eb2c8dc0ef9d779c02747039a214d | |
| parent | 5293a691d6036d9bccdfceab250443ca3dc92051 (diff) | |
| download | nng-260ce618d98c9ec732362ab82b2efeb2c412ac24.tar.gz nng-260ce618d98c9ec732362ab82b2efeb2c412ac24.tar.bz2 nng-260ce618d98c9ec732362ab82b2efeb2c412ac24.zip | |
Suppress exposure of contexts to code under test.
Fix timing display, and other output bugs.
| -rw-r--r-- | tests/demo.c | 5 | ||||
| -rw-r--r-- | tests/test.c | 48 | ||||
| -rw-r--r-- | tests/test.h | 18 |
3 files changed, 31 insertions, 40 deletions
diff --git a/tests/demo.c b/tests/demo.c index 26210391..9ff70727 100644 --- a/tests/demo.c +++ b/tests/demo.c @@ -54,8 +54,11 @@ test_main_group({ test_group("Second group", { int x = 1; + static int y =1; test_convey("x is 1", { - sleep(2); +#ifndef _WIN32 + sleep(1); +#endif test_so(x == 1); }); }); diff --git a/tests/test.c b/tests/test.c index 98c7d333..1fb99113 100644 --- a/tests/test.c +++ b/tests/test.c @@ -135,11 +135,9 @@ print_result(tctx_t *t) { int secs, usecs; - stop_perfcnt(&t->t_perfcnt); /* This is idempotent */ - if (t->t_root == t) { + stop_perfcnt(&t->t_perfcnt); /* This is idempotent */ - stop_perfcnt(&t->t_perfcnt); read_perfcnt(&t->t_perfcnt, &secs, &usecs); log_dump(t->t_fatallog, "Errors:", color_red); @@ -147,19 +145,16 @@ print_result(tctx_t *t) if (debug) { log_dump(t->t_debuglog, "Log:", color_none); } - if (!verbose) { - (void) printf("%-8s%-52s%4d.%03ds\n", - t->t_fatal ? "FATAL" : - t->t_fail ? "FAIL" : "ok", - t->t_name, secs, usecs / 1000); - } else { - printf("\n\n%s%d assertions thus far%s", + if (verbose) { + (void) printf("\n\n%s%d assertions thus far%s", color_asserts, nasserts, color_none); if (nskips) { - printf(" %s(one or more sections skipped)%s", - color_yellow, color_none); + (void) printf(" %s%s%s", + color_yellow, + "(one or more sections skipped)", + color_none); } - printf("\n\n--- %s: %s (%d.%02d)\n", + (void) printf("\n\n--- %s: %s (%d.%02d)\n", t->t_fatal ? "FATAL" : t->t_fail ? "FAIL" : "PASS", t->t_name, secs, usecs / 10000); @@ -191,10 +186,11 @@ print_result(tctx_t *t) * and it should be skipped. Otherwise, it needs to be done. */ int -test_i_start(test_ctx_t *ctx, test_ctx_t *parent, const char *name) +test_i_start(test_ctx_t *ctx, const char *name) { - tctx_t *t; + tctx_t *t, *parent; + parent = get_ctx(); if ((t = ctx->T_data) != NULL) { if (t->t_done) { @@ -211,7 +207,7 @@ test_i_start(test_ctx_t *ctx, test_ctx_t *parent, const char *name) (void) snprintf(t->t_name, sizeof(t->t_name)-1, "%s", name); if (parent != NULL) { - t->t_parent = parent->T_data; + t->t_parent = parent; t->t_root = t->t_parent->t_root; t->t_level = t->t_parent->t_level + 1; /* unified logging against the root context */ @@ -280,14 +276,14 @@ test_i_loop(test_ctx_t *ctx, int unwind) if (verbose) { if (t->t_root == t) { - printf("=== RUN: %s\n", t->t_name); + (void) printf("=== RUN: %s\n", t->t_name); } else { - printf("\n"); + (void) printf("\n"); for (i = 0; i < t->t_level; i++) { - printf(" "); + (void) printf(" "); } - printf("%s ", t->t_name); - fflush(stdout); + (void) printf("%s ", t->t_name); + (void) fflush(stdout); } } @@ -295,7 +291,7 @@ test_i_loop(test_ctx_t *ctx, int unwind) start_perfcnt(&t->t_perfcnt); } /* Reset TC for the following code. */ - set_specific(ctx); + set_specific(t); return (0); } @@ -564,16 +560,10 @@ get_specific(void) } #endif -test_ctx_t * -test_get_context(void) -{ - return (get_specific()); -} - static tctx_t * get_ctx(void) { - return (test_get_context()->T_data); + return (get_specific()); } /* diff --git a/tests/test.h b/tests/test.h index cf7bc76b..b14101f6 100644 --- a/tests/test.h +++ b/tests/test.h @@ -80,10 +80,8 @@ typedef struct test_ctx { void *T_data; } test_ctx_t; -#define T_C test_get_context() - /* These functions are not for use by tests -- they are used internally. */ -extern int test_i_start(test_ctx_t *, test_ctx_t *, const char *); +extern int test_i_start(test_ctx_t *, const char *); extern int test_i_loop(test_ctx_t *, int); extern void test_i_finish(test_ctx_t *, int *); extern int test_i_main(int, char **); @@ -102,11 +100,11 @@ extern void test_i_fatal(const char *, int, const char *); * code. It has to be here exposed, in order for setjmp() to work. * and for the code block to be inlined. */ -#define test_i_run(T_parent, T_name, T_code, T_reset, T_rvp) \ +#define test_i_run(T_name, T_code, T_reset, T_rvp) \ do { \ static test_ctx_t T_ctx; \ int T_unwind; \ - if (test_i_start(&T_ctx, T_parent, T_name) != 0) { \ + if (test_i_start(&T_ctx, T_name) != 0) { \ break; \ } \ T_unwind = setjmp(T_ctx.T_jmp); \ @@ -132,7 +130,7 @@ extern void test_i_fatal(const char *, int, const char *); #define test_main(T_name, T_code) \ int test_main_impl(void) { \ int T_rv; \ - test_i_run(NULL, T_name, T_code, /*NOP*/, &T_rv); \ + test_i_run(T_name, T_code, /*NOP*/, &T_rv); \ return (T_rv); \ } \ int main(int argc, char **argv) { \ @@ -161,7 +159,7 @@ extern void test_i_fatal(const char *, int, const char *); #define test_group_reset(T_name, T_code, T_reset) \ do { \ int T_rv; \ - test_i_run(NULL, T_name, T_code, T_reset, &T_rv); \ + test_i_run(T_name, T_code, T_reset, &T_rv); \ if (T_rv > test_main_rv) { \ test_main_rv = T_rv; \ } \ @@ -183,7 +181,7 @@ extern void test_i_fatal(const char *, int, const char *); * an error or failure in the code being tested. */ #define test_block(T_name, T_code, T_reset) \ - test_i_run(NULL, T_name, T_code, T_reset, NULL) + test_i_run(T_name, T_code, T_reset, NULL) /* * test_assert and test_so allow you to run assertions. @@ -218,7 +216,7 @@ extern void test_i_fatal(const char *, int, const char *); * within the body of a loop. */ #define test_convey(T_name, T_code) \ - test_i_run(T_C, T_name, T_code, /*NOP*/, NULL) + test_i_run(T_name, T_code, /*NOP*/, NULL) /* * test_convey_reset is like convey, but offers the ability to specify @@ -228,7 +226,7 @@ extern void test_i_fatal(const char *, int, const char *); * another way to clean up code just once.) */ #define test_convey_reset(T_name, T_code, T_reset) \ - test_i_run(T_C, T_name, T_code, T_reset, NULL) + test_i_run(T_name, T_code, T_reset, NULL) /* * test_skip() just stops processing of the rest of the current context, |
