mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-01-23 00:15:58 +01:00
Added type_sanitizer.rb to consolidate converting a string to a valid C identifier, which will allow CMock and Ceedling to use the same construct which is currently duplicated in each repo.
This commit is contained in:
@@ -7,6 +7,9 @@
|
||||
$QUICK_RUBY_VERSION = RUBY_VERSION.split('.').inject(0){|vv,v| vv * 100 + v.to_i }
|
||||
File.expand_path(File.join(File.dirname(__FILE__),'colour_prompt'))
|
||||
|
||||
HERE = File.expand_path(File.dirname(__FILE__))
|
||||
require "#{HERE}/type_sanitizer"
|
||||
|
||||
class UnityTestRunnerGenerator
|
||||
|
||||
def initialize(options = nil)
|
||||
@@ -190,7 +193,7 @@ class UnityTestRunnerGenerator
|
||||
output.puts(" GlobalOrderError = NULL;")
|
||||
end
|
||||
mocks.each do |mock|
|
||||
mock_clean = mock.gsub(/(?:-|\s+)/, "_")
|
||||
mock_clean = TypeSanitizer.sanitize_c_identifier(mock)
|
||||
output.puts(" #{mock_clean}_Init();")
|
||||
end
|
||||
output.puts("}\n")
|
||||
@@ -198,7 +201,7 @@ class UnityTestRunnerGenerator
|
||||
output.puts("static void CMock_Verify(void)")
|
||||
output.puts("{")
|
||||
mocks.each do |mock|
|
||||
mock_clean = mock.gsub(/(?:-|\s+)/, "_")
|
||||
mock_clean = TypeSanitizer.sanitize_c_identifier(mock)
|
||||
output.puts(" #{mock_clean}_Verify();")
|
||||
end
|
||||
output.puts("}\n")
|
||||
@@ -206,7 +209,7 @@ class UnityTestRunnerGenerator
|
||||
output.puts("static void CMock_Destroy(void)")
|
||||
output.puts("{")
|
||||
mocks.each do |mock|
|
||||
mock_clean = mock.gsub(/(?:-|\s+)/, "_")
|
||||
mock_clean = TypeSanitizer.sanitize_c_identifier(mock)
|
||||
output.puts(" #{mock_clean}_Destroy();")
|
||||
end
|
||||
output.puts("}\n")
|
||||
|
||||
8
auto/type_sanitizer.rb
Normal file
8
auto/type_sanitizer.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
module TypeSanitizer
|
||||
|
||||
def self.sanitize_c_identifier(unsanitized)
|
||||
# convert filename to valid C identifier by replacing invalid chars with '_'
|
||||
return unsanitized.gsub(/[-\/\\\.\,\s]/, "_")
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,2 +1,2 @@
|
||||
2.1.0
|
||||
2.2.0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user