Skip to content

Commit c546414

Browse files
committed
- 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.
1 parent 18fb339 commit c546414

File tree

5 files changed

+54
-37
lines changed

5 files changed

+54
-37
lines changed

auto/generate_test_runner.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ def create_main(output, filename, tests, used_mocks)
402402
end
403403
output.puts("#{@options[:main_export_decl]} int #{main_name}(int argc, char** argv)")
404404
output.puts('{')
405+
output.puts('#ifdef UNITY_USE_COMMAND_LINE_ARGS')
405406
output.puts(' int parse_status = UnityParseOptions(argc, argv);')
406407
output.puts(' if (parse_status != 0)')
407408
output.puts(' {')
@@ -424,6 +425,7 @@ def create_main(output, filename, tests, used_mocks)
424425
output.puts(' }')
425426
output.puts(' return parse_status;')
426427
output.puts(' }')
428+
output.puts('#endif')
427429
else
428430
main_return = @options[:omit_begin_end] ? 'void' : 'int'
429431
if main_name != 'main'

src/unity_internals.h

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,38 +47,51 @@
4747
#define UNITY_FUNCTION_ATTR(a) /* ignore */
4848
#endif
4949

50-
#ifndef UNITY_NORETURN
51-
#if defined(__cplusplus)
52-
#if __cplusplus >= 201103L
50+
/* UNITY_NORETURN is only required if we have setjmp.h. */
51+
#ifndef UNITY_EXCLUDE_SETJMP_H
52+
#ifndef UNITY_NORETURN
53+
#if defined(__cplusplus)
54+
#if __cplusplus >= 201103L
55+
#define UNITY_NORETURN [[ noreturn ]]
56+
#endif
57+
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && __STDC_VERSION__ < 202311L
58+
/* _Noreturn keyword is used from C11 but deprecated in C23. */
59+
#if defined(_WIN32) && defined(_MSC_VER)
60+
/* We are using MSVC compiler on Windows platform. */
61+
/* Not all Windows SDKs supports <stdnoreturn.h>, but compiler can support C11: */
62+
/* https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriving-in-msvc/ */
63+
/* Not sure, that Mingw compilers has Windows SDK headers at all. */
64+
#include <sdkddkver.h>
65+
#endif
66+
67+
/* Using Windows SDK predefined macro for detecting supported SDK with MSVC compiler. */
68+
/* Mingw GCC should work without that fixes. */
69+
/* Based on: */
70+
/* https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?view=msvc-170 */
71+
/* NTDDI_WIN10_FE is equal to Windows 10 SDK 2104 */
72+
#if defined(_MSC_VER) && ((!defined(NTDDI_WIN10_FE)) || WDK_NTDDI_VERSION < NTDDI_WIN10_FE)
73+
/* Based on tests and: */
74+
/* https://docs.microsoft.com/en-us/cpp/c-language/noreturn?view=msvc-170 */
75+
/* https://en.cppreference.com/w/c/language/_Noreturn */
76+
#define UNITY_NORETURN _Noreturn
77+
#else /* Using newer Windows SDK or not MSVC compiler */
78+
#if defined(__GNUC__)
79+
/* The header <stdnoreturn.h> collides with __attribute(noreturn)__ from GCC. */
80+
#define UNITY_NORETURN _Noreturn
81+
#else
82+
#include <stdnoreturn.h>
83+
#define UNITY_NORETURN noreturn
84+
#endif
85+
#endif
86+
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
87+
/* Since C23, the keyword _Noreturn has been replaced by the attribute noreturn, based on: */
88+
/* https://en.cppreference.com/w/c/language/attributes/noreturn */
5389
#define UNITY_NORETURN [[ noreturn ]]
5490
#endif
55-
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
56-
#if defined(_WIN32) && defined(_MSC_VER)
57-
/* We are using MSVC compiler on Windows platform. */
58-
/* Not all Windows SDKs supports <stdnoreturn.h>, but compiler can support C11: */
59-
/* https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriving-in-msvc/ */
60-
/* Not sure, that Mingw compilers has Windows SDK headers at all. */
61-
#include <sdkddkver.h>
62-
#endif
63-
64-
/* Using Windows SDK predefined macro for detecting supported SDK with MSVC compiler. */
65-
/* Mingw GCC should work without that fixes. */
66-
/* Based on: */
67-
/* https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?view=msvc-170 */
68-
/* NTDDI_WIN10_FE is equal to Windows 10 SDK 2104 */
69-
#if defined(_MSC_VER) && ((!defined(NTDDI_WIN10_FE)) || WDK_NTDDI_VERSION < NTDDI_WIN10_FE)
70-
/* Based on tests and: */
71-
/* https://docs.microsoft.com/en-us/cpp/c-language/noreturn?view=msvc-170 */
72-
/* https://en.cppreference.com/w/c/language/_Noreturn */
73-
#define UNITY_NORETURN _Noreturn
74-
#else /* Using newer Windows SDK or not MSVC compiler */
75-
#include <stdnoreturn.h>
76-
#define UNITY_NORETURN noreturn
77-
#endif
7891
#endif
79-
#endif
80-
#ifndef UNITY_NORETURN
81-
#define UNITY_NORETURN UNITY_FUNCTION_ATTR(__noreturn__)
92+
#ifndef UNITY_NORETURN
93+
#define UNITY_NORETURN UNITY_FUNCTION_ATTR(__noreturn__)
94+
#endif
8295
#endif
8396

