Skip to content

Commit

Permalink
Added messages
Browse files Browse the repository at this point in the history
  • Loading branch information
informatimago committed Aug 1, 2023
1 parent 2988d97 commit 1fd7f02
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
8 changes: 2 additions & 6 deletions lib/cmock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ def initialize(options = nil)

def setup_mocks(files, folder = nil)
[files].flatten.each do |src|
$stderr.puts "Creating mock for #{src}..." unless @silent
generate_mock(src, folder)
end
end

def setup_skeletons(files)
[files].flatten.each do |src|
$stderr.puts "Creating skeleton for #{src}..." unless @silent
generate_skeleton src
end
end
Expand All @@ -46,14 +44,12 @@ def setup_skeletons(files)
def generate_mock(src, folder)
name = File.basename(src, '.*')
ext = File.extname(src)
puts "Creating mock for #{name}..." unless @silent
@cm_generator.create_mock(name, @cm_parser.parse(src, name, File.read(src)), ext, folder,src)
@cm_generator.create_mock(name, @cm_parser.parse(src, name, File.read(src)), ext, folder, src)
end

def generate_skeleton(src)
name = File.basename(src, '.*')
puts "Creating skeleton for #{name}..." unless @silent
@cm_generator.create_skeleton(name, @cm_parser.parse(src, name, File.read(src)))
@cm_generator.create_skeleton(name, @cm_parser.parse(src, name, File.read(src)), src)
end
end

Expand Down
16 changes: 12 additions & 4 deletions lib/cmock_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def initialize(config, file_writer, utils, plugins)
@fail_on_unexpected_calls = @config.fail_on_unexpected_calls
@exclude_setjmp_h = @config.exclude_setjmp_h
@subdir = @config.subdir

@silent = (@config.verbosity < 2)
@includes_h_pre_orig_header = ((@config.includes || []) + (@config.includes_h_pre_orig_header || [])).uniq.map { |h| h =~ /</ ? h : "\"#{h}\"" }
@includes_h_post_orig_header = (@config.includes_h_post_orig_header || []).map { |h| h =~ /</ ? h : "\"#{h}\"" }
@includes_c_pre_header = (@config.includes_c_pre_header || []).map { |h| h =~ /</ ? h : "\"#{h}\"" }
Expand All @@ -45,6 +45,8 @@ def initialize(config, file_writer, utils, plugins)
end

def create_mock(module_name, parsed_stuff, module_ext = nil, folder = nil, src = nil)
$stderr.puts "Creating mock for #{src ? src : module_name}..." unless @silent

# determine the name for our new mock
mock_name = @prefix + module_name + @suffix

Expand Down Expand Up @@ -77,7 +79,9 @@ def create_mock(module_name, parsed_stuff, module_ext = nil, folder = nil, src =
create_mock_source_file(mock_project)
end

def create_skeleton(module_name, parsed_stuff)
def create_skeleton(module_name, parsed_stuff, src = nil)
$stderr.puts "Creating skeleton for #{src ? src : module_name}..." unless @silent

mock_project = {
:module_name => module_name,
:module_ext => '.h',
Expand Down Expand Up @@ -130,7 +134,7 @@ def create_mock_header_file(mock_project)
end

@file_writer.create_file(mock_project[:mock_name] + mock_project[:module_ext], mock_project[:folder]) do |file, filename|
file << "/* Source File: #{mock_project[:source]} */\n" # if mock_project[:source]
file << "/* Source File: #{mock_project[:source]} */\n"
create_mock_header_header(file, filename, mock_project)
create_mock_header_service_call_declarations(file, mock_project)
create_typedefs(file, mock_project)
Expand All @@ -144,7 +148,7 @@ def create_mock_header_file(mock_project)

def create_mock_source_file(mock_project)
@file_writer.create_file(mock_project[:mock_name] + '.c', mock_project[:folder]) do |file, filename|
file << "/* Source File: #{mock_project[:source]} */\n" # if mock_project[:source]
file << "/* Source File: #{mock_project[:source]} */\n"
create_source_header_section(file, filename, mock_project)
create_instance_structure(file, mock_project)
create_extern_declarations(file)
Expand Down Expand Up @@ -182,9 +186,13 @@ def create_mock_header_header(file, _filename, mock_project)
file << "#ifndef _#{define_name}_H\n"
file << "#define _#{define_name}_H\n\n"
file << "#include \"#{@framework}.h\"\n"
file << "/* pre_orig_headers: */\n"
@includes_h_pre_orig_header.each { |inc| file << "#include #{inc}\n" }
file << "/* orig_headers: */\n"
file << @config.orig_header_include_fmt.gsub(/%s/, orig_filename.to_s) + "\n"
file << "/* post_orig_headers: */\n"
@includes_h_post_orig_header.each { |inc| file << "#include #{inc}\n" }
file << "/* plugin_headers: */\n"
plugin_includes = @plugins.run(:include_files)
file << plugin_includes unless plugin_includes.empty?
file << "\n"
Expand Down
1 change: 1 addition & 0 deletions lib/cmock_header_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def raise_parse_error(message)
end

def parse(src_path, name, source)
$stderr.puts "Parsing #{src_path}" # if @verbosity >= 1
@parse_project = {
:source_path => src_path,
:module_name => name.gsub(/\W/, ''),
Expand Down

0 comments on commit 1fd7f02

Please sign in to comment.