Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions auto/generate_test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def find_tests(source)
source_scrubbed = source_scrubbed.gsub(/\/\/(?:.+\/\*|\*(?:$|[^\/])).*$/, '') # remove line comments that comment out the start of blocks
source_scrubbed = source_scrubbed.gsub(/\/\*.*?\*\//m, '') # remove block comments
source_scrubbed = source_scrubbed.gsub(/\/\/.*$/, '') # remove line comments (all that remain)
source_scrubbed = source_scrubbed.gsub(/TEST_(?:CASE|RANGE|MATRIX)\s*(\((?:[^()]|\g<1>)*\))/) { |s| s.gsub(substring_re, substring_subs) } # hide braces of compound literals in parameter lists
lines = source_scrubbed.split(/(^\s*\#.*$) | (;|\{|\}) /x) # Treat preprocessor directives as a logical line. Match ;, {, and } as end of lines
.map { |line| line.gsub(substring_unre, substring_unsubs) } # unhide the problematic characters previously removed

Expand Down
1 change: 1 addition & 0 deletions docs/UnityChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Significant Bugfixes:

- Default `UNITY_INCLUDE_EXEC_TIME` macros compile as ISO C99, are statement-safe, and accept `-Wsign-conversion` (#838)
- `unity_test_summary.rb` honors its own default result directory and root path again. @youdie006
- Test runner generator keeps `TEST_CASE` arguments that contain braces, such as compound literals (#752)

### Unity 2.7.0 (July 2026)

Expand Down
20 changes: 20 additions & 0 deletions test/tests/test_generate_test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,26 @@ def verify_number(expected, expression, output)
$generate_test_runner_tests += 1
end

should 'FindTestsKeepsBracesInTestCaseArguments' do
# Issue #752: a compound literal such as (uint8_t[]){1, 2} contains braces,
# which must not end the logical line before the test function is found.
source = "TEST_CASE((uint8_t[]){0x1, 0x2, 0x3}, 3)\n" \
"TEST_CASE((uint8_t[]){0x4}, 1)\n" \
"void test_WithArray(const uint8_t * data, unsigned len)\n" \
"{\n" \
"}\n"
found = UnityTestRunnerGenerator.new(use_param_tests: true).find_tests(source).map { |t| [t[:test], t[:args]] }
expected = [['test_WithArray', ['(uint8_t[]){0x1, 0x2, 0x3}, 3', '(uint8_t[]){0x4}, 1']]]
if found == expected
report 'Runner_FindTestsKeepsBracesInTestCaseArguments:PASS'
else
report " FAIL: expected #{expected.inspect}, got #{found.inspect}"
report 'Runner_FindTestsKeepsBracesInTestCaseArguments:FAIL'
$generate_test_runner_failures += 1
end
$generate_test_runner_tests += 1
end

RUNNER_TESTS.each do |testset|
basename = File.basename(testset[:testfile], C_EXTENSION)
testset_name = "Runner_#{basename}_#{testset[:name]}"
Expand Down
15 changes: 15 additions & 0 deletions test/tests/test_unity_parameterized.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,21 @@ void test_CharsArePreserved(unsigned index, char c)
NextExpectedCharIndex++;
}

TEST_CASE((const int[]){1, 2, 3}, 3, 6)
TEST_CASE((const int[]){4}, 1, 4)
void test_CompoundLiteralArgsArePreserved(const int * values, unsigned count, int sum)
{
int total = 0;
unsigned i;

for (i = 0; i < count; i++)
{
total += values[i];
}

TEST_ASSERT_EQUAL_INT(sum, total);
}

TEST_RANGE([0, 10, 2])
void test_SingleRange(unsigned value)
{
Expand Down