Skip to content

Commit

Permalink
- Protect against people not defining UNITY_USE_COMMAND)LINES_ARGS bu…
Browse files Browse the repository at this point in the history
…t enabling cmd_lines in test runner generator. (Cherry-pick PR 739)

- Fix UNITY_NORETURN usage (Cherry-pick PR 742)
- Other standards and formatting tweaks.
  • Loading branch information
mvandervoord committed Aug 1, 2024
1 parent 18fb339 commit c546414
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 37 deletions.
2 changes: 2 additions & 0 deletions auto/generate_test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ def create_main(output, filename, tests, used_mocks)
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(' {')
Expand All @@ -424,6 +425,7 @@ def create_main(output, filename, tests, used_mocks)
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'
Expand Down
71 changes: 42 additions & 29 deletions src/unity_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/*-------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions test/tests/self_assessment_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -123,7 +123,7 @@ void endFlushSpy(void)
flushSpyEnabled = 0;
}

int getFlushSpyCalls(void)
UNITY_COUNTER_TYPE getFlushSpyCalls(void)
{
return flushSpyCalls;
}
Expand Down
7 changes: 4 additions & 3 deletions test/tests/test_unity_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down

0 comments on commit c546414

Please sign in to comment.