Skip to content

Commit b32ca22

Browse files
committed
Fix command-line argument test builds
1 parent 29f1319 commit b32ca22

4 files changed

Lines changed: 18 additions & 5 deletions

File tree

src/unity.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,7 +2404,7 @@ void UnityPopDetail(UNITY_DETAIL_LABEL_TYPE label, UNITY_DETAIL_VALUE_TYPE value
24042404
*-----------------------------------------------*/
24052405
#ifdef UNITY_USE_COMMAND_LINE_ARGS
24062406

2407-
char* UnityOptionIncludeNamed = NULL;
2407+
const char* UnityOptionIncludeNamed = NULL;
24082408
char* UnityOptionExcludeNamed = NULL;
24092409
int UnityVerbosity = 1;
24102410
int UnityStrictMatch = 0;
@@ -2426,7 +2426,7 @@ extern char* getenv(const char* name);
24262426
testbridge_filter = UNITY_GETENV("TESTBRIDGE_TEST_ONLY");
24272427
if (testbridge_filter && testbridge_filter[0] != 0)
24282428
{
2429-
UnityOptionIncludeNamed = (char*)testbridge_filter;
2429+
UnityOptionIncludeNamed = testbridge_filter;
24302430
}
24312431

24322432
for (i = 1; i < argc; i++)

test/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ CFLAGS += -Wbad-function-cast -Wcast-qual -Wold-style-definition -Wshadow -Wstri
2222
CFLAGS += $(DEBUG)
2323
UNITY_SUPPORT_64 = -D UNITY_SUPPORT_64
2424
UNITY_INCLUDE_DOUBLE = -D UNITY_INCLUDE_DOUBLE
25+
UNITY_USE_COMMAND_LINE_ARGS = -D UNITY_USE_COMMAND_LINE_ARGS
2526
DEFINES = -D UNITY_OUTPUT_CHAR=putcharSpy
2627
DEFINES += -D UNITY_OUTPUT_CHAR_HEADER_DECLARATION=putcharSpy\(int\)
2728
DEFINES += -D UNITY_OUTPUT_FLUSH=flushSpy
@@ -53,7 +54,7 @@ coverage: $(SRC1) $(SRC2) $(SRC3) $(SRC4) $(SRC5) $(SRC6) $(SRC7) $(SRC8)
5354
gcov unity.c | head -3
5455
grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true
5556
cd $(BUILD_DIR) && \
56-
$(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC2), ../$i) $(COV_FLAGS) -o ../$(TARGET)
57+
$(CC) $(CFLAGS) $(DEFINES) $(UNITY_USE_COMMAND_LINE_ARGS) $(foreach i,$(SRC2), ../$i) $(COV_FLAGS) -o ../$(TARGET)
5758
rm -f $(BUILD_DIR)/*.gcda
5859
./$(TARGET) | grep 'Tests\|]]]' -A1
5960
cd $(BUILD_DIR) && \
@@ -105,7 +106,7 @@ coverage: $(SRC1) $(SRC2) $(SRC3) $(SRC4) $(SRC5) $(SRC6) $(SRC7) $(SRC8)
105106
test: $(SRC1) $(SRC2) $(SRC3) $(SRC4) $(SRC5) $(SRC6) $(SRC7) $(SRC8)
106107
$(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC1) -o $(TARGET)
107108
./$(TARGET)
108-
$(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC2) -o $(TARGET)
109+
$(CC) $(CFLAGS) $(DEFINES) $(UNITY_USE_COMMAND_LINE_ARGS) $(INC_DIR) $(SRC2) -o $(TARGET)
109110
./$(TARGET)
110111
$(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC3) -o $(TARGET)
111112
./$(TARGET)

test/rakefile_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def run_tests(test_files)
310310

311311
report "\nRunning Tests in #{test}"
312312
obj_list = []
313-
test_defines = []
313+
test_defines = File.basename(test) == 'test_unity_core.c' ? ['UNITY_USE_COMMAND_LINE_ARGS'] : []
314314

315315
# Detect dependencies and build required modules
316316
extract_headers(test).each do |header|

test/tests/test_unity_core.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
SPDX-License-Identifier: MIT
66
========================================================================= */
77

8+
#if defined(UNITY_USE_COMMAND_LINE_ARGS) && !defined(_WIN32) && !defined(_MSC_VER) && !defined(_POSIX_C_SOURCE)
9+
#define _POSIX_C_SOURCE 200112L
10+
#endif
11+
812
#include "unity.h"
913
#ifdef UNITY_USE_COMMAND_LINE_ARGS
1014
#include "unity_internals.h"
@@ -226,6 +230,8 @@ static void UnitySetTestContext(const char* testfile, const char* testname)
226230
void testUnityParseOptionsUsesTestbridgeFilter(void)
227231
{
228232
char* argv[] = { (char*)"prog", NULL };
233+
const char* testfile = Unity.TestFile;
234+
const char* testname = Unity.CurrentTestName;
229235

230236
UnitySetTestbridgeFilter("test_my_function");
231237
UnityParseOptions(1, argv);
@@ -236,11 +242,15 @@ void testUnityParseOptionsUsesTestbridgeFilter(void)
236242
TEST_ASSERT_FALSE(UnityTestMatches());
237243

238244
UnitySetTestbridgeFilter(NULL);
245+
UnityParseOptions(1, argv);
246+
UnitySetTestContext(testfile, testname);
239247
}
240248

241249
void testUnityParseOptionsArgsOverrideTestbridgeFilter(void)
242250
{
243251
char* argv[] = { (char*)"prog", (char*)"-n", (char*)"other", NULL };
252+
const char* testfile = Unity.TestFile;
253+
const char* testname = Unity.CurrentTestName;
244254

245255
UnitySetTestbridgeFilter("test_my_function");
246256
UnityParseOptions(3, argv);
@@ -251,6 +261,8 @@ void testUnityParseOptionsArgsOverrideTestbridgeFilter(void)
251261
TEST_ASSERT_FALSE(UnityTestMatches());
252262

253263
UnitySetTestbridgeFilter(NULL);
264+
UnityParseOptions(1, argv);
265+
UnitySetTestContext(testfile, testname);
254266
}
255267
#endif
256268

0 commit comments

Comments
 (0)