From a303e0885931ecda0c03c57de8864f0b919724cb Mon Sep 17 00:00:00 2001 From: anon Date: Tue, 29 Oct 2019 19:38:43 +0000 Subject: [PATCH] Option to omit UnityBegin/UnityEnd calls in generate_test_runner By passing --omit_begin_end=1 to generate_test_runner.rb, the script will now omit calls to UnityBegin and UnityEnd when running tests in a suite. This allows multiple suites to be executed in a row, and then have an overall summary of the tests which were executed across all suites. --- auto/generate_test_runner.rb | 21 ++++++++++++++++----- src/unity.c | 6 ++++++ src/unity_internals.h | 1 + 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index 3b979d0..5053210 100644 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -41,6 +41,7 @@ class UnityTestRunnerGenerator main_name: 'main', # set to :auto to automatically generate each time main_export_decl: '', cmdline_args: false, + omit_begin_end: false, use_param_tests: false } end @@ -376,14 +377,19 @@ class UnityTestRunnerGenerator output.puts(' return parse_status;') output.puts(' }') else + main_return = @options[:omit_begin_end] ? 'void' : 'int' 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 - output.puts("int #{main_name}(void)") + output.puts("#{main_return} #{main_name}(void)") output.puts('{') end 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| if (!@options[:use_param_tests]) || test[:args].nil? || test[:args].empty? output.puts(" run_test(#{test[:test]}, \"#{test[:test]}\", #{test[:line_number]});") @@ -398,9 +404,13 @@ class UnityTestRunnerGenerator output.puts output.puts(' CMock_Guts_MemFreeFinal();') unless used_mocks.empty? 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 - output.puts(' return UnityEnd();') + output.puts(' return UnityEnd();') if not @options[:omit_begin_end] end output.puts('}') end @@ -473,6 +483,7 @@ if $0 == __FILE__ ' --suite_setup="" - code to execute for setup of entire suite', ' --suite_teardown="" - code to execute for teardown of entire suite', ' --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") exit 1 end diff --git a/src/unity.c b/src/unity.c index 72d3855..5cc481e 100644 --- a/src/unity.c +++ b/src/unity.c @@ -1824,6 +1824,12 @@ void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int UnityConcludeTest(); } +/*-----------------------------------------------*/ +void UnitySetTestFile(const char* filename) +{ + Unity.TestFile = filename; +} + /*-----------------------------------------------*/ void UnityBegin(const char* filename) { diff --git a/src/unity_internals.h b/src/unity_internals.h index 7e2024f..3d5e60a 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -477,6 +477,7 @@ extern struct UNITY_STORAGE_T Unity; void UnityBegin(const char* filename); int UnityEnd(void); +void UnitySetTestFile(const char* filename); void UnityConcludeTest(void); void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum); -- GitLab