mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-07-29 07:17:49 +00:00
Generates same code as previous version now (fixed some remaining quirks)
git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@13 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
+17
-5
@@ -24,10 +24,22 @@ class CMockGenerator
|
||||
|
||||
def create_mock(parsed_stuff)
|
||||
update_vars
|
||||
create_shortcuts(parsed_stuff)
|
||||
create_mock_header_file(parsed_stuff)
|
||||
create_mock_source_file(parsed_stuff)
|
||||
end
|
||||
|
||||
def create_shortcuts(parsed_stuff)
|
||||
parsed_stuff[:functions].each do |function|
|
||||
function[:args_string_without_varargs] = function[:args_string].gsub(/\,[a-zA-Z0-9_\*\s]*\.\.\./,'')
|
||||
if (function[:modifier].empty?)
|
||||
function[:mod_and_rettype] = function[:rettype]
|
||||
else
|
||||
function[:mod_and_rettype] = function[:modifier] + ' ' + function[:rettype]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update_vars
|
||||
@mock_name = "Mock" + @module_name
|
||||
@mock_header_name_dest = @mock_name + ".h"
|
||||
@@ -49,8 +61,6 @@ class CMockGenerator
|
||||
create_mock_header_header(header, @mock_header_name_dest.gsub(/\.h/, "_h").upcase)
|
||||
create_mock_header_externs(header, parsed_stuff)
|
||||
parsed_stuff[:functions].each do |function|
|
||||
|
||||
function[:args_string_without_varargs] = function[:args_string].gsub(/\,[a-zA-Z0-9_\*\s]*\.\.\./,'')
|
||||
create_mock_header_function_declaration(header, function)
|
||||
end
|
||||
create_mock_header_footer(header)
|
||||
@@ -141,7 +151,9 @@ class CMockGenerator
|
||||
file << "#include <setjmp.h>\n"
|
||||
file << "#include \"unity.h\"\n"
|
||||
file << "#include \"Exception.h\"\n" if (@use_cexception) ####MSV : REMOVE ME
|
||||
include_files.each {|include| file << "#include \"#{include}\"\n"}
|
||||
|
||||
#(@includes + include_files).uniq.each {|include| file << "#include \"#{include}\"\n"} #### MSV This is what the comments said in original version, but it wasnt actually doing this
|
||||
@includes.each {|include| file << "#include \"#{include}\"\n"}
|
||||
file << "#include \"#{@mock_header_name_dest}\"\n\n"
|
||||
end
|
||||
|
||||
@@ -249,7 +261,7 @@ class CMockGenerator
|
||||
end
|
||||
|
||||
def create_mock_argument_verifier(file, function)
|
||||
file << "void AssertParameters_#{function[:name]}(#{function[:args_string]})\n{\n"
|
||||
file << "void AssertParameters_#{function[:name]}(#{function[:args_string_without_varargs]})\n{\n"
|
||||
function[:args].each do |arg|
|
||||
type = arg[:type].sub(/const/, '').strip
|
||||
file << make_handle_expected(function, type, arg[:name])
|
||||
@@ -268,7 +280,7 @@ class CMockGenerator
|
||||
|
||||
# Create mock function
|
||||
file << "#{function[:attributes]} " if (!function[:attributes].nil? && function[:attributes].length > 0)
|
||||
file << "#{function[:rettype]} #{function[:name]}(#{function[:args_string]})\n"
|
||||
file << "#{function[:mod_and_rettype]} #{function[:name]}(#{function[:args_string]})\n"
|
||||
file << "{\n"
|
||||
|
||||
# start ignore block
|
||||
|
||||
@@ -4,12 +4,12 @@ class CMockHeaderParser
|
||||
|
||||
def initialize(source, match_type=/\w+\**/, attributes=['static', '__monitor', '__ramfunc', '__irq', '__fiq'])
|
||||
source = source.gsub(/\/\/.*$/, '') #remove line comments
|
||||
source = source.gsub(/\#define.*$/, '') #remove defines
|
||||
source = source.gsub(/\/\*.*?\*\//m, '') #remove block comments
|
||||
@lines = source.split(/(^\s*\#.*$) # Treat preprocessor directives as a logical line
|
||||
| (;|\{|\}) /x) # Match ;, {, and } as end of lines
|
||||
@lines.delete_if {|line| line =~ /\\\n/} #ignore lines that contain continuation lines
|
||||
@lines.delete_if {|line| line =~ /typedef/} #ignore lines that contain typedef statements
|
||||
@lines.delete_if {|line| line =~ /\#define/} #remove defines
|
||||
|
||||
@functions = nil
|
||||
@match_type = match_type
|
||||
|
||||
Reference in New Issue
Block a user