diff options
Diffstat (limited to 'tap')
| -rw-r--r-- | tap/tap.c | 25 | ||||
| -rw-r--r-- | tap/tap.h | 43 |
2 files changed, 41 insertions, 27 deletions
| @@ -65,7 +65,8 @@ static void _cleanup(void); | |||
| 65 | * test_name -- the name of the test, may be NULL | 65 | * test_name -- the name of the test, may be NULL |
| 66 | * test_comment -- a comment to print afterwards, may be NULL | 66 | * test_comment -- a comment to print afterwards, may be NULL |
| 67 | */ | 67 | */ |
| 68 | unsigned int _gen_result(int ok, const char *func, char *file, unsigned int line, char *test_name, ...) { | 68 | unsigned int _gen_result(int ok, const char *func, char *file, unsigned int line, char *test_name, |
| 69 | ...) { | ||
| 69 | va_list ap; | 70 | va_list ap; |
| 70 | char *local_test_name = NULL; | 71 | char *local_test_name = NULL; |
| 71 | char *c; | 72 | char *c; |
| @@ -95,7 +96,9 @@ unsigned int _gen_result(int ok, const char *func, char *file, unsigned int line | |||
| 95 | } | 96 | } |
| 96 | 97 | ||
| 97 | if (name_is_digits) { | 98 | if (name_is_digits) { |
| 98 | diag(" You named your test '%s'. You shouldn't use numbers for your test names.", local_test_name); | 99 | diag( |
| 100 | " You named your test '%s'. You shouldn't use numbers for your test names.", | ||
| 101 | local_test_name); | ||
| 99 | diag(" Very confusing."); | 102 | diag(" Very confusing."); |
| 100 | } | 103 | } |
| 101 | } | 104 | } |
| @@ -116,8 +119,9 @@ unsigned int _gen_result(int ok, const char *func, char *file, unsigned int line | |||
| 116 | if (local_test_name != NULL) { | 119 | if (local_test_name != NULL) { |
| 117 | flockfile(stdout); | 120 | flockfile(stdout); |
| 118 | for (c = local_test_name; *c != '\0'; c++) { | 121 | for (c = local_test_name; *c != '\0'; c++) { |
| 119 | if (*c == '#') | 122 | if (*c == '#') { |
| 120 | fputc('\\', stdout); | 123 | fputc('\\', stdout); |
| 124 | } | ||
| 121 | fputc((int)*c, stdout); | 125 | fputc((int)*c, stdout); |
| 122 | } | 126 | } |
| 123 | funlockfile(stdout); | 127 | funlockfile(stdout); |
| @@ -135,14 +139,16 @@ unsigned int _gen_result(int ok, const char *func, char *file, unsigned int line | |||
| 135 | the test failed. */ | 139 | the test failed. */ |
| 136 | if (todo) { | 140 | if (todo) { |
| 137 | printf(" # TODO %s", todo_msg ? todo_msg : todo_msg_fixed); | 141 | printf(" # TODO %s", todo_msg ? todo_msg : todo_msg_fixed); |
| 138 | if (!ok) | 142 | if (!ok) { |
| 139 | failures--; | 143 | failures--; |
| 144 | } | ||
| 140 | } | 145 | } |
| 141 | 146 | ||
| 142 | printf("\n"); | 147 | printf("\n"); |
| 143 | 148 | ||
| 144 | if (!ok) | 149 | if (!ok) { |
| 145 | diag(" Failed %stest (%s:%s() at line %d)", todo ? "(TODO) " : "", file, func, line); | 150 | diag(" Failed %stest (%s:%s() at line %d)", todo ? "(TODO) " : "", file, func, line); |
| 151 | } | ||
| 146 | 152 | ||
| 147 | free(local_test_name); | 153 | free(local_test_name); |
| 148 | 154 | ||
| @@ -212,8 +218,9 @@ int plan_skip_all(char *reason) { | |||
| 212 | 218 | ||
| 213 | printf("1..0"); | 219 | printf("1..0"); |
| 214 | 220 | ||
| 215 | if (reason != NULL) | 221 | if (reason != NULL) { |
| 216 | printf(" # Skip %s", reason); | 222 | printf(" # Skip %s", reason); |
| 223 | } | ||
| 217 | 224 | ||
| 218 | printf("\n"); | 225 | printf("\n"); |
| 219 | 226 | ||
| @@ -294,7 +301,8 @@ int skip(unsigned int n, char *fmt, ...) { | |||
| 294 | 301 | ||
| 295 | while (n-- > 0) { | 302 | while (n-- > 0) { |
| 296 | test_count++; | 303 | test_count++; |
| 297 | printf("ok %d # skip %s\n", test_count, skip_msg != NULL ? skip_msg : "libtap():malloc() failed"); | 304 | printf("ok %d # skip %s\n", test_count, |
| 305 | skip_msg != NULL ? skip_msg : "libtap():malloc() failed"); | ||
| 298 | } | 306 | } |
| 299 | 307 | ||
| 300 | free(skip_msg); | 308 | free(skip_msg); |
| @@ -396,8 +404,9 @@ void _cleanup(void) { | |||
| 396 | return; | 404 | return; |
| 397 | } | 405 | } |
| 398 | 406 | ||
| 399 | if (failures) | 407 | if (failures) { |
| 400 | diag("Looks like you failed %d tests of %d.", failures, test_count); | 408 | diag("Looks like you failed %d tests of %d.", failures, test_count); |
| 409 | } | ||
| 401 | 410 | ||
| 402 | UNLOCK; | 411 | UNLOCK; |
| 403 | } | 412 | } |
| @@ -28,45 +28,50 @@ | |||
| 28 | and requires the caller to add the final comma if they've omitted | 28 | and requires the caller to add the final comma if they've omitted |
| 29 | the optional arguments */ | 29 | the optional arguments */ |
| 30 | #ifdef __GNUC__ | 30 | #ifdef __GNUC__ |
| 31 | # define ok(e, test, ...) \ | 31 | # define ok(e, test, ...) \ |
| 32 | ((e) ? _gen_result(1, __func__, __FILE__, __LINE__, test, ##__VA_ARGS__) \ | 32 | ((e) ? _gen_result(1, __func__, __FILE__, __LINE__, test, ##__VA_ARGS__) \ |
| 33 | : _gen_result(0, __func__, __FILE__, __LINE__, test, ##__VA_ARGS__)) | 33 | : _gen_result(0, __func__, __FILE__, __LINE__, test, ##__VA_ARGS__)) |
| 34 | 34 | ||
| 35 | # define ok1(e) ((e) ? _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) : _gen_result(0, __func__, __FILE__, __LINE__, "%s", #e)) | 35 | # define ok1(e) \ |
| 36 | ((e) ? _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) \ | ||
| 37 | : _gen_result(0, __func__, __FILE__, __LINE__, "%s", #e)) | ||
| 36 | 38 | ||
| 37 | # define pass(test, ...) ok(1, test, ##__VA_ARGS__); | 39 | # define pass(test, ...) ok(1, test, ##__VA_ARGS__); |
| 38 | # define fail(test, ...) ok(0, test, ##__VA_ARGS__); | 40 | # define fail(test, ...) ok(0, test, ##__VA_ARGS__); |
| 39 | 41 | ||
| 40 | # define skip_start(test, n, fmt, ...) \ | 42 | # define skip_start(test, n, fmt, ...) \ |
| 41 | do { \ | 43 | do { \ |
| 42 | if ((test)) { \ | 44 | if ((test)) { \ |
| 43 | skip(n, fmt, ##__VA_ARGS__); \ | 45 | skip(n, fmt, ##__VA_ARGS__); \ |
| 44 | continue; \ | 46 | continue; \ |
| 45 | } | 47 | } |
| 46 | #else /* __GNUC__ */ | 48 | #else /* __GNUC__ */ |
| 47 | /* The original tap.h used to test if __STDC_VERSION__ >= 199901L here. This | 49 | /* The original tap.h used to test if __STDC_VERSION__ >= 199901L here. This |
| 48 | * doesn't seem to work on HP-UX even though the code compile fine. I'm not | 50 | * doesn't seem to work on HP-UX even though the code compile fine. I'm not |
| 49 | * sure how to add an exception here for HP-UX so I just removed the check | 51 | * sure how to add an exception here for HP-UX so I just removed the check |
| 50 | * for now */ | 52 | * for now */ |
| 51 | # define ok(e, ...) \ | 53 | # define ok(e, ...) \ |
| 52 | ((e) ? _gen_result(1, __func__, __FILE__, __LINE__, __VA_ARGS__) : _gen_result(0, __func__, __FILE__, __LINE__, __VA_ARGS__)) | 54 | ((e) ? _gen_result(1, __func__, __FILE__, __LINE__, __VA_ARGS__) \ |
| 55 | : _gen_result(0, __func__, __FILE__, __LINE__, __VA_ARGS__)) | ||
| 53 | 56 | ||
| 54 | # define ok1(e) ((e) ? _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) : _gen_result(0, __func__, __FILE__, __LINE__, "%s", #e)) | 57 | # define ok1(e) \ |
| 58 | ((e) ? _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) \ | ||
| 59 | : _gen_result(0, __func__, __FILE__, __LINE__, "%s", #e)) | ||
| 55 | 60 | ||
| 56 | # define pass(...) ok(1, __VA_ARGS__); | 61 | # define pass(...) ok(1, __VA_ARGS__); |
| 57 | # define fail(...) ok(0, __VA_ARGS__); | 62 | # define fail(...) ok(0, __VA_ARGS__); |
| 58 | 63 | ||
| 59 | # define skip_start(test, n, ...) \ | 64 | # define skip_start(test, n, ...) \ |
| 60 | do { \ | 65 | do { \ |
| 61 | if ((test)) { \ | 66 | if ((test)) { \ |
| 62 | skip(n, __VA_ARGS__); \ | 67 | skip(n, __VA_ARGS__); \ |
| 63 | continue; \ | 68 | continue; \ |
| 64 | } | 69 | } |
| 65 | #endif /* __GNUC__ */ | 70 | #endif /* __GNUC__ */ |
| 66 | 71 | ||
| 67 | #define skip_end \ | 72 | #define skip_end \ |
| 68 | } \ | 73 | } \ |
| 69 | while (0) \ | 74 | while (0) \ |
| 70 | ; | 75 | ; |
| 71 | 76 | ||
| 72 | unsigned int _gen_result(int, const char *, char *, unsigned int, char *, ...); | 77 | unsigned int _gen_result(int, const char *, char *, unsigned int, char *, ...); |
