mirror of
https://github.com/moparisthebest/curl
synced 2025-01-10 21:48:10 -05:00
tests/unit: fix empty statements with no effect
... by making macros use "do {} while(0)"
This commit is contained in:
parent
8324dc8b1a
commit
b9746575a9
@ -22,29 +22,35 @@
|
|||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
/* The fail macros mark the current test step as failed, and continue */
|
/* The fail macros mark the current test step as failed, and continue */
|
||||||
#define fail_if(expr, msg) \
|
#define fail_if(expr, msg) \
|
||||||
if(expr) { \
|
do { \
|
||||||
fprintf(stderr, "%s:%d Assertion '%s' met: %s\n", \
|
if(expr) { \
|
||||||
__FILE__, __LINE__, #expr, msg); \
|
fprintf(stderr, "%s:%d Assertion '%s' met: %s\n", \
|
||||||
unitfail++; \
|
__FILE__, __LINE__, #expr, msg); \
|
||||||
}
|
unitfail++; \
|
||||||
|
} \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
#define fail_unless(expr, msg) \
|
#define fail_unless(expr, msg) \
|
||||||
if(!(expr)) { \
|
do { \
|
||||||
fprintf(stderr, "%s:%d Assertion '%s' failed: %s\n", \
|
if(!(expr)) { \
|
||||||
__FILE__, __LINE__, #expr, msg); \
|
fprintf(stderr, "%s:%d Assertion '%s' failed: %s\n", \
|
||||||
unitfail++; \
|
__FILE__, __LINE__, #expr, msg); \
|
||||||
}
|
unitfail++; \
|
||||||
|
} \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
#define verify_memory(dynamic, check, len) \
|
#define verify_memory(dynamic, check, len) \
|
||||||
if(dynamic && memcmp(dynamic, check, len)) { \
|
do { \
|
||||||
fprintf(stderr, "%s:%d Memory buffer mismatch size %d. '%s' is not\n", \
|
if(dynamic && memcmp(dynamic, check, len)) { \
|
||||||
__FILE__, __LINE__, len, \
|
fprintf(stderr, "%s:%d Memory buffer mismatch size %d. '%s' is not\n", \
|
||||||
hexdump((const unsigned char *)check, len)); \
|
__FILE__, __LINE__, len, \
|
||||||
fprintf(stderr, "%s:%d the same as '%s'\n", __FILE__, __LINE__, \
|
hexdump((const unsigned char *)check, len)); \
|
||||||
hexdump((const unsigned char *)dynamic, len)); \
|
fprintf(stderr, "%s:%d the same as '%s'\n", __FILE__, __LINE__, \
|
||||||
unitfail++; \
|
hexdump((const unsigned char *)dynamic, len)); \
|
||||||
}
|
unitfail++; \
|
||||||
|
} \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
/* fail() is for when the test case figured out by itself that a check
|
/* fail() is for when the test case figured out by itself that a check
|
||||||
proved a failure */
|
proved a failure */
|
||||||
@ -56,23 +62,28 @@
|
|||||||
|
|
||||||
|
|
||||||
/* The abort macros mark the current test step as failed, and exit the test */
|
/* The abort macros mark the current test step as failed, and exit the test */
|
||||||
#define abort_if(expr, msg) \
|
#define abort_if(expr, msg) \
|
||||||
if(expr) { \
|
do { \
|
||||||
fprintf(stderr, "%s:%d Abort assertion '%s' met: %s\n", \
|
if(expr) { \
|
||||||
__FILE__, __LINE__, #expr, msg); \
|
fprintf(stderr, "%s:%d Abort assertion '%s' met: %s\n", \
|
||||||
unitfail++; \
|
__FILE__, __LINE__, #expr, msg); \
|
||||||
goto unit_test_abort; \
|
unitfail++; \
|
||||||
}
|
goto unit_test_abort; \
|
||||||
|
} \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
#define abort_unless(expr, msg) \
|
#define abort_unless(expr, msg) \
|
||||||
if(!(expr)) { \
|
do { \
|
||||||
fprintf(stderr, "%s:%d Abort assertion '%s' failed: %s\n", \
|
if(!(expr)) { \
|
||||||
__FILE__, __LINE__, #expr, msg); \
|
fprintf(stderr, "%s:%d Abort assertion '%s' failed: %s\n", \
|
||||||
unitfail++; \
|
__FILE__, __LINE__, #expr, msg); \
|
||||||
goto unit_test_abort; \
|
unitfail++; \
|
||||||
}
|
goto unit_test_abort; \
|
||||||
|
} \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
#define abort_test(msg) do { \
|
#define abort_test(msg) \
|
||||||
|
do { \
|
||||||
fprintf(stderr, "%s:%d test aborted: '%s'\n", \
|
fprintf(stderr, "%s:%d test aborted: '%s'\n", \
|
||||||
__FILE__, __LINE__, msg); \
|
__FILE__, __LINE__, msg); \
|
||||||
unitfail++; \
|
unitfail++; \
|
||||||
@ -80,7 +91,6 @@
|
|||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern int unitfail;
|
extern int unitfail;
|
||||||
|
|
||||||
#define UNITTEST_START \
|
#define UNITTEST_START \
|
||||||
|
Loading…
Reference in New Issue
Block a user