hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit ad964a36eb27cc0f9d4fbf465e84d2c9f7d1cb59
parent e3c3a235545a110fe16bbd7d3667f3caf8d341d0
Author: Drew DeVault <sir@cmpwn.com>
Date:   Thu,  4 Feb 2021 13:50:23 -0500

rt: add basic test runner

Diffstat:
Art/+test/start.ha | 39+++++++++++++++++++++++++++++++++++++++
Rrt/start.ha -> rt/start-test.ha | 0
2 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/rt/+test/start.ha b/rt/+test/start.ha @@ -0,0 +1,39 @@ +const @symbol("__init_array_start") init_start: [*]*fn() void; +const @symbol("__init_array_end") init_end: [*]*fn() void; +const @symbol("__fini_array_start") fini_start: [*]*fn() void; +const @symbol("__fini_array_end") fini_end: [*]*fn() void; + +type test = struct { + name: str, + func: *fn() void, +}; + +const @symbol("__test_array_start") test_start: [*]test; +const @symbol("__test_array_end") test_end: [*]test; + +fn print(msg: str) void = write(1, msg: *const char, len(msg)); + +export fn start_ha() void = { + const ninit = (&init_end: uintptr - &init_start: uintptr): size + / size(*fn() void); + for (let i = 0z; i < ninit; i += 1z) { + init_start[i](); + }; + + const ntest = (&test_end: uintptr - &test_start: uintptr): size / size(test); + for (let i = 0z; i < ntest; i += 1z) { + print(test_start[i].name); + print("..."); + test_start[i].func(); + print("OK\n"); + }; + + const nfini = (&fini_end: uintptr - &fini_start: uintptr): size + / size(*fn() void); + for (let i = 0z; i < nfini; i += 1z) { + fini_start[i](); + }; + + exit(0); +}; + diff --git a/rt/start.ha b/rt/start-test.ha