mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-11-04 22:42:48 +00:00
Merge pull request #853 from r3wretrhy/fix/test-case-compound-literal-752
Keep braces in TEST_CASE arguments when finding tests
This commit is contained in:
@@ -140,6 +140,7 @@ class UnityTestRunnerGenerator
|
||||
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
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ Significant Bugfixes:
|
||||
- Correct Windows drive paths in the Python JUnit converter (#628) @nailongzhanshen666
|
||||
- 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)
|
||||
|
||||
|
||||
@@ -1412,6 +1412,26 @@ should 'NameMocksByBasenameWithoutFolderOption' do
|
||||
$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]}"
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user