提交 953b55c7 编写于 作者: M mvandervoord

- made RUN_TEST so that it doesn't require a custom runTest by default

- updated generator to lay simple foundation for parameterized test support

git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@101 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
上级 d1bd6e29
......@@ -67,10 +67,10 @@ class UnityTestRunnerGenerator
input_file.rewind
source_raw = input_file.read
source_scrubbed = source_raw.gsub(/\/\/.*$/, '') #remove line comments
source_scrubbed = source_scrubbed.gsub(/\/\*.*?\*\//m, '') #remove block comments
lines = source_scrubbed.split(/(^\s*\#.*$) # Treat preprocessor directives as a logical line
| (;|\{|\}) /x) # Match ;, {, and } as end of lines
source_scrubbed = source_raw.gsub(/\/\/.*$/, '') # remove line comments
source_scrubbed = source_scrubbed.gsub(/\/\*.*?\*\//m, '') # remove block comments
lines = source_scrubbed.split(/(^\s*\#.*$) # Treat preprocessor directives as a logical line
| (;|\{|\}) /x) # Match ;, {, and } as end of lines
lines.each_with_index do |line, index|
if line =~ /^\s*void\s+test(.*?)\s*\(\s*void\s*\)/
......@@ -193,23 +193,28 @@ class UnityTestRunnerGenerator
def create_runtest(output, used_mocks)
cexception = @options[:plugins].include? :cexception
output.puts("static void runTest(UnityTestFunction test)")
output.puts("{")
output.puts(" if (TEST_PROTECT())")
output.puts(" {")
output.puts(" CEXCEPTION_T e;") if cexception
output.puts(" Try {") if cexception
output.puts(" CMock_Init();") unless (used_mocks.empty?)
output.puts(" setUp();")
output.puts(" test();")
output.puts(" CMock_Verify();") unless (used_mocks.empty?)
output.puts(" } Catch(e) { TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, \"Unhandled Exception!\"); }") if cexception
output.puts(" }")
output.puts(" CMock_Destroy();") unless (used_mocks.empty?)
output.puts(" if (TEST_PROTECT() && !TEST_IS_IGNORED)")
output.puts(" {")
output.puts(" tearDown();")
output.puts(" }")
va_args1 = @options[:use_param_tests] ? ', ...' : ''
va_args2 = @options[:use_param_tests] ? '__VA_ARGS__' : ''
output.puts("#define TEST_RUN(TestFunc, TestLineNum#{va_args1}) \\")
output.puts("{ \\")
output.puts(" Unity.CurrentTestName = #TestFunc; \\")
output.puts(" Unity.CurrentTestLineNumber = TestLineNum; \\")
output.puts(" Unity.NumberOfTests++; \\")
output.puts(" if (TEST_PROTECT()) \\")
output.puts(" { \\")
output.puts(" CEXCEPTION_T e; \\") if cexception
output.puts(" Try { \\") if cexception
output.puts(" CMock_Init(); \\") unless (used_mocks.empty?)
output.puts(" setUp(); \\")
output.puts(" TestFunc(#{va_args2}); \\")
output.puts(" CMock_Verify(); \\") unless (used_mocks.empty?)
output.puts(" } Catch(e) { TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, \"Unhandled Exception!\"); } \\") if cexception
output.puts(" } \\")
output.puts(" CMock_Destroy(); \\") unless (used_mocks.empty?)
output.puts(" if (TEST_PROTECT() && !TEST_IS_IGNORED) \\")
output.puts(" { \\")
output.puts(" tearDown(); \\")
output.puts(" } \\")
output.puts("}")
end
......
此差异由.gitattributes 抑制。
此差异由.gitattributes 抑制。
......@@ -8,14 +8,10 @@ Unity Test API
Running Tests
-------------
RUN_TEST(func)
RUN_TEST(func, linenum)
Each Test is run within the macro RUN_TEST. This macro performs necessary setup before the test is called and handles cleanup and result tabulation afterwards.
TEST_WRAP(function)
If the test functions call helper functions and those helper functions have the ability to make assertions, calls to those helpers should be wrapped in a TEST_WRAP macro. This macro aborts the test if the helper triggered a failure.
--------------
Ignoring Tests
--------------
......
......@@ -790,6 +790,26 @@ void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line)
UNITY_IGNORE_AND_BAIL;
}
//-----------------------------------------------
void setUp(void);
void tearDown(void);
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum)
{
Unity.CurrentTestName = FuncName;
Unity.CurrentTestLineNumber = FuncLineNum;
Unity.NumberOfTests++;
if (TEST_PROTECT())
{
setUp();
Func();
}
if (TEST_PROTECT() && !(Unity.CurrentTestIgnored))
{
tearDown();
}
UnityConcludeTest();
}
//-----------------------------------------------
void UnityBegin(void)
{
......
......@@ -40,12 +40,9 @@
#define TEST_ABORT() {longjmp(Unity.AbortFrame, 1);}
#define RUN_TEST(func, line_num) \
Unity.CurrentTestName = #func; \
Unity.CurrentTestLineNumber = line_num; \
Unity.NumberOfTests++; \
runTest(func); \
UnityConcludeTest();
#ifndef RUN_TEST
#define RUN_TEST(func, line_num) UnityDefaultTestRun(func, #func, line_num)
#endif
#define TEST_LINE_NUM (Unity.CurrentTestLineNumber)
#define TEST_IS_IGNORED (Unity.CurrentTestIgnored)
......
......@@ -189,6 +189,7 @@ extern struct _Unity Unity;
void UnityBegin(void);
int UnityEnd(void);
void UnityConcludeTest(void);
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum);
//-------------------------------------------------------
// Test Output
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册