Custom test runner.

This commit is contained in:
Jeroen van Rijn
2021-09-08 21:17:16 +02:00
parent 027d69678a
commit e6905f8657
4 changed files with 85 additions and 23 deletions
+39 -5
View File
@@ -2,28 +2,62 @@ package test_core_image
import "core:strings"
import "core:testing"
import "core:fmt"
TEST_count := 0
TEST_fail := 0
when ODIN_TEST {
expect :: testing.expect
log :: testing.log
} else {
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
fmt.printf("[%v] ", loc)
TEST_count += 1
if !condition {
TEST_fail += 1
fmt.println(message)
return
}
fmt.println(" PASS")
}
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
fmt.printf("[%v] ", loc)
fmt.printf("log: %v\n", v)
}
}
main :: proc() {
t := testing.T{}
test_index_any_small_string_not_found(&t)
test_index_any_larger_string_not_found(&t)
test_index_any_small_string_found(&t)
test_index_any_larger_string_found(&t)
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
}
@test
test_index_any_small_string_not_found :: proc(t: ^testing.T) {
index := strings.index_any(".", "/:\"")
testing.log(t, index)
testing.expect(t, index == -1, "index_any should be negative")
log(t, index)
expect(t, index == -1, "index_any should be negative")
}
@test
test_index_any_larger_string_not_found :: proc(t: ^testing.T) {
index := strings.index_any("aaaaaaaa.aaaaaaaa", "/:\"")
testing.expect(t, index == -1, "index_any should be negative")
expect(t, index == -1, "index_any should be negative")
}
@test
test_index_any_small_string_found :: proc(t: ^testing.T) {
index := strings.index_any(".", "/:.\"")
testing.expect(t, index == 0, "index_any should be 0")
expect(t, index == 0, "index_any should be 0")
}
@test
test_index_any_larger_string_found :: proc(t: ^testing.T) {
index := strings.index_any("aaaaaaaa:aaaaaaaa", "/:\"")
testing.expect(t, index == 8, "index_any should be 8")
expect(t, index == 8, "index_any should be 8")
}