Merge pull request #1144 from Kelimion/test_runner

Custom test runner.
This commit is contained in:
Jeroen van Rijn
2021-09-08 21:21:57 +02:00
committed by GitHub
5 changed files with 88 additions and 26 deletions
+3 -3
View File
@@ -7,10 +7,10 @@ download_test_assets:
$(PYTHON) download_assets.py $(PYTHON) download_assets.py
image_test: image_test:
$(ODIN) test image/test_core_image.odin $(ODIN) run image/test_core_image.odin
compress_test: compress_test:
$(ODIN) test compress/test_core_compress.odin $(ODIN) run compress/test_core_compress.odin
strings_test: strings_test:
$(ODIN) test strings/test_core_strings.odin $(ODIN) run strings/test_core_strings.odin
+3 -3
View File
@@ -5,14 +5,14 @@ python3 download_assets.py
echo --- echo ---
echo Running core:image tests echo Running core:image tests
echo --- echo ---
%PATH_TO_ODIN% test image %COMMON% %PATH_TO_ODIN% run image %COMMON%
echo --- echo ---
echo Running core:compress tests echo Running core:compress tests
echo --- echo ---
%PATH_TO_ODIN% test compress %COMMON% %PATH_TO_ODIN% run compress %COMMON%
echo --- echo ---
echo Running core:strings tests echo Running core:strings tests
echo --- echo ---
%PATH_TO_ODIN% test strings %COMMON% %PATH_TO_ODIN% run strings %COMMON%
+21 -6
View File
@@ -22,14 +22,27 @@ import "core:mem"
import "core:os" import "core:os"
import "core:io" import "core:io"
TEST_count := 0
TEST_fail := 0
when ODIN_TEST { when ODIN_TEST {
expect :: testing.expect expect :: testing.expect
log :: testing.log
} else { } else {
expect :: proc(t: ^testing.T, condition: bool, message: string) { expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
if !condition { fmt.printf("[%v] ", loc)
fmt.println(message) 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() { main :: proc() {
@@ -37,6 +50,8 @@ main :: proc() {
t := testing.T{w=w} t := testing.T{w=w}
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)
} }
@test @test
+22 -9
View File
@@ -25,26 +25,39 @@ import "core:os"
import "core:time" import "core:time"
import "core:runtime" import "core:runtime"
import "core:io"
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_SUITE_PATH :: "assets/PNG"
TEST_count := 0
TEST_fail := 0
when ODIN_TEST { when ODIN_TEST {
expect :: testing.expect expect :: testing.expect
log :: testing.log
} else { } else {
expect :: proc(t: ^testing.T, condition: bool, message: string) { expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
if !condition { fmt.printf("[%v] ", loc)
fmt.println(message) 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)
}
} }
I_Error :: image.Error I_Error :: image.Error
main :: proc() { main :: proc() {
w, _ := io.to_writer(os.stream_from_handle(os.stdout)) t := testing.T{}
t := testing.T{w=w}
png_test(&t) png_test(&t)
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
} }
PNG_Test :: struct { PNG_Test :: struct {
+39 -5
View File
@@ -2,28 +2,62 @@ package test_core_image
import "core:strings" import "core:strings"
import "core:testing" 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
test_index_any_small_string_not_found :: proc(t: ^testing.T) { test_index_any_small_string_not_found :: proc(t: ^testing.T) {
index := strings.index_any(".", "/:\"") index := strings.index_any(".", "/:\"")
testing.log(t, index) log(t, index)
testing.expect(t, index == -1, "index_any should be negative") expect(t, index == -1, "index_any should be negative")
} }
@test @test
test_index_any_larger_string_not_found :: proc(t: ^testing.T) { test_index_any_larger_string_not_found :: proc(t: ^testing.T) {
index := strings.index_any("aaaaaaaa.aaaaaaaa", "/:\"") 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
test_index_any_small_string_found :: proc(t: ^testing.T) { test_index_any_small_string_found :: proc(t: ^testing.T) {
index := strings.index_any(".", "/:.\"") 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
test_index_any_larger_string_found :: proc(t: ^testing.T) { test_index_any_larger_string_found :: proc(t: ^testing.T) {
index := strings.index_any("aaaaaaaa:aaaaaaaa", "/:\"") 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")
} }