diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index 2589311c..f3b1699d 100755 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -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 diff --git a/docs/UnityChangeLog.md b/docs/UnityChangeLog.md index 6e73e27c..e67ae8ee 100644 --- a/docs/UnityChangeLog.md +++ b/docs/UnityChangeLog.md @@ -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) diff --git a/test/tests/test_generate_test_runner.rb b/test/tests/test_generate_test_runner.rb index 3d05020d..f9ade793 100644 --- a/test/tests/test_generate_test_runner.rb +++ b/test/tests/test_generate_test_runner.rb @@ -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]}" diff --git a/test/tests/test_unity_parameterized.c b/test/tests/test_unity_parameterized.c index 2faf1520..4c36f7ce 100644 --- a/test/tests/test_unity_parameterized.c +++ b/test/tests/test_unity_parameterized.c @@ -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) {