mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-06-05 21:15:20 +00:00
faceb864b8
If we have a 'empty' macro, f.e.: \#if <something> \#define MY_LIBRARY_INLINE \#endif and using the user pattern 'MY_LIBRARY_INLINE', we would get the following effect: match = 'MY_LIBRARY_INLINE\n' <--- NOTE THAT THE NEWLINE IS PART OF THE MATCH post-match = '#endif\n' <--- NO BEGINNING NEWLINE SINCE IT IS PART OF THE MATCH ABOVE And lead to the new header: \#if <something> Which gives a compilation error since the preprocessor-if is not terminated properly. The root cause is that we add a any-whitespace-character regex to the user regex. This any-whitespace-character regex was added only to cleanup the whitespaces after a user regex. So the next line will be deleted if we check for any whitespace character (THIS INCLUDES A NEWLINE!) after the user regex. But this had the side effect that when matching a user regex, the newline was also seen as part of the match. Which in the case of an empty macro would mean that in the cleanup of the post-match, we would delete the line immediately after the empty macro (\#endif in the example above). So instead of matching with every whitespace character (which includes newlines!), we explicitly only check for whitespaces. Taking the example above, this has the desired effect: match = 'MY_LIBRARY_INLINE' <--- NOTE THAT THE NEWLINE IS NO LONGER PART OF THE MATCH post-match = '\n#endif\n' <--- BEGINNING NEWLINE NOW Now the cleanup after a define will see the beginning newline in the post-match and only remove that newline and now the preprocessor-if is terminated properly