diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index 18da54c..452fbc8 100755 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -100,9 +100,10 @@ class UnityTestRunnerGenerator create_suite_setup(output) create_suite_teardown(output) create_reset(output) - create_run_test(output) unless tests.empty? + create_run_test(output) create_args_wrappers(output, tests) create_shuffle_tests(output) if @options[:shuffle_tests] + tests = create_warning_test(output, input_file, tests) create_main(output, input_file, tests, used_mocks) end @@ -406,10 +407,43 @@ class UnityTestRunnerGenerator end def create_run_test(output) - require 'erb' - file = File.read(File.join(__dir__, 'run_test.erb')) - template = ERB.new(file, trim_mode: '<>') - output.puts("\n#{template.result(binding)}") + output.puts("/*=======Test Runner Used To Run Each Test=====*/") + output.puts("static void run_test(UnityTestFunction func, const char* name, UNITY_LINE_TYPE line_num)") + output.puts("{") + output.puts(" Unity.CurrentTestName = name;") + output.puts(" Unity.CurrentTestLineNumber = (UNITY_UINT) line_num;") + output.puts("#ifdef UNITY_USE_COMMAND_LINE_ARGS") + output.puts(" if (!UnityTestMatches())") + output.puts(" return;") + output.puts("#endif") + output.puts(" Unity.NumberOfTests++;") + output.puts(" UNITY_CLR_DETAILS();") + output.puts(" UNITY_EXEC_TIME_START();") + output.puts(" CMock_Init();") + output.puts(" if (TEST_PROTECT())") + output.puts(" {") + if @options[:plugins].include?(:cexception) + output.puts(" volatile CEXCEPTION_T e;") + output.puts(" Try {") + output.puts(" #{@options[:setup_name]}();") + output.puts(" func();") + output.puts(" } Catch(e) {") + output.puts(" TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, \"Unhandled Exception!\");") + output.puts(" }") + else + output.puts(" #{@options[:setup_name]}();") + output.puts(" func();") + end + output.puts(" }") + output.puts(" if (TEST_PROTECT())") + output.puts(" {") + output.puts(" #{@options[:teardown_name]}();") + output.puts(" CMock_Verify();") + output.puts(" }") + output.puts(" CMock_Destroy();") + output.puts(" UNITY_EXEC_TIME_STOP();") + output.puts(" UnityConcludeTest();") + output.puts("}") end def create_args_wrappers(output, tests) @@ -428,6 +462,22 @@ class UnityTestRunnerGenerator end end + def create_warning_test(output, filename, tests) + if count_tests(tests) == 0 + warning_test = { + :test => "test_empty_warning", + :line_number => 0 + } + output.puts("\n/*=======Warning Test=====*/") + output.puts("static void #{warning_test[:test]}(void)") + output.puts('{') + output.puts(" TEST_IGNORE_MESSAGE(\"Test file '#{filename.gsub(/\\/, '\\\\\\')}' contains no tests.\");") + output.puts("}\n") + tests = [warning_test] + end + return tests + end + def create_shuffle_tests(output) output.puts("\n/*=======Shuffle Test Order=====*/") output.puts('static void shuffleTests(struct UnityRunTestParameters run_test_params_arr[], int num_of_tests)') diff --git a/auto/run_test.erb b/auto/run_test.erb deleted file mode 100644 index e334d65..0000000 --- a/auto/run_test.erb +++ /dev/null @@ -1,37 +0,0 @@ -/*=======Test Runner Used To Run Each Test=====*/ -static void run_test(UnityTestFunction func, const char* name, UNITY_LINE_TYPE line_num) -{ - Unity.CurrentTestName = name; - Unity.CurrentTestLineNumber = (UNITY_UINT) line_num; -#ifdef UNITY_USE_COMMAND_LINE_ARGS - if (!UnityTestMatches()) - return; -#endif - Unity.NumberOfTests++; - UNITY_CLR_DETAILS(); - UNITY_EXEC_TIME_START(); - CMock_Init(); - if (TEST_PROTECT()) - { -<% if @options[:plugins].include?(:cexception) %> - volatile CEXCEPTION_T e; - Try { - <%= @options[:setup_name] %>(); - func(); - } Catch(e) { - TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, "Unhandled Exception!"); - } -<% else %> - <%= @options[:setup_name] %>(); - func(); -<% end %> - } - if (TEST_PROTECT()) - { - <%= @options[:teardown_name] %>(); - CMock_Verify(); - } - CMock_Destroy(); - UNITY_EXEC_TIME_STOP(); - UnityConcludeTest(); -} diff --git a/src/unity.h b/src/unity.h index e7d472d..be645e9 100644 --- a/src/unity.h +++ b/src/unity.h @@ -11,7 +11,7 @@ #define UNITY_VERSION_MAJOR 2 #define UNITY_VERSION_MINOR 7 -#define UNITY_VERSION_BUILD 0 +#define UNITY_VERSION_BUILD 1 #define UNITY_VERSION ((UNITY_VERSION_MAJOR << 16) | (UNITY_VERSION_MINOR << 8) | UNITY_VERSION_BUILD) #ifdef __cplusplus diff --git a/test/testdata/testRunnerGeneratorEmpty.c b/test/testdata/testRunnerGeneratorEmpty.c new file mode 100644 index 0000000..939532b --- /dev/null +++ b/test/testdata/testRunnerGeneratorEmpty.c @@ -0,0 +1,13 @@ +/* ========================================================================= + Unity - A Test Framework for C + ThrowTheSwitch.org + Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams + SPDX-License-Identifier: MIT +========================================================================= */ + +/* This Test File Is Used To Verify The Warning When No Tests Are Found */ + +#include "unity.h" + +void setUp(void) {} +void tearDown(void) {} diff --git a/test/tests/test_generate_test_runner.rb b/test/tests/test_generate_test_runner.rb index 201c24d..8d54dac 100644 --- a/test/tests/test_generate_test_runner.rb +++ b/test/tests/test_generate_test_runner.rb @@ -336,6 +336,17 @@ RUNNER_TESTS = [ }, + { :name => 'EmptyFileWarning', + :testfile => 'testdata/testRunnerGeneratorEmpty.c', + :testdefines => ['TEST'], + :options => nil, #defaults + :expected => { + :to_pass => [ ], + :to_fail => [ ], + :to_ignore => [ 'test_empty_warning' ], + } + }, + #### WITH MOCKS ########################################## { :name => 'DefaultsThroughOptions',