未验证 提交 37a0f718 编写于 作者: M Mark VanderVoord 提交者: GitHub

Merge pull request #459 from elliot-gawthrop/combined_suite

Option to omit UnityBegin/UnityEnd calls in generate_test_runner
...@@ -41,6 +41,7 @@ class UnityTestRunnerGenerator ...@@ -41,6 +41,7 @@ class UnityTestRunnerGenerator
main_name: 'main', # set to :auto to automatically generate each time main_name: 'main', # set to :auto to automatically generate each time
main_export_decl: '', main_export_decl: '',
cmdline_args: false, cmdline_args: false,
omit_begin_end: false,
use_param_tests: false use_param_tests: false
} }
end end
...@@ -376,14 +377,19 @@ class UnityTestRunnerGenerator ...@@ -376,14 +377,19 @@ class UnityTestRunnerGenerator
output.puts(' return parse_status;') output.puts(' return parse_status;')
output.puts(' }') output.puts(' }')
else else
main_return = @options[:omit_begin_end] ? 'void' : 'int'
if main_name != 'main' if main_name != 'main'
output.puts("#{@options[:main_export_decl]} int #{main_name}(void);") output.puts("#{@options[:main_export_decl]} #{main_return} #{main_name}(void);")
end end
output.puts("int #{main_name}(void)") output.puts("#{main_return} #{main_name}(void)")
output.puts('{') output.puts('{')
end end
output.puts(' suiteSetUp();') if @options[:has_suite_setup] output.puts(' suiteSetUp();') if @options[:has_suite_setup]
output.puts(" UnityBegin(\"#{filename.gsub(/\\/, '\\\\\\')}\");") if @options[:omit_begin_end]
output.puts(" UnitySetTestFile(\"#{filename.gsub(/\\/, '\\\\\\')}\");")
else
output.puts(" UnityBegin(\"#{filename.gsub(/\\/, '\\\\\\')}\");")
end
tests.each do |test| tests.each do |test|
if (!@options[:use_param_tests]) || test[:args].nil? || test[:args].empty? if (!@options[:use_param_tests]) || test[:args].nil? || test[:args].empty?
output.puts(" run_test(#{test[:test]}, \"#{test[:test]}\", #{test[:line_number]});") output.puts(" run_test(#{test[:test]}, \"#{test[:test]}\", #{test[:line_number]});")
...@@ -398,9 +404,13 @@ class UnityTestRunnerGenerator ...@@ -398,9 +404,13 @@ class UnityTestRunnerGenerator
output.puts output.puts
output.puts(' CMock_Guts_MemFreeFinal();') unless used_mocks.empty? output.puts(' CMock_Guts_MemFreeFinal();') unless used_mocks.empty?
if @options[:has_suite_teardown] if @options[:has_suite_teardown]
output.puts(' return suiteTearDown(UnityEnd());') if @options[:omit_begin_end]
output.puts(' (void) suite_teardown(0);')
else
output.puts(' return suiteTearDown(UnityEnd());')
end
else else
output.puts(' return UnityEnd();') output.puts(' return UnityEnd();') if not @options[:omit_begin_end]
end end
output.puts('}') output.puts('}')
end end
...@@ -473,6 +483,7 @@ if $0 == __FILE__ ...@@ -473,6 +483,7 @@ if $0 == __FILE__
' --suite_setup="" - code to execute for setup of entire suite', ' --suite_setup="" - code to execute for setup of entire suite',
' --suite_teardown="" - code to execute for teardown of entire suite', ' --suite_teardown="" - code to execute for teardown of entire suite',
' --use_param_tests=1 - enable parameterized tests (disabled by default)', ' --use_param_tests=1 - enable parameterized tests (disabled by default)',
' --omit_begin_end=1 - omit calls to UnityBegin and UnityEnd (disabled by default)',
' --header_file="" - path/name of test header file to generate too'].join("\n") ' --header_file="" - path/name of test header file to generate too'].join("\n")
exit 1 exit 1
end end
......
...@@ -1820,6 +1820,12 @@ void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int ...@@ -1820,6 +1820,12 @@ void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int
UnityConcludeTest(); UnityConcludeTest();
} }
/*-----------------------------------------------*/
void UnitySetTestFile(const char* filename)
{
Unity.TestFile = filename;
}
/*-----------------------------------------------*/ /*-----------------------------------------------*/
void UnityBegin(const char* filename) void UnityBegin(const char* filename)
{ {
......
...@@ -477,6 +477,7 @@ extern struct UNITY_STORAGE_T Unity; ...@@ -477,6 +477,7 @@ extern struct UNITY_STORAGE_T Unity;
void UnityBegin(const char* filename); void UnityBegin(const char* filename);
int UnityEnd(void); int UnityEnd(void);
void UnitySetTestFile(const char* filename);
void UnityConcludeTest(void); void UnityConcludeTest(void);
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum); void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册