mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-01-23 00:15:58 +01:00
Better protection against nested comments (and things that look like comments)
This commit is contained in:
@@ -104,10 +104,10 @@ class UnityTestRunnerGenerator
|
|||||||
source_scrubbed = source_scrubbed.gsub(/\\"/, '@quote@') # hide escaped quotes to allow capture of the full string/char
|
source_scrubbed = source_scrubbed.gsub(/\\"/, '@quote@') # hide escaped quotes to allow capture of the full string/char
|
||||||
source_scrubbed = source_scrubbed.gsub(/\\'/, '@apos@') # hide escaped apostrophes to allow capture of the full string/char
|
source_scrubbed = source_scrubbed.gsub(/\\'/, '@apos@') # hide escaped apostrophes to allow capture of the full string/char
|
||||||
source_scrubbed = source_scrubbed.gsub(/("[^"\n]*")|('[^'\n]*')/) { |s| s.gsub(substring_re, substring_subs) } # temporarily hide problematic characters within strings
|
source_scrubbed = source_scrubbed.gsub(/("[^"\n]*")|('[^'\n]*')/) { |s| s.gsub(substring_re, substring_subs) } # temporarily hide problematic characters within strings
|
||||||
source_scrubbed = source_scrubbed.gsub(/\/\/.*$/, '') # remove line comments
|
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(/\/\*.*?\*\//m, '') # remove block comments
|
||||||
lines = source_scrubbed.split(/(^\s*\#.*$) # Treat preprocessor directives as a logical line
|
source_scrubbed = source_scrubbed.gsub(/\/\/.*$/, '') # remove line comments (all that remain)
|
||||||
| (;|\{|\}) /x) # Match ;, {, and } as end of lines
|
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
|
.map { |line| line.gsub(substring_unre, substring_unsubs) } # unhide the problematic characters previously removed
|
||||||
|
|
||||||
lines.each_with_index do |line, _index|
|
lines.each_with_index do |line, _index|
|
||||||
|
|||||||
2
test/testdata/testRunnerGenerator.c
vendored
2
test/testdata/testRunnerGenerator.c
vendored
@@ -124,7 +124,9 @@ void test_NotBeConfusedByLongComplicatedStrings(void)
|
|||||||
void test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings(void)
|
void test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings(void)
|
||||||
{
|
{
|
||||||
TEST_ASSERT_TRUE_MESSAGE(1, "1 Should be True");
|
TEST_ASSERT_TRUE_MESSAGE(1, "1 Should be True");
|
||||||
|
/* still should not break anything */
|
||||||
}
|
}
|
||||||
|
/* nor should this */
|
||||||
|
|
||||||
void test_StillNotBeConfusedByLongComplicatedStrings(void)
|
void test_StillNotBeConfusedByLongComplicatedStrings(void)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user