Skip to content

Commit

Permalink
🐛 :unity_helper_path handling for CMock config
Browse files Browse the repository at this point in the history
Docs were incomplete and did not agree with code. At least one code path was broken. All fixed up now.
  • Loading branch information
mkarlesky committed Jul 23, 2024
1 parent 3d809da commit 7f5ddf4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 31 deletions.
36 changes: 23 additions & 13 deletions docs/CeedlingPacket.md
Original file line number Diff line number Diff line change
Expand Up @@ -3937,12 +3937,6 @@ fashion are documented below. See [CMock] documentation.

**Default**: TRUE

* `:mock_path`:

Path for generated mocks

**Default**: <build path>/tests/mocks

* `:verbosity`:

If not set, defaults to Ceedling’s verbosity level
Expand All @@ -3967,26 +3961,42 @@ fashion are documented below. See [CMock] documentation.

To enable CMock’s optional and advanced features available via CMock plugin, simply add
`:cmock` ↳ `:plugins` to your configuration and specify your desired additional CMock
plugins as a list.
plugins as a simple list of the plugin names.

See [CMock's documentation][cmock-docs] to understand plugin options.

[cmock-docs]: https://github.com/ThrowTheSwitch/CMock/blob/master/docs/CMock_Summary.md

**Default**: `[]` (empty)

* `:unity_helper`:
* `:unity_helper_path`:

A Unity helper is a specific header file containing
A Unity helper is a simple header file used by convention to support your specialized
test case needs. For example, perhaps you want a Unity assertion macro for the
contents of a struct used throughout your project. Write the macro you need in a Unity
helper header file and `#include` that header file in your test file.

When a Unity helper is provided to CMock, it takes on more significance, and more
magic happens. CMock parses Unity helper header files and uses macros of a certain
naming convention to extend CMock’s handling of mocked parameters.

If `:cmock` ↳ `:unity_helper` set, prepopulated with unity_helper file
name (no path).
See the [Unity] and [CMock] documentation for more details.

`:unity_helper_path` may be a single string or a list. Each value must be a relative
path from your Ceedling working directory to a Unity helper header file (these are
typically organized within containing Ceedling `:paths` ↳ `:support` directories).

**Default**: `[]` (empty)

* `:includes`:

In certain advanced testing scenarios, you may need to inject additional header files
into generated mocks. The filenames in this list will be transformed in `#include`
directives within every generated mock.
into generated mocks. The filenames in this list will be transformed into `#include`
directives created at the top of every generated mock.

If `:unity_helper_path` is in use (see preceding), the filenames at the end of any
Unity helper file paths will be automatically injected into this list provided to
CMock.

**Default**: `[]` (empty)

Expand Down
19 changes: 8 additions & 11 deletions lib/ceedling/configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,6 @@ def populate_unity_config(config)
config[:unity][:defines] << 'UNITY_SUPPORT_TEST_CASES'
config[:unity][:defines] << 'UNITY_SUPPORT_VARIADIC_MACROS'
end

@loginator.log( "Unity configuration: #{config[:unity]}", Verbosity::DEBUG )
end


Expand All @@ -212,16 +210,17 @@ def populate_cmock_config(config)
cmock[:plugins].map! { |plugin| plugin.to_sym() }
cmock[:plugins].uniq!

cmock[:unity_helper] = false if (cmock[:unity_helper].nil?)
# CMock Unity helper and includes safe defaults
cmock[:includes] = [] if (cmock[:includes].nil?)
cmock[:unity_helper_path] = [] if (cmock[:unity_helper_path].nil?)
cmock[:unity_helper_path] = [cmock[:unity_helper_path]] if cmock[:unity_helper_path].is_a?( String )

if (cmock[:unity_helper])
cmock[:unity_helper] = [cmock[:unity_helper]] if cmock[:unity_helper].is_a? String
cmock[:includes] = [] if (cmock[:includes].nil?)
cmock[:includes] += cmock[:unity_helper].map{|helper| File.basename(helper) }
cmock[:includes].uniq!
# CMock Unity helper handling
cmock[:unity_helper_path].each do |path|
cmock[:includes] << File.basename( path )
end

@loginator.log( "CMock configuration: #{cmock}", Verbosity::DEBUG )
cmock[:includes].uniq!
end


Expand Down Expand Up @@ -253,8 +252,6 @@ def populate_test_runner_generation_config(config)
config[:test_runner][:defines] += config[:unity][:defines]
config[:test_runner][:use_param_tests] = config[:unity][:use_param_tests]

@loginator.log( "Test runner configuration: #{config[:test_runner]}", Verbosity::DEBUG )

@runner_config = config[:test_runner]
end

Expand Down
7 changes: 3 additions & 4 deletions lib/ceedling/configurator_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,9 @@ def validate_required_section_values(config)
def validate_paths(config)
valid = true

if config[:cmock][:unity_helper]
config[:cmock][:unity_helper].each do |path|
valid &= @configurator_validator.validate_filepath_simple( path, :cmock, :unity_helper )
end
# Ceedling ensures [:unity_helper_path] is an array
config[:cmock][:unity_helper_path].each do |path|
valid &= @configurator_validator.validate_filepath_simple( path, :cmock, :unity_helper_path )
end

config[:plugins][:load_paths].each do |path|
Expand Down
6 changes: 3 additions & 3 deletions lib/ceedling/test_invoker_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ def collect_test_framework_sources

# If we're (a) using mocks (b) a Unity helper is defined and (c) that unity helper includes a source file component,
# then link in the unity_helper object file too.
if ( @configurator.project_use_mocks and @configurator.cmock_unity_helper )
@configurator.cmock_unity_helper.each do |helper|
if @file_wrapper.exist?(helper.ext(EXTENSION_SOURCE))
if @configurator.project_use_mocks
@configurator.cmock_unity_helper_path.each do |helper|
if @file_wrapper.exist?( helper.ext(EXTENSION_SOURCE) )
sources << helper
end
end
Expand Down

0 comments on commit 7f5ddf4

Please sign in to comment.