mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-06-24 00:28:35 +08:00
Merge pull request #44 from shellyniz/master
copy include statements from test file to test runner (excluding cmock.h and unity.h) to better handle custom types in parameterized tests (Thanks Shelly)
This commit is contained in:
@ -45,7 +45,7 @@ class UnityTestRunnerGenerator
|
||||
end
|
||||
|
||||
#build runner file
|
||||
generate(input_file, output_file, tests, used_mocks)
|
||||
generate(input_file, output_file, tests, used_mocks, testfile_includes)
|
||||
|
||||
#determine which files were used to return them
|
||||
all_files_used = [input_file, output_file]
|
||||
@ -54,9 +54,9 @@ class UnityTestRunnerGenerator
|
||||
return all_files_used.uniq
|
||||
end
|
||||
|
||||
def generate(input_file, output_file, tests, used_mocks)
|
||||
def generate(input_file, output_file, tests, used_mocks, testfile_includes)
|
||||
File.open(output_file, 'w') do |output|
|
||||
create_header(output, used_mocks)
|
||||
create_header(output, used_mocks, testfile_includes)
|
||||
create_externs(output, tests, used_mocks)
|
||||
create_mock_management(output, used_mocks)
|
||||
create_suite_setup_and_teardown(output)
|
||||
@ -121,7 +121,10 @@ class UnityTestRunnerGenerator
|
||||
source.gsub!(/\/\/.*$/, '') # remove line comments (all that remain)
|
||||
|
||||
#parse out includes
|
||||
return source.scan(/^\s*#include\s+\"\s*(.+)\.[hH]\s*\"/).flatten
|
||||
includes = source.scan(/^\s*#include\s+\"\s*(.+)\.[hH]\s*\"/).flatten
|
||||
brackets_includes = source.scan(/^\s*#include\s+<\s*(.+)\s*>/).flatten
|
||||
brackets_includes.each { |inc| includes << '<' + inc +'>' }
|
||||
return includes
|
||||
end
|
||||
|
||||
def find_mocks(includes)
|
||||
@ -132,7 +135,7 @@ class UnityTestRunnerGenerator
|
||||
return mock_headers
|
||||
end
|
||||
|
||||
def create_header(output, mocks)
|
||||
def create_header(output, mocks, testfile_includes)
|
||||
output.puts('/* AUTOGENERATED FILE. DO NOT EDIT. */')
|
||||
create_runtest(output, mocks)
|
||||
output.puts("\n//=======Automagically Detected Files To Include=====")
|
||||
@ -144,6 +147,11 @@ class UnityTestRunnerGenerator
|
||||
output.puts('#include <setjmp.h>')
|
||||
output.puts('#include <stdio.h>')
|
||||
output.puts('#include "CException.h"') if @options[:plugins].include?(:cexception)
|
||||
testfile_includes.delete("unity").delete("cmock")
|
||||
testrunner_includes = testfile_includes - mocks
|
||||
testrunner_includes.each do |inc|
|
||||
output.puts("#include #{inc.include?('<') ? inc : "\"#{inc.gsub('.h','')}.h\""}")
|
||||
end
|
||||
mocks.each do |mock|
|
||||
output.puts("#include \"#{mock.gsub('.h','')}.h\"")
|
||||
end
|
||||
|
Reference in New Issue
Block a user