| ... | ... |
@@ -1,5 +1,5 @@ |
| 1 | 1 |
/* |
| 2 |
- * Copyright (c) 2011-2016 Scott Vokes <vokes.s@gmail.com> |
|
| 2 |
+ * Copyright (c) 2011-2017 Scott Vokes <vokes.s@gmail.com> |
|
| 3 | 3 |
* |
| 4 | 4 |
* Permission to use, copy, modify, and/or distribute this software for any |
| 5 | 5 |
* purpose with or without fee is hereby granted, provided that the above |
| ... | ... |
@@ -17,14 +17,14 @@ |
| 17 | 17 |
#ifndef GREATEST_H |
| 18 | 18 |
#define GREATEST_H |
| 19 | 19 |
|
| 20 |
-#ifdef __cplusplus |
|
| 20 |
+#if defined(__cplusplus) && !defined(GREATEST_NO_EXTERN_CPLUSPLUS) |
|
| 21 | 21 |
extern "C" {
|
| 22 | 22 |
#endif |
| 23 | 23 |
|
| 24 |
-/* 1.2.2 */ |
|
| 24 |
+/* 1.3.1 */ |
|
| 25 | 25 |
#define GREATEST_VERSION_MAJOR 1 |
| 26 |
-#define GREATEST_VERSION_MINOR 2 |
|
| 27 |
-#define GREATEST_VERSION_PATCH 2 |
|
| 26 |
+#define GREATEST_VERSION_MINOR 3 |
|
| 27 |
+#define GREATEST_VERSION_PATCH 1 |
|
| 28 | 28 |
|
| 29 | 29 |
/* A unit testing system for C, contained in 1 file. |
| 30 | 30 |
* It doesn't use dynamic allocation or depend on anything |
| ... | ... |
@@ -122,6 +122,12 @@ int main(int argc, char **argv) {
|
| 122 | 122 |
#define GREATEST_USE_LONGJMP 1 |
| 123 | 123 |
#endif |
| 124 | 124 |
|
| 125 |
+/* Make it possible to replace fprintf with another |
|
| 126 |
+ * function with the same interface. */ |
|
| 127 |
+#ifndef GREATEST_FPRINTF |
|
| 128 |
+#define GREATEST_FPRINTF fprintf |
|
| 129 |
+#endif |
|
| 130 |
+ |
|
| 125 | 131 |
#if GREATEST_USE_LONGJMP |
| 126 | 132 |
#include <setjmp.h> |
| 127 | 133 |
#endif |
| ... | ... |
@@ -141,6 +147,7 @@ int main(int argc, char **argv) {
|
| 141 | 147 |
#define GREATEST_FLOAT_FMT "%g" |
| 142 | 148 |
#endif |
| 143 | 149 |
|
| 150 |
+ |
|
| 144 | 151 |
/********* |
| 145 | 152 |
* Types * |
| 146 | 153 |
*********/ |
| ... | ... |
@@ -162,12 +169,12 @@ typedef struct greatest_suite_info {
|
| 162 | 169 |
} greatest_suite_info; |
| 163 | 170 |
|
| 164 | 171 |
/* Type for a suite function. */ |
| 165 |
-typedef void (greatest_suite_cb)(void); |
|
| 172 |
+typedef void greatest_suite_cb(void); |
|
| 166 | 173 |
|
| 167 | 174 |
/* Types for setup/teardown callbacks. If non-NULL, these will be run |
| 168 | 175 |
* and passed the pointer to their additional data. */ |
| 169 |
-typedef void (greatest_setup_cb)(void *udata); |
|
| 170 |
-typedef void (greatest_teardown_cb)(void *udata); |
|
| 176 |
+typedef void greatest_setup_cb(void *udata); |
|
| 177 |
+typedef void greatest_teardown_cb(void *udata); |
|
| 171 | 178 |
|
| 172 | 179 |
/* Type for an equality comparison between two pointers of the same type. |
| 173 | 180 |
* Should return non-0 if equal, otherwise 0. |
| ... | ... |
@@ -201,6 +208,20 @@ typedef enum {
|
| 201 | 208 |
GREATEST_FLAG_LIST_ONLY = 0x02 |
| 202 | 209 |
} greatest_flag_t; |
| 203 | 210 |
|
| 211 |
+/* Internal state for a PRNG, used to shuffle test order. */ |
|
| 212 |
+struct greatest_prng {
|
|
| 213 |
+ unsigned char random_order; /* use random ordering? */ |
|
| 214 |
+ unsigned char initialized; /* is random ordering initialized? */ |
|
| 215 |
+ unsigned char pad_0[2]; |
|
| 216 |
+ unsigned long state; /* PRNG state */ |
|
| 217 |
+ unsigned long count; /* how many tests, this pass */ |
|
| 218 |
+ unsigned long count_ceil; /* total number of tests */ |
|
| 219 |
+ unsigned long count_run; /* total tests run */ |
|
| 220 |
+ unsigned long mod; /* power-of-2 ceiling of count_ceil */ |
|
| 221 |
+ unsigned long a; /* LCG multiplier */ |
|
| 222 |
+ unsigned long c; /* LCG increment */ |
|
| 223 |
+}; |
|
| 224 |
+ |
|
| 204 | 225 |
/* Struct containing all test runner state. */ |
| 205 | 226 |
typedef struct greatest_run_info {
|
| 206 | 227 |
unsigned char flags; |
| ... | ... |
@@ -237,6 +258,9 @@ typedef struct greatest_run_info {
|
| 237 | 258 |
/* only run a specific suite or test */ |
| 238 | 259 |
const char *suite_filter; |
| 239 | 260 |
const char *test_filter; |
| 261 |
+ const char *test_exclude; |
|
| 262 |
+ |
|
| 263 |
+ struct greatest_prng prng[2]; /* 0: suites, 1: tests */ |
|
| 240 | 264 |
|
| 241 | 265 |
#if GREATEST_USE_TIME |
| 242 | 266 |
/* overall timers */ |
| ... | ... |
@@ -273,18 +297,25 @@ typedef const char *greatest_enum_str_fun(int value); |
| 273 | 297 |
void greatest_do_pass(const char *name); |
| 274 | 298 |
void greatest_do_fail(const char *name); |
| 275 | 299 |
void greatest_do_skip(const char *name); |
| 276 |
-int greatest_pre_test(const char *name); |
|
| 277 |
-void greatest_post_test(const char *name, int res); |
|
| 300 |
+int greatest_suite_pre(const char *suite_name); |
|
| 301 |
+void greatest_suite_post(void); |
|
| 302 |
+int greatest_test_pre(const char *name); |
|
| 303 |
+void greatest_test_post(const char *name, int res); |
|
| 278 | 304 |
void greatest_usage(const char *name); |
| 279 | 305 |
int greatest_do_assert_equal_t(const void *exp, const void *got, |
| 280 |
- greatest_type_info *type_info, void *udata); |
|
| 306 |
+greatest_type_info *type_info, void *udata); |
|
| 307 |
+void greatest_prng_init_first_pass(int id); |
|
| 308 |
+int greatest_prng_init_second_pass(int id, unsigned long seed); |
|
| 309 |
+void greatest_prng_step(int id); |
|
| 281 | 310 |
|
| 282 | 311 |
/* These are part of the public greatest API. */ |
| 283 | 312 |
void GREATEST_SET_SETUP_CB(greatest_setup_cb *cb, void *udata); |
| 284 | 313 |
void GREATEST_SET_TEARDOWN_CB(greatest_teardown_cb *cb, void *udata); |
| 285 | 314 |
int greatest_all_passed(void); |
| 286 |
-void greatest_set_test_filter(const char *name); |
|
| 287 |
-void greatest_set_suite_filter(const char *name); |
|
| 315 |
+void greatest_set_suite_filter(const char *filter); |
|
| 316 |
+void greatest_set_test_filter(const char *filter); |
|
| 317 |
+void greatest_set_test_exclude(const char *filter); |
|
| 318 |
+void greatest_stop_at_first_fail(void); |
|
| 288 | 319 |
void greatest_get_report(struct greatest_report_t *report); |
| 289 | 320 |
unsigned int greatest_get_verbosity(void); |
| 290 | 321 |
void greatest_set_verbosity(unsigned int verbosity); |
| ... | ... |
@@ -329,14 +360,12 @@ typedef enum greatest_test_res {
|
| 329 | 360 |
/* Run a test in the current suite. */ |
| 330 | 361 |
#define GREATEST_RUN_TEST(TEST) \ |
| 331 | 362 |
do { \
|
| 332 |
- if (greatest_pre_test(#TEST) == 1) { \
|
|
| 363 |
+ if (greatest_test_pre(#TEST) == 1) { \
|
|
| 333 | 364 |
enum greatest_test_res res = GREATEST_SAVE_CONTEXT(); \ |
| 334 | 365 |
if (res == GREATEST_TEST_RES_PASS) { \
|
| 335 | 366 |
res = TEST(); \ |
| 336 | 367 |
} \ |
| 337 |
- greatest_post_test(#TEST, res); \ |
|
| 338 |
- } else if (GREATEST_LIST_ONLY()) { \
|
|
| 339 |
- fprintf(GREATEST_STDOUT, " %s\n", #TEST); \ |
|
| 368 |
+ greatest_test_post(#TEST, res); \ |
|
| 340 | 369 |
} \ |
| 341 | 370 |
} while (0) |
| 342 | 371 |
|
| ... | ... |
@@ -347,22 +376,24 @@ typedef enum greatest_test_res {
|
| 347 | 376 |
* which can be a pointer to a struct with multiple arguments. */ |
| 348 | 377 |
#define GREATEST_RUN_TEST1(TEST, ENV) \ |
| 349 | 378 |
do { \
|
| 350 |
- if (greatest_pre_test(#TEST) == 1) { \
|
|
| 351 |
- int res = TEST(ENV); \ |
|
| 352 |
- greatest_post_test(#TEST, res); \ |
|
| 353 |
- } else if (GREATEST_LIST_ONLY()) { \
|
|
| 354 |
- fprintf(GREATEST_STDOUT, " %s\n", #TEST); \ |
|
| 379 |
+ if (greatest_test_pre(#TEST) == 1) { \
|
|
| 380 |
+ enum greatest_test_res res = GREATEST_SAVE_CONTEXT(); \ |
|
| 381 |
+ if (res == GREATEST_TEST_RES_PASS) { \
|
|
| 382 |
+ res = TEST(ENV); \ |
|
| 383 |
+ } \ |
|
| 384 |
+ greatest_test_post(#TEST, res); \ |
|
| 355 | 385 |
} \ |
| 356 | 386 |
} while (0) |
| 357 | 387 |
|
| 358 | 388 |
#ifdef GREATEST_VA_ARGS |
| 359 | 389 |
#define GREATEST_RUN_TESTp(TEST, ...) \ |
| 360 | 390 |
do { \
|
| 361 |
- if (greatest_pre_test(#TEST) == 1) { \
|
|
| 362 |
- int res = TEST(__VA_ARGS__); \ |
|
| 363 |
- greatest_post_test(#TEST, res); \ |
|
| 364 |
- } else if (GREATEST_LIST_ONLY()) { \
|
|
| 365 |
- fprintf(GREATEST_STDOUT, " %s\n", #TEST); \ |
|
| 391 |
+ if (greatest_test_pre(#TEST) == 1) { \
|
|
| 392 |
+ enum greatest_test_res res = GREATEST_SAVE_CONTEXT(); \ |
|
| 393 |
+ if (res == GREATEST_TEST_RES_PASS) { \
|
|
| 394 |
+ res = TEST(__VA_ARGS__); \ |
|
| 395 |
+ } \ |
|
| 396 |
+ greatest_test_post(#TEST, res); \ |
|
| 366 | 397 |
} \ |
| 367 | 398 |
} while (0) |
| 368 | 399 |
#endif |
| ... | ... |
@@ -375,7 +406,8 @@ typedef enum greatest_test_res {
|
| 375 | 406 |
#define GREATEST_FIRST_FAIL() \ |
| 376 | 407 |
(greatest_info.flags & GREATEST_FLAG_FIRST_FAIL) |
| 377 | 408 |
#define GREATEST_FAILURE_ABORT() \ |
| 378 |
- (greatest_info.suite.failed > 0 && GREATEST_FIRST_FAIL()) |
|
| 409 |
+ (GREATEST_FIRST_FAIL() && \ |
|
| 410 |
+ (greatest_info.suite.failed > 0 || greatest_info.failed > 0)) |
|
| 379 | 411 |
|
| 380 | 412 |
/* Message-less forms of tests defined below. */ |
| 381 | 413 |
#define GREATEST_PASS() GREATEST_PASSm(NULL) |
| ... | ... |
@@ -442,11 +474,11 @@ typedef enum greatest_test_res {
|
| 442 | 474 |
do { \
|
| 443 | 475 |
greatest_info.assertions++; \ |
| 444 | 476 |
if ((EXP) != (GOT)) { \
|
| 445 |
- fprintf(GREATEST_STDOUT, "\nExpected: "); \ |
|
| 446 |
- fprintf(GREATEST_STDOUT, FMT, EXP); \ |
|
| 447 |
- fprintf(GREATEST_STDOUT, "\n Got: "); \ |
|
| 448 |
- fprintf(GREATEST_STDOUT, FMT, GOT); \ |
|
| 449 |
- fprintf(GREATEST_STDOUT, "\n"); \ |
|
| 477 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\nExpected: "); \ |
|
| 478 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, FMT, EXP); \ |
|
| 479 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\n Got: "); \ |
|
| 480 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, FMT, GOT); \ |
|
| 481 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\n"); \ |
|
| 450 | 482 |
GREATEST_FAILm(MSG); \ |
| 451 | 483 |
} \ |
| 452 | 484 |
} while (0) |
| ... | ... |
@@ -458,9 +490,9 @@ typedef enum greatest_test_res {
|
| 458 | 490 |
int greatest_GOT = (int)(GOT); \ |
| 459 | 491 |
greatest_enum_str_fun *greatest_ENUM_STR = ENUM_STR; \ |
| 460 | 492 |
if (greatest_EXP != greatest_GOT) { \
|
| 461 |
- fprintf(GREATEST_STDOUT, "\nExpected: %s", \ |
|
| 493 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\nExpected: %s", \ |
|
| 462 | 494 |
greatest_ENUM_STR(greatest_EXP)); \ |
| 463 |
- fprintf(GREATEST_STDOUT, "\n Got: %s\n", \ |
|
| 495 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\n Got: %s\n", \ |
|
| 464 | 496 |
greatest_ENUM_STR(greatest_GOT)); \ |
| 465 | 497 |
GREATEST_FAILm(MSG); \ |
| 466 | 498 |
} \ |
| ... | ... |
@@ -477,7 +509,7 @@ typedef enum greatest_test_res {
|
| 477 | 509 |
greatest_EXP - greatest_GOT > greatest_TOL) || \ |
| 478 | 510 |
(greatest_EXP < greatest_GOT && \ |
| 479 | 511 |
greatest_GOT - greatest_EXP > greatest_TOL)) { \
|
| 480 |
- fprintf(GREATEST_STDOUT, \ |
|
| 512 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, \ |
|
| 481 | 513 |
"\nExpected: " GREATEST_FLOAT_FMT \ |
| 482 | 514 |
" +/- " GREATEST_FLOAT_FMT \ |
| 483 | 515 |
"\n Got: " GREATEST_FLOAT_FMT \ |
| ... | ... |
@@ -578,13 +610,13 @@ typedef enum greatest_test_res {
|
| 578 | 610 |
#define GREATEST_SET_TIME(NAME) \ |
| 579 | 611 |
NAME = clock(); \ |
| 580 | 612 |
if (NAME == (clock_t) -1) { \
|
| 581 |
- fprintf(GREATEST_STDOUT, \ |
|
| 613 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, \ |
|
| 582 | 614 |
"clock error: %s\n", #NAME); \ |
| 583 | 615 |
exit(EXIT_FAILURE); \ |
| 584 | 616 |
} |
| 585 | 617 |
|
| 586 | 618 |
#define GREATEST_CLOCK_DIFF(C1, C2) \ |
| 587 |
- fprintf(GREATEST_STDOUT, " (%lu ticks, %.3f sec)", \ |
|
| 619 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, " (%lu ticks, %.3f sec)", \ |
|
| 588 | 620 |
(long unsigned int) (C2) - (long unsigned int)(C1), \ |
| 589 | 621 |
(double)((C2) - (C1)) / (1.0 * (double)CLOCKS_PER_SEC)) |
| 590 | 622 |
#else |
| ... | ... |
@@ -594,8 +626,8 @@ typedef enum greatest_test_res {
|
| 594 | 626 |
|
| 595 | 627 |
#if GREATEST_USE_LONGJMP |
| 596 | 628 |
#define GREATEST_SAVE_CONTEXT() \ |
| 597 |
- /* setjmp returns 0 (GREATEST_TEST_RES_PASS) on first call */ \ |
|
| 598 |
- /* so the test runs, then RES_FAIL from FAIL_WITH_LONGJMP. */ \ |
|
| 629 |
+ /* setjmp returns 0 (GREATEST_TEST_RES_PASS) on first call * \ |
|
| 630 |
+ * so the test runs, then RES_FAIL from FAIL_WITH_LONGJMP. */ \ |
|
| 599 | 631 |
((enum greatest_test_res)(setjmp(greatest_info.jump_dest))) |
| 600 | 632 |
#else |
| 601 | 633 |
#define GREATEST_SAVE_CONTEXT() \ |
| ... | ... |
@@ -603,14 +635,46 @@ typedef enum greatest_test_res {
|
| 603 | 635 |
GREATEST_TEST_RES_PASS |
| 604 | 636 |
#endif |
| 605 | 637 |
|
| 638 |
+/* Run every suite / test function run within BODY in pseudo-random |
|
| 639 |
+ * order, seeded by SEED. (The top 3 bits of the seed are ignored.) |
|
| 640 |
+ * |
|
| 641 |
+ * This should be called like: |
|
| 642 |
+ * GREATEST_SHUFFLE_TESTS(seed, {
|
|
| 643 |
+ * GREATEST_RUN_TEST(some_test); |
|
| 644 |
+ * GREATEST_RUN_TEST(some_other_test); |
|
| 645 |
+ * GREATEST_RUN_TEST(yet_another_test); |
|
| 646 |
+ * }); |
|
| 647 |
+ * |
|
| 648 |
+ * Note that the body of the second argument will be evaluated |
|
| 649 |
+ * multiple times. */ |
|
| 650 |
+#define GREATEST_SHUFFLE_SUITES(SD, BODY) GREATEST_SHUFFLE(0, SD, BODY) |
|
| 651 |
+#define GREATEST_SHUFFLE_TESTS(SD, BODY) GREATEST_SHUFFLE(1, SD, BODY) |
|
| 652 |
+#define GREATEST_SHUFFLE(ID, SD, BODY) \ |
|
| 653 |
+ do { \
|
|
| 654 |
+ struct greatest_prng *prng = &greatest_info.prng[ID]; \ |
|
| 655 |
+ greatest_prng_init_first_pass(ID); \ |
|
| 656 |
+ do { \
|
|
| 657 |
+ prng->count = 0; \ |
|
| 658 |
+ if (prng->initialized) { greatest_prng_step(ID); } \
|
|
| 659 |
+ BODY; \ |
|
| 660 |
+ if (!prng->initialized) { \
|
|
| 661 |
+ if (!greatest_prng_init_second_pass(ID, SD)) { break; } \
|
|
| 662 |
+ } else if (prng->count_run == prng->count_ceil) { \
|
|
| 663 |
+ break; \ |
|
| 664 |
+ } \ |
|
| 665 |
+ } while (!GREATEST_FAILURE_ABORT()); \ |
|
| 666 |
+ prng->count_run = prng->random_order = prng->initialized = 0; \ |
|
| 667 |
+ } while(0) |
|
| 668 |
+ |
|
| 606 | 669 |
/* Include several function definitions in the main test file. */ |
| 607 | 670 |
#define GREATEST_MAIN_DEFS() \ |
| 608 | 671 |
\ |
| 609 | 672 |
/* Is FILTER a subset of NAME? */ \ |
| 610 |
-static int greatest_name_match(const char *name, \ |
|
| 611 |
- const char *filter) { \
|
|
| 673 |
+static int greatest_name_match(const char *name, const char *filter, \ |
|
| 674 |
+ int res_if_none) { \
|
|
| 612 | 675 |
size_t offset = 0; \ |
| 613 |
- size_t filter_len = strlen(filter); \ |
|
| 676 |
+ size_t filter_len = filter ? strlen(filter) : 0; \ |
|
| 677 |
+ if (filter_len == 0) { return res_if_none; } /* no filter */ \
|
|
| 614 | 678 |
while (name[offset] != '\0') { \
|
| 615 | 679 |
if (name[offset] == filter[0]) { \
|
| 616 | 680 |
if (0 == strncmp(&name[offset], filter, filter_len)) { \
|
| ... | ... |
@@ -623,22 +687,34 @@ static int greatest_name_match(const char *name, \ |
| 623 | 687 |
return 0; \ |
| 624 | 688 |
} \ |
| 625 | 689 |
\ |
| 626 |
-int greatest_pre_test(const char *name) { \
|
|
| 627 |
- if (!GREATEST_LIST_ONLY() \ |
|
| 628 |
- && (!GREATEST_FIRST_FAIL() || greatest_info.suite.failed == 0) \ |
|
| 629 |
- && (greatest_info.test_filter == NULL || \ |
|
| 630 |
- greatest_name_match(name, greatest_info.test_filter))) { \
|
|
| 631 |
- GREATEST_SET_TIME(greatest_info.suite.pre_test); \ |
|
| 632 |
- if (greatest_info.setup) { \
|
|
| 633 |
- greatest_info.setup(greatest_info.setup_udata); \ |
|
| 690 |
+/* Before running a test, check the name filtering and \ |
|
| 691 |
+ * test shuffling state, if applicable, and then call setup hooks. */ \ |
|
| 692 |
+int greatest_test_pre(const char *name) { \
|
|
| 693 |
+ struct greatest_run_info *g = &greatest_info; \ |
|
| 694 |
+ int match = greatest_name_match(name, g->test_filter, 1) && \ |
|
| 695 |
+ !greatest_name_match(name, g->test_exclude, 0); \ |
|
| 696 |
+ if (GREATEST_LIST_ONLY()) { /* just listing test names */ \
|
|
| 697 |
+ if (match) { fprintf(GREATEST_STDOUT, " %s\n", name); } \
|
|
| 698 |
+ return 0; \ |
|
| 699 |
+ } \ |
|
| 700 |
+ if (match && (!GREATEST_FIRST_FAIL() || g->suite.failed == 0)) { \
|
|
| 701 |
+ struct greatest_prng *p = &g->prng[1]; \ |
|
| 702 |
+ if (p->random_order) { \
|
|
| 703 |
+ p->count++; \ |
|
| 704 |
+ if (!p->initialized || ((p->count - 1) != p->state)) { \
|
|
| 705 |
+ return 0; /* don't run this test yet */ \ |
|
| 706 |
+ } \ |
|
| 634 | 707 |
} \ |
| 708 |
+ GREATEST_SET_TIME(g->suite.pre_test); \ |
|
| 709 |
+ if (g->setup) { g->setup(g->setup_udata); } \
|
|
| 710 |
+ p->count_run++; \ |
|
| 635 | 711 |
return 1; /* test should be run */ \ |
| 636 | 712 |
} else { \
|
| 637 | 713 |
return 0; /* skipped */ \ |
| 638 | 714 |
} \ |
| 639 | 715 |
} \ |
| 640 | 716 |
\ |
| 641 |
-void greatest_post_test(const char *name, int res) { \
|
|
| 717 |
+void greatest_test_post(const char *name, int res) { \
|
|
| 642 | 718 |
GREATEST_SET_TIME(greatest_info.suite.post_test); \ |
| 643 | 719 |
if (greatest_info.teardown) { \
|
| 644 | 720 |
void *udata = greatest_info.teardown_udata; \ |
| ... | ... |
@@ -657,9 +733,9 @@ void greatest_post_test(const char *name, int res) { \
|
| 657 | 733 |
if (GREATEST_IS_VERBOSE()) { \
|
| 658 | 734 |
GREATEST_CLOCK_DIFF(greatest_info.suite.pre_test, \ |
| 659 | 735 |
greatest_info.suite.post_test); \ |
| 660 |
- fprintf(GREATEST_STDOUT, "\n"); \ |
|
| 736 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\n"); \ |
|
| 661 | 737 |
} else if (greatest_info.col % greatest_info.width == 0) { \
|
| 662 |
- fprintf(GREATEST_STDOUT, "\n"); \ |
|
| 738 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\n"); \ |
|
| 663 | 739 |
greatest_info.col = 0; \ |
| 664 | 740 |
} \ |
| 665 | 741 |
fflush(GREATEST_STDOUT); \ |
| ... | ... |
@@ -667,7 +743,7 @@ void greatest_post_test(const char *name, int res) { \
|
| 667 | 743 |
\ |
| 668 | 744 |
static void report_suite(void) { \
|
| 669 | 745 |
if (greatest_info.suite.tests_run > 0) { \
|
| 670 |
- fprintf(GREATEST_STDOUT, \ |
|
| 746 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, \ |
|
| 671 | 747 |
"\n%u test%s - %u passed, %u failed, %u skipped", \ |
| 672 | 748 |
greatest_info.suite.tests_run, \ |
| 673 | 749 |
greatest_info.suite.tests_run == 1 ? "" : "s", \ |
| ... | ... |
@@ -676,7 +752,7 @@ static void report_suite(void) { \
|
| 676 | 752 |
greatest_info.suite.skipped); \ |
| 677 | 753 |
GREATEST_CLOCK_DIFF(greatest_info.suite.pre_suite, \ |
| 678 | 754 |
greatest_info.suite.post_suite); \ |
| 679 |
- fprintf(GREATEST_STDOUT, "\n"); \ |
|
| 755 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\n"); \ |
|
| 680 | 756 |
} \ |
| 681 | 757 |
} \ |
| 682 | 758 |
\ |
| ... | ... |
@@ -693,46 +769,63 @@ static void update_counts_and_reset_suite(void) { \
|
| 693 | 769 |
greatest_info.col = 0; \ |
| 694 | 770 |
} \ |
| 695 | 771 |
\ |
| 696 |
-static void greatest_run_suite(greatest_suite_cb *suite_cb, \ |
|
| 697 |
- const char *suite_name) { \
|
|
| 698 |
- if (greatest_info.suite_filter && \ |
|
| 699 |
- !greatest_name_match(suite_name, greatest_info.suite_filter)) { \
|
|
| 700 |
- return; \ |
|
| 772 |
+int greatest_suite_pre(const char *suite_name) { \
|
|
| 773 |
+ struct greatest_prng *p = &greatest_info.prng[0]; \ |
|
| 774 |
+ if (!greatest_name_match(suite_name, greatest_info.suite_filter, 1) \ |
|
| 775 |
+ || (GREATEST_FIRST_FAIL() && greatest_info.failed > 0)) { \
|
|
| 776 |
+ return 0; \ |
|
| 701 | 777 |
} \ |
| 778 |
+ if (p->random_order) { \
|
|
| 779 |
+ p->count++; \ |
|
| 780 |
+ if (!p->initialized || ((p->count - 1) != p->state)) { \
|
|
| 781 |
+ return 0; /* don't run this suite yet */ \ |
|
| 782 |
+ } \ |
|
| 783 |
+ } \ |
|
| 784 |
+ p->count_run++; \ |
|
| 702 | 785 |
update_counts_and_reset_suite(); \ |
| 703 |
- if (GREATEST_FIRST_FAIL() && greatest_info.failed > 0) { return; } \
|
|
| 704 |
- fprintf(GREATEST_STDOUT, "\n* Suite %s:\n", suite_name); \ |
|
| 786 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\n* Suite %s:\n", suite_name); \ |
|
| 705 | 787 |
GREATEST_SET_TIME(greatest_info.suite.pre_suite); \ |
| 706 |
- suite_cb(); \ |
|
| 788 |
+ return 1; \ |
|
| 789 |
+} \ |
|
| 790 |
+ \ |
|
| 791 |
+void greatest_suite_post(void) { \
|
|
| 707 | 792 |
GREATEST_SET_TIME(greatest_info.suite.post_suite); \ |
| 708 | 793 |
report_suite(); \ |
| 709 | 794 |
} \ |
| 710 | 795 |
\ |
| 796 |
+static void greatest_run_suite(greatest_suite_cb *suite_cb, \ |
|
| 797 |
+ const char *suite_name) { \
|
|
| 798 |
+ if (greatest_suite_pre(suite_name)) { \
|
|
| 799 |
+ suite_cb(); \ |
|
| 800 |
+ greatest_suite_post(); \ |
|
| 801 |
+ } \ |
|
| 802 |
+} \ |
|
| 803 |
+ \ |
|
| 711 | 804 |
void greatest_do_pass(const char *name) { \
|
| 712 | 805 |
if (GREATEST_IS_VERBOSE()) { \
|
| 713 |
- fprintf(GREATEST_STDOUT, "PASS %s: %s", \ |
|
| 806 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, "PASS %s: %s", \ |
|
| 714 | 807 |
name, greatest_info.msg ? greatest_info.msg : ""); \ |
| 715 | 808 |
} else { \
|
| 716 |
- fprintf(GREATEST_STDOUT, "."); \ |
|
| 809 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, "."); \ |
|
| 717 | 810 |
} \ |
| 718 | 811 |
greatest_info.suite.passed++; \ |
| 719 | 812 |
} \ |
| 720 | 813 |
\ |
| 721 | 814 |
void greatest_do_fail(const char *name) { \
|
| 722 | 815 |
if (GREATEST_IS_VERBOSE()) { \
|
| 723 |
- fprintf(GREATEST_STDOUT, \ |
|
| 816 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, \ |
|
| 724 | 817 |
"FAIL %s: %s (%s:%u)", \ |
| 725 | 818 |
name, greatest_info.msg ? greatest_info.msg : "", \ |
| 726 | 819 |
greatest_info.fail_file, greatest_info.fail_line); \ |
| 727 | 820 |
} else { \
|
| 728 |
- fprintf(GREATEST_STDOUT, "F"); \ |
|
| 821 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, "F"); \ |
|
| 729 | 822 |
greatest_info.col++; \ |
| 730 | 823 |
/* add linebreak if in line of '.'s */ \ |
| 731 | 824 |
if (greatest_info.col != 0) { \
|
| 732 |
- fprintf(GREATEST_STDOUT, "\n"); \ |
|
| 825 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\n"); \ |
|
| 733 | 826 |
greatest_info.col = 0; \ |
| 734 | 827 |
} \ |
| 735 |
- fprintf(GREATEST_STDOUT, "FAIL %s: %s (%s:%u)\n", \ |
|
| 828 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, "FAIL %s: %s (%s:%u)\n", \ |
|
| 736 | 829 |
name, \ |
| 737 | 830 |
greatest_info.msg ? greatest_info.msg : "", \ |
| 738 | 831 |
greatest_info.fail_file, greatest_info.fail_line); \ |
| ... | ... |
@@ -742,12 +835,12 @@ void greatest_do_fail(const char *name) { \
|
| 742 | 835 |
\ |
| 743 | 836 |
void greatest_do_skip(const char *name) { \
|
| 744 | 837 |
if (GREATEST_IS_VERBOSE()) { \
|
| 745 |
- fprintf(GREATEST_STDOUT, "SKIP %s: %s", \ |
|
| 838 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, "SKIP %s: %s", \ |
|
| 746 | 839 |
name, \ |
| 747 | 840 |
greatest_info.msg ? \ |
| 748 | 841 |
greatest_info.msg : "" ); \ |
| 749 | 842 |
} else { \
|
| 750 |
- fprintf(GREATEST_STDOUT, "s"); \ |
|
| 843 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, "s"); \ |
|
| 751 | 844 |
} \ |
| 752 | 845 |
greatest_info.suite.skipped++; \ |
| 753 | 846 |
} \ |
| ... | ... |
@@ -761,13 +854,13 @@ int greatest_do_assert_equal_t(const void *exp, const void *got, \ |
| 761 | 854 |
eq = type_info->equal(exp, got, udata); \ |
| 762 | 855 |
if (!eq) { \
|
| 763 | 856 |
if (type_info->print != NULL) { \
|
| 764 |
- fprintf(GREATEST_STDOUT, "\nExpected: "); \ |
|
| 857 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\nExpected: "); \ |
|
| 765 | 858 |
(void)type_info->print(exp, udata); \ |
| 766 |
- fprintf(GREATEST_STDOUT, "\n Got: "); \ |
|
| 859 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\n Got: "); \ |
|
| 767 | 860 |
(void)type_info->print(got, udata); \ |
| 768 |
- fprintf(GREATEST_STDOUT, "\n"); \ |
|
| 861 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, "\n"); \ |
|
| 769 | 862 |
} else { \
|
| 770 |
- fprintf(GREATEST_STDOUT, \ |
|
| 863 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, \ |
|
| 771 | 864 |
"GREATEST_ASSERT_EQUAL_T failure at %s:%u\n", \ |
| 772 | 865 |
greatest_info.fail_file, \ |
| 773 | 866 |
greatest_info.fail_line); \ |
| ... | ... |
@@ -777,63 +870,73 @@ int greatest_do_assert_equal_t(const void *exp, const void *got, \ |
| 777 | 870 |
} \ |
| 778 | 871 |
\ |
| 779 | 872 |
void greatest_usage(const char *name) { \
|
| 780 |
- fprintf(GREATEST_STDOUT, \ |
|
| 781 |
- "Usage: %s [-hlfv] [-s SUITE] [-t TEST]\n" \ |
|
| 873 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, \ |
|
| 874 |
+ "Usage: %s [--help] [-hlfv] [-s SUITE] [-t TEST]\n" \ |
|
| 782 | 875 |
" -h, --help print this Help\n" \ |
| 783 |
- " -l List suites and their tests, then exit\n" \ |
|
| 876 |
+ " -l List suites and tests, then exit (dry run)\n" \ |
|
| 784 | 877 |
" -f Stop runner after first failure\n" \ |
| 785 | 878 |
" -v Verbose output\n" \ |
| 786 | 879 |
" -s SUITE only run suites containing string SUITE\n" \ |
| 787 |
- " -t TEST only run tests containing string TEST\n", \ |
|
| 880 |
+ " -t TEST only run tests containing string TEST\n" \ |
|
| 881 |
+ " -x EXCLUDE exclude tests containing string EXCLUDE\n", \ |
|
| 788 | 882 |
name); \ |
| 789 | 883 |
} \ |
| 790 | 884 |
\ |
| 791 |
-static void greatest_parse_args(int argc, char **argv) { \
|
|
| 885 |
+static void greatest_parse_options(int argc, char **argv) { \
|
|
| 792 | 886 |
int i = 0; \ |
| 793 | 887 |
for (i = 1; i < argc; i++) { \
|
| 794 |
- if (0 == strncmp("-t", argv[i], 2)) { \
|
|
| 795 |
- if (argc <= i + 1) { \
|
|
| 796 |
- greatest_usage(argv[0]); \ |
|
| 797 |
- exit(EXIT_FAILURE); \ |
|
| 888 |
+ if (argv[i][0] == '-') { \
|
|
| 889 |
+ char f = argv[i][1]; \ |
|
| 890 |
+ if ((f == 's' || f == 't' || f == 'x') && argc <= i + 1) { \
|
|
| 891 |
+ greatest_usage(argv[0]); exit(EXIT_FAILURE); \ |
|
| 798 | 892 |
} \ |
| 799 |
- greatest_info.test_filter = argv[i+1]; \ |
|
| 800 |
- i++; \ |
|
| 801 |
- } else if (0 == strncmp("-s", argv[i], 2)) { \
|
|
| 802 |
- if (argc <= i + 1) { \
|
|
| 893 |
+ switch (f) { \
|
|
| 894 |
+ case 's': /* suite name filter */ \ |
|
| 895 |
+ greatest_set_suite_filter(argv[i + 1]); i++; break; \ |
|
| 896 |
+ case 't': /* test name filter */ \ |
|
| 897 |
+ greatest_set_test_filter(argv[i + 1]); i++; break; \ |
|
| 898 |
+ case 'x': /* test name exclusion */ \ |
|
| 899 |
+ greatest_set_test_exclude(argv[i + 1]); i++; break; \ |
|
| 900 |
+ case 'f': /* first fail flag */ \ |
|
| 901 |
+ greatest_stop_at_first_fail(); break; \ |
|
| 902 |
+ case 'l': /* list only (dry run) */ \ |
|
| 903 |
+ greatest_info.flags |= GREATEST_FLAG_LIST_ONLY; break; \ |
|
| 904 |
+ case 'v': /* first fail flag */ \ |
|
| 905 |
+ greatest_info.verbosity++; break; \ |
|
| 906 |
+ case 'h': /* help */ \ |
|
| 907 |
+ greatest_usage(argv[0]); exit(EXIT_SUCCESS); \ |
|
| 908 |
+ case '-': \ |
|
| 909 |
+ if (0 == strncmp("--help", argv[i], 6)) { \
|
|
| 910 |
+ greatest_usage(argv[0]); exit(EXIT_SUCCESS); \ |
|
| 911 |
+ } else if (0 == strncmp("--", argv[i], 2)) { \
|
|
| 912 |
+ return; /* ignore following arguments */ \ |
|
| 913 |
+ } /* fall through */ \ |
|
| 914 |
+ default: \ |
|
| 915 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, \ |
|
| 916 |
+ "Unknown argument '%s'\n", argv[i]); \ |
|
| 803 | 917 |
greatest_usage(argv[0]); \ |
| 804 | 918 |
exit(EXIT_FAILURE); \ |
| 805 | 919 |
} \ |
| 806 |
- greatest_info.suite_filter = argv[i+1]; \ |
|
| 807 |
- i++; \ |
|
| 808 |
- } else if (0 == strncmp("-f", argv[i], 2)) { \
|
|
| 809 |
- greatest_info.flags |= GREATEST_FLAG_FIRST_FAIL; \ |
|
| 810 |
- } else if (0 == strncmp("-v", argv[i], 2)) { \
|
|
| 811 |
- greatest_info.verbosity++; \ |
|
| 812 |
- } else if (0 == strncmp("-l", argv[i], 2)) { \
|
|
| 813 |
- greatest_info.flags |= GREATEST_FLAG_LIST_ONLY; \ |
|
| 814 |
- } else if (0 == strncmp("-h", argv[i], 2) || \
|
|
| 815 |
- 0 == strncmp("--help", argv[i], 6)) { \
|
|
| 816 |
- greatest_usage(argv[0]); \ |
|
| 817 |
- exit(EXIT_SUCCESS); \ |
|
| 818 |
- } else if (0 == strncmp("--", argv[i], 2)) { \
|
|
| 819 |
- break; \ |
|
| 820 |
- } else { \
|
|
| 821 |
- fprintf(GREATEST_STDOUT, \ |
|
| 822 |
- "Unknown argument '%s'\n", argv[i]); \ |
|
| 823 |
- greatest_usage(argv[0]); \ |
|
| 824 |
- exit(EXIT_FAILURE); \ |
|
| 825 | 920 |
} \ |
| 826 | 921 |
} \ |
| 827 | 922 |
} \ |
| 828 | 923 |
\ |
| 829 | 924 |
int greatest_all_passed(void) { return (greatest_info.failed == 0); } \
|
| 830 | 925 |
\ |
| 831 |
-void greatest_set_test_filter(const char *name) { \
|
|
| 832 |
- greatest_info.test_filter = name; \ |
|
| 926 |
+void greatest_set_test_filter(const char *filter) { \
|
|
| 927 |
+ greatest_info.test_filter = filter; \ |
|
| 833 | 928 |
} \ |
| 834 | 929 |
\ |
| 835 |
-void greatest_set_suite_filter(const char *name) { \
|
|
| 836 |
- greatest_info.suite_filter = name; \ |
|
| 930 |
+void greatest_set_test_exclude(const char *filter) { \
|
|
| 931 |
+ greatest_info.test_exclude = filter; \ |
|
| 932 |
+} \ |
|
| 933 |
+ \ |
|
| 934 |
+void greatest_set_suite_filter(const char *filter) { \
|
|
| 935 |
+ greatest_info.suite_filter = filter; \ |
|
| 936 |
+} \ |
|
| 937 |
+ \ |
|
| 938 |
+void greatest_stop_at_first_fail(void) { \
|
|
| 939 |
+ greatest_info.flags |= GREATEST_FLAG_FIRST_FAIL; \ |
|
| 837 | 940 |
} \ |
| 838 | 941 |
\ |
| 839 | 942 |
void greatest_get_report(struct greatest_report_t *report) { \
|
| ... | ... |
@@ -878,7 +981,7 @@ static int greatest_string_equal_cb(const void *exp, const void *got, \ |
| 878 | 981 |
\ |
| 879 | 982 |
static int greatest_string_printf_cb(const void *t, void *udata) { \
|
| 880 | 983 |
(void)udata; /* note: does not check \0 termination. */ \ |
| 881 |
- return fprintf(GREATEST_STDOUT, "%s", (const char *)t); \ |
|
| 984 |
+ return GREATEST_FPRINTF(GREATEST_STDOUT, "%s", (const char *)t); \ |
|
| 882 | 985 |
} \ |
| 883 | 986 |
\ |
| 884 | 987 |
greatest_type_info greatest_type_info_string = { \
|
| ... | ... |
@@ -892,6 +995,7 @@ static int greatest_memory_equal_cb(const void *exp, const void *got, \ |
| 892 | 995 |
return (0 == memcmp(exp, got, env->size)); \ |
| 893 | 996 |
} \ |
| 894 | 997 |
\ |
| 998 |
+/* Hexdump raw memory, with differences highlighted */ \ |
|
| 895 | 999 |
static int greatest_memory_printf_cb(const void *t, void *udata) { \
|
| 896 | 1000 |
greatest_memory_cmp_env *env = (greatest_memory_cmp_env *)udata; \ |
| 897 | 1001 |
const unsigned char *buf = (const unsigned char *)t; \ |
| ... | ... |
@@ -906,24 +1010,64 @@ static int greatest_memory_printf_cb(const void *t, void *udata) { \
|
| 906 | 1010 |
for (line_i = i; line_i < i + line_len; line_i++) { \
|
| 907 | 1011 |
if (env->exp[line_i] != env->got[line_i]) diff_mark = 'X'; \ |
| 908 | 1012 |
} \ |
| 909 |
- len += fprintf(out, "\n%04x %c ", (unsigned int)i, diff_mark); \ |
|
| 1013 |
+ len += GREATEST_FPRINTF(out, "\n%04x %c ", \ |
|
| 1014 |
+ (unsigned int)i, diff_mark); \ |
|
| 910 | 1015 |
for (line_i = i; line_i < i + line_len; line_i++) { \
|
| 911 | 1016 |
int m = env->exp[line_i] == env->got[line_i]; /* match? */ \ |
| 912 |
- len += fprintf(out, "%02x%c", buf[line_i], m ? ' ' : '<'); \ |
|
| 1017 |
+ len += GREATEST_FPRINTF(out, "%02x%c", \ |
|
| 1018 |
+ buf[line_i], m ? ' ' : '<'); \ |
|
| 913 | 1019 |
} \ |
| 914 | 1020 |
for (line_i = 0; line_i < 16 - line_len; line_i++) { \
|
| 915 |
- len += fprintf(out, " "); \ |
|
| 1021 |
+ len += GREATEST_FPRINTF(out, " "); \ |
|
| 916 | 1022 |
} \ |
| 917 |
- fprintf(out, " "); \ |
|
| 1023 |
+ GREATEST_FPRINTF(out, " "); \ |
|
| 918 | 1024 |
for (line_i = i; line_i < i + line_len; line_i++) { \
|
| 919 | 1025 |
unsigned char c = buf[line_i]; \ |
| 920 |
- len += fprintf(out, "%c", isprint(c) ? c : '.'); \ |
|
| 1026 |
+ len += GREATEST_FPRINTF(out, "%c", isprint(c) ? c : '.'); \ |
|
| 921 | 1027 |
} \ |
| 922 | 1028 |
} \ |
| 923 |
- len += fprintf(out, "\n"); \ |
|
| 1029 |
+ len += GREATEST_FPRINTF(out, "\n"); \ |
|
| 924 | 1030 |
return len; \ |
| 925 | 1031 |
} \ |
| 926 | 1032 |
\ |
| 1033 |
+void greatest_prng_init_first_pass(int id) { \
|
|
| 1034 |
+ greatest_info.prng[id].random_order = 1; \ |
|
| 1035 |
+ greatest_info.prng[id].count_run = 0; \ |
|
| 1036 |
+} \ |
|
| 1037 |
+ \ |
|
| 1038 |
+int greatest_prng_init_second_pass(int id, unsigned long seed) { \
|
|
| 1039 |
+ static unsigned long primes[] = { 11, 101, 1009, 10007, \
|
|
| 1040 |
+ 100003, 1000003, 10000019, 100000007, 1000000007, \ |
|
| 1041 |
+ 1538461, 1865471, 17471, 2147483647 /* 2**32 - 1 */, }; \ |
|
| 1042 |
+ struct greatest_prng *prng = &greatest_info.prng[id]; \ |
|
| 1043 |
+ if (prng->count == 0) { return 0; } \
|
|
| 1044 |
+ prng->mod = 1; \ |
|
| 1045 |
+ prng->count_ceil = prng->count; \ |
|
| 1046 |
+ while (prng->mod < prng->count) { prng->mod <<= 1; } \
|
|
| 1047 |
+ prng->state = seed & 0x1fffffff; /* only use lower 29 bits... */ \ |
|
| 1048 |
+ prng->a = (4LU * prng->state) + 1; /* to avoid overflow */ \ |
|
| 1049 |
+ prng->c = primes[(seed * 16451) % sizeof(primes)/sizeof(primes[0])];\ |
|
| 1050 |
+ prng->initialized = 1; \ |
|
| 1051 |
+ return 1; \ |
|
| 1052 |
+} \ |
|
| 1053 |
+ \ |
|
| 1054 |
+/* Step the pseudorandom number generator until its state reaches \ |
|
| 1055 |
+ * another test ID between 0 and the test count. \ |
|
| 1056 |
+ * This use a linear congruential pseudorandom number generator, \ |
|
| 1057 |
+ * with the power-of-two ceiling of the test count as the modulus, the \ |
|
| 1058 |
+ * masked seed as the multiplier, and a prime as the increment. For \ |
|
| 1059 |
+ * each generated value < the test count, run the corresponding test. \ |
|
| 1060 |
+ * This will visit all IDs 0 <= X < mod once before repeating, \ |
|
| 1061 |
+ * with a starting position chosen based on the initial seed. \ |
|
| 1062 |
+ * For details, see: Knuth, The Art of Computer Programming \ |
|
| 1063 |
+ * Volume. 2, section 3.2.1. */ \ |
|
| 1064 |
+void greatest_prng_step(int id) { \
|
|
| 1065 |
+ struct greatest_prng *p = &greatest_info.prng[id]; \ |
|
| 1066 |
+ do { \
|
|
| 1067 |
+ p->state = ((p->a * p->state) + p->c) & (p->mod - 1); \ |
|
| 1068 |
+ } while (p->state >= p->count_ceil); \ |
|
| 1069 |
+} \ |
|
| 1070 |
+ \ |
|
| 927 | 1071 |
greatest_type_info greatest_type_info_memory = { \
|
| 928 | 1072 |
greatest_memory_equal_cb, \ |
| 929 | 1073 |
greatest_memory_printf_cb, \ |
| ... | ... |
@@ -936,7 +1080,10 @@ greatest_run_info greatest_info |
| 936 | 1080 |
do { \
|
| 937 | 1081 |
/* Suppress unused function warning if features aren't used */ \ |
| 938 | 1082 |
(void)greatest_run_suite; \ |
| 939 |
- (void)greatest_parse_args; \ |
|
| 1083 |
+ (void)greatest_parse_options; \ |
|
| 1084 |
+ (void)greatest_prng_step; \ |
|
| 1085 |
+ (void)greatest_prng_init_first_pass; \ |
|
| 1086 |
+ (void)greatest_prng_init_second_pass; \ |
|
| 940 | 1087 |
\ |
| 941 | 1088 |
memset(&greatest_info, 0, sizeof(greatest_info)); \ |
| 942 | 1089 |
greatest_info.width = GREATEST_DEFAULT_WIDTH; \ |
| ... | ... |
@@ -947,7 +1094,7 @@ greatest_run_info greatest_info |
| 947 | 1094 |
#define GREATEST_MAIN_BEGIN() \ |
| 948 | 1095 |
do { \
|
| 949 | 1096 |
GREATEST_INIT(); \ |
| 950 |
- greatest_parse_args(argc, argv); \ |
|
| 1097 |
+ greatest_parse_options(argc, argv); \ |
|
| 951 | 1098 |
} while (0) |
| 952 | 1099 |
|
| 953 | 1100 |
/* Report passes, failures, skipped tests, the number of |
| ... | ... |
@@ -957,16 +1104,16 @@ greatest_run_info greatest_info |
| 957 | 1104 |
if (!GREATEST_LIST_ONLY()) { \
|
| 958 | 1105 |
update_counts_and_reset_suite(); \ |
| 959 | 1106 |
GREATEST_SET_TIME(greatest_info.end); \ |
| 960 |
- fprintf(GREATEST_STDOUT, \ |
|
| 1107 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, \ |
|
| 961 | 1108 |
"\nTotal: %u test%s", \ |
| 962 | 1109 |
greatest_info.tests_run, \ |
| 963 | 1110 |
greatest_info.tests_run == 1 ? "" : "s"); \ |
| 964 | 1111 |
GREATEST_CLOCK_DIFF(greatest_info.begin, \ |
| 965 | 1112 |
greatest_info.end); \ |
| 966 |
- fprintf(GREATEST_STDOUT, ", %u assertion%s\n", \ |
|
| 1113 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, ", %u assertion%s\n", \ |
|
| 967 | 1114 |
greatest_info.assertions, \ |
| 968 | 1115 |
greatest_info.assertions == 1 ? "" : "s"); \ |
| 969 |
- fprintf(GREATEST_STDOUT, \ |
|
| 1116 |
+ GREATEST_FPRINTF(GREATEST_STDOUT, \ |
|
| 970 | 1117 |
"Pass: %u, fail: %u, skip: %u.\n", \ |
| 971 | 1118 |
greatest_info.passed, \ |
| 972 | 1119 |
greatest_info.failed, greatest_info.skipped); \ |
| ... | ... |
@@ -1019,6 +1166,8 @@ greatest_run_info greatest_info |
| 1019 | 1166 |
#define SET_SETUP GREATEST_SET_SETUP_CB |
| 1020 | 1167 |
#define SET_TEARDOWN GREATEST_SET_TEARDOWN_CB |
| 1021 | 1168 |
#define CHECK_CALL GREATEST_CHECK_CALL |
| 1169 |
+#define SHUFFLE_TESTS GREATEST_SHUFFLE_TESTS |
|
| 1170 |
+#define SHUFFLE_SUITES GREATEST_SHUFFLE_SUITES |
|
| 1022 | 1171 |
|
| 1023 | 1172 |
#ifdef GREATEST_VA_ARGS |
| 1024 | 1173 |
#define RUN_TESTp GREATEST_RUN_TESTp |
| ... | ... |
@@ -1033,7 +1182,7 @@ greatest_run_info greatest_info |
| 1033 | 1182 |
|
| 1034 | 1183 |
#endif /* USE_ABBREVS */ |
| 1035 | 1184 |
|
| 1036 |
-#ifdef __cplusplus |
|
| 1185 |
+#if defined(__cplusplus) && !defined(GREATEST_NO_EXTERN_CPLUSPLUS) |
|
| 1037 | 1186 |
} |
| 1038 | 1187 |
#endif |
| 1039 | 1188 |
|
| ... | ... |
@@ -21,10 +21,10 @@ |
| 21 | 21 |
extern "C" {
|
| 22 | 22 |
#endif |
| 23 | 23 |
|
| 24 |
-/* 1.2.1 */ |
|
| 24 |
+/* 1.2.2 */ |
|
| 25 | 25 |
#define GREATEST_VERSION_MAJOR 1 |
| 26 | 26 |
#define GREATEST_VERSION_MINOR 2 |
| 27 |
-#define GREATEST_VERSION_PATCH 1 |
|
| 27 |
+#define GREATEST_VERSION_PATCH 2 |
|
| 28 | 28 |
|
| 29 | 29 |
/* A unit testing system for C, contained in 1 file. |
| 30 | 30 |
* It doesn't use dynamic allocation or depend on anything |
| ... | ... |
@@ -205,20 +205,23 @@ typedef enum {
|
| 205 | 205 |
typedef struct greatest_run_info {
|
| 206 | 206 |
unsigned char flags; |
| 207 | 207 |
unsigned char verbosity; |
| 208 |
+ unsigned char pad_0[2]; |
|
| 209 |
+ |
|
| 208 | 210 |
unsigned int tests_run; /* total test count */ |
| 209 | 211 |
|
| 212 |
+ /* currently running test suite */ |
|
| 213 |
+ greatest_suite_info suite; |
|
| 214 |
+ |
|
| 210 | 215 |
/* overall pass/fail/skip counts */ |
| 211 | 216 |
unsigned int passed; |
| 212 | 217 |
unsigned int failed; |
| 213 | 218 |
unsigned int skipped; |
| 214 | 219 |
unsigned int assertions; |
| 215 | 220 |
|
| 216 |
- /* currently running test suite */ |
|
| 217 |
- greatest_suite_info suite; |
|
| 218 |
- |
|
| 219 | 221 |
/* info to print about the most recent failure */ |
| 220 |
- const char *fail_file; |
|
| 221 | 222 |
unsigned int fail_line; |
| 223 |
+ unsigned int pad_1; |
|
| 224 |
+ const char *fail_file; |
|
| 222 | 225 |
const char *msg; |
| 223 | 226 |
|
| 224 | 227 |
/* current setup/teardown hooks and userdata */ |
| ... | ... |
@@ -242,6 +245,7 @@ typedef struct greatest_run_info {
|
| 242 | 245 |
#endif |
| 243 | 246 |
|
| 244 | 247 |
#if GREATEST_USE_LONGJMP |
| 248 |
+ int pad_jmp_buf; |
|
| 245 | 249 |
jmp_buf jump_dest; |
| 246 | 250 |
#endif |
| 247 | 251 |
} greatest_run_info; |
| ... | ... |
@@ -432,16 +436,16 @@ typedef enum greatest_test_res {
|
| 432 | 436 |
} while (0) |
| 433 | 437 |
|
| 434 | 438 |
/* Fail if EXP != GOT (equality comparison by ==). |
| 435 |
- * Warning: EXP and GOT will be evaluated more than once on failure. */ |
|
| 439 |
+ * Warning: FMT, EXP, and GOT will be evaluated more |
|
| 440 |
+ * than once on failure. */ |
|
| 436 | 441 |
#define GREATEST_ASSERT_EQ_FMTm(MSG, EXP, GOT, FMT) \ |
| 437 | 442 |
do { \
|
| 438 |
- const char *greatest_FMT = ( FMT ); \ |
|
| 439 | 443 |
greatest_info.assertions++; \ |
| 440 | 444 |
if ((EXP) != (GOT)) { \
|
| 441 | 445 |
fprintf(GREATEST_STDOUT, "\nExpected: "); \ |
| 442 |
- fprintf(GREATEST_STDOUT, greatest_FMT, EXP); \ |
|
| 446 |
+ fprintf(GREATEST_STDOUT, FMT, EXP); \ |
|
| 443 | 447 |
fprintf(GREATEST_STDOUT, "\n Got: "); \ |
| 444 |
- fprintf(GREATEST_STDOUT, greatest_FMT, GOT); \ |
|
| 448 |
+ fprintf(GREATEST_STDOUT, FMT, GOT); \ |
|
| 445 | 449 |
fprintf(GREATEST_STDOUT, "\n"); \ |
| 446 | 450 |
GREATEST_FAILm(MSG); \ |
| 447 | 451 |
} \ |
| ... | ... |
@@ -658,7 +662,7 @@ void greatest_post_test(const char *name, int res) { \
|
| 658 | 662 |
fprintf(GREATEST_STDOUT, "\n"); \ |
| 659 | 663 |
greatest_info.col = 0; \ |
| 660 | 664 |
} \ |
| 661 |
- if (GREATEST_STDOUT == stdout) fflush(stdout); \ |
|
| 665 |
+ fflush(GREATEST_STDOUT); \ |
|
| 662 | 666 |
} \ |
| 663 | 667 |
\ |
| 664 | 668 |
static void report_suite(void) { \
|
| ... | ... |
@@ -890,7 +894,8 @@ static int greatest_memory_equal_cb(const void *exp, const void *got, \ |
| 890 | 894 |
\ |
| 891 | 895 |
static int greatest_memory_printf_cb(const void *t, void *udata) { \
|
| 892 | 896 |
greatest_memory_cmp_env *env = (greatest_memory_cmp_env *)udata; \ |
| 893 |
- unsigned char *buf = (unsigned char *)t, diff_mark = ' '; \ |
|
| 897 |
+ const unsigned char *buf = (const unsigned char *)t; \ |
|
| 898 |
+ unsigned char diff_mark = ' '; \ |
|
| 894 | 899 |
FILE *out = GREATEST_STDOUT; \ |
| 895 | 900 |
size_t i, line_i, line_len = 0; \ |
| 896 | 901 |
int len = 0; /* format hexdump with differences highlighted */ \ |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,1035 @@ |
| 1 |
+/* |
|
| 2 |
+ * Copyright (c) 2011-2016 Scott Vokes <vokes.s@gmail.com> |
|
| 3 |
+ * |
|
| 4 |
+ * Permission to use, copy, modify, and/or distribute this software for any |
|
| 5 |
+ * purpose with or without fee is hereby granted, provided that the above |
|
| 6 |
+ * copyright notice and this permission notice appear in all copies. |
|
| 7 |
+ * |
|
| 8 |
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
| 9 |
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
| 10 |
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
| 11 |
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
| 12 |
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
| 13 |
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
| 14 |
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
| 15 |
+ */ |
|
| 16 |
+ |
|
| 17 |
+#ifndef GREATEST_H |
|
| 18 |
+#define GREATEST_H |
|
| 19 |
+ |
|
| 20 |
+#ifdef __cplusplus |
|
| 21 |
+extern "C" {
|
|
| 22 |
+#endif |
|
| 23 |
+ |
|
| 24 |
+/* 1.2.1 */ |
|
| 25 |
+#define GREATEST_VERSION_MAJOR 1 |
|
| 26 |
+#define GREATEST_VERSION_MINOR 2 |
|
| 27 |
+#define GREATEST_VERSION_PATCH 1 |
|
| 28 |
+ |
|
| 29 |
+/* A unit testing system for C, contained in 1 file. |
|
| 30 |
+ * It doesn't use dynamic allocation or depend on anything |
|
| 31 |
+ * beyond ANSI C89. |
|
| 32 |
+ * |
|
| 33 |
+ * An up-to-date version can be found at: |
|
| 34 |
+ * https://github.com/silentbicycle/greatest/ |
|
| 35 |
+ */ |
|
| 36 |
+ |
|
| 37 |
+ |
|
| 38 |
+/********************************************************************* |
|
| 39 |
+ * Minimal test runner template |
|
| 40 |
+ *********************************************************************/ |
|
| 41 |
+#if 0 |
|
| 42 |
+ |
|
| 43 |
+#include "greatest.h" |
|
| 44 |
+ |
|
| 45 |
+TEST foo_should_foo(void) {
|
|
| 46 |
+ PASS(); |
|
| 47 |
+} |
|
| 48 |
+ |
|
| 49 |
+static void setup_cb(void *data) {
|
|
| 50 |
+ printf("setup callback for each test case\n");
|
|
| 51 |
+} |
|
| 52 |
+ |
|
| 53 |
+static void teardown_cb(void *data) {
|
|
| 54 |
+ printf("teardown callback for each test case\n");
|
|
| 55 |
+} |
|
| 56 |
+ |
|
| 57 |
+SUITE(suite) {
|
|
| 58 |
+ /* Optional setup/teardown callbacks which will be run before/after |
|
| 59 |
+ * every test case. If using a test suite, they will be cleared when |
|
| 60 |
+ * the suite finishes. */ |
|
| 61 |
+ SET_SETUP(setup_cb, voidp_to_callback_data); |
|
| 62 |
+ SET_TEARDOWN(teardown_cb, voidp_to_callback_data); |
|
| 63 |
+ |
|
| 64 |
+ RUN_TEST(foo_should_foo); |
|
| 65 |
+} |
|
| 66 |
+ |
|
| 67 |
+/* Add definitions that need to be in the test runner's main file. */ |
|
| 68 |
+GREATEST_MAIN_DEFS(); |
|
| 69 |
+ |
|
| 70 |
+/* Set up, run suite(s) of tests, report pass/fail/skip stats. */ |
|
| 71 |
+int run_tests(void) {
|
|
| 72 |
+ GREATEST_INIT(); /* init. greatest internals */ |
|
| 73 |
+ /* List of suites to run (if any). */ |
|
| 74 |
+ RUN_SUITE(suite); |
|
| 75 |
+ |
|
| 76 |
+ /* Tests can also be run directly, without using test suites. */ |
|
| 77 |
+ RUN_TEST(foo_should_foo); |
|
| 78 |
+ |
|
| 79 |
+ GREATEST_PRINT_REPORT(); /* display results */ |
|
| 80 |
+ return greatest_all_passed(); |
|
| 81 |
+} |
|
| 82 |
+ |
|
| 83 |
+/* main(), for a standalone command-line test runner. |
|
| 84 |
+ * This replaces run_tests above, and adds command line option |
|
| 85 |
+ * handling and exiting with a pass/fail status. */ |
|
| 86 |
+int main(int argc, char **argv) {
|
|
| 87 |
+ GREATEST_MAIN_BEGIN(); /* init & parse command-line args */ |
|
| 88 |
+ RUN_SUITE(suite); |
|
| 89 |
+ GREATEST_MAIN_END(); /* display results */ |
|
| 90 |
+} |
|
| 91 |
+ |
|
| 92 |
+#endif |
|
| 93 |
+/*********************************************************************/ |
|
| 94 |
+ |
|
| 95 |
+ |
|
| 96 |
+#include <stdlib.h> |
|
| 97 |
+#include <stdio.h> |
|
| 98 |
+#include <string.h> |
|
| 99 |
+#include <ctype.h> |
|
| 100 |
+ |
|
| 101 |
+/*********** |
|
| 102 |
+ * Options * |
|
| 103 |
+ ***********/ |
|
| 104 |
+ |
|
| 105 |
+/* Default column width for non-verbose output. */ |
|
| 106 |
+#ifndef GREATEST_DEFAULT_WIDTH |
|
| 107 |
+#define GREATEST_DEFAULT_WIDTH 72 |
|
| 108 |
+#endif |
|
| 109 |
+ |
|
| 110 |
+/* FILE *, for test logging. */ |
|
| 111 |
+#ifndef GREATEST_STDOUT |
|
| 112 |
+#define GREATEST_STDOUT stdout |
|
| 113 |
+#endif |
|
| 114 |
+ |
|
| 115 |
+/* Remove GREATEST_ prefix from most commonly used symbols? */ |
|
| 116 |
+#ifndef GREATEST_USE_ABBREVS |
|
| 117 |
+#define GREATEST_USE_ABBREVS 1 |
|
| 118 |
+#endif |
|
| 119 |
+ |
|
| 120 |
+/* Set to 0 to disable all use of setjmp/longjmp. */ |
|
| 121 |
+#ifndef GREATEST_USE_LONGJMP |
|
| 122 |
+#define GREATEST_USE_LONGJMP 1 |
|
| 123 |
+#endif |
|
| 124 |
+ |
|
| 125 |
+#if GREATEST_USE_LONGJMP |
|
| 126 |
+#include <setjmp.h> |
|
| 127 |
+#endif |
|
| 128 |
+ |
|
| 129 |
+/* Set to 0 to disable all use of time.h / clock(). */ |
|
| 130 |
+#ifndef GREATEST_USE_TIME |
|
| 131 |
+#define GREATEST_USE_TIME 1 |
|
| 132 |
+#endif |
|
| 133 |
+ |
|
| 134 |
+#if GREATEST_USE_TIME |
|
| 135 |
+#include <time.h> |
|
| 136 |
+#endif |
|
| 137 |
+ |
|
| 138 |
+/* Floating point type, for ASSERT_IN_RANGE. */ |
|
| 139 |
+#ifndef GREATEST_FLOAT |
|
| 140 |
+#define GREATEST_FLOAT double |
|
| 141 |
+#define GREATEST_FLOAT_FMT "%g" |
|
| 142 |
+#endif |
|
| 143 |
+ |
|
| 144 |
+/********* |
|
| 145 |
+ * Types * |
|
| 146 |
+ *********/ |
|
| 147 |
+ |
|
| 148 |
+/* Info for the current running suite. */ |
|
| 149 |
+typedef struct greatest_suite_info {
|
|
| 150 |
+ unsigned int tests_run; |
|
| 151 |
+ unsigned int passed; |
|
| 152 |
+ unsigned int failed; |
|
| 153 |
+ unsigned int skipped; |
|
| 154 |
+ |
|
| 155 |
+#if GREATEST_USE_TIME |
|
| 156 |
+ /* timers, pre/post running suite and individual tests */ |
|
| 157 |
+ clock_t pre_suite; |
|
| 158 |
+ clock_t post_suite; |
|
| 159 |
+ clock_t pre_test; |
|
| 160 |
+ clock_t post_test; |
|
| 161 |
+#endif |
|
| 162 |
+} greatest_suite_info; |
|
| 163 |
+ |
|
| 164 |
+/* Type for a suite function. */ |
|
| 165 |
+typedef void (greatest_suite_cb)(void); |
|
| 166 |
+ |
|
| 167 |
+/* Types for setup/teardown callbacks. If non-NULL, these will be run |
|
| 168 |
+ * and passed the pointer to their additional data. */ |
|
| 169 |
+typedef void (greatest_setup_cb)(void *udata); |
|
| 170 |
+typedef void (greatest_teardown_cb)(void *udata); |
|
| 171 |
+ |
|
| 172 |
+/* Type for an equality comparison between two pointers of the same type. |
|
| 173 |
+ * Should return non-0 if equal, otherwise 0. |
|
| 174 |
+ * UDATA is a closure value, passed through from ASSERT_EQUAL_T[m]. */ |
|
| 175 |
+typedef int greatest_equal_cb(const void *exp, const void *got, void *udata); |
|
| 176 |
+ |
|
| 177 |
+/* Type for a callback that prints a value pointed to by T. |
|
| 178 |
+ * Return value has the same meaning as printf's. |
|
| 179 |
+ * UDATA is a closure value, passed through from ASSERT_EQUAL_T[m]. */ |
|
| 180 |
+typedef int greatest_printf_cb(const void *t, void *udata); |
|
| 181 |
+ |
|
| 182 |
+/* Callbacks for an arbitrary type; needed for type-specific |
|
| 183 |
+ * comparisons via GREATEST_ASSERT_EQUAL_T[m].*/ |
|
| 184 |
+typedef struct greatest_type_info {
|
|
| 185 |
+ greatest_equal_cb *equal; |
|
| 186 |
+ greatest_printf_cb *print; |
|
| 187 |
+} greatest_type_info; |
|
| 188 |
+ |
|
| 189 |
+typedef struct greatest_memory_cmp_env {
|
|
| 190 |
+ const unsigned char *exp; |
|
| 191 |
+ const unsigned char *got; |
|
| 192 |
+ size_t size; |
|
| 193 |
+} greatest_memory_cmp_env; |
|
| 194 |
+ |
|
| 195 |
+/* Callbacks for string and raw memory types. */ |
|
| 196 |
+extern greatest_type_info greatest_type_info_string; |
|
| 197 |
+extern greatest_type_info greatest_type_info_memory; |
|
| 198 |
+ |
|
| 199 |
+typedef enum {
|
|
| 200 |
+ GREATEST_FLAG_FIRST_FAIL = 0x01, |
|
| 201 |
+ GREATEST_FLAG_LIST_ONLY = 0x02 |
|
| 202 |
+} greatest_flag_t; |
|
| 203 |
+ |
|
| 204 |
+/* Struct containing all test runner state. */ |
|
| 205 |
+typedef struct greatest_run_info {
|
|
| 206 |
+ unsigned char flags; |
|
| 207 |
+ unsigned char verbosity; |
|
| 208 |
+ unsigned int tests_run; /* total test count */ |
|
| 209 |
+ |
|
| 210 |
+ /* overall pass/fail/skip counts */ |
|
| 211 |
+ unsigned int passed; |
|
| 212 |
+ unsigned int failed; |
|
| 213 |
+ unsigned int skipped; |
|
| 214 |
+ unsigned int assertions; |
|
| 215 |
+ |
|
| 216 |
+ /* currently running test suite */ |
|
| 217 |
+ greatest_suite_info suite; |
|
| 218 |
+ |
|
| 219 |
+ /* info to print about the most recent failure */ |
|
| 220 |
+ const char *fail_file; |
|
| 221 |
+ unsigned int fail_line; |
|
| 222 |
+ const char *msg; |
|
| 223 |
+ |
|
| 224 |
+ /* current setup/teardown hooks and userdata */ |
|
| 225 |
+ greatest_setup_cb *setup; |
|
| 226 |
+ void *setup_udata; |
|
| 227 |
+ greatest_teardown_cb *teardown; |
|
| 228 |
+ void *teardown_udata; |
|
| 229 |
+ |
|
| 230 |
+ /* formatting info for ".....s...F"-style output */ |
|
| 231 |
+ unsigned int col; |
|
| 232 |
+ unsigned int width; |
|
| 233 |
+ |
|
| 234 |
+ /* only run a specific suite or test */ |
|
| 235 |
+ const char *suite_filter; |
|
| 236 |
+ const char *test_filter; |
|
| 237 |
+ |
|
| 238 |
+#if GREATEST_USE_TIME |
|
| 239 |
+ /* overall timers */ |
|
| 240 |
+ clock_t begin; |
|
| 241 |
+ clock_t end; |
|
| 242 |
+#endif |
|
| 243 |
+ |
|
| 244 |
+#if GREATEST_USE_LONGJMP |
|
| 245 |
+ jmp_buf jump_dest; |
|
| 246 |
+#endif |
|
| 247 |
+} greatest_run_info; |
|
| 248 |
+ |
|
| 249 |
+struct greatest_report_t {
|
|
| 250 |
+ /* overall pass/fail/skip counts */ |
|
| 251 |
+ unsigned int passed; |
|
| 252 |
+ unsigned int failed; |
|
| 253 |
+ unsigned int skipped; |
|
| 254 |
+ unsigned int assertions; |
|
| 255 |
+}; |
|
| 256 |
+ |
|
| 257 |
+/* Global var for the current testing context. |
|
| 258 |
+ * Initialized by GREATEST_MAIN_DEFS(). */ |
|
| 259 |
+extern greatest_run_info greatest_info; |
|
| 260 |
+ |
|
| 261 |
+/* Type for ASSERT_ENUM_EQ's ENUM_STR argument. */ |
|
| 262 |
+typedef const char *greatest_enum_str_fun(int value); |
|
| 263 |
+ |
|
| 264 |
+/********************** |
|
| 265 |
+ * Exported functions * |
|
| 266 |
+ **********************/ |
|
| 267 |
+ |
|
| 268 |
+/* These are used internally by greatest. */ |
|
| 269 |
+void greatest_do_pass(const char *name); |
|
| 270 |
+void greatest_do_fail(const char *name); |
|
| 271 |
+void greatest_do_skip(const char *name); |
|
| 272 |
+int greatest_pre_test(const char *name); |
|
| 273 |
+void greatest_post_test(const char *name, int res); |
|
| 274 |
+void greatest_usage(const char *name); |
|
| 275 |
+int greatest_do_assert_equal_t(const void *exp, const void *got, |
|
| 276 |
+ greatest_type_info *type_info, void *udata); |
|
| 277 |
+ |
|
| 278 |
+/* These are part of the public greatest API. */ |
|
| 279 |
+void GREATEST_SET_SETUP_CB(greatest_setup_cb *cb, void *udata); |
|
| 280 |
+void GREATEST_SET_TEARDOWN_CB(greatest_teardown_cb *cb, void *udata); |
|
| 281 |
+int greatest_all_passed(void); |
|
| 282 |
+void greatest_set_test_filter(const char *name); |
|
| 283 |
+void greatest_set_suite_filter(const char *name); |
|
| 284 |
+void greatest_get_report(struct greatest_report_t *report); |
|
| 285 |
+unsigned int greatest_get_verbosity(void); |
|
| 286 |
+void greatest_set_verbosity(unsigned int verbosity); |
|
| 287 |
+void greatest_set_flag(greatest_flag_t flag); |
|
| 288 |
+ |
|
| 289 |
+ |
|
| 290 |
+/******************** |
|
| 291 |
+* Language Support * |
|
| 292 |
+********************/ |
|
| 293 |
+ |
|
| 294 |
+/* If __VA_ARGS__ (C99) is supported, allow parametric testing |
|
| 295 |
+* without needing to manually manage the argument struct. */ |
|
| 296 |
+#if __STDC_VERSION__ >= 19901L || _MSC_VER >= 1800 |
|
| 297 |
+#define GREATEST_VA_ARGS |
|
| 298 |
+#endif |
|
| 299 |
+ |
|
| 300 |
+ |
|
| 301 |
+/********** |
|
| 302 |
+ * Macros * |
|
| 303 |
+ **********/ |
|
| 304 |
+ |
|
| 305 |
+/* Define a suite. */ |
|
| 306 |
+#define GREATEST_SUITE(NAME) void NAME(void); void NAME(void) |
|
| 307 |
+ |
|
| 308 |
+/* Declare a suite, provided by another compilation unit. */ |
|
| 309 |
+#define GREATEST_SUITE_EXTERN(NAME) void NAME(void) |
|
| 310 |
+ |
|
| 311 |
+/* Start defining a test function. |
|
| 312 |
+ * The arguments are not included, to allow parametric testing. */ |
|
| 313 |
+#define GREATEST_TEST static enum greatest_test_res |
|
| 314 |
+ |
|
| 315 |
+/* PASS/FAIL/SKIP result from a test. Used internally. */ |
|
| 316 |
+typedef enum greatest_test_res {
|
|
| 317 |
+ GREATEST_TEST_RES_PASS = 0, |
|
| 318 |
+ GREATEST_TEST_RES_FAIL = -1, |
|
| 319 |
+ GREATEST_TEST_RES_SKIP = 1 |
|
| 320 |
+} greatest_test_res; |
|
| 321 |
+ |
|
| 322 |
+/* Run a suite. */ |
|
| 323 |
+#define GREATEST_RUN_SUITE(S_NAME) greatest_run_suite(S_NAME, #S_NAME) |
|
| 324 |
+ |
|
| 325 |
+/* Run a test in the current suite. */ |
|
| 326 |
+#define GREATEST_RUN_TEST(TEST) \ |
|
| 327 |
+ do { \
|
|
| 328 |
+ if (greatest_pre_test(#TEST) == 1) { \
|
|
| 329 |
+ enum greatest_test_res res = GREATEST_SAVE_CONTEXT(); \ |
|
| 330 |
+ if (res == GREATEST_TEST_RES_PASS) { \
|
|
| 331 |
+ res = TEST(); \ |
|
| 332 |
+ } \ |
|
| 333 |
+ greatest_post_test(#TEST, res); \ |
|
| 334 |
+ } else if (GREATEST_LIST_ONLY()) { \
|
|
| 335 |
+ fprintf(GREATEST_STDOUT, " %s\n", #TEST); \ |
|
| 336 |
+ } \ |
|
| 337 |
+ } while (0) |
|
| 338 |
+ |
|
| 339 |
+/* Ignore a test, don't warn about it being unused. */ |
|
| 340 |
+#define GREATEST_IGNORE_TEST(TEST) (void)TEST |
|
| 341 |
+ |
|
| 342 |
+/* Run a test in the current suite with one void * argument, |
|
| 343 |
+ * which can be a pointer to a struct with multiple arguments. */ |
|
| 344 |
+#define GREATEST_RUN_TEST1(TEST, ENV) \ |
|
| 345 |
+ do { \
|
|
| 346 |
+ if (greatest_pre_test(#TEST) == 1) { \
|
|
| 347 |
+ int res = TEST(ENV); \ |
|
| 348 |
+ greatest_post_test(#TEST, res); \ |
|
| 349 |
+ } else if (GREATEST_LIST_ONLY()) { \
|
|
| 350 |
+ fprintf(GREATEST_STDOUT, " %s\n", #TEST); \ |
|
| 351 |
+ } \ |
|
| 352 |
+ } while (0) |
|
| 353 |
+ |
|
| 354 |
+#ifdef GREATEST_VA_ARGS |
|
| 355 |
+#define GREATEST_RUN_TESTp(TEST, ...) \ |
|
| 356 |
+ do { \
|
|
| 357 |
+ if (greatest_pre_test(#TEST) == 1) { \
|
|
| 358 |
+ int res = TEST(__VA_ARGS__); \ |
|
| 359 |
+ greatest_post_test(#TEST, res); \ |
|
| 360 |
+ } else if (GREATEST_LIST_ONLY()) { \
|
|
| 361 |
+ fprintf(GREATEST_STDOUT, " %s\n", #TEST); \ |
|
| 362 |
+ } \ |
|
| 363 |
+ } while (0) |
|
| 364 |
+#endif |
|
| 365 |
+ |
|
| 366 |
+ |
|
| 367 |
+/* Check if the test runner is in verbose mode. */ |
|
| 368 |
+#define GREATEST_IS_VERBOSE() ((greatest_info.verbosity) > 0) |
|
| 369 |
+#define GREATEST_LIST_ONLY() \ |
|
| 370 |
+ (greatest_info.flags & GREATEST_FLAG_LIST_ONLY) |
|
| 371 |
+#define GREATEST_FIRST_FAIL() \ |
|
| 372 |
+ (greatest_info.flags & GREATEST_FLAG_FIRST_FAIL) |
|
| 373 |
+#define GREATEST_FAILURE_ABORT() \ |
|
| 374 |
+ (greatest_info.suite.failed > 0 && GREATEST_FIRST_FAIL()) |
|
| 375 |
+ |
|
| 376 |
+/* Message-less forms of tests defined below. */ |
|
| 377 |
+#define GREATEST_PASS() GREATEST_PASSm(NULL) |
|
| 378 |
+#define GREATEST_FAIL() GREATEST_FAILm(NULL) |
|
| 379 |
+#define GREATEST_SKIP() GREATEST_SKIPm(NULL) |
|
| 380 |
+#define GREATEST_ASSERT(COND) \ |
|
| 381 |
+ GREATEST_ASSERTm(#COND, COND) |
|
| 382 |
+#define GREATEST_ASSERT_OR_LONGJMP(COND) \ |
|
| 383 |
+ GREATEST_ASSERT_OR_LONGJMPm(#COND, COND) |
|
| 384 |
+#define GREATEST_ASSERT_FALSE(COND) \ |
|
| 385 |
+ GREATEST_ASSERT_FALSEm(#COND, COND) |
|
| 386 |
+#define GREATEST_ASSERT_EQ(EXP, GOT) \ |
|
| 387 |
+ GREATEST_ASSERT_EQm(#EXP " != " #GOT, EXP, GOT) |
|
| 388 |
+#define GREATEST_ASSERT_EQ_FMT(EXP, GOT, FMT) \ |
|
| 389 |
+ GREATEST_ASSERT_EQ_FMTm(#EXP " != " #GOT, EXP, GOT, FMT) |
|
| 390 |
+#define GREATEST_ASSERT_IN_RANGE(EXP, GOT, TOL) \ |
|
| 391 |
+ GREATEST_ASSERT_IN_RANGEm(#EXP " != " #GOT " +/- " #TOL, EXP, GOT, TOL) |
|
| 392 |
+#define GREATEST_ASSERT_EQUAL_T(EXP, GOT, TYPE_INFO, UDATA) \ |
|
| 393 |
+ GREATEST_ASSERT_EQUAL_Tm(#EXP " != " #GOT, EXP, GOT, TYPE_INFO, UDATA) |
|
| 394 |
+#define GREATEST_ASSERT_STR_EQ(EXP, GOT) \ |
|
| 395 |
+ GREATEST_ASSERT_STR_EQm(#EXP " != " #GOT, EXP, GOT) |
|
| 396 |
+#define GREATEST_ASSERT_STRN_EQ(EXP, GOT, SIZE) \ |
|
| 397 |
+ GREATEST_ASSERT_STRN_EQm(#EXP " != " #GOT, EXP, GOT, SIZE) |
|
| 398 |
+#define GREATEST_ASSERT_MEM_EQ(EXP, GOT, SIZE) \ |
|
| 399 |
+ GREATEST_ASSERT_MEM_EQm(#EXP " != " #GOT, EXP, GOT, SIZE) |
|
| 400 |
+#define GREATEST_ASSERT_ENUM_EQ(EXP, GOT, ENUM_STR) \ |
|
| 401 |
+ GREATEST_ASSERT_ENUM_EQm(#EXP " != " #GOT, EXP, GOT, ENUM_STR) |
|
| 402 |
+ |
|
| 403 |
+/* The following forms take an additional message argument first, |
|
| 404 |
+ * to be displayed by the test runner. */ |
|
| 405 |
+ |
|
| 406 |
+/* Fail if a condition is not true, with message. */ |
|
| 407 |
+#define GREATEST_ASSERTm(MSG, COND) \ |
|
| 408 |
+ do { \
|
|
| 409 |
+ greatest_info.assertions++; \ |
|
| 410 |
+ if (!(COND)) { GREATEST_FAILm(MSG); } \
|
|
| 411 |
+ } while (0) |
|
| 412 |
+ |
|
| 413 |
+/* Fail if a condition is not true, longjmping out of test. */ |
|
| 414 |
+#define GREATEST_ASSERT_OR_LONGJMPm(MSG, COND) \ |
|
| 415 |
+ do { \
|
|
| 416 |
+ greatest_info.assertions++; \ |
|
| 417 |
+ if (!(COND)) { GREATEST_FAIL_WITH_LONGJMPm(MSG); } \
|
|
| 418 |
+ } while (0) |
|
| 419 |
+ |
|
| 420 |
+/* Fail if a condition is not false, with message. */ |
|
| 421 |
+#define GREATEST_ASSERT_FALSEm(MSG, COND) \ |
|
| 422 |
+ do { \
|
|
| 423 |
+ greatest_info.assertions++; \ |
|
| 424 |
+ if ((COND)) { GREATEST_FAILm(MSG); } \
|
|
| 425 |
+ } while (0) |
|
| 426 |
+ |
|
| 427 |
+/* Fail if EXP != GOT (equality comparison by ==). */ |
|
| 428 |
+#define GREATEST_ASSERT_EQm(MSG, EXP, GOT) \ |
|
| 429 |
+ do { \
|
|
| 430 |
+ greatest_info.assertions++; \ |
|
| 431 |
+ if ((EXP) != (GOT)) { GREATEST_FAILm(MSG); } \
|
|
| 432 |
+ } while (0) |
|
| 433 |
+ |
|
| 434 |
+/* Fail if EXP != GOT (equality comparison by ==). |
|
| 435 |
+ * Warning: EXP and GOT will be evaluated more than once on failure. */ |
|
| 436 |
+#define GREATEST_ASSERT_EQ_FMTm(MSG, EXP, GOT, FMT) \ |
|
| 437 |
+ do { \
|
|
| 438 |
+ const char *greatest_FMT = ( FMT ); \ |
|
| 439 |
+ greatest_info.assertions++; \ |
|
| 440 |
+ if ((EXP) != (GOT)) { \
|
|
| 441 |
+ fprintf(GREATEST_STDOUT, "\nExpected: "); \ |
|
| 442 |
+ fprintf(GREATEST_STDOUT, greatest_FMT, EXP); \ |
|
| 443 |
+ fprintf(GREATEST_STDOUT, "\n Got: "); \ |
|
| 444 |
+ fprintf(GREATEST_STDOUT, greatest_FMT, GOT); \ |
|
| 445 |
+ fprintf(GREATEST_STDOUT, "\n"); \ |
|
| 446 |
+ GREATEST_FAILm(MSG); \ |
|
| 447 |
+ } \ |
|
| 448 |
+ } while (0) |
|
| 449 |
+ |
|
| 450 |
+/* Fail if EXP is not equal to GOT, printing enum IDs. */ |
|
| 451 |
+#define GREATEST_ASSERT_ENUM_EQm(MSG, EXP, GOT, ENUM_STR) \ |
|
| 452 |
+ do { \
|
|
| 453 |
+ int greatest_EXP = (int)(EXP); \ |
|
| 454 |
+ int greatest_GOT = (int)(GOT); \ |
|
| 455 |
+ greatest_enum_str_fun *greatest_ENUM_STR = ENUM_STR; \ |
|
| 456 |
+ if (greatest_EXP != greatest_GOT) { \
|
|
| 457 |
+ fprintf(GREATEST_STDOUT, "\nExpected: %s", \ |
|
| 458 |
+ greatest_ENUM_STR(greatest_EXP)); \ |
|
| 459 |
+ fprintf(GREATEST_STDOUT, "\n Got: %s\n", \ |
|
| 460 |
+ greatest_ENUM_STR(greatest_GOT)); \ |
|
| 461 |
+ GREATEST_FAILm(MSG); \ |
|
| 462 |
+ } \ |
|
| 463 |
+ } while (0) \ |
|
| 464 |
+ |
|
| 465 |
+/* Fail if GOT not in range of EXP +|- TOL. */ |
|
| 466 |
+#define GREATEST_ASSERT_IN_RANGEm(MSG, EXP, GOT, TOL) \ |
|
| 467 |
+ do { \
|
|
| 468 |
+ GREATEST_FLOAT greatest_EXP = (EXP); \ |
|
| 469 |
+ GREATEST_FLOAT greatest_GOT = (GOT); \ |
|
| 470 |
+ GREATEST_FLOAT greatest_TOL = (TOL); \ |
|
| 471 |
+ greatest_info.assertions++; \ |
|
| 472 |
+ if ((greatest_EXP > greatest_GOT && \ |
|
| 473 |
+ greatest_EXP - greatest_GOT > greatest_TOL) || \ |
|
| 474 |
+ (greatest_EXP < greatest_GOT && \ |
|
| 475 |
+ greatest_GOT - greatest_EXP > greatest_TOL)) { \
|
|
| 476 |
+ fprintf(GREATEST_STDOUT, \ |
|
| 477 |
+ "\nExpected: " GREATEST_FLOAT_FMT \ |
|
| 478 |
+ " +/- " GREATEST_FLOAT_FMT \ |
|
| 479 |
+ "\n Got: " GREATEST_FLOAT_FMT \ |
|
| 480 |
+ "\n", \ |
|
| 481 |
+ greatest_EXP, greatest_TOL, greatest_GOT); \ |
|
| 482 |
+ GREATEST_FAILm(MSG); \ |
|
| 483 |
+ } \ |
|
| 484 |
+ } while (0) |
|
| 485 |
+ |
|
| 486 |
+/* Fail if EXP is not equal to GOT, according to strcmp. */ |
|
| 487 |
+#define GREATEST_ASSERT_STR_EQm(MSG, EXP, GOT) \ |
|
| 488 |
+ do { \
|
|
| 489 |
+ GREATEST_ASSERT_EQUAL_Tm(MSG, EXP, GOT, \ |
|
| 490 |
+ &greatest_type_info_string, NULL); \ |
|
| 491 |
+ } while (0) \ |
|
| 492 |
+ |
|
| 493 |
+/* Fail if EXP is not equal to GOT, according to strcmp. */ |
|
| 494 |
+#define GREATEST_ASSERT_STRN_EQm(MSG, EXP, GOT, SIZE) \ |
|
| 495 |
+ do { \
|
|
| 496 |
+ size_t size = SIZE; \ |
|
| 497 |
+ GREATEST_ASSERT_EQUAL_Tm(MSG, EXP, GOT, \ |
|
| 498 |
+ &greatest_type_info_string, &size); \ |
|
| 499 |
+ } while (0) \ |
|
| 500 |
+ |
|
| 501 |
+/* Fail if EXP is not equal to GOT, according to memcmp. */ |
|
| 502 |
+#define GREATEST_ASSERT_MEM_EQm(MSG, EXP, GOT, SIZE) \ |
|
| 503 |
+ do { \
|
|
| 504 |
+ greatest_memory_cmp_env env; \ |
|
| 505 |
+ env.exp = (const unsigned char *)EXP; \ |
|
| 506 |
+ env.got = (const unsigned char *)GOT; \ |
|
| 507 |
+ env.size = SIZE; \ |
|
| 508 |
+ GREATEST_ASSERT_EQUAL_Tm(MSG, env.exp, env.got, \ |
|
| 509 |
+ &greatest_type_info_memory, &env); \ |
|
| 510 |
+ } while (0) \ |
|
| 511 |
+ |
|
| 512 |
+/* Fail if EXP is not equal to GOT, according to a comparison |
|
| 513 |
+ * callback in TYPE_INFO. If they are not equal, optionally use a |
|
| 514 |
+ * print callback in TYPE_INFO to print them. */ |
|
| 515 |
+#define GREATEST_ASSERT_EQUAL_Tm(MSG, EXP, GOT, TYPE_INFO, UDATA) \ |
|
| 516 |
+ do { \
|
|
| 517 |
+ greatest_type_info *type_info = (TYPE_INFO); \ |
|
| 518 |
+ greatest_info.assertions++; \ |
|
| 519 |
+ if (!greatest_do_assert_equal_t(EXP, GOT, \ |
|
| 520 |
+ type_info, UDATA)) { \
|
|
| 521 |
+ if (type_info == NULL || type_info->equal == NULL) { \
|
|
| 522 |
+ GREATEST_FAILm("type_info->equal callback missing!"); \
|
|
| 523 |
+ } else { \
|
|
| 524 |
+ GREATEST_FAILm(MSG); \ |
|
| 525 |
+ } \ |
|
| 526 |
+ } \ |
|
| 527 |
+ } while (0) \ |
|
| 528 |
+ |
|
| 529 |
+/* Pass. */ |
|
| 530 |
+#define GREATEST_PASSm(MSG) \ |
|
| 531 |
+ do { \
|
|
| 532 |
+ greatest_info.msg = MSG; \ |
|
| 533 |
+ return GREATEST_TEST_RES_PASS; \ |
|
| 534 |
+ } while (0) |
|
| 535 |
+ |
|
| 536 |
+/* Fail. */ |
|
| 537 |
+#define GREATEST_FAILm(MSG) \ |
|
| 538 |
+ do { \
|
|
| 539 |
+ greatest_info.fail_file = __FILE__; \ |
|
| 540 |
+ greatest_info.fail_line = __LINE__; \ |
|
| 541 |
+ greatest_info.msg = MSG; \ |
|
| 542 |
+ return GREATEST_TEST_RES_FAIL; \ |
|
| 543 |
+ } while (0) |
|
| 544 |
+ |
|
| 545 |
+/* Optional GREATEST_FAILm variant that longjmps. */ |
|
| 546 |
+#if GREATEST_USE_LONGJMP |
|
| 547 |
+#define GREATEST_FAIL_WITH_LONGJMP() GREATEST_FAIL_WITH_LONGJMPm(NULL) |
|
| 548 |
+#define GREATEST_FAIL_WITH_LONGJMPm(MSG) \ |
|
| 549 |
+ do { \
|
|
| 550 |
+ greatest_info.fail_file = __FILE__; \ |
|
| 551 |
+ greatest_info.fail_line = __LINE__; \ |
|
| 552 |
+ greatest_info.msg = MSG; \ |
|
| 553 |
+ longjmp(greatest_info.jump_dest, GREATEST_TEST_RES_FAIL); \ |
|
| 554 |
+ } while (0) |
|
| 555 |
+#endif |
|
| 556 |
+ |
|
| 557 |
+/* Skip the current test. */ |
|
| 558 |
+#define GREATEST_SKIPm(MSG) \ |
|
| 559 |
+ do { \
|
|
| 560 |
+ greatest_info.msg = MSG; \ |
|
| 561 |
+ return GREATEST_TEST_RES_SKIP; \ |
|
| 562 |
+ } while (0) |
|
| 563 |
+ |
|
| 564 |
+/* Check the result of a subfunction using ASSERT, etc. */ |
|
| 565 |
+#define GREATEST_CHECK_CALL(RES) \ |
|
| 566 |
+ do { \
|
|
| 567 |
+ enum greatest_test_res greatest_RES = RES; \ |
|
| 568 |
+ if (greatest_RES != GREATEST_TEST_RES_PASS) { \
|
|
| 569 |
+ return greatest_RES; \ |
|
| 570 |
+ } \ |
|
| 571 |
+ } while (0) \ |
|
| 572 |
+ |
|
| 573 |
+#if GREATEST_USE_TIME |
|
| 574 |
+#define GREATEST_SET_TIME(NAME) \ |
|
| 575 |
+ NAME = clock(); \ |
|
| 576 |
+ if (NAME == (clock_t) -1) { \
|
|
| 577 |
+ fprintf(GREATEST_STDOUT, \ |
|
| 578 |
+ "clock error: %s\n", #NAME); \ |
|
| 579 |
+ exit(EXIT_FAILURE); \ |
|
| 580 |
+ } |
|
| 581 |
+ |
|
| 582 |
+#define GREATEST_CLOCK_DIFF(C1, C2) \ |
|
| 583 |
+ fprintf(GREATEST_STDOUT, " (%lu ticks, %.3f sec)", \ |
|
| 584 |
+ (long unsigned int) (C2) - (long unsigned int)(C1), \ |
|
| 585 |
+ (double)((C2) - (C1)) / (1.0 * (double)CLOCKS_PER_SEC)) |
|
| 586 |
+#else |
|
| 587 |
+#define GREATEST_SET_TIME(UNUSED) |
|
| 588 |
+#define GREATEST_CLOCK_DIFF(UNUSED1, UNUSED2) |
|
| 589 |
+#endif |
|
| 590 |
+ |
|
| 591 |
+#if GREATEST_USE_LONGJMP |
|
| 592 |
+#define GREATEST_SAVE_CONTEXT() \ |
|
| 593 |
+ /* setjmp returns 0 (GREATEST_TEST_RES_PASS) on first call */ \ |
|
| 594 |
+ /* so the test runs, then RES_FAIL from FAIL_WITH_LONGJMP. */ \ |
|
| 595 |
+ ((enum greatest_test_res)(setjmp(greatest_info.jump_dest))) |
|
| 596 |
+#else |
|
| 597 |
+#define GREATEST_SAVE_CONTEXT() \ |
|
| 598 |
+ /*a no-op, since setjmp/longjmp aren't being used */ \ |
|
| 599 |
+ GREATEST_TEST_RES_PASS |
|
| 600 |
+#endif |
|
| 601 |
+ |
|
| 602 |
+/* Include several function definitions in the main test file. */ |
|
| 603 |
+#define GREATEST_MAIN_DEFS() \ |
|
| 604 |
+ \ |
|
| 605 |
+/* Is FILTER a subset of NAME? */ \ |
|
| 606 |
+static int greatest_name_match(const char *name, \ |
|
| 607 |
+ const char *filter) { \
|
|
| 608 |
+ size_t offset = 0; \ |
|
| 609 |
+ size_t filter_len = strlen(filter); \ |
|
| 610 |
+ while (name[offset] != '\0') { \
|
|
| 611 |
+ if (name[offset] == filter[0]) { \
|
|
| 612 |
+ if (0 == strncmp(&name[offset], filter, filter_len)) { \
|
|
| 613 |
+ return 1; \ |
|
| 614 |
+ } \ |
|
| 615 |
+ } \ |
|
| 616 |
+ offset++; \ |
|
| 617 |
+ } \ |
|
| 618 |
+ \ |
|
| 619 |
+ return 0; \ |
|
| 620 |
+} \ |
|
| 621 |
+ \ |
|
| 622 |
+int greatest_pre_test(const char *name) { \
|
|
| 623 |
+ if (!GREATEST_LIST_ONLY() \ |
|
| 624 |
+ && (!GREATEST_FIRST_FAIL() || greatest_info.suite.failed == 0) \ |
|
| 625 |
+ && (greatest_info.test_filter == NULL || \ |
|
| 626 |
+ greatest_name_match(name, greatest_info.test_filter))) { \
|
|
| 627 |
+ GREATEST_SET_TIME(greatest_info.suite.pre_test); \ |
|
| 628 |
+ if (greatest_info.setup) { \
|
|
| 629 |
+ greatest_info.setup(greatest_info.setup_udata); \ |
|
| 630 |
+ } \ |
|
| 631 |
+ return 1; /* test should be run */ \ |
|
| 632 |
+ } else { \
|
|
| 633 |
+ return 0; /* skipped */ \ |
|
| 634 |
+ } \ |
|
| 635 |
+} \ |
|
| 636 |
+ \ |
|
| 637 |
+void greatest_post_test(const char *name, int res) { \
|
|
| 638 |
+ GREATEST_SET_TIME(greatest_info.suite.post_test); \ |
|
| 639 |
+ if (greatest_info.teardown) { \
|
|
| 640 |
+ void *udata = greatest_info.teardown_udata; \ |
|
| 641 |
+ greatest_info.teardown(udata); \ |
|
| 642 |
+ } \ |
|
| 643 |
+ \ |
|
| 644 |
+ if (res <= GREATEST_TEST_RES_FAIL) { \
|
|
| 645 |
+ greatest_do_fail(name); \ |
|
| 646 |
+ } else if (res >= GREATEST_TEST_RES_SKIP) { \
|
|
| 647 |
+ greatest_do_skip(name); \ |
|
| 648 |
+ } else if (res == GREATEST_TEST_RES_PASS) { \
|
|
| 649 |
+ greatest_do_pass(name); \ |
|
| 650 |
+ } \ |
|
| 651 |
+ greatest_info.suite.tests_run++; \ |
|
| 652 |
+ greatest_info.col++; \ |
|
| 653 |
+ if (GREATEST_IS_VERBOSE()) { \
|
|
| 654 |
+ GREATEST_CLOCK_DIFF(greatest_info.suite.pre_test, \ |
|
| 655 |
+ greatest_info.suite.post_test); \ |
|
| 656 |
+ fprintf(GREATEST_STDOUT, "\n"); \ |
|
| 657 |
+ } else if (greatest_info.col % greatest_info.width == 0) { \
|
|
| 658 |
+ fprintf(GREATEST_STDOUT, "\n"); \ |
|
| 659 |
+ greatest_info.col = 0; \ |
|
| 660 |
+ } \ |
|
| 661 |
+ if (GREATEST_STDOUT == stdout) fflush(stdout); \ |
|
| 662 |
+} \ |
|
| 663 |
+ \ |
|
| 664 |
+static void report_suite(void) { \
|
|
| 665 |
+ if (greatest_info.suite.tests_run > 0) { \
|
|
| 666 |
+ fprintf(GREATEST_STDOUT, \ |
|
| 667 |
+ "\n%u test%s - %u passed, %u failed, %u skipped", \ |
|
| 668 |
+ greatest_info.suite.tests_run, \ |
|
| 669 |
+ greatest_info.suite.tests_run == 1 ? "" : "s", \ |
|
| 670 |
+ greatest_info.suite.passed, \ |
|
| 671 |
+ greatest_info.suite.failed, \ |
|
| 672 |
+ greatest_info.suite.skipped); \ |
|
| 673 |
+ GREATEST_CLOCK_DIFF(greatest_info.suite.pre_suite, \ |
|
| 674 |
+ greatest_info.suite.post_suite); \ |
|
| 675 |
+ fprintf(GREATEST_STDOUT, "\n"); \ |
|
| 676 |
+ } \ |
|
| 677 |
+} \ |
|
| 678 |
+ \ |
|
| 679 |
+static void update_counts_and_reset_suite(void) { \
|
|
| 680 |
+ greatest_info.setup = NULL; \ |
|
| 681 |
+ greatest_info.setup_udata = NULL; \ |
|
| 682 |
+ greatest_info.teardown = NULL; \ |
|
| 683 |
+ greatest_info.teardown_udata = NULL; \ |
|
| 684 |
+ greatest_info.passed += greatest_info.suite.passed; \ |
|
| 685 |
+ greatest_info.failed += greatest_info.suite.failed; \ |
|
| 686 |
+ greatest_info.skipped += greatest_info.suite.skipped; \ |
|
| 687 |
+ greatest_info.tests_run += greatest_info.suite.tests_run; \ |
|
| 688 |
+ memset(&greatest_info.suite, 0, sizeof(greatest_info.suite)); \ |
|
| 689 |
+ greatest_info.col = 0; \ |
|
| 690 |
+} \ |
|
| 691 |
+ \ |
|
| 692 |
+static void greatest_run_suite(greatest_suite_cb *suite_cb, \ |
|
| 693 |
+ const char *suite_name) { \
|
|
| 694 |
+ if (greatest_info.suite_filter && \ |
|
| 695 |
+ !greatest_name_match(suite_name, greatest_info.suite_filter)) { \
|
|
| 696 |
+ return; \ |
|
| 697 |
+ } \ |
|
| 698 |
+ update_counts_and_reset_suite(); \ |
|
| 699 |
+ if (GREATEST_FIRST_FAIL() && greatest_info.failed > 0) { return; } \
|
|
| 700 |
+ fprintf(GREATEST_STDOUT, "\n* Suite %s:\n", suite_name); \ |
|
| 701 |
+ GREATEST_SET_TIME(greatest_info.suite.pre_suite); \ |
|
| 702 |
+ suite_cb(); \ |
|
| 703 |
+ GREATEST_SET_TIME(greatest_info.suite.post_suite); \ |
|
| 704 |
+ report_suite(); \ |
|
| 705 |
+} \ |
|
| 706 |
+ \ |
|
| 707 |
+void greatest_do_pass(const char *name) { \
|
|
| 708 |
+ if (GREATEST_IS_VERBOSE()) { \
|
|
| 709 |
+ fprintf(GREATEST_STDOUT, "PASS %s: %s", \ |
|
| 710 |
+ name, greatest_info.msg ? greatest_info.msg : ""); \ |
|
| 711 |
+ } else { \
|
|
| 712 |
+ fprintf(GREATEST_STDOUT, "."); \ |
|
| 713 |
+ } \ |
|
| 714 |
+ greatest_info.suite.passed++; \ |
|
| 715 |
+} \ |
|
| 716 |
+ \ |
|
| 717 |
+void greatest_do_fail(const char *name) { \
|
|
| 718 |
+ if (GREATEST_IS_VERBOSE()) { \
|
|
| 719 |
+ fprintf(GREATEST_STDOUT, \ |
|
| 720 |
+ "FAIL %s: %s (%s:%u)", \ |
|
| 721 |
+ name, greatest_info.msg ? greatest_info.msg : "", \ |
|
| 722 |
+ greatest_info.fail_file, greatest_info.fail_line); \ |
|
| 723 |
+ } else { \
|
|
| 724 |
+ fprintf(GREATEST_STDOUT, "F"); \ |
|
| 725 |
+ greatest_info.col++; \ |
|
| 726 |
+ /* add linebreak if in line of '.'s */ \ |
|
| 727 |
+ if (greatest_info.col != 0) { \
|
|
| 728 |
+ fprintf(GREATEST_STDOUT, "\n"); \ |
|
| 729 |
+ greatest_info.col = 0; \ |
|
| 730 |
+ } \ |
|
| 731 |
+ fprintf(GREATEST_STDOUT, "FAIL %s: %s (%s:%u)\n", \ |
|
| 732 |
+ name, \ |
|
| 733 |
+ greatest_info.msg ? greatest_info.msg : "", \ |
|
| 734 |
+ greatest_info.fail_file, greatest_info.fail_line); \ |
|
| 735 |
+ } \ |
|
| 736 |
+ greatest_info.suite.failed++; \ |
|
| 737 |
+} \ |
|
| 738 |
+ \ |
|
| 739 |
+void greatest_do_skip(const char *name) { \
|
|
| 740 |
+ if (GREATEST_IS_VERBOSE()) { \
|
|
| 741 |
+ fprintf(GREATEST_STDOUT, "SKIP %s: %s", \ |
|
| 742 |
+ name, \ |
|
| 743 |
+ greatest_info.msg ? \ |
|
| 744 |
+ greatest_info.msg : "" ); \ |
|
| 745 |
+ } else { \
|
|
| 746 |
+ fprintf(GREATEST_STDOUT, "s"); \ |
|
| 747 |
+ } \ |
|
| 748 |
+ greatest_info.suite.skipped++; \ |
|
| 749 |
+} \ |
|
| 750 |
+ \ |
|
| 751 |
+int greatest_do_assert_equal_t(const void *exp, const void *got, \ |
|
| 752 |
+ greatest_type_info *type_info, void *udata) { \
|
|
| 753 |
+ int eq = 0; \ |
|
| 754 |
+ if (type_info == NULL || type_info->equal == NULL) { \
|
|
| 755 |
+ return 0; \ |
|
| 756 |
+ } \ |
|
| 757 |
+ eq = type_info->equal(exp, got, udata); \ |
|
| 758 |
+ if (!eq) { \
|
|
| 759 |
+ if (type_info->print != NULL) { \
|
|
| 760 |
+ fprintf(GREATEST_STDOUT, "\nExpected: "); \ |
|
| 761 |
+ (void)type_info->print(exp, udata); \ |
|
| 762 |
+ fprintf(GREATEST_STDOUT, "\n Got: "); \ |
|
| 763 |
+ (void)type_info->print(got, udata); \ |
|
| 764 |
+ fprintf(GREATEST_STDOUT, "\n"); \ |
|
| 765 |
+ } else { \
|
|
| 766 |
+ fprintf(GREATEST_STDOUT, \ |
|
| 767 |
+ "GREATEST_ASSERT_EQUAL_T failure at %s:%u\n", \ |
|
| 768 |
+ greatest_info.fail_file, \ |
|
| 769 |
+ greatest_info.fail_line); \ |
|
| 770 |
+ } \ |
|
| 771 |
+ } \ |
|
| 772 |
+ return eq; \ |
|
| 773 |
+} \ |
|
| 774 |
+ \ |
|
| 775 |
+void greatest_usage(const char *name) { \
|
|
| 776 |
+ fprintf(GREATEST_STDOUT, \ |
|
| 777 |
+ "Usage: %s [-hlfv] [-s SUITE] [-t TEST]\n" \ |
|
| 778 |
+ " -h, --help print this Help\n" \ |
|
| 779 |
+ " -l List suites and their tests, then exit\n" \ |
|
| 780 |
+ " -f Stop runner after first failure\n" \ |
|
| 781 |
+ " -v Verbose output\n" \ |
|
| 782 |
+ " -s SUITE only run suites containing string SUITE\n" \ |
|
| 783 |
+ " -t TEST only run tests containing string TEST\n", \ |
|
| 784 |
+ name); \ |
|
| 785 |
+} \ |
|
| 786 |
+ \ |
|
| 787 |
+static void greatest_parse_args(int argc, char **argv) { \
|
|
| 788 |
+ int i = 0; \ |
|
| 789 |
+ for (i = 1; i < argc; i++) { \
|
|
| 790 |
+ if (0 == strncmp("-t", argv[i], 2)) { \
|
|
| 791 |
+ if (argc <= i + 1) { \
|
|
| 792 |
+ greatest_usage(argv[0]); \ |
|
| 793 |
+ exit(EXIT_FAILURE); \ |
|
| 794 |
+ } \ |
|
| 795 |
+ greatest_info.test_filter = argv[i+1]; \ |
|
| 796 |
+ i++; \ |
|
| 797 |
+ } else if (0 == strncmp("-s", argv[i], 2)) { \
|
|
| 798 |
+ if (argc <= i + 1) { \
|
|
| 799 |
+ greatest_usage(argv[0]); \ |
|
| 800 |
+ exit(EXIT_FAILURE); \ |
|
| 801 |
+ } \ |
|
| 802 |
+ greatest_info.suite_filter = argv[i+1]; \ |
|
| 803 |
+ i++; \ |
|
| 804 |
+ } else if (0 == strncmp("-f", argv[i], 2)) { \
|
|
| 805 |
+ greatest_info.flags |= GREATEST_FLAG_FIRST_FAIL; \ |
|
| 806 |
+ } else if (0 == strncmp("-v", argv[i], 2)) { \
|
|
| 807 |
+ greatest_info.verbosity++; \ |
|
| 808 |
+ } else if (0 == strncmp("-l", argv[i], 2)) { \
|
|
| 809 |
+ greatest_info.flags |= GREATEST_FLAG_LIST_ONLY; \ |
|
| 810 |
+ } else if (0 == strncmp("-h", argv[i], 2) || \
|
|
| 811 |
+ 0 == strncmp("--help", argv[i], 6)) { \
|
|
| 812 |
+ greatest_usage(argv[0]); \ |
|
| 813 |
+ exit(EXIT_SUCCESS); \ |
|
| 814 |
+ } else if (0 == strncmp("--", argv[i], 2)) { \
|
|
| 815 |
+ break; \ |
|
| 816 |
+ } else { \
|
|
| 817 |
+ fprintf(GREATEST_STDOUT, \ |
|
| 818 |
+ "Unknown argument '%s'\n", argv[i]); \ |
|
| 819 |
+ greatest_usage(argv[0]); \ |
|
| 820 |
+ exit(EXIT_FAILURE); \ |
|
| 821 |
+ } \ |
|
| 822 |
+ } \ |
|
| 823 |
+} \ |
|
| 824 |
+ \ |
|
| 825 |
+int greatest_all_passed(void) { return (greatest_info.failed == 0); } \
|
|
| 826 |
+ \ |
|
| 827 |
+void greatest_set_test_filter(const char *name) { \
|
|
| 828 |
+ greatest_info.test_filter = name; \ |
|
| 829 |
+} \ |
|
| 830 |
+ \ |
|
| 831 |
+void greatest_set_suite_filter(const char *name) { \
|
|
| 832 |
+ greatest_info.suite_filter = name; \ |
|
| 833 |
+} \ |
|
| 834 |
+ \ |
|
| 835 |
+void greatest_get_report(struct greatest_report_t *report) { \
|
|
| 836 |
+ if (report) { \
|
|
| 837 |
+ report->passed = greatest_info.passed; \ |
|
| 838 |
+ report->failed = greatest_info.failed; \ |
|
| 839 |
+ report->skipped = greatest_info.skipped; \ |
|
| 840 |
+ report->assertions = greatest_info.assertions; \ |
|
| 841 |
+ } \ |
|
| 842 |
+} \ |
|
| 843 |
+ \ |
|
| 844 |
+unsigned int greatest_get_verbosity(void) { \
|
|
| 845 |
+ return greatest_info.verbosity; \ |
|
| 846 |
+} \ |
|
| 847 |
+ \ |
|
| 848 |
+void greatest_set_verbosity(unsigned int verbosity) { \
|
|
| 849 |
+ greatest_info.verbosity = (unsigned char)verbosity; \ |
|
| 850 |
+} \ |
|
| 851 |
+ \ |
|
| 852 |
+void greatest_set_flag(greatest_flag_t flag) { \
|
|
| 853 |
+ greatest_info.flags |= flag; \ |
|
| 854 |
+} \ |
|
| 855 |
+ \ |
|
| 856 |
+void GREATEST_SET_SETUP_CB(greatest_setup_cb *cb, void *udata) { \
|
|
| 857 |
+ greatest_info.setup = cb; \ |
|
| 858 |
+ greatest_info.setup_udata = udata; \ |
|
| 859 |
+} \ |
|
| 860 |
+ \ |
|
| 861 |
+void GREATEST_SET_TEARDOWN_CB(greatest_teardown_cb *cb, \ |
|
| 862 |
+ void *udata) { \
|
|
| 863 |
+ greatest_info.teardown = cb; \ |
|
| 864 |
+ greatest_info.teardown_udata = udata; \ |
|
| 865 |
+} \ |
|
| 866 |
+ \ |
|
| 867 |
+static int greatest_string_equal_cb(const void *exp, const void *got, \ |
|
| 868 |
+ void *udata) { \
|
|
| 869 |
+ size_t *size = (size_t *)udata; \ |
|
| 870 |
+ return (size != NULL \ |
|
| 871 |
+ ? (0 == strncmp((const char *)exp, (const char *)got, *size)) \ |
|
| 872 |
+ : (0 == strcmp((const char *)exp, (const char *)got))); \ |
|
| 873 |
+} \ |
|
| 874 |
+ \ |
|
| 875 |
+static int greatest_string_printf_cb(const void *t, void *udata) { \
|
|
| 876 |
+ (void)udata; /* note: does not check \0 termination. */ \ |
|
| 877 |
+ return fprintf(GREATEST_STDOUT, "%s", (const char *)t); \ |
|
| 878 |
+} \ |
|
| 879 |
+ \ |
|
| 880 |
+greatest_type_info greatest_type_info_string = { \
|
|
| 881 |
+ greatest_string_equal_cb, \ |
|
| 882 |
+ greatest_string_printf_cb, \ |
|
| 883 |
+}; \ |
|
| 884 |
+ \ |
|
| 885 |
+static int greatest_memory_equal_cb(const void *exp, const void *got, \ |
|
| 886 |
+ void *udata) { \
|
|
| 887 |
+ greatest_memory_cmp_env *env = (greatest_memory_cmp_env *)udata; \ |
|
| 888 |
+ return (0 == memcmp(exp, got, env->size)); \ |
|
| 889 |
+} \ |
|
| 890 |
+ \ |
|
| 891 |
+static int greatest_memory_printf_cb(const void *t, void *udata) { \
|
|
| 892 |
+ greatest_memory_cmp_env *env = (greatest_memory_cmp_env *)udata; \ |
|
| 893 |
+ unsigned char *buf = (unsigned char *)t, diff_mark = ' '; \ |
|
| 894 |
+ FILE *out = GREATEST_STDOUT; \ |
|
| 895 |
+ size_t i, line_i, line_len = 0; \ |
|
| 896 |
+ int len = 0; /* format hexdump with differences highlighted */ \ |
|
| 897 |
+ for (i = 0; i < env->size; i+= line_len) { \
|
|
| 898 |
+ diff_mark = ' '; \ |
|
| 899 |
+ line_len = env->size - i; \ |
|
| 900 |
+ if (line_len > 16) { line_len = 16; } \
|
|
| 901 |
+ for (line_i = i; line_i < i + line_len; line_i++) { \
|
|
| 902 |
+ if (env->exp[line_i] != env->got[line_i]) diff_mark = 'X'; \ |
|
| 903 |
+ } \ |
|
| 904 |
+ len += fprintf(out, "\n%04x %c ", (unsigned int)i, diff_mark); \ |
|
| 905 |
+ for (line_i = i; line_i < i + line_len; line_i++) { \
|
|
| 906 |
+ int m = env->exp[line_i] == env->got[line_i]; /* match? */ \ |
|
| 907 |
+ len += fprintf(out, "%02x%c", buf[line_i], m ? ' ' : '<'); \ |
|
| 908 |
+ } \ |
|
| 909 |
+ for (line_i = 0; line_i < 16 - line_len; line_i++) { \
|
|
| 910 |
+ len += fprintf(out, " "); \ |
|
| 911 |
+ } \ |
|
| 912 |
+ fprintf(out, " "); \ |
|
| 913 |
+ for (line_i = i; line_i < i + line_len; line_i++) { \
|
|
| 914 |
+ unsigned char c = buf[line_i]; \ |
|
| 915 |
+ len += fprintf(out, "%c", isprint(c) ? c : '.'); \ |
|
| 916 |
+ } \ |
|
| 917 |
+ } \ |
|
| 918 |
+ len += fprintf(out, "\n"); \ |
|
| 919 |
+ return len; \ |
|
| 920 |
+} \ |
|
| 921 |
+ \ |
|
| 922 |
+greatest_type_info greatest_type_info_memory = { \
|
|
| 923 |
+ greatest_memory_equal_cb, \ |
|
| 924 |
+ greatest_memory_printf_cb, \ |
|
| 925 |
+}; \ |
|
| 926 |
+ \ |
|
| 927 |
+greatest_run_info greatest_info |
|
| 928 |
+ |
|
| 929 |
+/* Init internals. */ |
|
| 930 |
+#define GREATEST_INIT() \ |
|
| 931 |
+ do { \
|
|
| 932 |
+ /* Suppress unused function warning if features aren't used */ \ |
|
| 933 |
+ (void)greatest_run_suite; \ |
|
| 934 |
+ (void)greatest_parse_args; \ |
|
| 935 |
+ \ |
|
| 936 |
+ memset(&greatest_info, 0, sizeof(greatest_info)); \ |
|
| 937 |
+ greatest_info.width = GREATEST_DEFAULT_WIDTH; \ |
|
| 938 |
+ GREATEST_SET_TIME(greatest_info.begin); \ |
|
| 939 |
+ } while (0) \ |
|
| 940 |
+ |
|
| 941 |
+/* Handle command-line arguments, etc. */ |
|
| 942 |
+#define GREATEST_MAIN_BEGIN() \ |
|
| 943 |
+ do { \
|
|
| 944 |
+ GREATEST_INIT(); \ |
|
| 945 |
+ greatest_parse_args(argc, argv); \ |
|
| 946 |
+ } while (0) |
|
| 947 |
+ |
|
| 948 |
+/* Report passes, failures, skipped tests, the number of |
|
| 949 |
+ * assertions, and the overall run time. */ |
|
| 950 |
+#define GREATEST_PRINT_REPORT() \ |
|
| 951 |
+ do { \
|
|
| 952 |
+ if (!GREATEST_LIST_ONLY()) { \
|
|
| 953 |
+ update_counts_and_reset_suite(); \ |
|
| 954 |
+ GREATEST_SET_TIME(greatest_info.end); \ |
|
| 955 |
+ fprintf(GREATEST_STDOUT, \ |
|
| 956 |
+ "\nTotal: %u test%s", \ |
|
| 957 |
+ greatest_info.tests_run, \ |
|
| 958 |
+ greatest_info.tests_run == 1 ? "" : "s"); \ |
|
| 959 |
+ GREATEST_CLOCK_DIFF(greatest_info.begin, \ |
|
| 960 |
+ greatest_info.end); \ |
|
| 961 |
+ fprintf(GREATEST_STDOUT, ", %u assertion%s\n", \ |
|
| 962 |
+ greatest_info.assertions, \ |
|
| 963 |
+ greatest_info.assertions == 1 ? "" : "s"); \ |
|
| 964 |
+ fprintf(GREATEST_STDOUT, \ |
|
| 965 |
+ "Pass: %u, fail: %u, skip: %u.\n", \ |
|
| 966 |
+ greatest_info.passed, \ |
|
| 967 |
+ greatest_info.failed, greatest_info.skipped); \ |
|
| 968 |
+ } \ |
|
| 969 |
+ } while (0) |
|
| 970 |
+ |
|
| 971 |
+/* Report results, exit with exit status based on results. */ |
|
| 972 |
+#define GREATEST_MAIN_END() \ |
|
| 973 |
+ do { \
|
|
| 974 |
+ GREATEST_PRINT_REPORT(); \ |
|
| 975 |
+ return (greatest_all_passed() ? EXIT_SUCCESS : EXIT_FAILURE); \ |
|
| 976 |
+ } while (0) |
|
| 977 |
+ |
|
| 978 |
+/* Make abbreviations without the GREATEST_ prefix for the |
|
| 979 |
+ * most commonly used symbols. */ |
|
| 980 |
+#if GREATEST_USE_ABBREVS |
|
| 981 |
+#define TEST GREATEST_TEST |
|
| 982 |
+#define SUITE GREATEST_SUITE |
|
| 983 |
+#define SUITE_EXTERN GREATEST_SUITE_EXTERN |
|
| 984 |
+#define RUN_TEST GREATEST_RUN_TEST |
|
| 985 |
+#define RUN_TEST1 GREATEST_RUN_TEST1 |
|
| 986 |
+#define RUN_SUITE GREATEST_RUN_SUITE |
|
| 987 |
+#define IGNORE_TEST GREATEST_IGNORE_TEST |
|
| 988 |
+#define ASSERT GREATEST_ASSERT |
|
| 989 |
+#define ASSERTm GREATEST_ASSERTm |
|
| 990 |
+#define ASSERT_FALSE GREATEST_ASSERT_FALSE |
|
| 991 |
+#define ASSERT_EQ GREATEST_ASSERT_EQ |
|
| 992 |
+#define ASSERT_EQ_FMT GREATEST_ASSERT_EQ_FMT |
|
| 993 |
+#define ASSERT_IN_RANGE GREATEST_ASSERT_IN_RANGE |
|
| 994 |
+#define ASSERT_EQUAL_T GREATEST_ASSERT_EQUAL_T |
|
| 995 |
+#define ASSERT_STR_EQ GREATEST_ASSERT_STR_EQ |
|
| 996 |
+#define ASSERT_STRN_EQ GREATEST_ASSERT_STRN_EQ |
|
| 997 |
+#define ASSERT_MEM_EQ GREATEST_ASSERT_MEM_EQ |
|
| 998 |
+#define ASSERT_ENUM_EQ GREATEST_ASSERT_ENUM_EQ |
|
| 999 |
+#define ASSERT_FALSEm GREATEST_ASSERT_FALSEm |
|
| 1000 |
+#define ASSERT_EQm GREATEST_ASSERT_EQm |
|
| 1001 |
+#define ASSERT_EQ_FMTm GREATEST_ASSERT_EQ_FMTm |
|
| 1002 |
+#define ASSERT_IN_RANGEm GREATEST_ASSERT_IN_RANGEm |
|
| 1003 |
+#define ASSERT_EQUAL_Tm GREATEST_ASSERT_EQUAL_Tm |
|
| 1004 |
+#define ASSERT_STR_EQm GREATEST_ASSERT_STR_EQm |
|
| 1005 |
+#define ASSERT_STRN_EQm GREATEST_ASSERT_STRN_EQm |
|
| 1006 |
+#define ASSERT_MEM_EQm GREATEST_ASSERT_MEM_EQm |
|
| 1007 |
+#define ASSERT_ENUM_EQm GREATEST_ASSERT_ENUM_EQm |
|
| 1008 |
+#define PASS GREATEST_PASS |
|
| 1009 |
+#define FAIL GREATEST_FAIL |
|
| 1010 |
+#define SKIP GREATEST_SKIP |
|
| 1011 |
+#define PASSm GREATEST_PASSm |
|
| 1012 |
+#define FAILm GREATEST_FAILm |
|
| 1013 |
+#define SKIPm GREATEST_SKIPm |
|
| 1014 |
+#define SET_SETUP GREATEST_SET_SETUP_CB |
|
| 1015 |
+#define SET_TEARDOWN GREATEST_SET_TEARDOWN_CB |
|
| 1016 |
+#define CHECK_CALL GREATEST_CHECK_CALL |
|
| 1017 |
+ |
|
| 1018 |
+#ifdef GREATEST_VA_ARGS |
|
| 1019 |
+#define RUN_TESTp GREATEST_RUN_TESTp |
|
| 1020 |
+#endif |
|
| 1021 |
+ |
|
| 1022 |
+#if GREATEST_USE_LONGJMP |
|
| 1023 |
+#define ASSERT_OR_LONGJMP GREATEST_ASSERT_OR_LONGJMP |
|
| 1024 |
+#define ASSERT_OR_LONGJMPm GREATEST_ASSERT_OR_LONGJMPm |
|
| 1025 |
+#define FAIL_WITH_LONGJMP GREATEST_FAIL_WITH_LONGJMP |
|
| 1026 |
+#define FAIL_WITH_LONGJMPm GREATEST_FAIL_WITH_LONGJMPm |
|
| 1027 |
+#endif |
|
| 1028 |
+ |
|
| 1029 |
+#endif /* USE_ABBREVS */ |
|
| 1030 |
+ |
|
| 1031 |
+#ifdef __cplusplus |
|
| 1032 |
+} |
|
| 1033 |
+#endif |
|
| 1034 |
+ |
|
| 1035 |
+#endif |