Skip to content

Commit

Permalink
🐛 Fixed mocks & plugin handling
Browse files Browse the repository at this point in the history
- Mock defaults were being skipped if project mocking was not enabled. This was a mistake.
- Debug logging and exception handling added to build directory structure handling.
- Moved programmatic CException enabling up higher in the pipeline to match other configuration handling.
- Flipped the order of config plugins merging and plugin settings population to ensure that raw output setting for testing plugins is handled properly.
- Added debug logging for test runner generation configuration.
  • Loading branch information
mkarlesky committed Jun 24, 2024
1 parent e0b46d4 commit 09c8d55
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 28 deletions.
17 changes: 14 additions & 3 deletions lib/ceedling/configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ def populate_cmock_defaults(config, default_config)
# so they're present for the build environment to access;
# Note: these need to end up in the hash given to initialize cmock for this to be successful

return if !config[:project][:use_mocks]

msg = @reportinator.generate_progress( 'Collecting CMock defaults' )
@loginator.log( msg, Verbosity::OBNOXIOUS )

Expand Down Expand Up @@ -197,7 +195,7 @@ def populate_cmock_config(config)
msg = @reportinator.generate_progress( 'Processing CMock configuration' )
@loginator.log( msg, Verbosity::OBNOXIOUS )

cmock[:plugins] = [] if (cmock[:plugins].nil?)
# Plugins housekeeping
cmock[:plugins].map! { |plugin| plugin.to_sym() }
cmock[:plugins].uniq!

Expand Down Expand Up @@ -241,10 +239,23 @@ def populate_test_runner_generation_config(config)
# Merge Unity options used by test runner generation
config[:test_runner][:defines] += config[:unity][:defines]

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

@runner_config = config[:test_runner]
end


def populate_exceptions_config(config)
# Automagically set exception handling if CMock is configured for it
if config[:cmock][:plugins] && config[:cmock][:plugins].include?(:cexception)
msg = @reportinator.generate_progress( 'Enabling CException use based on CMock plugins settings' )
@loginator.log( msg, Verbosity::OBNOXIOUS )

config[:project][:use_exceptions] = true
end
end


def get_runner_config
# Clone because test runner generation is not thread-safe;
# The runner generator is manufactured for each use with configuration changes for each use.
Expand Down
29 changes: 8 additions & 21 deletions lib/ceedling/configurator_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def flattenify(config)

config.each_key do | parent |

# gracefully handle empty top-level entries
# Gracefully handle empty top-level entries
next if (config[parent].nil?)

case config[parent]
Expand All @@ -69,12 +69,14 @@ def flattenify(config)
key = "#{parent.to_s.downcase}_#{hash.keys[0].to_s.downcase}".to_sym
new_hash[key] = hash[hash.keys[0]]
end

when Hash
config[parent].each_pair do | child, value |
key = "#{parent.to_s.downcase}_#{child.to_s.downcase}".to_sym
new_hash[key] = value
end
# handle entries with no children, only values

# Handle entries with no children, only values
else
new_hash["#{parent.to_s.downcase}".to_sym] = config[parent]
end
Expand Down Expand Up @@ -103,26 +105,11 @@ def populate_defaults(config, defaults)


def cleanup(in_hash)
# ensure that include files inserted into test runners have file extensions & proper ones at that
# Ensure that include files inserted into test runners have file extensions & proper ones at that
in_hash[:test_runner_includes].map!{|include| include.ext(in_hash[:extension_header])}
end


def set_exception_handling(in_hash)
# If project defines exception handling, do not change the setting.
# But, if the project omits exception handling setting...
if not in_hash[:project_use_exceptions]
# Automagically set it if cmock is configured for it
if in_hash[:cmock_plugins] && in_hash[:cmock_plugins].include?(:cexception)
in_hash[:project_use_exceptions] = true
# Otherwise, disable exceptions for the project
else
in_hash[:project_use_exceptions] = false
end
end
end


def set_build_paths(in_hash)
out_hash = {}

Expand Down Expand Up @@ -161,17 +148,17 @@ def set_build_paths(in_hash)

out_hash[:project_build_paths] = []

# fetch already set mock path
# Fetch already set mock path
out_hash[:project_build_paths] << in_hash[:cmock_mock_path] if (in_hash[:project_use_mocks])

paths.each do |path|
build_path_name = path[0]
build_path = path[1]
build_path_add_condition = path[2]

# insert path into build paths if associated with true condition
# Insert path into build paths if associated with true condition
out_hash[:project_build_paths] << build_path if build_path_add_condition
# set path symbol name and path for each entry in paths array
# Set path symbol name and path for each entry in paths array
out_hash[build_path_name] = build_path
end

Expand Down
16 changes: 13 additions & 3 deletions lib/ceedling/configurator_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# =========================================================================

require 'ceedling/constants'
require 'ceedling/exceptions'

# Add sort-ability to symbol so we can order keys array in hash for test-ability
class Symbol
Expand All @@ -30,11 +31,10 @@ def inspect
end

def build_project_config(ceedling_lib_path, flattened_config)
### flesh out config
# Housekeeping
@configurator_builder.cleanup( flattened_config )
@configurator_builder.set_exception_handling( flattened_config )

### add to hash values we build up from configuration & file system contents
# Add to hash values we build up from configuration & file system contents
flattened_config.merge!( @configurator_builder.set_build_paths( flattened_config ) )
flattened_config.merge!( @configurator_builder.set_rakefile_components( ceedling_lib_path, flattened_config ) )
flattened_config.merge!( @configurator_builder.set_release_target( flattened_config ) )
Expand All @@ -44,7 +44,17 @@ def build_project_config(ceedling_lib_path, flattened_config)
end

def build_directory_structure(flattened_config)
msg = "Build paths:"
flattened_config[:project_build_paths].each do |path|
msg += "\n - #{(path.nil? or path.empty?) ? '<empty>' : path}"
end
@loginator.log( msg, Verbosity::DEBUG )

flattened_config[:project_build_paths].each do |path|
if path.nil? or path.empty?
raise CeedlingException.new( "Blank internal project build path subdirectory value" )
end

@file_wrapper.mkdir( path )
end
end
Expand Down
5 changes: 4 additions & 1 deletion lib/ceedling/setupinator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def do_setup( app_cfg )

# Plugin handling
@configurator.discover_plugins( plugins_paths_hash, config_hash )
@configurator.populate_plugins_config( plugins_paths_hash, config_hash )
@configurator.merge_config_plugins( config_hash )
@configurator.populate_plugins_config( plugins_paths_hash, config_hash )

##
## 4. Collect and apply defaults to user configuration
Expand All @@ -115,6 +115,9 @@ def do_setup( app_cfg )
# Configure test runner generation
@configurator.populate_test_runner_generation_config( config_hash )

# Automagically enable use of exceptions based on CMock settings
@configurator.populate_exceptions_config( config_hash )

# Evaluate environment vars again before subsequent configurations that might reference with inline Ruby string expansion
@configurator.eval_environment_variables( config_hash )

Expand Down

0 comments on commit 09c8d55

Please sign in to comment.