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)
{
}
+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;
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);
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);
}
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();
printf("Enter next test, or 'enter' to see menu\n");
}
}
-