port os functions, add testing module

This commit is contained in:
Krzosa Karol
2025-02-02 17:34:06 +01:00
parent 85a6c218b2
commit 9f33ea0914
27 changed files with 1120 additions and 889 deletions

View File

@@ -0,0 +1,6 @@
fn void run_tests(void) {
test_s8();
test_hash_table();
test_intern_table();
os_test();
}

View File

@@ -0,0 +1,32 @@
void mt_testing(ma_arena_t *arena) {
mt_files_t files = mt_lex_files(arena, mt_main_path(arena), mt_get_include_paths(arena));
sb8_t *tests = sb8_serial_begin(arena);
for (mt_file_t *it = files.first; it; it = it->next) {
parser_t *par = parser_make(arena, it->tokens.data);
for (;par->at->kind != lex_kind_eof;) {
b32 matched = false;
if (par->at->inside_macro == false && parser_matchi(par, s8_lit("fn_test"))) {
parser_expecti(par, s8_lit("void"));
lex_t *ident = parser_match(par, lex_kind_ident);
sb8_append(tests, ident->string);
matched = true;
}
if (!matched) {
parser_next(par);
}
}
}
sb8_t *c = sb8_serial_begin(arena);
sb8_printf(c, "fn void run_tests(void) {\n");
for (sb8_node_t *it = tests->first; it; it = it->next) {
sb8_printf(c, " %S();\n", it->string);
}
sb8_printf(c, "}\n");
s8_t result = sb8_serial_end(arena, c);
os_write_file(mt_cpath(arena), result);
}

View File

@@ -0,0 +1,12 @@
#include "core/core.h"
#include "os/os.h"
#include "core/core.c"
#include "os/os.c"
#include "testing.gen.c"
int main() {
core_init();
run_tests();
return 0;
}