diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2021-12-05 02:40:13 +0100 |
|---|---|---|
| committer | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2021-12-05 02:53:09 +0100 |
| commit | d7200f61441b6acfc4f0b47e900095f08490da58 (patch) | |
| tree | 29e8d89dfac713d069125ae3864fc930b3d4bc10 /tests/core/encoding | |
| parent | d65d6edb0e1887871c4de6a4e8a1630927153eae (diff) | |
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.
Diffstat (limited to 'tests/core/encoding')
| -rw-r--r-- | tests/core/encoding/json/test_core_json.odin | 9 | ||||
| -rw-r--r-- | tests/core/encoding/xml/test_core_xml.odin | 43 |
2 files changed, 23 insertions, 29 deletions
diff --git a/tests/core/encoding/json/test_core_json.odin b/tests/core/encoding/json/test_core_json.odin index 4f415c008..6f2e8c35a 100644 --- a/tests/core/encoding/json/test_core_json.odin +++ b/tests/core/encoding/json/test_core_json.odin @@ -12,18 +12,15 @@ when ODIN_TEST { 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) + fmt.printf("[%v] %v\n", loc, 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) + fmt.printf("[%v] LOG:\n\t%v\n", loc, v) } } @@ -33,7 +30,7 @@ main :: proc() { parse_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 diff --git a/tests/core/encoding/xml/test_core_xml.odin b/tests/core/encoding/xml/test_core_xml.odin index 5cb59e001..f9f7a2992 100644 --- a/tests/core/encoding/xml/test_core_xml.odin +++ b/tests/core/encoding/xml/test_core_xml.odin @@ -173,23 +173,20 @@ TESTS :: []TEST{ } 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) + } } test_file_path :: proc(filename: string) -> (path: string) { @@ -229,7 +226,7 @@ doc_to_string :: proc(doc: ^xml.Document) -> (result: string) { written += wprintf(writer, "[DOCTYPE] %v\n", doc.doctype.ident) if len(doc.doctype.rest) > 0 { - wprintf(writer, "\t%v\n", doc.doctype.rest) + wprintf(writer, "\t%v\n", doc.doctype.rest) } } @@ -238,9 +235,9 @@ doc_to_string :: proc(doc: ^xml.Document) -> (result: string) { } if doc.root != nil { - wprintln(writer, " --- ") - print_element(writer, doc.root) - wprintln(writer, " --- ") + wprintln(writer, " --- ") + print_element(writer, doc.root) + wprintln(writer, " --- ") } return written, .None @@ -293,7 +290,7 @@ run_tests :: proc(t: ^testing.T) { for test in TESTS { 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) defer xml.destroy(doc) @@ -323,7 +320,7 @@ run_tests :: proc(t: ^testing.T) { } main :: proc() { - t := testing.T{} + t := testing.T{} track: mem.Tracking_Allocator mem.tracking_allocator_init(&track, context.allocator) @@ -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) }
\ No newline at end of file |