From 7f5ddf44ca0fba40174e3301d0a370245391afea Mon Sep 17 00:00:00 2001 From: Michael Karlesky Date: Tue, 23 Jul 2024 12:45:34 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20:unity=5Fhelper=5Fpath=20handlin?= =?UTF-8?q?g=20for=20CMock=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docs were incomplete and did not agree with code. At least one code path was broken. All fixed up now. --- docs/CeedlingPacket.md | 36 ++++++++++++++++++----------- lib/ceedling/configurator.rb | 19 +++++++-------- lib/ceedling/configurator_setup.rb | 7 +++--- lib/ceedling/test_invoker_helper.rb | 6 ++--- 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/docs/CeedlingPacket.md b/docs/CeedlingPacket.md index 6864a3b0..551cee1a 100644 --- a/docs/CeedlingPacket.md +++ b/docs/CeedlingPacket.md @@ -3937,12 +3937,6 @@ fashion are documented below. See [CMock] documentation. **Default**: TRUE -* `:mock_path`: - - Path for generated mocks - - **Default**: /tests/mocks - * `:verbosity`: If not set, defaults to Ceedling’s verbosity level @@ -3967,7 +3961,7 @@ 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. @@ -3975,18 +3969,34 @@ fashion are documented below. See [CMock] documentation. **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) diff --git a/lib/ceedling/configurator.rb b/lib/ceedling/configurator.rb index e643230f..7278054c 100644 --- a/lib/ceedling/configurator.rb +++ b/lib/ceedling/configurator.rb @@ -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 @@ -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 @@ -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 diff --git a/lib/ceedling/configurator_setup.rb b/lib/ceedling/configurator_setup.rb index fefffbda..3c78023e 100644 --- a/lib/ceedling/configurator_setup.rb +++ b/lib/ceedling/configurator_setup.rb @@ -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| diff --git a/lib/ceedling/test_invoker_helper.rb b/lib/ceedling/test_invoker_helper.rb index ff4738a0..395de3ff 100644 --- a/lib/ceedling/test_invoker_helper.rb +++ b/lib/ceedling/test_invoker_helper.rb @@ -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