mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-09-29 21:47:26 +00:00
made header parsing marginally better until we handle function declarations in an awesome way; removed filewriter system test from unit test (tested thoroughly by system tests); pushed all auxilliary includes into mock header file instead of source
git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@85 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
@@ -52,6 +52,7 @@ class CMockGenerator
|
||||
file << "/* AUTOGENERATED FILE. DO NOT EDIT. */\n"
|
||||
file << "#ifndef _#{define_name}\n"
|
||||
file << "#define _#{define_name}\n\n"
|
||||
@config.includes.each {|include| file << "#include \"#{include}\"\n"}
|
||||
file << "#include \"#{orig_filename}\"\n\n"
|
||||
file << "void #{@mock_name}_Init(void);\n"
|
||||
file << "void #{@mock_name}_Destroy(void);\n"
|
||||
@@ -69,9 +70,7 @@ class CMockGenerator
|
||||
file << "#include <stdlib.h>\n"
|
||||
file << "#include <setjmp.h>\n"
|
||||
file << "#include \"unity.h\"\n"
|
||||
file << @plugins.run(:include_files)
|
||||
|
||||
@config.includes.each {|include| file << "#include \"#{include}\"\n"}
|
||||
file << @plugins.run(:include_files)
|
||||
file << "#include \"#{header_file}\"\n\n"
|
||||
end
|
||||
|
||||
|
||||
+10
-10
@@ -3,10 +3,12 @@ class CMockHeaderParser
|
||||
attr_accessor :src_lines, :funcs, :c_attributes
|
||||
|
||||
def initialize(source, cfg)
|
||||
import_source(source)
|
||||
@funcs = []
|
||||
@c_attributes = cfg.attributes
|
||||
@declaration_parse_matcher = /(.+??)\((.*)\)/m
|
||||
@declaration_parse_matcher = /([\d\w\s\*\(\),]+??)\(([\d\w\s\*\(\),\.]*)\)/m
|
||||
@braces_matcher = /(\{|\})/m
|
||||
|
||||
import_source(source)
|
||||
end
|
||||
|
||||
def parse
|
||||
@@ -23,11 +25,11 @@ class CMockHeaderParser
|
||||
private
|
||||
|
||||
def import_source(source)
|
||||
source = source.gsub(/\s*\\\s*/m, ' ') # smush multiline into single line
|
||||
source = source.gsub(/\/\/.*$/, '') # remove line comments
|
||||
source = source.gsub(/\/\*.*?\*\//m, '') # remove block comments
|
||||
source = source.gsub(/#.*/, '') # remove preprocessor statements
|
||||
source = source.gsub(/typedef.*/i, '') # remove typedef statements
|
||||
source.gsub!(/\s*\\\s*/m, ' ') # smush multiline into single line
|
||||
source.gsub!(/\/\/.*$/, '') # remove line comments
|
||||
source.gsub!(/\/\*.*?\*\//m, '') # remove block comments
|
||||
source.gsub!(/#.*/, '') # remove preprocessor statements
|
||||
source.gsub!(/typedef.*/, '') # remove typedef statements
|
||||
|
||||
@src_lines = source.split(/;/)
|
||||
@src_lines.delete_if {|line| line.strip.length == 0} # remove blank lines
|
||||
@@ -40,9 +42,7 @@ class CMockHeaderParser
|
||||
|
||||
def parse_functions
|
||||
@src_lines.each do |line|
|
||||
if line =~ @declaration_parse_matcher
|
||||
@funcs << line.strip.gsub(/\s+/, ' ')
|
||||
end
|
||||
@funcs << line.strip.gsub(/\s+/, ' ') if line =~ @declaration_parse_matcher
|
||||
end
|
||||
return @funcs
|
||||
end
|
||||
|
||||
@@ -20,21 +20,5 @@ class CMockFileWriterTest < Test::Unit::TestCase
|
||||
assert false, "Should Have Thrown An Error When Calling Without A Block"
|
||||
rescue
|
||||
end
|
||||
end
|
||||
|
||||
should "create a file when requested and put a block of data in it" do
|
||||
begin
|
||||
File.delete('test/unit/tmp/test.txt')
|
||||
rescue
|
||||
end
|
||||
|
||||
@config.expect.mock_path.returns("test/unit/tmp/")
|
||||
@config.expect.mock_path.returns("test/unit/tmp/")
|
||||
|
||||
@cmock_file_writer.create_file("test.txt") { |file, filename| file << 'VICTORY!' }
|
||||
|
||||
retval = File.open('test/unit/tmp/test.txt', 'r').readlines[0]
|
||||
assert_equal 'VICTORY!', retval
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -59,6 +59,7 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
|
||||
should "create the top of a header file" do
|
||||
@config.expect.mock_prefix.returns("Mock")
|
||||
@config.expect.includes.returns("included.h")
|
||||
orig_filename = "PoutPoutFish.h"
|
||||
define_name = "MOCKPOUTPOUTFISH_H"
|
||||
mock_name = "MockPoutPoutFish"
|
||||
@@ -66,6 +67,7 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
expected = [ "/* AUTOGENERATED FILE. DO NOT EDIT. */\n",
|
||||
"#ifndef _#{define_name}\n",
|
||||
"#define _#{define_name}\n\n",
|
||||
"#include \"included.h\"\n",
|
||||
"#include \"#{orig_filename}\"\n\n",
|
||||
"void #{mock_name}_Init(void);\n",
|
||||
"void #{mock_name}_Destroy(void);\n",
|
||||
@@ -94,12 +96,9 @@ class CMockGeneratorTest < Test::Unit::TestCase
|
||||
"#include <setjmp.h>\n",
|
||||
"#include \"unity.h\"\n",
|
||||
"#include \"PluginRequiredHeader.h\"\n",
|
||||
"#include \"ConfigRequiredHeader1.h\"\n",
|
||||
"#include \"ConfigRequiredHeader2.h\"\n",
|
||||
"#include \"MockPoutPoutFish.h\"\n\n"
|
||||
]
|
||||
@plugins.expect.run(:include_files).returns("#include \"PluginRequiredHeader.h\"\n")
|
||||
@config.expect.includes.returns(["ConfigRequiredHeader1.h","ConfigRequiredHeader2.h"])
|
||||
|
||||
@cmock_generator.create_source_header_section(output, "MockPoutPoutFish.c")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user