Repository navigation
Conversation
find_tests splits the scrubbed source into logical lines at every ;, {
and }. Braces inside string and character literals are already hidden
first, but braces in the argument list itself are not, so a compound
literal such as
TEST_CASE((uint8_t[]){0x1, 0x2}, 2)
void test_with_array(const uint8_t * data, unsigned len)
ends the logical line inside the TEST_CASE. The test is then found
without its arguments and the runner calls it as a plain void(void)
test, which modern GCC rejects with -Wincompatible-pointer-types.
Hide ;, {, } and / inside TEST_CASE/TEST_RANGE/TEST_MATRIX parentheses
the same way they are hidden inside literals, and restore them after
the split. Add a find_tests regression and a compound literal case to
test_unity_parameterized.c.
Fixes ThrowTheSwitch#752
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🍍
Problem
find_testssplits the scrubbed source into logical lines at every;,{and}. Braces inside string and character literals are hidden before the split, but braces in theTEST_CASEargument list itself are not. A compound literal therefore ends the logical line in the middle of theTEST_CASE:The test is found without its arguments, so the runner registers it as a plain
void (void)test:GCC 14 rejects that with
-Wincompatible-pointer-types. With a compiler that only warns, the test is called without its arguments.Fix
Hide
;,{,}and/inside the parentheses ofTEST_CASE/TEST_RANGE/TEST_MATRIXwith the same markers that are already used for literals, so they are restored after the split. The parenthesised list is matched with a recursive group, so nested parentheses such as(uint8_t[])are kept.The example above now generates
runner_args1_test_with_array()callingtest_with_array((uint8_t[]){0x1, 0x2, 0x3}, 3);.Fixes #752
Verification
FindTestsKeepsBracesInTestCaseArgumentsintest_generate_test_runner.rb: fails on master (argsisnil), passes with the change.test_CompoundLiteralArgsArePreservedintest_unity_parameterized.c: on master,rake test:unitstops with the incompatible-pointer-types error above (GCC 14.2); with the change both cases run and pass.rake test:scripts,test:unit,test:fixture,test:memory,test:summaryandtest:makepass on Linux (Ruby 3.3, GCC 14.2).test:stylewas not run because rubocop and astyle are not installed here.