mirror of
https://github.com/ThrowTheSwitch/Unity
synced 2025-03-10 15:51:13 -04:00
- Protect against people not defining UNITY_USE_COMMAND)LINES_ARGS but enabling cmd_lines in test runner generator. (Cherry-pick PR 739)
- Fix UNITY_NORETURN usage (Cherry-pick PR 742) - Other standards and formatting tweaks.
This commit is contained in:
parent
18fb33921f
commit
c546414657
@ -402,6 +402,7 @@ class UnityTestRunnerGenerator
|
||||
end
|
||||
output.puts("#{@options[:main_export_decl]} int #{main_name}(int argc, char** argv)")
|
||||
output.puts('{')
|
||||
output.puts('#ifdef UNITY_USE_COMMAND_LINE_ARGS')
|
||||
output.puts(' int parse_status = UnityParseOptions(argc, argv);')
|
||||
output.puts(' if (parse_status != 0)')
|
||||
output.puts(' {')
|
||||
@ -424,6 +425,7 @@ class UnityTestRunnerGenerator
|
||||
output.puts(' }')
|
||||
output.puts(' return parse_status;')
|
||||
output.puts(' }')
|
||||
output.puts('#endif')
|
||||
else
|
||||
main_return = @options[:omit_begin_end] ? 'void' : 'int'
|
||||
if main_name != 'main'
|
||||
|
@ -47,38 +47,51 @@
|
||||
#define UNITY_FUNCTION_ATTR(a) /* ignore */
|
||||
#endif
|
||||
|
||||
#ifndef UNITY_NORETURN
|
||||
#if defined(__cplusplus)
|
||||
#if __cplusplus >= 201103L
|
||||
/* UNITY_NORETURN is only required if we have setjmp.h. */
|
||||
#ifndef UNITY_EXCLUDE_SETJMP_H
|
||||
#ifndef UNITY_NORETURN
|
||||
#if defined(__cplusplus)
|
||||
#if __cplusplus >= 201103L
|
||||
#define UNITY_NORETURN [[ noreturn ]]
|
||||
#endif
|
||||
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && __STDC_VERSION__ < 202311L
|
||||
/* _Noreturn keyword is used from C11 but deprecated in C23. */
|
||||
#if defined(_WIN32) && defined(_MSC_VER)
|
||||
/* We are using MSVC compiler on Windows platform. */
|
||||
/* Not all Windows SDKs supports <stdnoreturn.h>, but compiler can support C11: */
|
||||
/* https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriving-in-msvc/ */
|
||||
/* Not sure, that Mingw compilers has Windows SDK headers at all. */
|
||||
#include <sdkddkver.h>
|
||||
#endif
|
||||
|
||||
/* Using Windows SDK predefined macro for detecting supported SDK with MSVC compiler. */
|
||||
/* Mingw GCC should work without that fixes. */
|
||||
/* Based on: */
|
||||
/* https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?view=msvc-170 */
|
||||
/* NTDDI_WIN10_FE is equal to Windows 10 SDK 2104 */
|
||||
#if defined(_MSC_VER) && ((!defined(NTDDI_WIN10_FE)) || WDK_NTDDI_VERSION < NTDDI_WIN10_FE)
|
||||
/* Based on tests and: */
|
||||
/* https://docs.microsoft.com/en-us/cpp/c-language/noreturn?view=msvc-170 */
|
||||
/* https://en.cppreference.com/w/c/language/_Noreturn */
|
||||
#define UNITY_NORETURN _Noreturn
|
||||
#else /* Using newer Windows SDK or not MSVC compiler */
|
||||
#if defined(__GNUC__)
|
||||
/* The header <stdnoreturn.h> collides with __attribute(noreturn)__ from GCC. */
|
||||
#define UNITY_NORETURN _Noreturn
|
||||
#else
|
||||
#include <stdnoreturn.h>
|
||||
#define UNITY_NORETURN noreturn
|
||||
#endif
|
||||
#endif
|
||||
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
|
||||
/* Since C23, the keyword _Noreturn has been replaced by the attribute noreturn, based on: */
|
||||
/* https://en.cppreference.com/w/c/language/attributes/noreturn */
|
||||
#define UNITY_NORETURN [[ noreturn ]]
|
||||
#endif
|
||||
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
|
||||
#if defined(_WIN32) && defined(_MSC_VER)
|
||||
/* We are using MSVC compiler on Windows platform. */
|
||||
/* Not all Windows SDKs supports <stdnoreturn.h>, but compiler can support C11: */
|
||||
/* https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriving-in-msvc/ */
|
||||
/* Not sure, that Mingw compilers has Windows SDK headers at all. */
|
||||
#include <sdkddkver.h>
|
||||
#endif
|
||||
|
||||
/* Using Windows SDK predefined macro for detecting supported SDK with MSVC compiler. */
|
||||
/* Mingw GCC should work without that fixes. */
|
||||
/* Based on: */
|
||||
/* https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?view=msvc-170 */
|
||||
/* NTDDI_WIN10_FE is equal to Windows 10 SDK 2104 */
|
||||
#if defined(_MSC_VER) && ((!defined(NTDDI_WIN10_FE)) || WDK_NTDDI_VERSION < NTDDI_WIN10_FE)
|
||||
/* Based on tests and: */
|
||||
/* https://docs.microsoft.com/en-us/cpp/c-language/noreturn?view=msvc-170 */
|
||||
/* https://en.cppreference.com/w/c/language/_Noreturn */
|
||||
#define UNITY_NORETURN _Noreturn
|
||||
#else /* Using newer Windows SDK or not MSVC compiler */
|
||||
#include <stdnoreturn.h>
|
||||
#define UNITY_NORETURN noreturn
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#ifndef UNITY_NORETURN
|
||||
#define UNITY_NORETURN UNITY_FUNCTION_ATTR(__noreturn__)
|
||||
#ifndef UNITY_NORETURN
|
||||
#define UNITY_NORETURN UNITY_FUNCTION_ATTR(__noreturn__)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------
|
||||
|
@ -17,6 +17,7 @@ CFLAGS += -std=c99 -pedantic -Wall -Wextra -Werror
|
||||
#CFLAGS += -Wconversion #disabled because if falsely complains about the isinf and isnan macros
|
||||
CFLAGS += -Wno-switch-enum -Wno-double-promotion
|
||||
CFLAGS += -Wno-poison-system-directories
|
||||
CFLAGS += -Wno-covered-switch-default
|
||||
CFLAGS += -Wbad-function-cast -Wcast-qual -Wold-style-definition -Wshadow -Wstrict-overflow \
|
||||
-Wstrict-prototypes -Wswitch-default -Wundef
|
||||
#DEBUG = -O0 -g
|
||||
|
@ -69,8 +69,8 @@ static const UNITY_DOUBLE d_zero = 0.0;
|
||||
#define SPY_BUFFER_MAX 40
|
||||
static char putcharSpyBuffer[SPY_BUFFER_MAX];
|
||||
#endif
|
||||
static int indexSpyBuffer;
|
||||
static int putcharSpyEnabled;
|
||||
static UNITY_COUNTER_TYPE indexSpyBuffer;
|
||||
static UNITY_COUNTER_TYPE putcharSpyEnabled;
|
||||
|
||||
void startPutcharSpy(void)
|
||||
{
|
||||
@ -108,8 +108,8 @@ void putcharSpy(int c)
|
||||
}
|
||||
|
||||
/* This is for counting the calls to the flushSpy */
|
||||
static int flushSpyEnabled;
|
||||
static int flushSpyCalls = 0;
|
||||
static UNITY_COUNTER_TYPE flushSpyEnabled;
|
||||
static UNITY_COUNTER_TYPE flushSpyCalls = 0;
|
||||
|
||||
void startFlushSpy(void)
|
||||
{
|
||||
@ -123,7 +123,7 @@ void endFlushSpy(void)
|
||||
flushSpyEnabled = 0;
|
||||
}
|
||||
|
||||
int getFlushSpyCalls(void)
|
||||
UNITY_COUNTER_TYPE getFlushSpyCalls(void)
|
||||
{
|
||||
return flushSpyCalls;
|
||||
}
|
||||
|
@ -293,8 +293,9 @@ void testFailureCountIncrementsAndIsReturnedAtEnd(void)
|
||||
#ifndef USING_OUTPUT_SPY
|
||||
TEST_IGNORE();
|
||||
#else
|
||||
UNITY_UINT savedGetFlushSpyCalls = 0;
|
||||
UNITY_UINT savedFailures = Unity.TestFailures;
|
||||
int failures = 0;
|
||||
UNITY_COUNTER_TYPE savedGetFlushSpyCalls = 0;
|
||||
UNITY_COUNTER_TYPE savedFailures = Unity.TestFailures;
|
||||
Unity.CurrentTestFailed = 1;
|
||||
startPutcharSpy(); /* Suppress output */
|
||||
startFlushSpy();
|
||||
@ -311,7 +312,7 @@ void testFailureCountIncrementsAndIsReturnedAtEnd(void)
|
||||
endFlushSpy();
|
||||
|
||||
startPutcharSpy(); /* Suppress output */
|
||||
int failures = UnityEnd();
|
||||
failures = UnityEnd();
|
||||
Unity.TestFailures--;
|
||||
endPutcharSpy();
|
||||
TEST_ASSERT_EQUAL(savedFailures + 1, failures);
|
||||
|
Loading…
Reference in New Issue
Block a user