diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index 2985b65..47c08ea 100644 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -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 diff --git a/docs/Unity Summary.odt b/docs/Unity Summary.odt index a90c0f3..1c43695 100644 Binary files a/docs/Unity Summary.odt and b/docs/Unity Summary.odt differ diff --git a/docs/Unity Summary.pdf b/docs/Unity Summary.pdf index 7605b17..1e289bb 100644 Binary files a/docs/Unity Summary.pdf and b/docs/Unity Summary.pdf differ diff --git a/docs/Unity Summary.txt b/docs/Unity Summary.txt index 5384b6e..4d7d56b 100644 --- a/docs/Unity Summary.txt +++ b/docs/Unity Summary.txt @@ -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 -------------- diff --git a/src/unity.c b/src/unity.c index cdf282f..d7df8ef 100644 --- a/src/unity.c +++ b/src/unity.c @@ -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) { diff --git a/src/unity.h b/src/unity.h index efdc2ae..da6dd99 100644 --- a/src/unity.h +++ b/src/unity.h @@ -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) diff --git a/src/unity_internals.h b/src/unity_internals.h index c9c7dc0..e95bc36 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -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