From f03f932b681435dabafe59b19eeefcb201fd8855 Mon Sep 17 00:00:00 2001 From: Michael Karlesky Date: Wed, 14 Oct 2026 14:25:38 -0400 Subject: [PATCH] Match module naming conventions to their help text bumpy produced camelCase and camel produced BumpyCase, the reverse of the help text. A convention given as a symbol, as YAML configuration supplies it, was ignored. The Subversion add check read $! where it needed $?, the exit status. Co-Authored-By: Claude Opus 5.5 --- auto/generate_module.rb | 8 ++--- test/spec/generate_module_naming_spec.rb | 38 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 test/spec/generate_module_naming_spec.rb diff --git a/auto/generate_module.rb b/auto/generate_module.rb index 128d36b5c..dcdfe2059 100644 --- a/auto/generate_module.rb +++ b/auto/generate_module.rb @@ -182,9 +182,9 @@ def neutralize_filename(name, start_cap: true) ############################ def create_filename(part1, part2 = '') name = part2.empty? ? part1 : "#{part1}_#{part2}" - case @options[:naming] - when 'bumpy' then neutralize_filename(name, start_cap: false).delete('_') - when 'camel' then neutralize_filename(name).delete('_') + case @options[:naming]&.to_s + when 'bumpy' then neutralize_filename(name).delete('_') + when 'camel' then neutralize_filename(name, start_cap: false).delete('_') when 'snake' then neutralize_filename(name).downcase when 'caps' then neutralize_filename(name).upcase else name @@ -221,7 +221,7 @@ def generate(module_name, pattern = nil) end if @options[:update_svn] `svn add \"#{file[:path]}\"` - if $!.exitstatus.zero? + if $?.exitstatus.zero? puts "File #{file[:path]} created and added to source control" else puts "File #{file[:path]} created but FAILED adding to source control!" diff --git a/test/spec/generate_module_naming_spec.rb b/test/spec/generate_module_naming_spec.rb new file mode 100644 index 000000000..9b5f2fce9 --- /dev/null +++ b/test/spec/generate_module_naming_spec.rb @@ -0,0 +1,38 @@ +# ========================================================================= +# Unity - A Test Framework for C +# ThrowTheSwitch.org +# Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams +# SPDX-License-Identifier: MIT +# ========================================================================= + +require '../auto/generate_module.rb' + +# Each naming convention produces the case its help text names, whether the +# convention arrives as a string or, from YAML, as a symbol +describe 'UnityModuleGenerator naming' do + def filename(naming, name = 'mad_science') + UnityModuleGenerator.new(naming: naming).create_filename(name) + end + + it 'makes bumpy names start with a capital' do + expect(filename('bumpy')).to eq('MadScience') + end + + it 'makes camel names start with a lowercase letter' do + expect(filename('camel')).to eq('madScience') + end + + it 'makes snake and caps names' do + expect(filename('snake', 'MadScience')).to eq('mad_science') + expect(filename('caps', 'MadScience')).to eq('MAD_SCIENCE') + end + + it 'accepts a convention given as a symbol' do + expect(filename(:bumpy)).to eq('MadScience') + expect(filename(:snake, 'MadScience')).to eq('mad_science') + end + + it 'keeps a name as given without a convention' do + expect(filename(nil, 'MadScience')).to eq('MadScience') + end +end