mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-01-23 08:25:58 +01:00
Merge pull request #634 from erijo/test-case-space
Improve handling of space in TEST_CASE/RANGE (Thanks @erijo !)
This commit is contained in:
@@ -140,10 +140,15 @@ class UnityTestRunnerGenerator
|
|||||||
|
|
||||||
if @options[:use_param_tests] && !arguments.empty?
|
if @options[:use_param_tests] && !arguments.empty?
|
||||||
args = []
|
args = []
|
||||||
arguments.scan(/\s*TEST_CASE\s*\(\s*(.*)\s*\)\s*$/) { |a| args << a[0] }
|
type_and_args = arguments.split(/TEST_(CASE|RANGE)/)
|
||||||
|
for i in (1...type_and_args.length).step(2)
|
||||||
|
if type_and_args[i] == "CASE"
|
||||||
|
args << type_and_args[i + 1].sub(/^\s*\(\s*(.*?)\s*\)\s*$/m, '\1')
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
arguments.scan(/\s*TEST_RANGE\s*\((.*)\)\s*$/).flatten.each do |range_str|
|
# RANGE
|
||||||
args += range_str.scan(/\[\s*(-?\d+.?\d*),\s*(-?\d+.?\d*),\s*(-?\d+.?\d*)\s*\]/).map do |arg_values_str|
|
args += type_and_args[i + 1].scan(/\[\s*(-?\d+.?\d*)\s*,\s*(-?\d+.?\d*)\s*,\s*(-?\d+.?\d*)\s*\]/m).map do |arg_values_str|
|
||||||
arg_values_str.map do |arg_value_str|
|
arg_values_str.map do |arg_value_str|
|
||||||
arg_value_str.include?('.') ? arg_value_str.to_f : arg_value_str.to_i
|
arg_value_str.include?('.') ? arg_value_str.to_f : arg_value_str.to_i
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
/* Support for Meta Test Rig */
|
/* Support for Meta Test Rig */
|
||||||
#define TEST_CASE(...)
|
#define TEST_CASE(...)
|
||||||
|
#define TEST_RANGE(...)
|
||||||
|
|
||||||
/* Include Passthroughs for Linking Tests */
|
/* Include Passthroughs for Linking Tests */
|
||||||
void putcharSpy(int c) { (void)putchar(c);}
|
void putcharSpy(int c) { (void)putchar(c);}
|
||||||
@@ -48,11 +49,13 @@ static int SetToOneToFailInTearDown;
|
|||||||
static int SetToOneMeanWeAlreadyCheckedThisGuy;
|
static int SetToOneMeanWeAlreadyCheckedThisGuy;
|
||||||
static unsigned NextExpectedStringIndex;
|
static unsigned NextExpectedStringIndex;
|
||||||
static unsigned NextExpectedCharIndex;
|
static unsigned NextExpectedCharIndex;
|
||||||
|
static unsigned NextExpectedSpaceIndex;
|
||||||
|
|
||||||
void suiteSetUp(void)
|
void suiteSetUp(void)
|
||||||
{
|
{
|
||||||
NextExpectedStringIndex = 0;
|
NextExpectedStringIndex = 0;
|
||||||
NextExpectedCharIndex = 0;
|
NextExpectedCharIndex = 0;
|
||||||
|
NextExpectedSpaceIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setUp(void)
|
void setUp(void)
|
||||||
@@ -169,3 +172,25 @@ void test_CharsArePreserved(unsigned index, char c)
|
|||||||
|
|
||||||
NextExpectedCharIndex++;
|
NextExpectedCharIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE(0,
|
||||||
|
|
||||||
|
1)
|
||||||
|
TEST_CASE(1,
|
||||||
|
|
||||||
|
2
|
||||||
|
|
||||||
|
)
|
||||||
|
TEST_RANGE([2,
|
||||||
|
5 ,
|
||||||
|
1], [6, 6, 1])
|
||||||
|
TEST_CASE(
|
||||||
|
|
||||||
|
6 , 7)
|
||||||
|
void test_SpaceInTestCase(unsigned index, unsigned bigger)
|
||||||
|
{
|
||||||
|
TEST_ASSERT_EQUAL_UINT32(NextExpectedSpaceIndex, index);
|
||||||
|
TEST_ASSERT_LESS_THAN(bigger, index);
|
||||||
|
|
||||||
|
NextExpectedSpaceIndex++;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user