|
|
@@ -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] == '!')
|
|
|
+ {
|
|
|
+ s_invert = true;
|
|
|
+ ++idx;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ s_invert = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (cmdline[idx] == '*')
|
|
|
{
|
|
|
unity_run_all_tests();
|
|
|
}
|
|
|
- else if (cmdline[0] =='[')
|
|
|
+ else if (cmdline[idx] =='[')
|
|
|
{
|
|
|
- unity_run_tests_with_filter(cmdline);
|
|
|
+ unity_run_tests_with_filter(cmdline + idx);
|
|
|
}
|
|
|
- else if (cmdline[0] =='"')
|
|
|
+ else if (cmdline[idx] =='"')
|
|
|
{
|
|
|
- unity_run_single_test_by_name(cmdline);
|
|
|
+ unity_run_single_test_by_name(cmdline + idx);
|
|
|
}
|
|
|
- else
|
|
|
+ else if (isdigit((unsigned char)cmdline[idx]))
|
|
|
{
|
|
|
- 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);
|
|
|
- }
|
|
|
+ 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");
|
|
|
}
|
|
|
}
|
|
|
-
|