unit-test-app: Fix capability to use !<filter> to inverse that filter

This commit is contained in:
Anton Maklakov 2017-06-01 12:11:45 +08:00
parent 5389329729
commit 144d345b3b

View File

@ -16,6 +16,8 @@
static struct test_desc_t* s_unity_tests_first = NULL;
static struct test_desc_t* s_unity_tests_last = NULL;
// Inverse of the filter
static bool s_invert = false;
void unity_putc(int c)
{
@ -73,8 +75,33 @@ static void unity_run_single_test_by_index(int index)
}
static void unity_run_single_test_by_index_parse(const char* filter, int index_max)
{
if (s_invert)
{
printf("Inverse is not supported for that kind of filter\n");
return;
}
int test_index = strtol(filter, NULL, 10);
if (test_index >= 1 && test_index <= index_max)
{
uint32_t start;
RSR(CCOUNT, start);
unity_run_single_test_by_index(test_index - 1);
uint32_t end;
RSR(CCOUNT, end);
uint32_t ms = (end - start) / (XT_CLOCK_FREQ / 1000);
printf("Test ran in %dms\n", ms);
}
}
static void unity_run_single_test_by_name(const char* filter)
{
{
if (s_invert)
{
printf("Inverse is not supported for that kind of filter\n");
return;
}
char tmp[256];
strncpy(tmp, filter + 1, sizeof(tmp) - 1);
tmp[strlen(filter) - 2] = 0;
@ -89,6 +116,11 @@ static void unity_run_single_test_by_name(const char* filter)
void unity_run_all_tests()
{
if (s_invert)
{
printf("Inverse is not supported for that kind of filter\n");
return;
}
for (const struct test_desc_t* test = s_unity_tests_first; test != NULL; test = test->next)
{
unity_run_single_test(test);
@ -97,13 +129,14 @@ void unity_run_all_tests()
void unity_run_tests_with_filter(const char* filter)
{
bool invert = filter[0] == '!';
if (invert) {
filter++;
if (s_invert)
{
++filter;
}
for (const struct test_desc_t* test = s_unity_tests_first; test != NULL; test = test->next)
{
if ((strstr(test->desc, filter) != NULL) == !invert)
if ((strstr(test->desc, filter) != NULL) == !s_invert)
{
unity_run_single_test(test);
}
@ -155,31 +188,32 @@ void unity_run_menu()
UNITY_BEGIN();
if (cmdline[0] == '*')
size_t idx = 0;
if (cmdline[idx] == '!')
{
unity_run_all_tests();
}
else if (cmdline[0] =='[')
{
unity_run_tests_with_filter(cmdline);
}
else if (cmdline[0] =='"')
{
unity_run_single_test_by_name(cmdline);
s_invert = true;
++idx;
}
else
{
int test_index = strtol(cmdline, NULL, 10);
if (test_index >= 1 && test_index <= test_count)
{
uint32_t start;
RSR(CCOUNT, start);
unity_run_single_test_by_index(test_index - 1);
uint32_t end;
RSR(CCOUNT, end);
uint32_t ms = (end - start) / (XT_CLOCK_FREQ / 1000);
printf("Test ran in %dms\n", ms);
}
s_invert = false;
}
if (cmdline[idx] == '*')
{
unity_run_all_tests();
}
else if (cmdline[idx] =='[')
{
unity_run_tests_with_filter(cmdline + idx);
}
else if (cmdline[idx] =='"')
{
unity_run_single_test_by_name(cmdline + idx);
}
else if (isdigit((unsigned char)cmdline[idx]))
{
unity_run_single_test_by_index_parse(cmdline + idx, test_count);
}
UNITY_END();
@ -187,4 +221,3 @@ void unity_run_menu()
printf("Enter next test, or 'enter' to see menu\n");
}
}