Improve tests in general.

Less spammy core tests: They don't print PASSes now, only logs and failures.

`core:image` and `core:encoding/xml` tests also find their assets relative to `ODIN_ROOT` now.
This commit is contained in:
Jeroen van Rijn
2021-12-05 02:53:09 +01:00
parent d65d6edb0e
commit d7200f6144
8 changed files with 948 additions and 960 deletions
+28 -31
View File
@@ -8,56 +8,53 @@ TEST_count := 0
TEST_fail := 0
when ODIN_TEST {
expect :: testing.expect
log :: testing.log
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)
}
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
TEST_count += 1
if !condition {
TEST_fail += 1
fmt.printf("[%v] %v\n", loc, message)
return
}
}
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
fmt.printf("[%v] LOG:\n\t%v\n", loc, 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)
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)
fmt.printf("\n%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(".", "/:\"")
log(t, index)
expect(t, index == -1, "index_any should be negative")
index := strings.index_any(".", "/:\"")
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", "/:\"")
expect(t, index == -1, "index_any should be negative")
index := strings.index_any("aaaaaaaa.aaaaaaaa", "/:\"")
expect(t, index == -1, "index_any should be negative")
}
@test
test_index_any_small_string_found :: proc(t: ^testing.T) {
index := strings.index_any(".", "/:.\"")
expect(t, index == 0, "index_any should be 0")
index := strings.index_any(".", "/:.\"")
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", "/:\"")
expect(t, index == 8, "index_any should be 8")
index := strings.index_any("aaaaaaaa:aaaaaaaa", "/:\"")
expect(t, index == 8, "index_any should be 8")
}