test_core_testing.odin 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package test_core_testing
  2. import "core:c/libc"
  3. import "core:math/rand"
  4. import "core:testing"
  5. @test
  6. test_expected_assert :: proc(t: ^testing.T) {
  7. target := #location(); target.line += 2; target.column = 2
  8. testing.expect_assert_from(t, target)
  9. assert(false)
  10. }
  11. @test
  12. test_expected_two_assert :: proc(t: ^testing.T) {
  13. target1 := #location(); target1.line += 5; target1.column = 3
  14. target2 := #location(); target2.line += 6; target2.column = 3
  15. testing.expect_assert_from(t, target1)
  16. testing.expect_assert_from(t, target2)
  17. if rand.uint32() & 1 == 0 {
  18. assert(false)
  19. } else {
  20. assert(false)
  21. }
  22. }
  23. some_proc :: proc() {
  24. assert(false)
  25. }
  26. @test
  27. test_expected_assert_in_proc :: proc(t: ^testing.T) {
  28. target := #location(some_proc)
  29. target.line += 1
  30. target.column = 2
  31. assert(target.procedure == "", "The bug's been fixed; this line and the next can be deleted.")
  32. target.procedure = "some_proc" // TODO: Is this supposed to be blank on #location(...)?
  33. testing.expect_assert(t, target)
  34. some_proc()
  35. }
  36. @test
  37. test_expected_assert_message :: proc(t: ^testing.T) {
  38. testing.expect_assert(t, "failure")
  39. assert(false, "failure")
  40. }
  41. @test
  42. test_expected_signal :: proc(t: ^testing.T) {
  43. testing.expect_signal(t, libc.SIGILL)
  44. libc.raise(libc.SIGILL)
  45. }