提交 68cc45a9 编写于 作者: J John Lindgren

Make sure setUp/tearDown are always defined.

上级 5fc72fbc
...@@ -85,6 +85,8 @@ class UnityTestRunnerGenerator ...@@ -85,6 +85,8 @@ class UnityTestRunnerGenerator
create_header(output, used_mocks, testfile_includes) create_header(output, used_mocks, testfile_includes)
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_setup(output)
create_teardown(output)
create_suite_setup(output) create_suite_setup(output)
create_suite_teardown(output) create_suite_teardown(output)
create_reset(output, used_mocks) create_reset(output, used_mocks)
...@@ -220,8 +222,8 @@ class UnityTestRunnerGenerator ...@@ -220,8 +222,8 @@ class UnityTestRunnerGenerator
def create_externs(output, tests, _mocks) def create_externs(output, tests, _mocks)
output.puts("\n/*=======External Functions This Runner Calls=====*/") output.puts("\n/*=======External Functions This Runner Calls=====*/")
output.puts("extern void #{@options[:setup_name]}(void);") if @options[:has_setup] output.puts("extern void #{@options[:setup_name]}(void);")
output.puts("extern void #{@options[:teardown_name]}(void);") if @options[:has_teardown] output.puts("extern void #{@options[:teardown_name]}(void);")
output.puts("\n#ifdef __cplusplus\nextern \"C\"\n{\n#endif") if @options[:externc] output.puts("\n#ifdef __cplusplus\nextern \"C\"\n{\n#endif") if @options[:externc]
tests.each do |test| tests.each do |test|
output.puts("extern void #{test[:test]}(#{test[:call] || 'void'});") output.puts("extern void #{test[:test]}(#{test[:call] || 'void'});")
...@@ -267,32 +269,34 @@ class UnityTestRunnerGenerator ...@@ -267,32 +269,34 @@ class UnityTestRunnerGenerator
output.puts("}\n") output.puts("}\n")
end end
def create_setup(output)
return if @options[:has_setup]
output.puts("\n/*=======Setup (stub)=====*/")
output.puts("void #{@options[:setup_name]}(void) {}")
end
def create_teardown(output)
return if @options[:has_teardown]
output.puts("\n/*=======Teardown (stub)=====*/")
output.puts("void #{@options[:teardown_name]}(void) {}")
end
def create_suite_setup(output) def create_suite_setup(output)
if @options[:has_suite_setup] return if @options[:suite_setup].nil?
if !@options[:suite_setup].nil? output.puts("\n/*=======Suite Setup=====*/")
output.puts("\n/*=======Suite Setup=====*/") output.puts('void suiteSetUp(void)')
output.puts('void suiteSetUp(void)') output.puts('{')
output.puts('{') output.puts(@options[:suite_setup])
output.puts(@options[:suite_setup]) output.puts('}')
output.puts('}')
else
output.puts('extern void suiteSetUp(void);')
end
end
end end
def create_suite_teardown(output) def create_suite_teardown(output)
if @options[:has_suite_teardown] return if @options[:suite_teardown].nil?
if !@options[:suite_teardown].nil? output.puts("\n/*=======Suite Teardown=====*/")
output.puts("\n/*=======Suite Teardown=====*/") output.puts('int suiteTearDown(int num_failures)')
output.puts('int suiteTearDown(int num_failures)') output.puts('{')
output.puts('{') output.puts(@options[:suite_teardown])
output.puts(@options[:suite_teardown]) output.puts('}')
output.puts('}')
else
output.puts('extern int suiteTearDown(int num_failures);')
end
end
end end
def create_runtest(output, used_mocks) def create_runtest(output, used_mocks)
...@@ -314,13 +318,13 @@ class UnityTestRunnerGenerator ...@@ -314,13 +318,13 @@ class UnityTestRunnerGenerator
output.puts(' { \\') output.puts(' { \\')
output.puts(' CEXCEPTION_T e; \\') if cexception output.puts(' CEXCEPTION_T e; \\') if cexception
output.puts(' Try { \\') if cexception output.puts(' Try { \\') if cexception
output.puts(" #{@options[:setup_name]}(); \\") if @options[:has_setup] output.puts(" #{@options[:setup_name]}(); \\")
output.puts(" TestFunc(#{va_args2}); \\") output.puts(" TestFunc(#{va_args2}); \\")
output.puts(' } Catch(e) { TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, "Unhandled Exception!"); } \\') if cexception output.puts(' } Catch(e) { TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, "Unhandled Exception!"); } \\') if cexception
output.puts(' } \\') output.puts(' } \\')
output.puts(' if (TEST_PROTECT()) \\') output.puts(' if (TEST_PROTECT()) \\')
output.puts(' { \\') output.puts(' { \\')
output.puts(" #{@options[:teardown_name]}(); \\") if @options[:has_teardown] output.puts(" #{@options[:teardown_name]}(); \\")
output.puts(' CMock_Verify(); \\') unless used_mocks.empty? output.puts(' CMock_Verify(); \\') unless used_mocks.empty?
output.puts(' } \\') output.puts(' } \\')
output.puts(' CMock_Destroy(); \\') unless used_mocks.empty? output.puts(' CMock_Destroy(); \\') unless used_mocks.empty?
...@@ -337,9 +341,9 @@ class UnityTestRunnerGenerator ...@@ -337,9 +341,9 @@ class UnityTestRunnerGenerator
output.puts('{') output.puts('{')
output.puts(' CMock_Verify();') unless used_mocks.empty? output.puts(' CMock_Verify();') unless used_mocks.empty?
output.puts(' CMock_Destroy();') unless used_mocks.empty? output.puts(' CMock_Destroy();') unless used_mocks.empty?
output.puts(" #{@options[:teardown_name]}();") if @options[:has_teardown] output.puts(" #{@options[:teardown_name]}();")
output.puts(' CMock_Init();') unless used_mocks.empty? output.puts(' CMock_Init();') unless used_mocks.empty?
output.puts(" #{@options[:setup_name]}();") if @options[:has_setup] output.puts(" #{@options[:setup_name]}();")
output.puts('}') output.puts('}')
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册