Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New command line options for fixtures #762

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 51 additions & 14 deletions extras/fixture/src/unity_fixture.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,25 @@ int UnityMain(int argc, const char* argv[], void (*runAllTests)(void))
return (int)Unity.TestFailures;
}

static int selected(const char* filter, const char* name)
static int selected(const char* filter, const char* select, const char* name)
{
if (filter == 0)
if (filter == 0 && select == 0)
return 1;
return strstr(name, filter) ? 1 : 0;
if (filter && strstr(name, filter))
return 1;
if (select && strcmp(name, select) == 0)
return 1;
return 0;
}

static int testSelected(const char* test)
{
return selected(UnityFixture.NameFilter, test);
return selected(UnityFixture.NameFilter, UnityFixture.Name, test);
}

static int groupSelected(const char* group)
{
return selected(UnityFixture.GroupFilter, group);
return selected(UnityFixture.GroupFilter, UnityFixture.Group, group);
}

void UnityTestRunner(unityfunction* setup,
Expand Down Expand Up @@ -96,17 +100,20 @@ void UnityTestRunner(unityfunction* setup,
Unity.NumberOfTests++;
UnityPointer_Init();

UNITY_EXEC_TIME_START();
if (!UnityFixture.DryRun) {
UNITY_EXEC_TIME_START();

if (TEST_PROTECT())
{
setup();
testBody();
}
if (TEST_PROTECT())
{
teardown();
if (TEST_PROTECT())
{
setup();
testBody();
}
if (TEST_PROTECT())
{
teardown();
}
}

if (TEST_PROTECT())
{
UnityPointer_UndoAllSets();
Expand Down Expand Up @@ -183,8 +190,11 @@ int UnityGetCommandLineOptions(int argc, const char* argv[])
int i;
UnityFixture.Verbose = 0;
UnityFixture.Silent = 0;
UnityFixture.DryRun = 0;
UnityFixture.GroupFilter = 0;
UnityFixture.Group = 0;
UnityFixture.NameFilter = 0;
UnityFixture.Name = 0;
UnityFixture.RepeatCount = 1;

if (argc == 1)
Expand All @@ -207,10 +217,16 @@ int UnityGetCommandLineOptions(int argc, const char* argv[])
UNITY_PRINT_EOL();
UnityPrint(" -s Silent mode: minimal output showing only test failures");
UNITY_PRINT_EOL();
UnityPrint(" -d Dry run all tests");
UNITY_PRINT_EOL();
UnityPrint(" -g NAME Only run tests in groups that contain the string NAME");
UNITY_PRINT_EOL();
UnityPrint(" -G NAME Only run tests in groups named NAME");
UNITY_PRINT_EOL();
UnityPrint(" -n NAME Only run tests whose name contains the string NAME");
UNITY_PRINT_EOL();
UnityPrint(" -N NAME Only run tests named NAME");
UNITY_PRINT_EOL();
UnityPrint(" -r NUMBER Repeatedly run all tests NUMBER times");
UNITY_PRINT_EOL();
UnityPrint(" -h, --help Display this help message");
Expand All @@ -237,6 +253,11 @@ int UnityGetCommandLineOptions(int argc, const char* argv[])
UnityFixture.Silent = 1;
i++;
}
else if (strcmp(argv[i], "-d") == 0)
{
UnityFixture.DryRun = 1;
i++;
}
else if (strcmp(argv[i], "-g") == 0)
{
i++;
Expand All @@ -245,6 +266,14 @@ int UnityGetCommandLineOptions(int argc, const char* argv[])
UnityFixture.GroupFilter = argv[i];
i++;
}
else if (strcmp(argv[i], "-G") == 0)
{
i++;
if (i >= argc)
return 1;
UnityFixture.Group= argv[i];
i++;
}
else if (strcmp(argv[i], "-n") == 0)
{
i++;
Expand All @@ -253,6 +282,14 @@ int UnityGetCommandLineOptions(int argc, const char* argv[])
UnityFixture.NameFilter = argv[i];
i++;
}
else if (strcmp(argv[i], "-N") == 0)
{
i++;
if (i >= argc)
return 1;
UnityFixture.Name = argv[i];
i++;
}
else if (strcmp(argv[i], "-r") == 0)
{
UnityFixture.RepeatCount = 2;
Expand Down
3 changes: 3 additions & 0 deletions extras/fixture/src/unity_fixture_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ struct UNITY_FIXTURE_T
{
int Verbose;
int Silent;
int DryRun;
unsigned int RepeatCount;
const char* NameFilter;
const char* Name;
const char* GroupFilter;
const char* Group;
};
extern struct UNITY_FIXTURE_T UnityFixture;

Expand Down
Loading