Skip to content

Commit

Permalink
🐛 Setting config for incomplete :unity & :cmock
Browse files Browse the repository at this point in the history
The order of revised defaults and automatic configuration settings handling left the possiblilty of trying to set a value in Unity and CMock configuration that was incomplete.

A user’s configuration might create a partial configuration block that automatic settings tried to fill out but would encounter nil references dpeending on the accompanying logic.

The fix was to reorder how user config, defaults, and auto configuration values are processed.
  • Loading branch information
mkarlesky committed Nov 28, 2024
1 parent fa80d1e commit 3d5680a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 31 deletions.
41 changes: 22 additions & 19 deletions lib/ceedling/configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,28 +187,38 @@ def merge_ceedling_runtime_config(config, runtime_config)
config.deep_merge( runtime_config )
end

def populate_with_defaults( config_hash, defaults_hash )
msg = @reportinator.generate_progress( 'Populating project configuration with collected default values' )
@loginator.log( msg, Verbosity::OBNOXIOUS )

@configurator_builder.populate_with_defaults( config_hash, defaults_hash )
end


def populate_unity_config(config)
msg = @reportinator.generate_progress( 'Processing Unity configuration' )
@loginator.log( msg, Verbosity::OBNOXIOUS )

# :unity is not guaranteed to exist in a user configuration before populating it.

if config[:unity][:use_param_tests]
config[:unity][:defines] << 'UNITY_SUPPORT_TEST_CASES'
config[:unity][:defines] << 'UNITY_SUPPORT_VARIADIC_MACROS'
end

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


def populate_cmock_config(config)
# :unity is not guaranteed to exist in a user configuration before populating it.
# Save CMock config reference
@cmock_config = config[:cmock]

# Populate config with CMock config
cmock = config[:cmock] || {}
@cmock_config = cmock
cmock = config[:cmock]

return if !config[:project][:use_mocks]
# Do no more prep if we're not using mocks
if !config[:project][:use_mocks]
@loginator.log( "CMock configuration >> #{cmock}", Verbosity::DEBUG )
return
end

msg = @reportinator.generate_progress( 'Processing CMock configuration' )
@loginator.log( msg, Verbosity::OBNOXIOUS )
Expand All @@ -217,11 +227,6 @@ def populate_cmock_config(config)
cmock[:plugins].map! { |plugin| plugin.to_sym() }
cmock[:plugins].uniq!

# CMock includes safe defaults
cmock[:includes] = [] if (cmock[:includes].nil?)

# Default to empty array if cmock[:unity_helper_path] not provided
cmock[:unity_helper_path] = [] if cmock[:unity_helper_path].nil?
# Reformulate CMock helper path value as array of one element if it's a string in config
cmock[:unity_helper_path] = [cmock[:unity_helper_path]] if cmock[:unity_helper_path].is_a?( String )

Expand All @@ -231,14 +236,8 @@ def populate_cmock_config(config)
end

cmock[:includes].uniq!
end


def populate_with_defaults( config_hash, defaults_hash )
msg = @reportinator.generate_progress( 'Populating project configuration with collected default values' )
@loginator.log( msg, Verbosity::OBNOXIOUS )

@configurator_builder.populate_with_defaults( config_hash, defaults_hash )
@loginator.log( "CMock configuration >> #{cmock}", Verbosity::DEBUG )
end


Expand All @@ -263,6 +262,8 @@ def populate_test_runner_generation_config(config)
config[:test_runner][:use_param_tests] = config[:unity][:use_param_tests]

@runner_config = config[:test_runner]

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


Expand All @@ -274,6 +275,8 @@ def populate_exceptions_config(config)

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

@loginator.log( "CException configuration >> #{config[:cexception]}", Verbosity::DEBUG )
end


Expand Down
19 changes: 7 additions & 12 deletions lib/ceedling/setupinator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,14 @@ def do_setup( app_cfg )
## 2. Handle basic configuration
##

log_step( 'Project Configuration Handling' )
log_step( 'Base configuration handling', heading:false )

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

# Standardize paths and add to Ruby load paths
plugins_paths_hash = @configurator.prepare_plugins_load_paths( app_cfg[:ceedling_plugins_path], config_hash )

# Populate Unity configuration with values to tie vendor tool configurations together
@configurator.populate_unity_config( config_hash )

# Populate CMock configuration with values to tie vendor tool configurations together
@configurator.populate_cmock_config( config_hash )

##
## 3. Plugin Handling
##
Expand Down Expand Up @@ -115,14 +109,15 @@ def do_setup( app_cfg )

log_step( 'Completing Project Configuration' )

# Populate Unity configuration with values to tie vendor tool configurations together
@configurator.populate_unity_config( config_hash )

# Populate CMock configuration with values to tie vendor tool configurations together
@configurator.populate_cmock_config( config_hash )

# Configure test runner generation
@configurator.populate_test_runner_generation_config( config_hash )

@loginator.log( "Unity configuration >> #{config_hash[:unity]}", Verbosity::DEBUG )
@loginator.log( "CMock configuration >> #{config_hash[:cmock]}", Verbosity::DEBUG )
@loginator.log( "Test Runner configuration >> #{config_hash[:test_runner]}", Verbosity::DEBUG )
@loginator.log( "CException configuration >> #{config_hash[:cexception]}", Verbosity::DEBUG )

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

Expand Down

0 comments on commit 3d5680a

Please sign in to comment.