runner.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c), Recep Aslantas.
  3. *
  4. * MIT License (MIT), http://opensource.org/licenses/MIT
  5. * Full license can be found in the LICENSE file
  6. */
  7. #include "include/common.h"
  8. #include "tests.h"
  9. #include <stdlib.h>
  10. #include <time.h>
  11. #include <string.h>
  12. int
  13. main(int argc, const char * argv[]) {
  14. test_entry_t *entry;
  15. test_status_t st;
  16. int32_t i, count, passed, failed, maxlen;
  17. double start, end, elapsed, total;
  18. (void)argc;
  19. (void)argv;
  20. passed = failed = maxlen = 0;
  21. total = 0.0;
  22. count = sizeof(tests) / sizeof(tests[0]);
  23. fprintf(stderr, CYAN "\nWelcome to cglm tests\n\n" RESET);
  24. srand((unsigned int)time(NULL));
  25. for (i = 0; i < count; i++) {
  26. int32_t len;
  27. entry = tests + i;
  28. len = (int32_t)strlen(entry->name);
  29. maxlen = GLM_MAX(maxlen, len);
  30. }
  31. maxlen += 5;
  32. fprintf(stderr,
  33. BOLDWHITE " %-*s %-*s\n",
  34. maxlen, "Test Name", maxlen, "Elapsed Time");
  35. for (i = 0; i < count; i++) {
  36. entry = tests + i;
  37. start = clock();
  38. st = entry->entry();
  39. end = clock();
  40. elapsed = (end - start) / CLOCKS_PER_SEC;
  41. total += elapsed;
  42. if (!st.status) {
  43. fprintf(stderr,
  44. BOLDRED " " FAIL_TEXT BOLDWHITE " %s " RESET, entry->name);
  45. if (st.msg) {
  46. fprintf(stderr,
  47. YELLOW "- %s" RESET,
  48. st.msg);
  49. }
  50. fprintf(stderr, "\n");
  51. failed++;
  52. } else {
  53. fprintf(stderr, GREEN " " OK_TEXT RESET " %-*s ", maxlen, entry->name);
  54. if (elapsed > 0.01)
  55. fprintf(stderr, YELLOW "%.2fs", elapsed);
  56. else
  57. fprintf(stderr, "0");
  58. fprintf(stderr, "\n" RESET);
  59. passed++;
  60. }
  61. }
  62. if (failed == 0) {
  63. fprintf(stderr,
  64. BOLDGREEN "\n All tests passed " FINAL_TEXT "\n" RESET);
  65. }
  66. fprintf(stderr,
  67. CYAN "\ncglm test results (%0.2fs):\n" RESET
  68. "--------------------------\n"
  69. MAGENTA "%d" RESET " tests ran, "
  70. GREEN "%d" RESET " passed, "
  71. RED "%d" RESET " failed\n\n" RESET,
  72. total,
  73. count,
  74. passed,
  75. failed);
  76. return failed;
  77. }