Skip to content

Commit

Permalink
🐛 Fixed error message formatting exception
Browse files Browse the repository at this point in the history
- Fixes issue #927
- Improved error messages for use of `:flags` and `:defines` matchers outside of the `:text` context
  • Loading branch information
mkarlesky committed Sep 12, 2024
1 parent d880297 commit 4190c33
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
12 changes: 6 additions & 6 deletions docs/CeedlingPacket.md
Original file line number Diff line number Diff line change
Expand Up @@ -3460,7 +3460,7 @@ General case:
- ...
```

Advanced matching for test build handling only:
Advanced matching for **_test_** build handling only:
```yaml
:defines:
:test:
Expand Down Expand Up @@ -3561,7 +3561,7 @@ Ceedling treats each test executable as a mini project. As a reminder, each test
together with all C sources and frameworks, becomes an individual test executable of
the same name.

_In the `:test` context only_, symbols may be defined for only those test executable
**_In the `:test` context only_**, symbols may be defined for only those test executable
builds that match file name criteria. Matchers match on test file names only, and the
specified symbols are added to the build step for all files that are components of
matched test executables.
Expand Down Expand Up @@ -3839,7 +3839,7 @@ General case:
- ...
```

Advanced matching for test build handling only:
Advanced matching for **_test_** build handling only:
```yaml
:flags:
:test:
Expand All @@ -3864,9 +3864,9 @@ You specify the flags you want to add to a build step beneath `:<context>` ↳ `
In many cases this is a simple YAML list of strings that will become flags in a tool's
command line.

Specifically in the `:test` context you also have the option to create test file matchers
that apply flags to some subset of your test build. Note that file matchers and the simpler
flags list format cannot be mixed for `:flags` ↳ `:test`.
**_Specifically and only in the `:test` context_** you also have the option to create test
file matchers that apply flags to some subset of your test build. Note that file matchers
and the simpler flags list format cannot be mixed for `:flags` ↳ `:test`.

* <h3><code>:flags</code> ↳ <code>:release</code> ↳ <code>:compile</code></h3>

Expand Down
40 changes: 26 additions & 14 deletions lib/ceedling/configurator_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def validate_defines(_config)

# Ensure config[:defines] is a hash
if defines.class != Hash
msg = ":defines must contain key / value pairs, not #{defines.class.downcase} (see docs for examples)"
msg = ":defines must contain key / value pairs, not #{defines.class.to_s.downcase} (see docs for examples)"
@loginator.log( msg, Verbosity::ERRORS )
return false
end
Expand Down Expand Up @@ -226,15 +226,21 @@ def validate_defines(_config)

# Non-test contexts
if context != :test
if config.class != Array
msg = "#{walk} entry '#{config}' must be a list, not #{config.class.downcase} (see docs for examples)"
# Handle the (probably) common case of trying to use matchers for any context other than test
if config.class == Hash
msg = "#{walk} entry '#{config}' must be a list--matcher hashes only availalbe for the :test context (see docs for details)"
@loginator.log( msg, Verbosity::ERRORS )
valid = false
# Catchall for any oddball entries
elsif config.class != Array
msg = "#{walk} entry '#{config}' must be a list, not #{config.class.to_s.downcase} (see docs for examples)"
@loginator.log( msg, Verbosity::ERRORS )
valid = false
end
# Test contexts
else
if config.class != Array and config.class != Hash
msg = "#{walk} entry '#{config}' must be a list or matcher, not #{config.class.downcase} (see docs for examples)"
msg = "#{walk} entry '#{config}' must be a list or matcher, not #{config.class.to_s.downcase} (see docs for examples)"
@loginator.log( msg, Verbosity::ERRORS )
valid = false
end
Expand All @@ -254,7 +260,7 @@ def validate_defines(_config)
config.each do |symbol|
if symbol.class != String
walk = @reportinator.generate_config_walk( [:defines, context] )
msg = "#{walk} list entry #{symbol} must be a string, not #{symbol.class.downcase} (see docs for examples)"
msg = "#{walk} list entry #{symbol} must be a string, not #{symbol.class.to_s.downcase} (see docs for examples)"
@loginator.log( msg, Verbosity::ERRORS )
valid = false
end
Expand Down Expand Up @@ -320,7 +326,7 @@ def validate_flags(_config)

# Ensure config[:flags] is a hash
if flags.class != Hash
msg = ":flags must contain key / value pairs, not #{flags.class.downcase} (see docs for examples)"
msg = ":flags must contain key / value pairs, not #{flags.class.to_s.downcase} (see docs for examples)"
@loginator.log( msg, Verbosity::ERRORS )
# Immediately bail out
return false
Expand All @@ -337,7 +343,7 @@ def validate_flags(_config)
if operations.class != Hash
walk = @reportinator.generate_config_walk( [:flags, context] )
example = @reportinator.generate_config_walk( [:flags, context, :compile] )
msg = "#{walk} context must contain :<operation> key / value pairs, not #{operations.class.downcase} (ex. #{example})"
msg = "#{walk} context must contain :<operation> key / value pairs, not #{operations.class.to_s.downcase} (ex. #{example})"
@loginator.log( msg, Verbosity::ERRORS )

# Immediately bail out
Expand All @@ -364,15 +370,21 @@ def validate_flags(_config)

# Non-test contexts
if context != :test
if config.class != Array
msg = "#{walk} entry '#{config}' must be a list, not #{config.class.downcase} (see docs for examples)"
# Handle the (probably) common case of trying to use matchers for any context other than test
if config.class == Hash
msg = "#{walk} entry '#{config}' must be a list--matcher hashes only availalbe for the :test context (see docs for details)"
@loginator.log( msg, Verbosity::ERRORS )
valid = false
# Catchall for any oddball entries
elsif config.class != Array
msg = "#{walk} entry '#{config}' must be a list, not #{config.class.to_s.downcase} (see docs for examples)"
@loginator.log( msg, Verbosity::ERRORS )
valid = false
end
# Test contexts
else
if config.class != Array and config.class != Hash
msg = "#{walk} entry '#{config}' must be a list or matcher, not #{config.class.downcase} (see docs for examples)"
msg = "#{walk} entry '#{config}' must be a list or matcher, not #{config.class.to_s.downcase} (see docs for examples)"
@loginator.log( msg, Verbosity::ERRORS )
valid = false
end
Expand All @@ -395,7 +407,7 @@ def validate_flags(_config)
flags.each do |flag|
if flag.class != String
walk = @reportinator.generate_config_walk( [:flags, context, operation] )
msg = "#{walk} simple list entry '#{flag}' must be a string, not #{flag.class.downcase} (see docs for examples)"
msg = "#{walk} simple list entry '#{flag}' must be a string, not #{flag.class.to_s.downcase} (see docs for examples)"
@loginator.log( msg, Verbosity::ERRORS )
valid = false
end
Expand Down Expand Up @@ -494,7 +506,7 @@ def validate_environment_vars(config)

# Ensure config[:environment] is an array (of simple hashes--validated below)
if environment.class != Array
msg = ":environment must contain a list of key / value pairs, not #{environment.class.downcase} (see docs for examples)"
msg = ":environment must contain a list of key / value pairs, not #{environment.class.to_s.downcase} (see docs for examples)"
@loginator.log( msg, Verbosity::ERRORS )
return false
end
Expand Down Expand Up @@ -543,7 +555,7 @@ def validate_environment_vars(config)

# Ensure entry value is a string or list
if not (value.class == String or value.class == Array)
msg = ":environment entry #{key} is associated with #{value.class.downcase}, not a string or list (see docs for details)"
msg = ":environment entry #{key} is associated with #{value.class.to_s.downcase}, not a string or list (see docs for details)"
@loginator.log( msg, Verbosity::ERRORS )
valid = false
end
Expand All @@ -552,7 +564,7 @@ def validate_environment_vars(config)
if value.class == Array
value.each do |item|
if item.class != String
msg = ":environment entry #{key} contains a list element '#{item}' (#{item.class.downcase}) that is not a string"
msg = ":environment entry #{key} contains a list element '#{item}' (#{item.class.to_s.downcase}) that is not a string"
@loginator.log( msg, Verbosity::ERRORS )
valid = false
end
Expand Down

0 comments on commit 4190c33

Please sign in to comment.