1
0
mirror of https://github.com/moparisthebest/curl synced 2024-08-13 17:03:50 -04:00
curl/tests/unit/curlcheck.h
Jay Satiro 9c1806ae46 build: Disable Visual Studio warning "conditional expression is constant"
- Disable warning C4127 "conditional expression is constant" globally
  in curl_setup.h for when building with Microsoft's compiler.

This mainly affects building with the Visual Studio project files found
in the projects dir.

Prior to this change the cmake and winbuild build systems already
disabled 4127 globally for when building with Microsoft's compiler.
Also, 4127 was already disabled for all build systems in the limited
circumstance of the WHILE_FALSE macro which disabled the warning
specifically for while(0). This commit removes the WHILE_FALSE macro and
all other cruft in favor of disabling globally in curl_setup.

Background:

We have various macros that cause 0 or 1 to be evaluated, which would
cause warning C4127 in Visual Studio. For example this causes it:

    #define Curl_resolver_asynch() 1

Full behavior is not clearly defined and inconsistent across versions.
However it is documented that since VS 2015 Update 3 Microsoft has
addressed this somewhat but not entirely, not warning on while(true) for
example.

Prior to this change some C4127 warnings occurred when I built with
Visual Studio using the generated projects in the projects dir.

Closes https://github.com/curl/curl/pull/4658
2019-12-01 19:01:02 -05:00

102 lines
4.5 KiB
C

/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "test.h"
/* The fail macros mark the current test step as failed, and continue */
#define fail_if(expr, msg) \
if(expr) { \
fprintf(stderr, "%s:%d Assertion '%s' met: %s\n", \
__FILE__, __LINE__, #expr, msg); \
unitfail++; \
}
#define fail_unless(expr, msg) \
if(!(expr)) { \
fprintf(stderr, "%s:%d Assertion '%s' failed: %s\n", \
__FILE__, __LINE__, #expr, msg); \
unitfail++; \
}
#define verify_memory(dynamic, check, len) \
if(dynamic && memcmp(dynamic, check, len)) { \
fprintf(stderr, "%s:%d Memory buffer mismatch size %d. '%s' is not\n", \
__FILE__, __LINE__, len, \
hexdump((const unsigned char *)check, len)); \
fprintf(stderr, "%s:%d the same as '%s'\n", __FILE__, __LINE__, \
hexdump((const unsigned char *)dynamic, len)); \
unitfail++; \
}
/* fail() is for when the test case figured out by itself that a check
proved a failure */
#define fail(msg) do { \
fprintf(stderr, "%s:%d test failed: '%s'\n", \
__FILE__, __LINE__, msg); \
unitfail++; \
} while(0)
/* The abort macros mark the current test step as failed, and exit the test */
#define abort_if(expr, msg) \
if(expr) { \
fprintf(stderr, "%s:%d Abort assertion '%s' met: %s\n", \
__FILE__, __LINE__, #expr, msg); \
unitfail++; \
goto unit_test_abort; \
}
#define abort_unless(expr, msg) \
if(!(expr)) { \
fprintf(stderr, "%s:%d Abort assertion '%s' failed: %s\n", \
__FILE__, __LINE__, #expr, msg); \
unitfail++; \
goto unit_test_abort; \
}
#define abort_test(msg) do { \
fprintf(stderr, "%s:%d test aborted: '%s'\n", \
__FILE__, __LINE__, msg); \
unitfail++; \
goto unit_test_abort; \
} while(0)
extern int unitfail;
#define UNITTEST_START \
int test(char *arg) \
{ \
(void)arg; \
if(unit_setup()) { \
fail("unit_setup() failure"); \
} \
else {
#define UNITTEST_STOP \
goto unit_test_abort; /* avoid warning */ \
unit_test_abort: \
unit_stop(); \
} \
return unitfail; \
}