提交 7deba787 编写于 作者: M mvandervoord

- backed out Mike's incorrect changes to generate_test_runner

- made generate_test_runner's two include groups more clearly differentiated
- added negative tests to int16's.

git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@133 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
上级 b44d3f3e
...@@ -31,7 +31,7 @@ class UnityTestRunnerGenerator ...@@ -31,7 +31,7 @@ class UnityTestRunnerGenerator
def run(input_file, output_file, options=nil) def run(input_file, output_file, options=nil)
tests = [] tests = []
includes = [] testfile_includes = []
used_mocks = [] used_mocks = []
@options.merge!(options) unless options.nil? @options.merge!(options) unless options.nil?
...@@ -39,24 +39,24 @@ class UnityTestRunnerGenerator ...@@ -39,24 +39,24 @@ class UnityTestRunnerGenerator
#pull required data from source file #pull required data from source file
File.open(input_file, 'r') do |input| File.open(input_file, 'r') do |input|
tests = find_tests(input) tests = find_tests(input)
includes = find_includes(input) testfile_includes = find_includes(input)
used_mocks = find_mocks(includes) used_mocks = find_mocks(testfile_includes)
end end
#build runner file #build runner file
generate(input_file, output_file, tests, includes, used_mocks) generate(input_file, output_file, tests, used_mocks)
#determine which files were used to return them #determine which files were used to return them
all_files_used = [input_file, output_file] all_files_used = [input_file, output_file]
all_files_used += includes.map {|filename| filename + '.c'} unless includes.empty? all_files_used += testfile_includes.map {|filename| filename + '.c'} unless testfile_includes.empty?
all_files_used += @options[:includes] unless @options[:includes].empty? all_files_used += @options[:includes] unless @options[:includes].empty?
return all_files_used.uniq return all_files_used.uniq
end end
def generate(input_file, output_file, tests, includes, used_mocks) def generate(input_file, output_file, tests, used_mocks)
File.open(output_file, 'w') do |output| File.open(output_file, 'w') do |output|
create_header(output, includes, used_mocks) create_header(output, used_mocks)
create_externs(output, tests, used_mocks) create_externs(output, tests, used_mocks)
create_mock_management(output, used_mocks) create_mock_management(output, used_mocks)
create_suite_setup_and_teardown(output) create_suite_setup_and_teardown(output)
...@@ -127,13 +127,13 @@ class UnityTestRunnerGenerator ...@@ -127,13 +127,13 @@ class UnityTestRunnerGenerator
return mock_headers return mock_headers
end end
def create_header(output, includes, mocks) def create_header(output, mocks)
output.puts('/* AUTOGENERATED FILE. DO NOT EDIT. */') output.puts('/* AUTOGENERATED FILE. DO NOT EDIT. */')
create_runtest(output, mocks) create_runtest(output, mocks)
output.puts("\n//=======Automagically Detected Files To Include=====") output.puts("\n//=======Automagically Detected Files To Include=====")
output.puts("#include \"#{@options[:framework].to_s}.h\"") output.puts("#include \"#{@options[:framework].to_s}.h\"")
output.puts('#include "cmock.h"') unless (mocks.empty?) output.puts('#include "cmock.h"') unless (mocks.empty?)
((@options[:includes] + includes).flatten.uniq.compact).each do |inc| @options[:includes].flatten.uniq.compact.each do |inc|
output.puts("#include #{inc.include?('<') ? inc : "\"#{inc.gsub('.h','')}.h\""}") output.puts("#include #{inc.include?('<') ? inc : "\"#{inc.gsub('.h','')}.h\""}")
end end
output.puts('#include <setjmp.h>') output.puts('#include <setjmp.h>')
...@@ -155,7 +155,7 @@ class UnityTestRunnerGenerator ...@@ -155,7 +155,7 @@ class UnityTestRunnerGenerator
output.puts("extern void setUp(void);") output.puts("extern void setUp(void);")
output.puts("extern void tearDown(void);") output.puts("extern void tearDown(void);")
tests.each do |test| tests.each do |test|
output.puts("extern void #{test[:test]}(#{test[:call]});") output.puts("extern void #{test[:test]}(#{test[:call] || 'void'});")
end end
output.puts('') output.puts('')
end end
......
...@@ -359,18 +359,37 @@ void testEqualInt16s(void) ...@@ -359,18 +359,37 @@ void testEqualInt16s(void)
_US16 v0, v1; _US16 v0, v1;
_US16 *p0, *p1; _US16 *p0, *p1;
v0 = 0x9876; v0 = 0x7876;
v1 = 0x9876; v1 = 0x7876;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_EQUAL_INT16(0x7876, 0x7876);
TEST_ASSERT_EQUAL_INT16(v0, v1);
TEST_ASSERT_EQUAL_INT16(0x7876, v1);
TEST_ASSERT_EQUAL_INT16(v0, 0x7876);
TEST_ASSERT_EQUAL_INT16(*p0, v1);
TEST_ASSERT_EQUAL_INT16(*p0, *p1);
TEST_ASSERT_EQUAL_INT16(*p0, 0x7876);
}
void testEqualInt16sNegatives(void)
{
_US16 v0, v1;
_US16 *p0, *p1;
v0 = -7876;
v1 = -7876;
p0 = &v0; p0 = &v0;
p1 = &v1; p1 = &v1;
TEST_ASSERT_EQUAL_INT16(0x9876, 0x9876); TEST_ASSERT_EQUAL_INT16(-7876, -7876);
TEST_ASSERT_EQUAL_INT16(v0, v1); TEST_ASSERT_EQUAL_INT16(v0, v1);
TEST_ASSERT_EQUAL_INT16(0x9876, v1); TEST_ASSERT_EQUAL_INT16(-7876, v1);
TEST_ASSERT_EQUAL_INT16(v0, 0x9876); TEST_ASSERT_EQUAL_INT16(v0, -7876);
TEST_ASSERT_EQUAL_INT16(*p0, v1); TEST_ASSERT_EQUAL_INT16(*p0, v1);
TEST_ASSERT_EQUAL_INT16(*p0, *p1); TEST_ASSERT_EQUAL_INT16(*p0, *p1);
TEST_ASSERT_EQUAL_INT16(*p0, 0x9876); TEST_ASSERT_EQUAL_INT16(*p0, -7876);
} }
void testEqualInt16sWhenThereAreDifferencesOutside16Bits(void) void testEqualInt16sWhenThereAreDifferencesOutside16Bits(void)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册