.
This commit is contained in:
parent
95d74c2ef4
commit
a66e58193f
25 changed files with 2600 additions and 93 deletions
15
tools/nob.c
15
tools/nob.c
|
|
@ -1,4 +1,5 @@
|
|||
#define COLLA_NO_CONDITION_VARIABLE 1
|
||||
#define COLLA_NO_NET 1
|
||||
|
||||
#include "../build.c"
|
||||
#include <windows.h>
|
||||
|
|
@ -296,7 +297,7 @@ int main(int argc, char **argv) {
|
|||
|
||||
options_t opt = parse_options(&arena, argc, argv);
|
||||
|
||||
if (!os_file_exists(strv("build/"))) {
|
||||
if (!os_dir_exists(strv("build/"))) {
|
||||
info("creating build folder");
|
||||
_mkdir("build");
|
||||
}
|
||||
|
|
@ -307,7 +308,14 @@ int main(int argc, char **argv) {
|
|||
arena_t scratch = arena;
|
||||
str_t vcvars_path = find_vcvars_path(&scratch);
|
||||
|
||||
if (!os_run_cmd(scratch, os_make_cmd(strv(vcvars_path), strv("&&"), strv("set"), strv(">"), strv("build\\cache.ini")), NULL)) {
|
||||
os_cmd_t *cmd = NULL;
|
||||
darr_push(&scratch, cmd, strv(vcvars_path));
|
||||
darr_push(&scratch, cmd, strv("&&"));
|
||||
darr_push(&scratch, cmd, strv("set"));
|
||||
darr_push(&scratch, cmd, strv(">"));
|
||||
darr_push(&scratch, cmd, strv("build\\cache.ini"));
|
||||
|
||||
if (!os_run_cmd(scratch, cmd, NULL)) {
|
||||
fatal("failed to run vcvars64.bat");
|
||||
os_abort(1);
|
||||
}
|
||||
|
|
@ -366,6 +374,7 @@ int main(int argc, char **argv) {
|
|||
|
||||
if (opt.debug) {
|
||||
darr_push(&scratch, cmd, strv("/Zi"));
|
||||
darr_push(&scratch, cmd, strv("/D_DEBUG"));
|
||||
}
|
||||
|
||||
for_each (def, opt.defines) {
|
||||
|
|
@ -415,4 +424,4 @@ int main(int argc, char **argv) {
|
|||
arena_cleanup(&arena);
|
||||
|
||||
os_cleanup();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
80
tools/unit_tests.c
Normal file
80
tools/unit_tests.c
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
#pragma section(".CRT$XCU", read)
|
||||
|
||||
#include "../build.c"
|
||||
#include "../tests/runner.h"
|
||||
|
||||
#include "../tests/arena_tests.c"
|
||||
#include "../tests/core_tests.c"
|
||||
#include "../tests/net_tests.c"
|
||||
#include "../tests/os_tests.c"
|
||||
// #include "../tests/parsers_tests.c"
|
||||
// #include "../tests/pretty_print_tests.c"
|
||||
#include "../tests/str_tests.c"
|
||||
|
||||
unit_test_t *test_head = NULL;
|
||||
unit_test_t *test_tail = NULL;
|
||||
const char *last_fail_reason = NULL;
|
||||
bool last_failed = false;
|
||||
|
||||
void ut_register(const char *file, const char *name, void (*fn)(void)) {
|
||||
strview_t fname;
|
||||
os_file_split_path(strv(file), NULL, &fname, NULL);
|
||||
|
||||
fname = strv_remove_suffix(fname, arrlen("_tests") - 1);
|
||||
|
||||
unit_test_t *test = calloc(1, sizeof(unit_test_t));
|
||||
test->name = strv(name);
|
||||
test->fn = fn;
|
||||
test->fname = fname;
|
||||
|
||||
olist_push(test_head, test_tail, test);
|
||||
}
|
||||
|
||||
int main() {
|
||||
colla_init(COLLA_ALL);
|
||||
arena_t arena = arena_make(ARENA_VIRTUAL, GB(1));
|
||||
|
||||
strview_t last_file = STRV_EMPTY;
|
||||
int success = 0;
|
||||
int failed = 0;
|
||||
int total = 0;
|
||||
|
||||
unit_test_t *test = test_head;
|
||||
while (test) {
|
||||
if (!strv_equals(test->fname, last_file)) {
|
||||
last_file = test->fname;
|
||||
pretty_print(arena, "<blue>> %v</>\n", test->fname);
|
||||
}
|
||||
|
||||
test->fn();
|
||||
|
||||
total++;
|
||||
|
||||
if (last_failed) {
|
||||
pretty_print(arena, "%4s<red>[X]</> %v: %s\n", "", test->name, last_fail_reason);
|
||||
}
|
||||
else {
|
||||
pretty_print(arena, "%4s<green>[V]</> %v\n", "", test->name);
|
||||
success++;
|
||||
}
|
||||
|
||||
last_failed = false;
|
||||
|
||||
test = test->next;
|
||||
}
|
||||
|
||||
print("\n");
|
||||
|
||||
strview_t colors[] = {
|
||||
cstrv("red"),
|
||||
cstrv("light_red"),
|
||||
cstrv("yellow"),
|
||||
cstrv("light_yellow"),
|
||||
cstrv("light_green"),
|
||||
cstrv("green"),
|
||||
};
|
||||
|
||||
usize col = success * (arrlen(colors) - 1) / total;
|
||||
|
||||
pretty_print(arena, "<%v>%d</>/<blue>%d</> tests passed\n", colors[col], success, total);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue