Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the combination of use_test_preprocessor and CMock's treat_inlines #421

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/cmock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def initialize(options = nil)
@silent = (cm_config.verbosity < 2)
end

def setup_mocks(files, folder = nil)
def setup_mocks(files, orig_file = nil, folder = nil)
[files].flatten.each do |src|
generate_mock(src, folder)
generate_mock(src, orig_file, folder)
end
end

Expand All @@ -41,11 +41,11 @@ def setup_skeletons(files)

private ###############################

def generate_mock(src, folder)
def generate_mock(src, orig_file, folder)
name = File.basename(src, '.*')
ext = File.extname(src)
puts "Creating mock for #{name}..." unless @silent
@cm_generator.create_mock(name, @cm_parser.parse(name, File.read(src)), ext, folder)
@cm_generator.create_mock(name, @cm_parser.parse(name, File.read(src), orig_file), ext, folder)
end

def generate_skeleton(src)
Expand Down Expand Up @@ -106,6 +106,6 @@ def option_maker(options, key, val)
if options[:skeleton]
CMock.new(options).setup_skeletons(filelist)
else
CMock.new(options).setup_mocks(filelist)
CMock.new(options).setup_mocks(filelist, "")
end
end
18 changes: 12 additions & 6 deletions lib/cmock_header_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def initialize(cfg)
@c_strippables += ['inline'] if @treat_inlines == :include # we'll need to remove the attribute if we're allowing inlines
end

def parse(name, source)
def parse(name, source, orig_file)
parse_project = {
:module_name => name.gsub(/\W/, ''),
:typedefs => [],
Expand All @@ -49,11 +49,17 @@ def parse(name, source)
end
end

parse_project[:normalized_source] = if @treat_inlines == :include
transform_inline_functions(source)
else
''
end
if @treat_inlines == :include
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "Ruby Way" of doing this same thing would be to have a single line which is like raise "Blah" if orig_file.nil? In this case, however, I think if an original file isn't provided, there's no reason it shouldn't just go with the specified source instead?

if orig_file == nil
raise "Treat inlines is active but not-preprocessed original file is missing for " + name
elsif File.file?(orig_file)
# Run the inline transform on the original and never on the preprocessed source.
parse_project[:normalized_source] = transform_inline_functions(File.read(orig_file))
else
# CMock.rb directly calls with orig_file="". In this case restore the original behavior.
parse_project[:normalized_source] = transform_inline_functions(source)
end
end

{ :includes => nil,
:functions => parse_project[:functions],
Expand Down