mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 08:08:50 +00:00
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:
@@ -30,18 +30,15 @@ when ODIN_TEST {
|
|||||||
log :: testing.log
|
log :: testing.log
|
||||||
} else {
|
} else {
|
||||||
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
||||||
fmt.printf("[%v] ", loc)
|
|
||||||
TEST_count += 1
|
TEST_count += 1
|
||||||
if !condition {
|
if !condition {
|
||||||
TEST_fail += 1
|
TEST_fail += 1
|
||||||
fmt.println(message)
|
fmt.printf("[%v] %v\n", loc, message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.println(" PASS")
|
|
||||||
}
|
}
|
||||||
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
||||||
fmt.printf("[%v] ", loc)
|
fmt.printf("[%v] LOG:\n\t%v\n", loc, v)
|
||||||
fmt.printf("log: %v\n", v)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +48,7 @@ main :: proc() {
|
|||||||
zlib_test(&t)
|
zlib_test(&t)
|
||||||
gzip_test(&t)
|
gzip_test(&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
|
||||||
|
|||||||
@@ -45,18 +45,15 @@ when ODIN_TEST {
|
|||||||
log :: testing.log
|
log :: testing.log
|
||||||
} else {
|
} else {
|
||||||
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
||||||
fmt.printf("[%v] ", loc)
|
|
||||||
TEST_count += 1
|
TEST_count += 1
|
||||||
if !condition {
|
if !condition {
|
||||||
TEST_fail += 1
|
TEST_fail += 1
|
||||||
fmt.println(message)
|
fmt.printf("[%v] %v\n", loc, message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.println(" PASS")
|
|
||||||
}
|
}
|
||||||
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
||||||
fmt.printf("[%v] ", loc)
|
fmt.printf("[%v] LOG:\n\t%v\n", loc, v)
|
||||||
fmt.printf("log: %v\n", v)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +121,7 @@ main :: proc() {
|
|||||||
|
|
||||||
bench_modern(&t)
|
bench_modern(&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)
|
||||||
}
|
}
|
||||||
|
|
||||||
TestHash :: struct {
|
TestHash :: struct {
|
||||||
|
|||||||
@@ -12,18 +12,15 @@ when ODIN_TEST {
|
|||||||
log :: testing.log
|
log :: testing.log
|
||||||
} else {
|
} else {
|
||||||
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
||||||
fmt.printf("[%v] ", loc)
|
|
||||||
TEST_count += 1
|
TEST_count += 1
|
||||||
if !condition {
|
if !condition {
|
||||||
TEST_fail += 1
|
TEST_fail += 1
|
||||||
fmt.println(message)
|
fmt.printf("[%v] %v\n", loc, message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.println(" PASS")
|
|
||||||
}
|
}
|
||||||
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
||||||
fmt.printf("[%v] ", loc)
|
fmt.printf("[%v] LOG:\n\t%v\n", loc, v)
|
||||||
fmt.printf("log: %v\n", v)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +30,7 @@ main :: proc() {
|
|||||||
parse_json(&t)
|
parse_json(&t)
|
||||||
marshal_json(&t)
|
marshal_json(&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
|
||||||
|
|||||||
@@ -177,18 +177,15 @@ when ODIN_TEST {
|
|||||||
log :: testing.log
|
log :: testing.log
|
||||||
} else {
|
} else {
|
||||||
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
||||||
fmt.printf("[%v] ", loc)
|
|
||||||
TEST_count += 1
|
TEST_count += 1
|
||||||
if !condition {
|
if !condition {
|
||||||
TEST_fail += 1
|
TEST_fail += 1
|
||||||
fmt.println(message)
|
fmt.printf("[%v] %v\n", loc, message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.println(" PASS")
|
|
||||||
}
|
}
|
||||||
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
||||||
fmt.printf("[%v] ", loc)
|
fmt.printf("[%v] LOG:\n\t%v\n", loc, v)
|
||||||
fmt.printf("log: %v\n", v)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,7 +290,7 @@ run_tests :: proc(t: ^testing.T) {
|
|||||||
|
|
||||||
for test in TESTS {
|
for test in TESTS {
|
||||||
path := test_file_path(test.filename)
|
path := test_file_path(test.filename)
|
||||||
printf("\nTrying to parse %v\n\n", path)
|
log(t, fmt.tprintf("Trying to parse %v", path))
|
||||||
|
|
||||||
doc, err := xml.parse(path, test.options, Silent)
|
doc, err := xml.parse(path, test.options, Silent)
|
||||||
defer xml.destroy(doc)
|
defer xml.destroy(doc)
|
||||||
@@ -338,5 +335,5 @@ main :: proc() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
@@ -14,18 +14,15 @@ when ODIN_TEST {
|
|||||||
log :: testing.log
|
log :: testing.log
|
||||||
} else {
|
} else {
|
||||||
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
||||||
fmt.printf("[%v] ", loc)
|
|
||||||
TEST_count += 1
|
TEST_count += 1
|
||||||
if !condition {
|
if !condition {
|
||||||
TEST_fail += 1
|
TEST_fail += 1
|
||||||
fmt.println(" FAIL:", message)
|
fmt.printf("[%v] %v", loc, message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.println(" PASS")
|
|
||||||
}
|
}
|
||||||
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
||||||
fmt.printf("[%v] ", loc)
|
fmt.printf("[%v] LOG:\n\t%v\n", loc, v)
|
||||||
fmt.printf("log: %v\n", v)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,7 +31,7 @@ main :: proc() {
|
|||||||
test_benchmark_runner(&t)
|
test_benchmark_runner(&t)
|
||||||
test_xxhash_vectors(&t)
|
test_xxhash_vectors(&t)
|
||||||
test_crc64_vectors(&t)
|
test_crc64_vectors(&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)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import "core:time"
|
|||||||
import "core:runtime"
|
import "core:runtime"
|
||||||
|
|
||||||
WRITE_PPM_ON_FAIL :: #config(WRITE_PPM_ON_FAIL, false)
|
WRITE_PPM_ON_FAIL :: #config(WRITE_PPM_ON_FAIL, false)
|
||||||
TEST_SUITE_PATH :: "assets/PNG"
|
TEST_FILE_PATH_PREFIX :: "tests/core/assets/PNG"
|
||||||
|
|
||||||
TEST_count := 0
|
TEST_count := 0
|
||||||
TEST_fail := 0
|
TEST_fail := 0
|
||||||
@@ -36,27 +36,38 @@ when ODIN_TEST {
|
|||||||
log :: testing.log
|
log :: testing.log
|
||||||
} else {
|
} else {
|
||||||
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
||||||
fmt.printf("[%v] ", loc)
|
|
||||||
TEST_count += 1
|
TEST_count += 1
|
||||||
if !condition {
|
if !condition {
|
||||||
TEST_fail += 1
|
TEST_fail += 1
|
||||||
fmt.println(message)
|
fmt.printf("[%v] %v\n", loc, message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.println(" PASS")
|
|
||||||
}
|
}
|
||||||
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
||||||
fmt.printf("[%v] ", loc)
|
fmt.printf("[%v] LOG:\n\t%v\n", loc, v)
|
||||||
fmt.printf("log: %v\n", v)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
I_Error :: image.Error
|
I_Error :: image.Error
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
t := testing.T{}
|
t := testing.T{}
|
||||||
png_test(&t)
|
png_test(&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_file_path :: proc(filename: string, extension := "png") -> (path: string) {
|
||||||
|
|
||||||
|
path = fmt.tprintf("%v%v/%v.%v", ODIN_ROOT, TEST_FILE_PATH_PREFIX, filename, extension)
|
||||||
|
temp := transmute([]u8)path
|
||||||
|
|
||||||
|
for r, i in path {
|
||||||
|
if r == '\\' {
|
||||||
|
temp[i] = '/'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
PNG_Test :: struct {
|
PNG_Test :: struct {
|
||||||
@@ -1461,7 +1472,7 @@ run_png_suite :: proc(t: ^testing.T, suite: []PNG_Test) -> (subtotal: int) {
|
|||||||
context = runtime.default_context()
|
context = runtime.default_context()
|
||||||
|
|
||||||
for file in suite {
|
for file in suite {
|
||||||
test_file := fmt.tprintf("%v/%v.png", TEST_SUITE_PATH, file.file)
|
test_file := test_file_path(file.file)
|
||||||
|
|
||||||
img: ^png.Image
|
img: ^png.Image
|
||||||
err: png.Error
|
err: png.Error
|
||||||
|
|||||||
@@ -14,30 +14,25 @@ when ODIN_TEST {
|
|||||||
log :: testing.log
|
log :: testing.log
|
||||||
} else {
|
} else {
|
||||||
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
||||||
fmt.printf("[%v] ", loc)
|
|
||||||
TEST_count += 1
|
TEST_count += 1
|
||||||
if !condition {
|
if !condition {
|
||||||
TEST_fail += 1
|
TEST_fail += 1
|
||||||
fmt.println(message)
|
fmt.printf("[%v] %v\n", loc, message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.println(" PASS")
|
|
||||||
}
|
}
|
||||||
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
||||||
fmt.printf("[%v] ", loc)
|
fmt.printf("[%v] LOG:\n\t%v\n", loc, v)
|
||||||
fmt.printf("log: %v\n", v)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
t := testing.T{}
|
t := testing.T{}
|
||||||
test_parse_demo(&t)
|
test_parse_demo(&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
|
||||||
test_parse_demo :: proc(t: ^testing.T) {
|
test_parse_demo :: proc(t: ^testing.T) {
|
||||||
pkg, ok := parser.parse_package_from_path("examples/demo")
|
pkg, ok := parser.parse_package_from_path("examples/demo")
|
||||||
|
|||||||
@@ -12,18 +12,15 @@ when ODIN_TEST {
|
|||||||
log :: testing.log
|
log :: testing.log
|
||||||
} else {
|
} else {
|
||||||
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
|
||||||
fmt.printf("[%v] ", loc)
|
|
||||||
TEST_count += 1
|
TEST_count += 1
|
||||||
if !condition {
|
if !condition {
|
||||||
TEST_fail += 1
|
TEST_fail += 1
|
||||||
fmt.println(message)
|
fmt.printf("[%v] %v\n", loc, message)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.println(" PASS")
|
|
||||||
}
|
}
|
||||||
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
|
||||||
fmt.printf("[%v] ", loc)
|
fmt.printf("[%v] LOG:\n\t%v\n", loc, v)
|
||||||
fmt.printf("log: %v\n", v)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,7 +31,7 @@ main :: proc() {
|
|||||||
test_index_any_small_string_found(&t)
|
test_index_any_small_string_found(&t)
|
||||||
test_index_any_larger_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
|
||||||
|
|||||||
Reference in New Issue
Block a user