mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-05-22 01:47:26 +08:00
- Added alias for filter -n of -f
- Added ability to surround filter strings in either type of quotes - Added ability to filter on multiple test strings as a comma delimited list - Added ability to filter on test_file:test_name - Added ability to use alternate syntax for filter of -f="blah"
This commit is contained in:
59
src/unity.c
59
src/unity.c
@ -1323,8 +1323,10 @@ int UnityParseOptions(int argc, char** argv)
|
|||||||
case 'l': /* list tests */
|
case 'l': /* list tests */
|
||||||
return -1;
|
return -1;
|
||||||
case 'n': /* include tests with name including this string */
|
case 'n': /* include tests with name including this string */
|
||||||
i++;
|
case 'f': /* an alias for -n */
|
||||||
if (i < argc)
|
if (argv[i][2] == '=')
|
||||||
|
UnityOptionIncludeNamed = &argv[i][3];
|
||||||
|
else if (++i < argc)
|
||||||
UnityOptionIncludeNamed = argv[i];
|
UnityOptionIncludeNamed = argv[i];
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1340,8 +1342,9 @@ int UnityParseOptions(int argc, char** argv)
|
|||||||
UnityVerbosity = 2;
|
UnityVerbosity = 2;
|
||||||
break;
|
break;
|
||||||
case 'x': /* exclude tests with name including this string */
|
case 'x': /* exclude tests with name including this string */
|
||||||
i++;
|
if (argv[i][2] == '=')
|
||||||
if (i < argc)
|
UnityOptionExcludeNamed = &argv[i][3];
|
||||||
|
else if (++i < argc)
|
||||||
UnityOptionExcludeNamed = argv[i];
|
UnityOptionExcludeNamed = argv[i];
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1381,6 +1384,14 @@ int IsStringInBiggerString(const char* longstring, const char* shortstring)
|
|||||||
/* We're done if we match the entire string or up to a wildcard */
|
/* We're done if we match the entire string or up to a wildcard */
|
||||||
if (*sptr == '*')
|
if (*sptr == '*')
|
||||||
return 1;
|
return 1;
|
||||||
|
if (*sptr == ',')
|
||||||
|
return 1;
|
||||||
|
if (*sptr == '"')
|
||||||
|
return 1;
|
||||||
|
if (*sptr == '\'')
|
||||||
|
return 1;
|
||||||
|
if (*sptr == ':')
|
||||||
|
return 2;
|
||||||
if (*sptr == 0)
|
if (*sptr == 0)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -1394,11 +1405,45 @@ int IsStringInBiggerString(const char* longstring, const char* shortstring)
|
|||||||
|
|
||||||
int UnityStringArgumentMatches(const char* str)
|
int UnityStringArgumentMatches(const char* str)
|
||||||
{
|
{
|
||||||
if (IsStringInBiggerString(Unity.TestFile, str))
|
int retval;
|
||||||
|
const char* ptr1;
|
||||||
|
const char* ptr2;
|
||||||
|
|
||||||
|
//Go through the options and get the substrings for matching one at a time
|
||||||
|
ptr1 = str;
|
||||||
|
while (ptr1[0] != 0)
|
||||||
|
{
|
||||||
|
if ((ptr1[0] == '"') || (ptr1[0] == '\''))
|
||||||
|
ptr1++;
|
||||||
|
|
||||||
|
//look for the start of the next partial
|
||||||
|
ptr2 = ptr1;
|
||||||
|
do {
|
||||||
|
ptr2++;
|
||||||
|
} while ((ptr2[0] != 0) && (ptr2[0] != ':') && (ptr2[0] != '\'') && (ptr2[0] != '"') && (ptr2[0] != ','));
|
||||||
|
while ((ptr2[0] == ':') || (ptr2[0] == '\'') || (ptr2[0] == '"') || (ptr2[0] == ','))
|
||||||
|
ptr2++;
|
||||||
|
|
||||||
|
//done if complete filename match
|
||||||
|
retval = IsStringInBiggerString(Unity.TestFile, ptr1);
|
||||||
|
if (retval == 1)
|
||||||
|
return retval;
|
||||||
|
|
||||||
|
//done if testname match after filename partial match
|
||||||
|
if (retval == 2)
|
||||||
|
{
|
||||||
|
if (IsStringInBiggerString(Unity.CurrentTestName, ptr2))
|
||||||
return 1;
|
return 1;
|
||||||
else if (IsStringInBiggerString(Unity.CurrentTestName, str))
|
}
|
||||||
|
|
||||||
|
//done if complete testname match
|
||||||
|
if (IsStringInBiggerString(Unity.CurrentTestName, ptr1) == 1)
|
||||||
return 1;
|
return 1;
|
||||||
else
|
|
||||||
|
ptr1 = ptr2;
|
||||||
|
}
|
||||||
|
|
||||||
|
//we couldn't find a match for any substrings
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -756,6 +756,24 @@ RUNNER_TESTS = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{ :name => 'ArgsNameFilterTestAndShould',
|
||||||
|
:testfile => 'testdata/testRunnerGenerator.c',
|
||||||
|
:testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
|
||||||
|
:options => {
|
||||||
|
:cmdline_args => true,
|
||||||
|
},
|
||||||
|
:cmdline_args => "-n should_,test_",
|
||||||
|
:expected => {
|
||||||
|
:to_pass => [ 'test_ThisTestAlwaysPasses',
|
||||||
|
'test_NotBeConfusedByLongComplicatedStrings',
|
||||||
|
'test_NotDisappearJustBecauseTheTestBeforeAndAfterHaveCrazyStrings',
|
||||||
|
'test_StillNotBeConfusedByLongComplicatedStrings',
|
||||||
|
'should_RunTestsStartingWithShouldByDefault' ],
|
||||||
|
:to_fail => [ 'test_ThisTestAlwaysFails' ],
|
||||||
|
:to_ignore => [ 'test_ThisTestAlwaysIgnored' ],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
{ :name => 'ArgsExcludeFilterJustTest',
|
{ :name => 'ArgsExcludeFilterJustTest',
|
||||||
:testfile => 'testdata/testRunnerGenerator.c',
|
:testfile => 'testdata/testRunnerGenerator.c',
|
||||||
:testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
|
:testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
|
||||||
@ -807,6 +825,76 @@ RUNNER_TESTS = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{ :name => 'ArgsIncludeSingleTestInSpecificFile',
|
||||||
|
:testfile => 'testdata/testRunnerGenerator.c',
|
||||||
|
:testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
|
||||||
|
:options => {
|
||||||
|
:cmdline_args => true,
|
||||||
|
},
|
||||||
|
:cmdline_args => "-n testRunnerGenerator:ThisTestAlwaysPasses",
|
||||||
|
:expected => {
|
||||||
|
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
|
||||||
|
:to_fail => [ ],
|
||||||
|
:to_ignore => [ ],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
{ :name => 'ArgsIncludeTestFileWithExtension',
|
||||||
|
:testfile => 'testdata/testRunnerGenerator.c',
|
||||||
|
:testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
|
||||||
|
:options => {
|
||||||
|
:cmdline_args => true,
|
||||||
|
},
|
||||||
|
:cmdline_args => "-n testRunnerGenerator.c:ThisTestAlwaysPasses",
|
||||||
|
:expected => {
|
||||||
|
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
|
||||||
|
:to_fail => [ ],
|
||||||
|
:to_ignore => [ ],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
{ :name => 'ArgsIncludeDoubleQuotes',
|
||||||
|
:testfile => 'testdata/testRunnerGenerator.c',
|
||||||
|
:testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
|
||||||
|
:options => {
|
||||||
|
:cmdline_args => true,
|
||||||
|
},
|
||||||
|
:cmdline_args => "-n \"testRunnerGenerator:ThisTestAlwaysPasses,test_ThisTestAlwaysFails\"",
|
||||||
|
:expected => {
|
||||||
|
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
|
||||||
|
:to_fail => [ 'test_ThisTestAlwaysFails' ],
|
||||||
|
:to_ignore => [ ],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
{ :name => 'ArgsIncludeSingleQuotes',
|
||||||
|
:testfile => 'testdata/testRunnerGenerator.c',
|
||||||
|
:testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
|
||||||
|
:options => {
|
||||||
|
:cmdline_args => true,
|
||||||
|
},
|
||||||
|
:cmdline_args => "-n 'testRunnerGenerator:ThisTestAlwaysPasses,test_ThisTestAlwaysFails'",
|
||||||
|
:expected => {
|
||||||
|
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
|
||||||
|
:to_fail => [ 'test_ThisTestAlwaysFails' ],
|
||||||
|
:to_ignore => [ ],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
{ :name => 'ArgsIncludeAValidTestForADifferentFile',
|
||||||
|
:testfile => 'testdata/testRunnerGenerator.c',
|
||||||
|
:testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
|
||||||
|
:options => {
|
||||||
|
:cmdline_args => true,
|
||||||
|
},
|
||||||
|
:cmdline_args => "-n AnotherFile:ThisTestDoesNotExist",
|
||||||
|
:expected => {
|
||||||
|
:to_pass => [ ],
|
||||||
|
:to_fail => [ ],
|
||||||
|
:to_ignore => [ ],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
{ :name => 'ArgsIncludeNoTests',
|
{ :name => 'ArgsIncludeNoTests',
|
||||||
:testfile => 'testdata/testRunnerGenerator.c',
|
:testfile => 'testdata/testRunnerGenerator.c',
|
||||||
:testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
|
:testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
|
||||||
@ -857,6 +945,20 @@ RUNNER_TESTS = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{ :name => 'ArgsIncludeWithAlternateFlag',
|
||||||
|
:testfile => 'testdata/testRunnerGenerator.c',
|
||||||
|
:testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
|
||||||
|
:options => {
|
||||||
|
:cmdline_args => true,
|
||||||
|
},
|
||||||
|
:cmdline_args => "-f=\"testRunnerGenerator:ThisTestAlwaysPasses,test_ThisTestAlwaysFails\"",
|
||||||
|
:expected => {
|
||||||
|
:to_pass => [ 'test_ThisTestAlwaysPasses' ],
|
||||||
|
:to_fail => [ 'test_ThisTestAlwaysFails' ],
|
||||||
|
:to_ignore => [ ],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
{ :name => 'ArgsIncludeWithParameterized',
|
{ :name => 'ArgsIncludeWithParameterized',
|
||||||
:testfile => 'testdata/testRunnerGenerator.c',
|
:testfile => 'testdata/testRunnerGenerator.c',
|
||||||
:testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
|
:testdefines => ['TEST', 'UNITY_USE_COMMAND_LINE_ARGS'],
|
||||||
|
Reference in New Issue
Block a user