mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-01-23 00:15:58 +01: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:
@@ -402,6 +402,7 @@ class UnityTestRunnerGenerator
|
|||||||
end
|
end
|
||||||
output.puts("#{@options[:main_export_decl]} int #{main_name}(int argc, char** argv)")
|
output.puts("#{@options[:main_export_decl]} int #{main_name}(int argc, char** argv)")
|
||||||
output.puts('{')
|
output.puts('{')
|
||||||
|
output.puts('#ifdef UNITY_USE_COMMAND_LINE_ARGS')
|
||||||
output.puts(' int parse_status = UnityParseOptions(argc, argv);')
|
output.puts(' int parse_status = UnityParseOptions(argc, argv);')
|
||||||
output.puts(' if (parse_status != 0)')
|
output.puts(' if (parse_status != 0)')
|
||||||
output.puts(' {')
|
output.puts(' {')
|
||||||
@@ -424,6 +425,7 @@ class UnityTestRunnerGenerator
|
|||||||
output.puts(' }')
|
output.puts(' }')
|
||||||
output.puts(' return parse_status;')
|
output.puts(' return parse_status;')
|
||||||
output.puts(' }')
|
output.puts(' }')
|
||||||
|
output.puts('#endif')
|
||||||
else
|
else
|
||||||
main_return = @options[:omit_begin_end] ? 'void' : 'int'
|
main_return = @options[:omit_begin_end] ? 'void' : 'int'
|
||||||
if main_name != 'main'
|
if main_name != 'main'
|
||||||
|
|||||||
@@ -47,12 +47,15 @@
|
|||||||
#define UNITY_FUNCTION_ATTR(a) /* ignore */
|
#define UNITY_FUNCTION_ATTR(a) /* ignore */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef UNITY_NORETURN
|
/* UNITY_NORETURN is only required if we have setjmp.h. */
|
||||||
|
#ifndef UNITY_EXCLUDE_SETJMP_H
|
||||||
|
#ifndef UNITY_NORETURN
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
#if __cplusplus >= 201103L
|
#if __cplusplus >= 201103L
|
||||||
#define UNITY_NORETURN [[ noreturn ]]
|
#define UNITY_NORETURN [[ noreturn ]]
|
||||||
#endif
|
#endif
|
||||||
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
|
#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)
|
#if defined(_WIN32) && defined(_MSC_VER)
|
||||||
/* We are using MSVC compiler on Windows platform. */
|
/* We are using MSVC compiler on Windows platform. */
|
||||||
/* Not all Windows SDKs supports <stdnoreturn.h>, but compiler can support C11: */
|
/* Not all Windows SDKs supports <stdnoreturn.h>, but compiler can support C11: */
|
||||||
@@ -72,13 +75,23 @@
|
|||||||
/* https://en.cppreference.com/w/c/language/_Noreturn */
|
/* https://en.cppreference.com/w/c/language/_Noreturn */
|
||||||
#define UNITY_NORETURN _Noreturn
|
#define UNITY_NORETURN _Noreturn
|
||||||
#else /* Using newer Windows SDK or not MSVC compiler */
|
#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>
|
#include <stdnoreturn.h>
|
||||||
#define UNITY_NORETURN noreturn
|
#define UNITY_NORETURN noreturn
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
|
||||||
#ifndef UNITY_NORETURN
|
/* 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
|
||||||
|
#endif
|
||||||
|
#ifndef UNITY_NORETURN
|
||||||
#define UNITY_NORETURN UNITY_FUNCTION_ATTR(__noreturn__)
|
#define UNITY_NORETURN UNITY_FUNCTION_ATTR(__noreturn__)
|
||||||
|
#endif
|
||||||
#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 += -Wconversion #disabled because if falsely complains about the isinf and isnan macros
|
||||||
CFLAGS += -Wno-switch-enum -Wno-double-promotion
|
CFLAGS += -Wno-switch-enum -Wno-double-promotion
|
||||||
CFLAGS += -Wno-poison-system-directories
|
CFLAGS += -Wno-poison-system-directories
|
||||||
|
CFLAGS += -Wno-covered-switch-default
|
||||||
CFLAGS += -Wbad-function-cast -Wcast-qual -Wold-style-definition -Wshadow -Wstrict-overflow \
|
CFLAGS += -Wbad-function-cast -Wcast-qual -Wold-style-definition -Wshadow -Wstrict-overflow \
|
||||||
-Wstrict-prototypes -Wswitch-default -Wundef
|
-Wstrict-prototypes -Wswitch-default -Wundef
|
||||||
#DEBUG = -O0 -g
|
#DEBUG = -O0 -g
|
||||||
|
|||||||
@@ -69,8 +69,8 @@ static const UNITY_DOUBLE d_zero = 0.0;
|
|||||||
#define SPY_BUFFER_MAX 40
|
#define SPY_BUFFER_MAX 40
|
||||||
static char putcharSpyBuffer[SPY_BUFFER_MAX];
|
static char putcharSpyBuffer[SPY_BUFFER_MAX];
|
||||||
#endif
|
#endif
|
||||||
static int indexSpyBuffer;
|
static UNITY_COUNTER_TYPE indexSpyBuffer;
|
||||||
static int putcharSpyEnabled;
|
static UNITY_COUNTER_TYPE putcharSpyEnabled;
|
||||||
|
|
||||||
void startPutcharSpy(void)
|
void startPutcharSpy(void)
|
||||||
{
|
{
|
||||||
@@ -108,8 +108,8 @@ void putcharSpy(int c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* This is for counting the calls to the flushSpy */
|
/* This is for counting the calls to the flushSpy */
|
||||||
static int flushSpyEnabled;
|
static UNITY_COUNTER_TYPE flushSpyEnabled;
|
||||||
static int flushSpyCalls = 0;
|
static UNITY_COUNTER_TYPE flushSpyCalls = 0;
|
||||||
|
|
||||||
void startFlushSpy(void)
|
void startFlushSpy(void)
|
||||||
{
|
{
|
||||||
@@ -123,7 +123,7 @@ void endFlushSpy(void)
|
|||||||
flushSpyEnabled = 0;
|
flushSpyEnabled = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getFlushSpyCalls(void)
|
UNITY_COUNTER_TYPE getFlushSpyCalls(void)
|
||||||
{
|
{
|
||||||
return flushSpyCalls;
|
return flushSpyCalls;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -293,8 +293,9 @@ void testFailureCountIncrementsAndIsReturnedAtEnd(void)
|
|||||||
#ifndef USING_OUTPUT_SPY
|
#ifndef USING_OUTPUT_SPY
|
||||||
TEST_IGNORE();
|
TEST_IGNORE();
|
||||||
#else
|
#else
|
||||||
UNITY_UINT savedGetFlushSpyCalls = 0;
|
int failures = 0;
|
||||||
UNITY_UINT savedFailures = Unity.TestFailures;
|
UNITY_COUNTER_TYPE savedGetFlushSpyCalls = 0;
|
||||||
|
UNITY_COUNTER_TYPE savedFailures = Unity.TestFailures;
|
||||||
Unity.CurrentTestFailed = 1;
|
Unity.CurrentTestFailed = 1;
|
||||||
startPutcharSpy(); /* Suppress output */
|
startPutcharSpy(); /* Suppress output */
|
||||||
startFlushSpy();
|
startFlushSpy();
|
||||||
@@ -311,7 +312,7 @@ void testFailureCountIncrementsAndIsReturnedAtEnd(void)
|
|||||||
endFlushSpy();
|
endFlushSpy();
|
||||||
|
|
||||||
startPutcharSpy(); /* Suppress output */
|
startPutcharSpy(); /* Suppress output */
|
||||||
int failures = UnityEnd();
|
failures = UnityEnd();
|
||||||
Unity.TestFailures--;
|
Unity.TestFailures--;
|
||||||
endPutcharSpy();
|
endPutcharSpy();
|
||||||
TEST_ASSERT_EQUAL(savedFailures + 1, failures);
|
TEST_ASSERT_EQUAL(savedFailures + 1, failures);
|
||||||
|
|||||||
Reference in New Issue
Block a user