8497
/*-------------------------------------------------------

test/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ CFLAGS += -std=c99 -pedantic -Wall -Wextra -Werror
1717
#CFLAGS += -Wconversion #disabled because if falsely complains about the isinf and isnan macros
1818
CFLAGS += -Wno-switch-enum -Wno-double-promotion
1919
CFLAGS += -Wno-poison-system-directories
20+
CFLAGS += -Wno-covered-switch-default
2021
CFLAGS += -Wbad-function-cast -Wcast-qual -Wold-style-definition -Wshadow -Wstrict-overflow \
2122
-Wstrict-prototypes -Wswitch-default -Wundef
2223
#DEBUG = -O0 -g

test/tests/self_assessment_utils.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ static const UNITY_DOUBLE d_zero = 0.0;
6969
#define SPY_BUFFER_MAX 40
7070
static char putcharSpyBuffer[SPY_BUFFER_MAX];
7171
#endif
72-
static int indexSpyBuffer;
73-
static int putcharSpyEnabled;
72+
static UNITY_COUNTER_TYPE indexSpyBuffer;
73+
static UNITY_COUNTER_TYPE putcharSpyEnabled;
7474

7575
void startPutcharSpy(void)
7676
{
@@ -108,8 +108,8 @@ void putcharSpy(int c)
108108
}
109109

110110
/* This is for counting the calls to the flushSpy */
111-
static int flushSpyEnabled;
112-
static int flushSpyCalls = 0;
111+
static UNITY_COUNTER_TYPE flushSpyEnabled;
112+
static UNITY_COUNTER_TYPE flushSpyCalls = 0;
113113

114114
void startFlushSpy(void)
115115
{
@@ -123,7 +123,7 @@ void endFlushSpy(void)
123123
flushSpyEnabled = 0;
124124
}
125125

126-
int getFlushSpyCalls(void)
126+
UNITY_COUNTER_TYPE getFlushSpyCalls(void)
127127
{
128128
return flushSpyCalls;
129129
}

test/tests/test_unity_core.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,9 @@ void testFailureCountIncrementsAndIsReturnedAtEnd(void)
293293
#ifndef USING_OUTPUT_SPY
294294
TEST_IGNORE();
295295
#else
296-
UNITY_UINT savedGetFlushSpyCalls = 0;
297-
UNITY_UINT savedFailures = Unity.TestFailures;
296+
int failures = 0;
297+
UNITY_COUNTER_TYPE savedGetFlushSpyCalls = 0;
298+
UNITY_COUNTER_TYPE savedFailures = Unity.TestFailures;
298299
Unity.CurrentTestFailed = 1;
299300
startPutcharSpy(); /* Suppress output */
300301
startFlushSpy();
@@ -311,7 +312,7 @@ void testFailureCountIncrementsAndIsReturnedAtEnd(void)
311312
endFlushSpy();
312313

313314
startPutcharSpy(); /* Suppress output */
314-
int failures = UnityEnd();
315+
failures = UnityEnd();
315316
Unity.TestFailures--;
316317
endPutcharSpy();
317318
TEST_ASSERT_EQUAL(savedFailures + 1, failures);

0 commit comments

Comments
 (0)