port os functions, add testing module
This commit is contained in:
6
src/testing/testing.gen.c
Normal file
6
src/testing/testing.gen.c
Normal file
@@ -0,0 +1,6 @@
|
||||
fn void run_tests(void) {
|
||||
test_s8();
|
||||
test_hash_table();
|
||||
test_intern_table();
|
||||
os_test();
|
||||
}
|
||||
32
src/testing/testing.meta.c
Normal file
32
src/testing/testing.meta.c
Normal 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);
|
||||
}
|
||||
12
src/testing/testing_main.c
Normal file
12
src/testing/testing_main.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user