Skip to content

Add support for Catch framework #8

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

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
044d081
Added alternative catch helper
pJunger May 27, 2017
799dc29
Added catch macros to get callorder up to 20
pJunger May 28, 2017
83432e7
Added template from C4C plugin
pJunger May 29, 2017
82ea113
Generate template
pJunger May 29, 2017
0fea2e0
Prototyping of working matcher
pJunger May 29, 2017
04aaad8
Added working thing - though some macros should be generated (and uni…
pJunger May 31, 2017
b61f878
Temporarily readd static macro files
pJunger May 31, 2017
a8ed6d8
Update fff_catch_helper.h
pJunger Jun 1, 2017
2bc3fbc
Update fff_catch_helper.h
pJunger Jun 1, 2017
16e17f3
Fixed obsolete functions. Replaced CHECK_ARG\d\(... with CHECK_ARG\(\…
pJunger Jun 2, 2017
2bed478
Removed generation of templates. Used Cmock properties to find out if…
pJunger Jun 2, 2017
dd07b7f
Merge branch 'master' of https://github.com/pJunger/fake_function_fra…
pJunger Jun 2, 2017
50c03d3
Renamed Matcher classes, added virtual destructor to remove gcc warnings
pJunger Jun 3, 2017
140d459
Added comma ...
pJunger Jun 3, 2017
5b66bee
Added underscore in macro
pJunger Jun 3, 2017
bc94d47
Update fff_mock_generator.rb
pJunger Jun 3, 2017
4319f43
Update fake_function_framework.rb
pJunger Jun 3, 2017
73a328f
Update fff_mock_generator.rb
pJunger Jun 3, 2017
deba6a0
Delete template.erb
pJunger Jun 3, 2017
800a40d
Update fake_function_framework.rb
pJunger Jun 3, 2017
5fb01be
Removed pure function that was not necessary anymore
pJunger Jun 4, 2017
938a2c0
Readded initial output, but filtered by verbosity flag
pJunger Jun 4, 2017
0cda9eb
Removed debug puts...
pJunger Jun 4, 2017
c930b44
Removed mocked functions hash
pJunger Jun 4, 2017
f49128c
Modified get_mock_path function
pJunger Jun 4, 2017
b5dabca
Reverted line break
pJunger Jun 4, 2017
58bfe01
Added argument to get_mock_path, removed fileutils import
pJunger Jun 4, 2017
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
33 changes: 20 additions & 13 deletions lib/fake_function_framework.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ class FakeFunctionFramework < Plugin
def setup
# Get the location of this plugin.
@plugin_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
puts "Using fake function framework (fff)..."
@mock_config = @ceedling[:setupinator].config_hash[:cmock]
@silent = (@mock_config[:verbosity] < 2)
puts "Using fake function framework (fff)..." unless @silent

# Switch out the cmock_builder with our own.
@ceedling[:cmock_builder].cmock = FffMockGeneratorForCMock.new(@ceedling[:setupinator].config_hash[:cmock])
@ceedling[:cmock_builder].cmock = FffMockGeneratorForCMock.new(@mock_config)

# Add the path to fff.h to the include paths.
COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR << "#{@plugin_root}/vendor/fff"
Expand All @@ -23,9 +25,9 @@ def post_runner_generate(arg_hash)
# all mocks linked into the test.
File.open(arg_hash[:runner_file], 'a') do |f|
f.puts
f.puts "//=======Defintions of FFF variables====="
f.puts "//=======Definitions of FFF variables====="
f.puts %{#include "fff.h"}
f.puts "DEFINE_FFF_GLOBALS;"
f.puts "DEFINE_FFF_GLOBALS"
end
end

Expand All @@ -37,6 +39,7 @@ def initialize(options=nil)
@cm_config = CMockConfig.new(options)
@cm_parser = CMockHeaderParser.new(@cm_config)
@silent = (@cm_config.verbosity < 2)
FffMockGenerator.set_framework(@cm_config.framework)

# These are the additional files to include in the mock files.
@includes_h_pre_orig_header = (@cm_config.includes || @cm_config.includes_h_pre_orig_header || []).map{|h| h =~ /</ ? h : "\"#{h}\""}
Expand All @@ -51,20 +54,25 @@ def setup_mocks(files)
end
end

def generate_mock (header_file_to_mock)
def get_mock_path(mock_name)
mock_path = @cm_config.mock_path
if @cm_config.subdir
# If a subdirectory has been configured, append it to the mock path.
mock_path = "#{mock_path}/#{@cm_config.subdir}"
end
full_path_for_mock = "#{mock_path}/#{mock_name}"
end

def generate_mock(header_file_to_mock)
module_name = File.basename(header_file_to_mock, '.h')
puts "Creating mock for #{module_name}..." unless @silent
mock_name = @cm_config.mock_prefix + module_name + @cm_config.mock_suffix
mock_path = @cm_config.mock_path
if @cm_config.subdir
# If a subdirectory has been configured, append it to the mock path.
mock_path = "#{mock_path}/#{@cm_config.subdir}"
end
full_path_for_mock = "#{mock_path}/#{mock_name}"

full_path_for_mock = get_mock_path(mock_name)

# Parse the header file so we know what to mock.
parsed_header = @cm_parser.parse(module_name, File.read(header_file_to_mock))

# Create the directory if it doesn't exist.
mkdir_p full_path_for_mock.pathmap("%d")

Expand All @@ -83,5 +91,4 @@ def generate_mock (header_file_to_mock)
@includes_c_pre_orig_header, @includes_c_post_orig_header))
end
end

end
14 changes: 10 additions & 4 deletions lib/fff_mock_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
# The mocks created are compatible with CMock for use with Ceedling.

class FffMockGenerator
@@framework = :unity

def self.create_mock_header(module_name, mock_name, parsed_header, pre_includes=nil,
post_includes=nil)
def self.set_framework(framework)
@@framework = framework
end

def self.create_mock_header(module_name, mock_name, parsed_header, pre_includes=nil, post_includes=nil)
output = StringIO.new
write_opening_include_guard(mock_name, output)
output.puts
Expand Down Expand Up @@ -46,8 +50,10 @@ def self.write_opening_include_guard(mock_name, output)

def self.write_header_includes(module_name, output)
output.puts %{#include "fff.h"}
output.puts %{#include "fff_unity_helper.h"}
output.puts %{#include "fff_#{@@framework.to_s}_helper.h"}
output.puts 'FFF_EXTERN_C'
output.puts %{#include "#{module_name}.h"}
output.puts 'FFF_END_EXTERN_C'
end

def self.write_typedefs(parsed_header, output)
Expand Down Expand Up @@ -156,7 +162,7 @@ def self.write_function_macros(macro_type, parsed_header, output)
end

# Close the declaration.
output.puts ");"
output.puts ")"
end
end

Expand Down
Loading