aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2021-09-08 21:21:57 +0200
committerGitHub <noreply@github.com>2021-09-08 21:21:57 +0200
commiteb76b00a5e05b914f020dd874bc13b2af51a0920 (patch)
tree82accdeaa3950de72762b744bd79252d15a860f0
parent027d69678aa9a2b2e95da8f94ea3d7600a478604 (diff)
parent66ead6cf09207e8dce71c735293f6910e913abd8 (diff)
Merge pull request #1144 from Kelimion/test_runner
Custom test runner.
-rw-r--r--tests/core/Makefile6
-rw-r--r--tests/core/build.bat6
-rw-r--r--tests/core/compress/test_core_compress.odin27
-rw-r--r--tests/core/image/test_core_image.odin31
-rw-r--r--tests/core/strings/test_core_strings.odin44
5 files changed, 88 insertions, 26 deletions
diff --git a/tests/core/Makefile b/tests/core/Makefile
index 8454ea271..65af21204 100644
--- a/tests/core/Makefile
+++ b/tests/core/Makefile
@@ -7,10 +7,10 @@ download_test_assets:
$(PYTHON) download_assets.py
image_test:
- $(ODIN) test image/test_core_image.odin
+ $(ODIN) run image/test_core_image.odin
compress_test:
- $(ODIN) test compress/test_core_compress.odin
+ $(ODIN) run compress/test_core_compress.odin
strings_test:
- $(ODIN) test strings/test_core_strings.odin
+ $(ODIN) run strings/test_core_strings.odin
diff --git a/tests/core/build.bat b/tests/core/build.bat
index 849384bee..d298bfc3e 100644
--- a/tests/core/build.bat
+++ b/tests/core/build.bat
@@ -5,14 +5,14 @@ python3 download_assets.py
echo ---
echo Running core:image tests
echo ---
-%PATH_TO_ODIN% test image %COMMON%
+%PATH_TO_ODIN% run image %COMMON%
echo ---
echo Running core:compress tests
echo ---
-%PATH_TO_ODIN% test compress %COMMON%
+%PATH_TO_ODIN% run compress %COMMON%
echo ---
echo Running core:strings tests
echo ---
-%PATH_TO_ODIN% test strings %COMMON%
+%PATH_TO_ODIN% run strings %COMMON%
diff --git a/tests/core/compress/test_core_compress.odin b/tests/core/compress/test_core_compress.odin
index ae0712c7a..e2b0b8d9f 100644
--- a/tests/core/compress/test_core_compress.odin
+++ b/tests/core/compress/test_core_compress.odin
@@ -22,14 +22,27 @@ import "core:mem"
import "core:os"
import "core:io"
+TEST_count := 0
+TEST_fail := 0
+
when ODIN_TEST {
- expect :: testing.expect
+ expect :: testing.expect
+ log :: testing.log
} else {
- expect :: proc(t: ^testing.T, condition: bool, message: string) {
- if !condition {
- fmt.println(message)
- }
- }
+ 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() {
@@ -37,6 +50,8 @@ main :: proc() {
t := testing.T{w=w}
zlib_test(&t)
gzip_test(&t)
+
+ fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
}
@test
diff --git a/tests/core/image/test_core_image.odin b/tests/core/image/test_core_image.odin
index 381b89eae..339faff58 100644
--- a/tests/core/image/test_core_image.odin
+++ b/tests/core/image/test_core_image.odin
@@ -25,26 +25,39 @@ import "core:os"
import "core:time"
import "core:runtime"
-import "core:io"
WRITE_PPM_ON_FAIL :: #config(WRITE_PPM_ON_FAIL, false)
TEST_SUITE_PATH :: "assets/PNG"
+TEST_count := 0
+TEST_fail := 0
+
when ODIN_TEST {
- expect :: testing.expect
+ expect :: testing.expect
+ log :: testing.log
} else {
- expect :: proc(t: ^testing.T, condition: bool, message: string) {
- if !condition {
- fmt.println(message)
- }
- }
+ 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)
+ }
}
I_Error :: image.Error
main :: proc() {
- w, _ := io.to_writer(os.stream_from_handle(os.stdout))
- t := testing.T{w=w}
+ t := testing.T{}
png_test(&t)
+
+ fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
}
PNG_Test :: struct {
diff --git a/tests/core/strings/test_core_strings.odin b/tests/core/strings/test_core_strings.odin
index c9da5a688..fc1518349 100644
--- a/tests/core/strings/test_core_strings.odin
+++ b/tests/core/strings/test_core_strings.odin
@@ -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")
}