Skip to content

Commit 3caf511

Browse files
committed
fix: Don't smush macros which have an escaped empty line at the end
nanopb has a habit of generating macros which end with an escaped empty line (for example for messages which are empty). They look like this: #define some_msg_t_FIELDLIST(X, a) \ #define some_msg_t_CALLBACK NULL This caused CMock to strip all of the newlines after the backslash instead of only one, which the backslash was escaping. This in turn caused both the macros to be in one line, causing a compile error in the generated mock.
1 parent 379a9a8 commit 3caf511

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/cmock_header_parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def transform_inline_functions(source)
137137
# If the user uses a macro to declare an inline function,
138138
# smushing the macros makes it easier to recognize them as a macro and if required,
139139
# remove them later on in this function
140-
source.gsub!(/\s*\\\s*/m, ' ')
140+
source.gsub!(/\s*\\(\n|\s*)/m, ' ')
141141

142142
# Just looking for static|inline in the gsub is a bit too aggressive (functions that are named like this, ...), so we try to be a bit smarter
143143
# Instead, look for an inline pattern (f.e. "static inline") and parse it.

test/unit/cmock_header_parser_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2867,5 +2867,19 @@ class Classy {
28672867
assert_equal(expected, @parser.transform_inline_functions(source))
28682868
end
28692869

2870+
it "Transform macros with escapes of empty lines" do
2871+
source =
2872+
"#define some_msg_t_FIELDLIST(X, a) \\\n" +
2873+
"\n" +
2874+
"#define some_msg_t_CALLBACK NULL\n"
2875+
2876+
expected =
2877+
"#define some_msg_t_FIELDLIST(X, a) \n" +
2878+
"#define some_msg_t_CALLBACK NULL\n"
2879+
2880+
@parser.treat_inlines = :include
2881+
assert_equal(expected, @parser.transform_inline_functions(source))
2882+
end
2883+
28702884

28712885
end

0 commit comments

Comments
 (0)