Skip to content

Commit

Permalink
Merge a347d99 into 2efb946
Browse files Browse the repository at this point in the history
  • Loading branch information
basvodde committed Apr 28, 2020
2 parents 2efb946 + a347d99 commit 5e14643
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/CppUTest/CommandLineArguments.h
Expand Up @@ -92,6 +92,7 @@ class CommandLineArguments
void setRepeatCount(int ac, const char *const *av, int& index);
bool setShuffle(int ac, const char *const *av, int& index);
void addGroupFilter(int ac, const char *const *av, int& index);
bool addGroupDotNameFilter(int ac, const char *const *av, int& index);
void addStrictGroupFilter(int ac, const char *const *av, int& index);
void addExcludeGroupFilter(int ac, const char *const *av, int& index);
void addExcludeStrictGroupFilter(int ac, const char *const *av, int& index);
Expand Down
19 changes: 18 additions & 1 deletion src/CppUTest/CommandLineArguments.cpp
Expand Up @@ -64,6 +64,7 @@ bool CommandLineArguments::parse(TestPlugin* plugin)
else if (argument == "-ri") runIgnored_ = true;
else if (argument.startsWith("-r")) setRepeatCount(ac_, av_, i);
else if (argument.startsWith("-g")) addGroupFilter(ac_, av_, i);
else if (argument.startsWith("-t")) correctParameters = addGroupDotNameFilter(ac_, av_, i);
else if (argument.startsWith("-sg")) addStrictGroupFilter(ac_, av_, i);
else if (argument.startsWith("-xg")) addExcludeGroupFilter(ac_, av_, i);
else if (argument.startsWith("-xsg")) addExcludeStrictGroupFilter(ac_, av_, i);
Expand All @@ -88,7 +89,9 @@ bool CommandLineArguments::parse(TestPlugin* plugin)

const char* CommandLineArguments::usage() const
{
return "use -h for more extensive help\nusage [-h] [-v] [-c] [-p] [-lg] [-ln] [-ri] [-r#] [-g|sg|xg|xsg groupName]... [-n|sn|xn|xsn testName]... [-b] [-s [randomizerSeed>0]] [\"TEST(groupName, testName)\"]... [-o{normal, junit, teamcity}] [-k packageName]\n";
return "use -h for more extensive help\nusage [-h] [-v] [-c] [-p] [-lg] [-ln] [-ri] [-r#]\n"
" [-g|sg|xg|xsg groupName]... [-n|sn|xn|xsn testName]... [-t groupName.testName]...\n"
" [-b] [-s [randomizerSeed>0]] [\"TEST(groupName, testName)\"]... [-o{normal, junit, teamcity}] [-k packageName]\n";
}

const char* CommandLineArguments::help() const
Expand All @@ -114,6 +117,7 @@ const char* CommandLineArguments::help() const
"Options that control which tests are run:\n"
" -g group - only run test whose group contains the substring group\n"
" -n name - only run test whose name contains the substring name\n"
" -t group.name - only run test whose name contains the substring group and name\n"
" -sg group - only run test whose group exactly matches the string group\n"
" -sn name - only run test whose name exactly matches the string name\n"
" -xg group - exclude tests whose group contains the substring group (v3.8)\n"
Expand Down Expand Up @@ -246,6 +250,19 @@ void CommandLineArguments::addGroupFilter(int ac, const char *const *av, int& i)
groupFilters_ = groupFilter->add(groupFilters_);
}

bool CommandLineArguments::addGroupDotNameFilter(int ac, const char *const *av, int& i)
{
SimpleString groupDotName = getParameterField(ac, av, i, "-t");
SimpleStringCollection collection;
groupDotName.split(".", collection);

if (collection.size() != 2) return false;

groupFilters_ = (new TestFilter(collection[0].subString(0, collection[0].size()-1)))->add(groupFilters_);
nameFilters_ = (new TestFilter(collection[1]))->add(nameFilters_);
return true;
}

void CommandLineArguments::addStrictGroupFilter(int ac, const char *const *av, int& i)
{
TestFilter* groupFilter = new TestFilter(getParameterField(ac, av, i, "-sg"));
Expand Down
20 changes: 19 additions & 1 deletion tests/CppUTest/CommandLineArgumentsTest.cpp
Expand Up @@ -193,6 +193,22 @@ TEST(CommandLineArguments, setGroupFilter)
CHECK_EQUAL(TestFilter("group"), *args->getGroupFilters());
}

TEST(CommandLineArguments, setCompleteGroupDotNameFilterInvalidArgument)
{
int argc = 3;
const char* argv[] = { "tests.exe", "-t", "groupname" };
CHECK_FALSE(newArgumentParser(argc, argv));
}
TEST(CommandLineArguments, setCompleteGroupDotNameFilter)
{
int argc = 3;
const char* argv[] = { "tests.exe", "-t", "group.name" };
CHECK(newArgumentParser(argc, argv));
CHECK_EQUAL(TestFilter("group"), *args->getGroupFilters());
CHECK_EQUAL(TestFilter("name"), *args->getNameFilters());
}


TEST(CommandLineArguments, setGroupFilterSameParameter)
{
int argc = 2;
Expand Down Expand Up @@ -441,7 +457,9 @@ TEST(CommandLineArguments, weirdParamatersReturnsFalse)

TEST(CommandLineArguments, printUsage)
{
STRCMP_EQUAL("use -h for more extensive help\nusage [-h] [-v] [-c] [-p] [-lg] [-ln] [-ri] [-r#] [-g|sg|xg|xsg groupName]... [-n|sn|xn|xsn testName]... [-b] [-s [randomizerSeed>0]] [\"TEST(groupName, testName)\"]... [-o{normal, junit, teamcity}] [-k packageName]\n",
STRCMP_EQUAL("use -h for more extensive help\nusage [-h] [-v] [-c] [-p] [-lg] [-ln] [-ri] [-r#]\n"
" [-g|sg|xg|xsg groupName]... [-n|sn|xn|xsn testName]... [-t groupName.testName]...\n"
" [-b] [-s [randomizerSeed>0]] [\"TEST(groupName, testName)\"]... [-o{normal, junit, teamcity}] [-k packageName]\n",
args->usage());
}

Expand Down

0 comments on commit 5e14643

Please sign in to comment.