mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 23:58:50 +00:00
Port tests\core\odin
This commit is contained in:
+8
-1
@@ -21,6 +21,7 @@ all_bsd: download_test_assets \
|
|||||||
match_test \
|
match_test \
|
||||||
math_test \
|
math_test \
|
||||||
noise_test \
|
noise_test \
|
||||||
|
odin_test \
|
||||||
os_exit_test \
|
os_exit_test \
|
||||||
reflect_test \
|
reflect_test \
|
||||||
runtime_test \
|
runtime_test \
|
||||||
@@ -86,8 +87,11 @@ net_test:
|
|||||||
os_exit_test:
|
os_exit_test:
|
||||||
$(ODIN) run os/test_core_os_exit.odin -file -out:test_core_os_exit && exit 1 || exit 0
|
$(ODIN) run os/test_core_os_exit.odin -file -out:test_core_os_exit && exit 1 || exit 0
|
||||||
|
|
||||||
|
odin_test:
|
||||||
|
$(ODIN) test odin $(COMMON) -out:test_core_odin
|
||||||
|
|
||||||
reflect_test:
|
reflect_test:
|
||||||
$(ODIN) run reflect $(COMMON) $(COLLECTION) -out:test_core_reflect
|
$(ODIN) test reflect $(COMMON) -out:test_core_reflect
|
||||||
|
|
||||||
runtime_test:
|
runtime_test:
|
||||||
$(ODIN) run runtime $(COMMON) -out:test_core_runtime
|
$(ODIN) run runtime $(COMMON) -out:test_core_runtime
|
||||||
@@ -103,3 +107,6 @@ thread_test:
|
|||||||
|
|
||||||
time_test:
|
time_test:
|
||||||
$(ODIN) run time $(COMMON) -out:test_core_time
|
$(ODIN) run time $(COMMON) -out:test_core_time
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm test_*
|
||||||
@@ -87,7 +87,7 @@ echo ---
|
|||||||
echo ---
|
echo ---
|
||||||
echo Running core:odin tests
|
echo Running core:odin tests
|
||||||
echo ---
|
echo ---
|
||||||
%PATH_TO_ODIN% run odin %COMMON% -o:size -out:test_core_odin.exe || exit /b
|
%PATH_TO_ODIN% test odin %COMMON% -o:size -out:test_core_odin.exe || exit /b
|
||||||
|
|
||||||
echo ---
|
echo ---
|
||||||
echo Running core:reflect tests
|
echo Running core:reflect tests
|
||||||
|
|||||||
@@ -1,58 +1,29 @@
|
|||||||
package test_core_odin_parser
|
package test_core_odin_parser
|
||||||
|
|
||||||
import "core:fmt"
|
|
||||||
import "core:odin/ast"
|
import "core:odin/ast"
|
||||||
import "core:odin/parser"
|
import "core:odin/parser"
|
||||||
import "core:os"
|
import "base:runtime"
|
||||||
import "core:testing"
|
import "core:testing"
|
||||||
|
|
||||||
|
|
||||||
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) {
|
|
||||||
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] ", loc)
|
|
||||||
fmt.printf("log: %v\n", v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
main :: proc() {
|
|
||||||
t := testing.T{}
|
|
||||||
test_parse_demo(&t)
|
|
||||||
test_parse_bitfield(&t)
|
|
||||||
|
|
||||||
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
|
|
||||||
if TEST_fail > 0 {
|
|
||||||
os.exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@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")
|
context.allocator = context.temp_allocator
|
||||||
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
|
|
||||||
expect(t, ok == true, "parser.parse_package_from_path failed")
|
pkg, ok := parser.parse_package_from_path(ODIN_ROOT + "examples/demo")
|
||||||
|
|
||||||
|
testing.expect(t, ok, "parser.parse_package_from_path failed")
|
||||||
|
|
||||||
for key, value in pkg.files {
|
for key, value in pkg.files {
|
||||||
expect(t, value.syntax_error_count == 0, fmt.tprintf("%v should contain zero errors", key))
|
testing.expectf(t, value.syntax_error_count == 0, "%v should contain zero errors", key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@test
|
@test
|
||||||
test_parse_bitfield :: proc(t: ^testing.T) {
|
test_parse_bitfield :: proc(t: ^testing.T) {
|
||||||
|
context.allocator = context.temp_allocator
|
||||||
|
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||||
|
|
||||||
file := ast.File{
|
file := ast.File{
|
||||||
fullpath = "test.odin",
|
fullpath = "test.odin",
|
||||||
src = `
|
src = `
|
||||||
@@ -78,5 +49,5 @@ Foo :: bit_field uint {
|
|||||||
|
|
||||||
p := parser.default_parser()
|
p := parser.default_parser()
|
||||||
ok := parser.parse_file(&p, &file)
|
ok := parser.parse_file(&p, &file)
|
||||||
expect(t, ok == true, "bad parse")
|
testing.expect(t, ok, "bad parse")
|
||||||
}
|
}
|
||||||
Binary file not shown.
Reference in New Issue
Block a user