runner.odin 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //+private
  2. package testing
  3. import "core:io"
  4. import "core:os"
  5. import "core:slice"
  6. reset_t :: proc(t: ^T) {
  7. clear(&t.cleanups)
  8. t.error_count = 0
  9. }
  10. end_t :: proc(t: ^T) {
  11. for i := len(t.cleanups)-1; i >= 0; i -= 1 {
  12. c := t.cleanups[i]
  13. c.procedure(c.user_data)
  14. }
  15. }
  16. runner :: proc(internal_tests: []Internal_Test) -> bool {
  17. stream := os.stream_from_handle(os.stdout)
  18. w := io.to_writer(stream)
  19. t := &T{}
  20. t.w = w
  21. reserve(&t.cleanups, 1024)
  22. defer delete(t.cleanups)
  23. total_success_count := 0
  24. total_test_count := len(internal_tests)
  25. slice.sort_by(internal_tests, proc(a, b: Internal_Test) -> bool {
  26. if a.pkg < b.pkg {
  27. return true
  28. }
  29. return a.name < b.name
  30. })
  31. prev_pkg := ""
  32. for it in internal_tests {
  33. if it.p == nil {
  34. total_test_count -= 1
  35. continue
  36. }
  37. free_all(context.temp_allocator)
  38. reset_t(t)
  39. defer end_t(t)
  40. if prev_pkg != it.pkg {
  41. prev_pkg = it.pkg
  42. logf(t, "[Package: %s]", it.pkg)
  43. }
  44. logf(t, "[Test: %s]", it.name)
  45. run_internal_test(t, it)
  46. if failed(t) {
  47. logf(t, "[%s : FAILURE]", it.name)
  48. } else {
  49. logf(t, "[%s : SUCCESS]", it.name)
  50. total_success_count += 1
  51. }
  52. }
  53. logf(t, "----------------------------------------")
  54. if total_test_count == 0 {
  55. log(t, "NO TESTS RAN")
  56. } else {
  57. logf(t, "%d/%d SUCCESSFUL", total_success_count, total_test_count)
  58. }
  59. return total_success_count == total_test_count
  60. }