runner.c 2.2 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. passed = failed = maxlen = 0;
  19. total = 0.0;
  20. count = sizeof(tests) / sizeof(tests[0]);
  21. fprintf(stderr, CYAN "\nWelcome to cglm tests\n\n" RESET);
  22. srand((unsigned int)time(NULL));
  23. for (i = 0; i < count; i++) {
  24. int32_t len;
  25. entry = tests + i;
  26. len = (int32_t)strlen(entry->name);
  27. maxlen = GLM_MAX(maxlen, len);
  28. }
  29. maxlen += 5;
  30. fprintf(stderr,
  31. BOLDWHITE " %-*s %-*s\n",
  32. maxlen, "Test Name", maxlen, "Elapsed Time");
  33. for (i = 0; i < count; i++) {
  34. entry = tests + i;
  35. start = clock();
  36. st = entry->entry();
  37. end = clock();
  38. elapsed = (end - start) / CLOCKS_PER_SEC;
  39. total += elapsed;
  40. if (!st.status) {
  41. fprintf(stderr,
  42. BOLDRED " " FAIL_TEXT BOLDWHITE " %s " RESET, entry->name);
  43. if (st.msg) {
  44. fprintf(stderr,
  45. YELLOW "- %s" RESET,
  46. st.msg);
  47. }
  48. fprintf(stderr, "\n");
  49. failed++;
  50. } else {
  51. fprintf(stderr, GREEN " " OK_TEXT RESET " %-*s ", maxlen, entry->name);
  52. if (elapsed > 0.01)
  53. fprintf(stderr, YELLOW "%.2fs", elapsed);
  54. else
  55. fprintf(stderr, "0");
  56. fprintf(stderr, "\n" RESET);
  57. passed++;
  58. }
  59. }
  60. if (failed == 0) {
  61. fprintf(stderr,
  62. BOLDGREEN "\n All tests are passed " FINAL_TEXT "\n" RESET);
  63. }
  64. fprintf(stderr,
  65. CYAN "\ncglm test results (%0.2fs):\n" RESET
  66. "--------------------------\n"
  67. MAGENTA "%d" RESET " tests are runned, "
  68. GREEN "%d" RESET " %s passed, "
  69. RED "%d" RESET " %s failed\n\n" RESET,
  70. total,
  71. count,
  72. passed,
  73. passed > 1 ? "are" : "is",
  74. failed,
  75. failed > 1 ? "are" : "is");
  76. return failed;
  77. }