static int is_list_tests(int argc, char *argv[], unit_test_t *tests) { int i, size = tests->size; char *list_comment = tests->list_comment; test_t *arr = tests->arr; if (argc != 2 || strcmp(argv[1], "list")) return 0; p_colour(C_HIGHLIGHT, "%s unit tests%s%s%s\n", app_name(argv[0]), list_comment ? " (" : "", list_comment ? list_comment : "", list_comment ? ")" : ""); for (i = 0; i < size - 1; i++) { test_t *t = &arr[i]; int is_disabled = UT_DISABLED(tests, t); printf("%i. ", i + 1); p_colour(is_disabled ? C_GREY : C_NORMAL, "%s", t->description); if (is_disabled) { p_colour(C_CYAN, " (disabled)"); } else if (t->known_issue) { p_colour(C_BLUE, " (known issue: "); p_colour(C_GREY, t->known_issue); p_colour(C_BLUE, ")"); } printf("\n"); } return 1; }
int unit_test(int argc, char *argv[], unit_test_t *tests) { test_t *t; int from, to, max = tests->size, ret; int total = 0, disabled = 0, passed = 0, failed = 0, known_issues = 0; if (tests->tests_init) tests->tests_init(argc, argv); if (is_list_tests(argc, argv, tests)) return 0; if (test_getargs(argc, argv, &from, &to, max - 1)) return -1; for (t = &tests->arr[from]; t < tests->arr + MIN(to, max); t++) { first_comment = 1; total++; printf("%i. %s: ", from + total, t->description); if (UT_DISABLED(tests, t)) { disabled++; p_colour(C_CYAN, "disabled\n"); continue; } if (t->known_issue) { p_colour(C_BLUE, "known issue: "); p_colour(C_NORMAL, "%s\n", t->known_issue); known_issues++; continue; } if (!t->func) { p_colour(C_CYAN, "function does not exist\n"); return -1; } fflush(stdout); if (tests->pre_test) tests->pre_test(); if ((ret = t->func())) { p_colour(C_RED, "Failed"); failed++; } else { p_colour(C_GREEN, "OK"); passed++; } printf("\n"); } p_test_summery(total, passed, failed, known_issues, disabled, tests->summery_comment); return 0; }
int key() const { return p_colour() + rank/(p_grp_size*group_size)*p_grp_size; }