mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-09-21 17:47:25 +00:00
Add "ignore" test when there are no tests provided in a runner (fixed Ceedling #1181).
Remove erb dependency.
This commit is contained in:
@@ -100,9 +100,10 @@ class UnityTestRunnerGenerator
|
|||||||
create_suite_setup(output)
|
create_suite_setup(output)
|
||||||
create_suite_teardown(output)
|
create_suite_teardown(output)
|
||||||
create_reset(output)
|
create_reset(output)
|
||||||
create_run_test(output) unless tests.empty?
|
create_run_test(output)
|
||||||
create_args_wrappers(output, tests)
|
create_args_wrappers(output, tests)
|
||||||
create_shuffle_tests(output) if @options[:shuffle_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)
|
create_main(output, input_file, tests, used_mocks)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -406,10 +407,43 @@ class UnityTestRunnerGenerator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_run_test(output)
|
def create_run_test(output)
|
||||||
require 'erb'
|
output.puts("/*=======Test Runner Used To Run Each Test=====*/")
|
||||||
file = File.read(File.join(__dir__, 'run_test.erb'))
|
output.puts("static void run_test(UnityTestFunction func, const char* name, UNITY_LINE_TYPE line_num)")
|
||||||
template = ERB.new(file, trim_mode: '<>')
|
output.puts("{")
|
||||||
output.puts("\n#{template.result(binding)}")
|
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
|
end
|
||||||
|
|
||||||
def create_args_wrappers(output, tests)
|
def create_args_wrappers(output, tests)
|
||||||
@@ -428,6 +462,22 @@ class UnityTestRunnerGenerator
|
|||||||
end
|
end
|
||||||
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)
|
def create_shuffle_tests(output)
|
||||||
output.puts("\n/*=======Shuffle Test Order=====*/")
|
output.puts("\n/*=======Shuffle Test Order=====*/")
|
||||||
output.puts('static void shuffleTests(struct UnityRunTestParameters run_test_params_arr[], int num_of_tests)')
|
output.puts('static void shuffleTests(struct UnityRunTestParameters run_test_params_arr[], int num_of_tests)')
|
||||||
|
|||||||
@@ -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();
|
|
||||||
}
|
|
||||||
+1
-1
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
#define UNITY_VERSION_MAJOR 2
|
#define UNITY_VERSION_MAJOR 2
|
||||||
#define UNITY_VERSION_MINOR 7
|
#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)
|
#define UNITY_VERSION ((UNITY_VERSION_MAJOR << 16) | (UNITY_VERSION_MINOR << 8) | UNITY_VERSION_BUILD)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
+13
@@ -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) {}
|
||||||
@@ -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 ##########################################
|
#### WITH MOCKS ##########################################
|
||||||
|
|
||||||
{ :name => 'DefaultsThroughOptions',
|
{ :name => 'DefaultsThroughOptions',
|
||||||
|
|||||||
Reference in New Issue
Block a user