提交 2939c420 编写于 作者: M Mark VanderVoord

Better protection against nested comments (and things that look like comments)

上级 7514b89f
......@@ -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(/\\'/, '@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(/\/\/.*$/, '') # remove line comments
source_scrubbed = source_scrubbed.gsub(/\/\*.*?\*\//m, '') # remove block comments
lines = source_scrubbed.split(/(^\s*\#.*$) # Treat preprocessor directives as a logical line
| (;|\{|\}) /x) # Match ;, {, and } as end of lines
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)
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
lines.each_with_index do |line, _index|
......
......@@ -124,7 +124,9 @@ void test_NotBeConfusedByLongComplicatedStrings(void)
void test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings(void)
{
TEST_ASSERT_TRUE_MESSAGE(1, "1 Should be True");
/* still should not break anything */
}
/* nor should this */
void test_StillNotBeConfusedByLongComplicatedStrings(void)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册